Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

DB qeury taking too long to execute

rohit_trivedi
Participant
0 Kudos

Hi,

This DB query is taking too long on the customer system!

DB stats checked with DB20. Everything seems okay!

Any Pointer which would lead me to solution are most welcome.

Query is:

"

SELECT DISTINCT * FROM /sapsll/cuhdsta

AS a

INNER JOIN /sapsll/cuhd

AS b

ON amandt EQ bmandt

AND aguid_pobj EQ bguid_cuhd

INTO CORRESPONDING FIELDS OF TABLE lt_cuhd

WHERE a~prost IN lr_prost

AND a~sticm IN lr_sticm

AND a~pobjt EQ gc_pobjr-customs_doc_head.

"

The Table /sapsll/cuhdsta contains about 7 million entries.

Thanks,

Rohit.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

Welcome to SDN!!!

I think if you fix INDEXES for DB Table it will solve your problem.

Thanks.

If this helps award points and close the thread.

6 REPLIES 6

Former Member
0 Kudos

Hi,

Welcome to SDN!!!

I think if you fix INDEXES for DB Table it will solve your problem.

Thanks.

If this helps award points and close the thread.

kanthimathikris
Employee
Employee
0 Kudos

Try using for all entries as follows

select mandt guid_cuhd from /sapsll/cuhd

into table i_tab2.

SELECT DISTINCT *

into table i_tab1

FROM /sapsll/cuhdsta

for all entries in i_tab2

where a~prost IN lr_prost

and a~sticm IN lr_sticm

and a~pobjt EQ gc_pobjr-customs_doc_head

and a~guid_pobj = i_tab2-guid_cuhd

former_member186741
Active Contributor
0 Kudos

Distinct can cause problems. Index use sometimes does not occur if it is coded. Try it without and remove adjacent dupliactes from the result table in abap. But 7mill is pretty big so I think you can expect it to be slow however you code it.

Former Member
0 Kudos

Hi,

Pass as many key fields as possible in the where condition so that the performance will be faster,

Regds,

former_member186741
Active Contributor
0 Kudos

naming the specific fields you want rather than * may improve things too if you are retrieving a lot of data.

Former Member
0 Kudos

Hi Rohit,

First Check Secondary index if it's not available then create it. It will reduce the time of execution.

Regards,

Digesh Panchal