‎2009 May 27 7:25 PM
Dear All,
Can you please let me know, if I can use 'IN' instead of 'OR' in select statement. Also Let me know which one will have better performance.
here is code.
DATA: BEGIN OF ITAB OCCURS 0,
EBELN TYPE EKPO-EBELN,
EBELP TYPE EKPO-EBELP,
AEDAT TYPE EKPO-AEDAT,
MATNR TYPE EKPO-MATNR,
MENGE TYPE EKPO-MENGE,
END OF ITAB.
select EBELN EBELP AEDAT MATNR MENGE INTO TABLE ITAB
FROM EKPO
WHERE ( EBELN = '414001' OR
EBELN = '41200' ) .
or
select EBELN EBELP AEDAT MATNR MENGE INTO TABLE ITAB
FROM EKPO
WHERE EBELN IN ('414001','41200') .
will the two codes have same output.which code has better performance ?
Thank you.
Madhu
Moderator message - Moved to the correct forum
Edited by: Rob Burbank on May 27, 2009 2:30 PM
‎2009 May 27 7:44 PM
Hi,
Check it in ST05
this will give you better performance
select EBELN EBELP AEDAT MATNR MENGE INTO TABLE ITAB
FROM EKPO
WHERE EBELN IN ('414001','41200') .
Regards
Krishna
‎2009 May 27 7:44 PM
Hi,
Check it in ST05
this will give you better performance
select EBELN EBELP AEDAT MATNR MENGE INTO TABLE ITAB
FROM EKPO
WHERE EBELN IN ('414001','41200') .
Regards
Krishna
‎2009 May 27 8:02 PM
Krishna - you didn't follow your own advice, did you
Rob
‎2009 May 28 12:32 AM
Hi Rob,
he maybe did by running the program once and traicing it.
If the OR was the first and the IN the second... and he compared
only the execution times... the IN is faster but not because of the IN
but because the OR statement is probably filling the db cache
and the IN statement is using it. If he would have run it multible times
and if he would have compared the execution planes he would have
seen that there is no difference between these two.
Kind regards,
Hermann
‎2009 May 28 5:42 AM
I agree with u. I have experienced it in the same way the if we just check it once the one when check 2nd is faster because it caches the data.
Nafran
‎2009 May 28 7:30 AM
there is nearly no difference between the two variants, but still the one with the IN is recommended.
Differences are database dependent, and it can happen that the optimizers will give different estimates
for the two ... which makes only a difference if the clauses can together with others.
no performance issue, just a small recommendation.
One definite advantage, the IN is easier to read, if the number of choices becomes large.
‎2009 May 28 4:51 PM
Dear All,
Thank you for your replies.
I used SE30 to evaluate the performance of both statements. I agree with the point that first executed program takes more time. second executed program is using the cache and taking less time.
I am using 'IN' is my program as it is easy to read.
I am closing this thread and allotting points to all of you.
BUT, Honestly This is still not 100% answered.
Thank you.
Madhu.
‎2009 May 29 5:54 AM
IN will take less time as compared to OR u have used.
So better to go with IN.