‎2008 Mar 17 7:54 PM
Hi Guys,
I have a query on table VBAP which fetches data based on date-time stamp and few other fields. Date-tme fields are always filled. If no plant is additionally entered, query runs for about 20 minutes. However, when user enters a plant, query runs for ever (Last run took about 16 hours). I tried tweaking the "where clause" a bit with no sign of improved performance. I really don't understand why should plant mess with the index.
Your replies are appreciated.
Thanks
Yogi
SELECT bvbeln bposnr buepos bmatnr bwerks bmeins b~objnr
berdat cwebaz cplifz efabkl e~pipatg
INTO TABLE pt_order
FROM vbak AS a
INNER JOIN vbap AS b
ON avbeln = bvbeln
INNER JOIN marc AS c
ON bmatnr = cmatnr AND
bwerks = cwerks
INNER JOIN vbuk AS d
ON avbeln = dvbeln
INNER JOIN tvst AS e
ON bvstel = evstel
WHERE a~vkorg IN s_vkorg
AND a~auart IN s_auart
AND ( ( ( berdat LT s_erdat-high ) OR ( berdat EQ s_erdat-high
AND b~erzet LE p_totim ) )
AND ( ( berdat GT s_erdat-low ) OR ( berdat EQ s_erdat-low
AND b~erzet GE p_frtim ) ) )
AND b~werks IN s_werks
AND b~abgru IN s_abgru
AND c~mtvfp IN s_mtvfp
AND d~cmgst IN s_cmgst.
‎2008 Mar 18 9:47 AM
Hi,
your query seems to have been fetching data from the tables:
vbap
marc
tvst
so, I think you can modify your query with the above 3 tables as under:
SELECT bvbeln bposnr buepos bmatnr bwerks bmeins b~objnr
berdat cwebaz cplifz efabkl e~pipatg
INTO TABLE pt_order
FROM vbap AS b
INNER JOIN marc AS c
ON bmatnr = cmatnr
AND
bwerks = cwerks
INNER JOIN tvst AS e
ON bvstel = evstel
WHERE
AND ( ( ( berdat LT s_erdat-high ) OR ( berdat EQ s_erdat-high
AND b~erzet LE p_totim ) )
AND ( ( berdat GT s_erdat-low ) OR ( berdat EQ s_erdat-low
AND b~erzet GE p_frtim ) ) )
AND b~werks IN s_werks
AND b~abgru IN s_abgru
AND c~mtvfp IN s_mtvfp.
and test the changes how it is working for you.
Please make changes as the per above suggestions and let me know how it worked for you.
Thanks,
Vishnu.
‎2008 Mar 18 9:47 AM
Hi,
your query seems to have been fetching data from the tables:
vbap
marc
tvst
so, I think you can modify your query with the above 3 tables as under:
SELECT bvbeln bposnr buepos bmatnr bwerks bmeins b~objnr
berdat cwebaz cplifz efabkl e~pipatg
INTO TABLE pt_order
FROM vbap AS b
INNER JOIN marc AS c
ON bmatnr = cmatnr
AND
bwerks = cwerks
INNER JOIN tvst AS e
ON bvstel = evstel
WHERE
AND ( ( ( berdat LT s_erdat-high ) OR ( berdat EQ s_erdat-high
AND b~erzet LE p_totim ) )
AND ( ( berdat GT s_erdat-low ) OR ( berdat EQ s_erdat-low
AND b~erzet GE p_frtim ) ) )
AND b~werks IN s_werks
AND b~abgru IN s_abgru
AND c~mtvfp IN s_mtvfp.
and test the changes how it is working for you.
Please make changes as the per above suggestions and let me know how it worked for you.
Thanks,
Vishnu.
‎2008 Mar 18 11:58 AM
First thing is avoid joining more than 3 tables. So split your query, use select for all entries construct (with an initial check on the driver table). Select the data roughly in the same order as they appear in the table.
‎2008 Mar 18 12:29 PM
Hi,
dont use so many inner joins in the query...may be you can split the query aand try...
Regards,
Ramesh.
‎2008 Mar 18 3:12 PM
Difficult to say without more information, so run a SQL trace through ST05 to pinpoint where the issue is. At a guess it's table-scanning somewhere.
What database platform are you on? Do you have any custom indexes on VBAP?
‎2008 Mar 21 6:17 PM
ST05 trace revealed that MARC table was executed in interation when user entered plant on the selection-screen. I split the query such that data from transaction tables and master tables are fetched separately.