Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

performance

Status
Not open for further replies.

raji96

Programmer
Aug 7, 2001
64
US
Which result will be faster?

subqueries or having unions.
 
If you are joining most of the rows of 2 big tables, union will be faster (using full table scan and sort merge). If a sub-query is executed thousands of time to return more than 30 percent of a table, you would be better of by scanning all the information once (table scan) and merging the info via a union. This might not be true but in many situation, the subquery will use an index, and read the data in one of the table. The problem is that it's the data in the driving table that tells what data to read in the second table. Bottom line, you might end up reading multiple time the same block to read the data of table 2, instead of one once in the case of a table scan.

This might not describe your situation properly. Like carp said, it depends of lots of things. But what I have described might help you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top