If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Performance : INTERSECT or join ?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-01-09, 09:55
CogitoErgoSum CogitoErgoSum is offline
Registered User
 
Join Date: Oct 2009
Posts: 14
Question Performance : INTERSECT or join ?

Will INTERSECT option provide better performance as opposed to the 'join' shown below ?

Code:
SELECT COUNT(COL1)
  FROM
  (SELECT A.COL1
     FROM XXL_TABLE A,
          XL_TABLE B
    WHERE A.SOME_COL1 = B.SOME_COL1
      AND MONTH(A.DATE_COL) = 8
      AND A.SOME_COL2 BETWEEN 100 AND 200
   INTERSECT
   SELECT A.COL1
     FROM XXL_TABLE A,
          XL_TABLE B
    WHERE A.SOME_COL1 = B.SOME_COL1
      AND MONTH(A.DATE_COL) = 9
      AND A.SOME_COL2 > 200
   )
Code:
SELECT COUNT(DISTINCT COL1)
  FROM
  (SELECT A.COL1
     FROM XXL_TABLE A,
          XL_TABLE B
    WHERE A.SOME_COL1 = B.SOME_COL1
      AND MONTH(A.DATE_COL) = 8
      AND A.SOME_COL2 BETWEEN 100 AND 200
   ) X,
  (SELECT A.COL1
     FROM XXL_TABLE A,
          XL_TABLE B
    WHERE A.SOME_COL1 = B.SOME_COL1
      AND MONTH(A.DATE_COL) = 9
      AND A.SOME_COL2 > 200
   ) Y
WHERE X.COL1 = Y.COL1
Maybe, the above information is not enough. But, I am interested in knowing the difference between the INTERSECT and join options.
Reply With Quote
  #2 (permalink)  
Old 10-01-09, 11:55
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
If you cogito hard enough, you can use the explain facility to answer that question.
Reply With Quote
  #3 (permalink)  
Old 10-03-09, 00:39
CogitoErgoSum CogitoErgoSum is offline
Registered User
 
Join Date: Oct 2009
Posts: 14
ok, will cogito some more
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On