Application Development and Automation 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: 
Read only

performance optimization in SQL

Former Member
0 Likes
821

I have a SQL that retrieves data from BSAK with 13 million records and it is taking very long time. I have the following SQL and I don't see how else I can optimize it! If anyone has any suggestions, please let me know.

select bbukrs bzuonr bgjahr bmonat bbelnr bbuzei

blifnr bblart bbldat bxblnr b~budat

bshkzg bwrbtr bsknto baugbl

b~augdt

into corresponding fields of table i_bsak

from bsak as b

where b~bukrs in s_bukrs

and b~lifnr in s_lifnr

and b~umsks in s_umsks

and b~umskz in s_umskz

and b~augdt in s_augdt

and b~augbl in s_augbl

and b~zuonr in s_zuonr

and b~gjahr in s_gjahr

and b~belnr in s_belnr

and b~buzei in s_buzei

and b~blart in s_blart

and b~monat in s_monat

and b~bldat in s_bldat

and b~xblnr in s_xblnr

and b~cpudt in s_cpudt

and b~budat in s_budat

and b~wrbtr in s_wrbtr

and b~sknto in s_sknto.

Thanks.

Mithun

9 REPLIES 9
Read only

JozsefSzikszai
Active Contributor
0 Likes
792

hi Mithun,

some suggestions:

"into corresponding fields of table i_bsak"

==> replace with INTO TABLE i_BSAK (and make sure that it has exactly the same structure like the fields you select)

than you have to consider if you really need all of these fields in the WHERE:

and b~gjahr in s_gjahr

...

and b~monat in s_monat

...

and b~budat in s_budat

==> either gajhr and monat OR budat only (gjahr and monat will come from budat, so there is no need to check all three)

and b~buzei in s_buzei

==> this one you definetly don't need

and so on...

hope this helps

ec

Read only

Former Member
0 Likes
792

Hello,

You are only using one table BSAK and there is no join involved. So you may use select <field1> <field2> ... into table i_bsak where ....

Also, do not use 'corresponding' and instead define internal table i_bsak with the fields you need.

Thanks,

Venu

Read only

Former Member
0 Likes
792

What would really help is look for suitable secondary indices and see if you can use these fields in the where condition with value = instad of value in. Simgle value so to speak.

Good luck,

Bert

Read only

Former Member
0 Likes
792

Just make sure there are entries in both s_bukrs and s_lifnr.

Rob

Read only

ThomasZloch
Active Contributor
0 Likes
792

Hi,

you'd better make sure that S_BUKRS and S_LIFNR have very narrow selection criteria. If possible, S_BUKRS should have only ONE company code.

Otherwise I see no way to quickly select from 13 million BSAK records.

Greetings

Thomas

Edit: did not see Rob's post before I posted mine

Read only

Former Member
0 Likes
792

hi

good

i would suggest you to check with st22, and se30 to more about the points that needs to change in your select statement.

or

check these points.

1-Check wheather you r accessing data using key fields or not

2-Check whether you can use any alternative table other than the table you have used .

thanks

mrutyun^

Read only

0 Likes
792

Hi Mrutyunjaya Tripathy,

I'm curious why you are writing "good" in the second line of your posts.

Would you tell me? No offense intended.

Greetings

Thomas

Read only

0 Likes
792

probably it is some traditional greeting, however I am curious as well

Read only

Former Member
0 Likes
792

Hi,

1. The select query can be modified little by changing INTO CORRESPONDING FIELDS with INTO TABLE as there are huge no.of records to reduce lil bit of time.

2. Can check that there are actually entries in the Select-Options for Primary or Secondary index key fields.

3. Can use less no.of Select-Options in the selection screen if possible or else make sure tht Select-Options have values(use small range or if possible single values) before executing the report.

4. Check the performance with ST05(SQL Trace) or SE30.

Regards,

Srilatha