sql server 2005 - SQL EXCEPT performance -


i'm trying use query similar following query find differences between 2 tables (the same table in dev database vs test database). each table has ~30k rows , ~5 columns.

select field1,field2,field3,field4,field5 dev.dbo.table1  field1+field2 in ('string1','string2','string3',...,'string50') except select field1,field2,field3,field4,field5 test.dbo.table1  field1+field2 in ('string1','string2','string3',...,'string50') 

field1 char(5) , field2 char(1)

this query never terminates.

when analyze query using set showplan_all on, can see there nested loop pretty high in tree. when change above query to

select * dev.dbo.table1  except select * test.dbo.table2 

the query runs , there no nested loop in execution plan.

can explain this? don't understand why there drastic difference.

my best guess optimizer doing poor job of estimating cardinality (size) of 2 tables. because underestimates size, generating poor query plan.

in sql server, can use join hints on except. so, can query want with:

select field1,field2,field3,field4,field5 dev.dbo.table1  field1+field2 in ('string1','string2','string3',...,'string50') except select field1,field2,field3,field4,field5 test.dbo.table1  field1+field2 in ('string1','string2','string3',...,'string50') option (hash join, merge join) 

this eliminates option of nested loop join, choosing more favorable method.


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -