View previous topic :: View next topic
|
Author |
Message |
prasadplease
New User
Joined: 02 Sep 2006 Posts: 31 Location: Mumbai
|
|
|
|
Hi,
Can anyone give me details of how IN clause operates internally
In my IN clause I have several values, some of them are repeated, will the repeated values be ignored(replaced by a single occurrence of the value) while processing the query?
Thanks,
Prasad. |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
Would it not be better for you to try it and see what happens for yourself.
That is the best way to learn things, test and observe. |
|
Back to top |
|
|
prasadplease
New User
Joined: 02 Sep 2006 Posts: 31 Location: Mumbai
|
|
|
|
Thanks for enlightening me, Expat
But I thought forums are where ppl who know help ppl who dont...
never mind... |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
The forums are for helping with problems, which is not to be confused with a shortcut for you testing something yourself and seeing what the results are.
How long will it take you to perform a simple test. Probably a lot less time than you have already been waiting for the answer here. |
|
Back to top |
|
|
prasadplease
New User
Joined: 02 Sep 2006 Posts: 31 Location: Mumbai
|
|
|
|
Hi Expat,
There is no way I can test that.
You either have to know it by virtue of having read that somewhere or being told about it by someone. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
prasadplease,
I agree with expat. You should do a little looking on your own.
actually, you are a whinny-ass who does not have the whitherwithall to
do a little research.
your attitude almost prevented me from posting the following quote from
the DB2 Developer's Guide from Craig Mullins:
Quote: |
When using the IN predicate with a list of values, DB2 sorts the IN-list into ascending sequence and removes duplicates if the column specified is indexed. The IN-list values are then used to probe the index to find the matching rows. However, if there is no index for the column, DB2 will not sort the IN-list and any duplicates will remain. Upon retrieval of a row, the column value is used to search the IN-list (duplicates and all).
Therefore, it makes sense to order the elements of the IN-list, code your most restrictive predicates first, and never code duplicates in the IN-list.
Order the Elements in Your IN Lists
The order of elements in a SQL IN list can impact performance when an index is not used to process the IN list. DB2 will search the list of elements from left to right until a match is found or the end of the list is reached. For this reason, code the most commonly occurring values first in your IN lists. Doing so will cause DB2 to match as early as possible most of the time—thereby improving performance. For example, consider the following SQL statement:
SELECT EMPNO, WORKDEPT, EDLEVEL, SALARY
FROM DSN8810.EMP
WHERE WORKDEPT IN ('A00', 'A01', 'E21');
This SQL statement demonstrates the natural tendency to order lists alphabetically or numerically. The statement is correctly coded only if A00 occurs more often than A01, which occurs more often than E21. But if A01 was most common, followed by E21 and then A00, the statement would be better coded (performance-wise) as
SELECT EMPNO, WORKDEPT, EDLEVEL, SALARY
FROM DSN8810.EMP
WHERE WORKDEPT IN ('A01', 'E21', 'A00');
|
|
|
Back to top |
|
|
prasadplease
New User
Joined: 02 Sep 2006 Posts: 31 Location: Mumbai
|
|
|
|
Dick,
Thanks a lot for the information. |
|
Back to top |
|
|
|