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

SELECT with WHERE/JOIN: performance

gabriele_mazza
Explorer
1,361

Hi experts, I have a question on JOIN condition. Sometimes i need to insert the same fields in WHERE condition and in JOIN condition.

For example:

  SELECT        * 
         FROM kblk join kblp
              ON kblk~belnr eq kblp~belnr
         WHERE  kblk~belnr  eq lv_belnr
           AND  kblp~blpos  eq lv_blpos. 

My question is about performances of this select. What is processed before? Where or join?

If WHERE condition is processed before

JOIN
  SELECT        * 
         FROM  kblk join kblp
              ON kblk~belnr eq kblp~belnr
         WHERE  kblk~belnr  eq lv_belnr
           AND  kblp~belnr  eq lv_belnr
    AND  kblp~blpos  eq lv_blpos. 

is better because i can express all the key fields of table KBLP.

if JOIN condition is processed before WHERE the condition "kblp~belnr eq lv_belnr" is useless because of "kblk~belnr eq lv_belnr". The joined records already have the filter on belnr.

What is the best condition in performance?

Hi experts, I have a question on JOIN condition. Sometimes i need to insert the same fields in WHERE condition and in JOIN condition.

For example:

  SELECT        * 
         FROM kblk join kblp
              ON kblk~belnr eq kblp~belnr
         WHERE  kblk~belnr  eq lv_belnr
           AND  kblp~blpos  eq lv_blpos. 

My question is about performances of this select. What is processed before? Where or join?

If WHERE condition is processed before

JOIN
  SELECT        * 
         FROM  kblk join kblp
              ON kblk~belnr eq kblp~belnr
         WHERE  kblk~belnr  eq lv_belnr
           AND  kblp~belnr  eq lv_belnr
    AND  kblp~blpos  eq lv_blpos. 

is better because i can express all the key fields of table KBLP.

if JOIN condition is processed before WHERE the condition "kblp~belnr eq lv_belnr" is useless because of "kblk~belnr eq lv_belnr". The joined records already have the filter on belnr.

What is the best condition in performance?

4 REPLIES 4
Read only

former_member184158
Active Contributor
1,185

Hi Gabriele,

coul you try ST05 to analyze the performance and compare between them which on is faster.

Read only

Sandra_Rossi
Active Contributor
1,185

In complement to what said Ebrahim Hatem, in ST05 you have the possibility to see the execution plan, which tells you what the database decides in your conditions (might differ on other systems).

Read only

DoanManhQuynh
Active Contributor
1,185

put F1 help on WHERE, i can see that its said:

The addition WHERE restricts the number of lines included in the result set by the statement SELECT...

so I think JOIN will evaluate first. But there are some discussions about it:

https://dba.stackexchange.com/questions/5038/sql-server-join-where-processing-order

Read only

matt
Active Contributor
0 Likes
1,185

I did once get it the wrong way round and ended up running out of memory.