03-24-2020 9:22 AM
Hello,
I made a selection query from table AFRU but it is taking too long time to execute.
What can I do to optimize it?
This is the query:
SELECT a~werks a~aufnr a~budat a~vornr a~grund a~zzcurrency a~stokz SUM( a~xmnga ) AS xmnga SUM( a~zzscrapvalue) AS zzscrapvalue SUM( a~lmnga ) AS lmnga b~lead_aufnr b~plnbez c~matnr d~arbpl e~steus e~ltxa1
FROM afru AS a
INNER JOIN afko AS b ON b~aufnr = a~aufnr
INNER JOIN afpo AS c ON c~aufnr = b~aufnr
INNER JOIN s022 AS d ON d~aufnr = b~aufnr AND d~werks = p_werks AND d~matnr = b~plnbez AND d~posnr = c~posnr
INNER JOIN afvc AS e ON e~aufpl = b~aufpl AND e~plnfl = d~plnfl AND e~vornr = d~vornr
INTO CORRESPONDING FIELDS OF TABLE gt_dummy
WHERE a~werks = p_werks
AND a~ersda = p_ersda
GROUP BY a~werks a~aufnr a~budat a~vornr a~grund a~zzcurrency a~stokz b~lead_aufnr b~plnbez c~matnr d~arbpl e~steus e~ltxa1.
I can't put another selection parameter because the query must work with only plant and confirmation entry date.
I did a test with a confirmation date that had 15.000+ records in table AFRU and the query took 20+ min to execute..
Thank you for your help!
Alex
03-24-2020 9:58 AM
Before you start with the following recommendations 1. and 2., I would recommend to check, which select or join takes the most time. So you would at first only select from AFRU, than add to your join AFKO and so on and comparing the time that has passed for each select.
I am assuming, that AFRU and S022 are the ones taking the most time, depending on whether Index AFRU~E1 is not activated or there is not a similar one, otherwise it might be 'just' S022 that has a missing index for your join statement. You can also do a performance trace for your SQL statement with ST05 and ST01 and see whether the select for the different tables is either done sequantially or by index.
With ST04 you can create SQL statements to test your selects in productive system without having to transport different versions of your code.
Here is what you most likely have to do, to fix your performance issue:
If activating or creating is not an option, the only thing left for you is, to look for other ways to select and join the tables, that will utilize primary or secondary table indexes. Otherwise, you are out of luck.
03-24-2020 9:58 AM
Before you start with the following recommendations 1. and 2., I would recommend to check, which select or join takes the most time. So you would at first only select from AFRU, than add to your join AFKO and so on and comparing the time that has passed for each select.
I am assuming, that AFRU and S022 are the ones taking the most time, depending on whether Index AFRU~E1 is not activated or there is not a similar one, otherwise it might be 'just' S022 that has a missing index for your join statement. You can also do a performance trace for your SQL statement with ST05 and ST01 and see whether the select for the different tables is either done sequantially or by index.
With ST04 you can create SQL statements to test your selects in productive system without having to transport different versions of your code.
Here is what you most likely have to do, to fix your performance issue:
If activating or creating is not an option, the only thing left for you is, to look for other ways to select and join the tables, that will utilize primary or secondary table indexes. Otherwise, you are out of luck.
07-17-2020 8:49 AM
Thank you for help! I made a index for table AFRU on WERKS and ERSDA and it reduced the time to 20 seconds.
03-24-2020 2:02 PM
Please provide the "execution plan" (via performance trace ST05 for instance) so that we can help you interpret it.
05-13-2020 3:46 PM
sorin_t, please follow up on your open question.