本文发表在 rolia.net 枫下论坛TABLE_ONE:
ItemID, other fields (8 million+ records)
TABLE_TWO
ItemID, other fields (150000+ records)
Query A:
SELECT ItemID FROM TABLE_TWO WHERE ItemID NOT IN (SELECT ItemID FROM TABLE_ONE)
Query B (Same result as Query A):
SELECT T2.ItemID FROM TABLE_TWO T2 LEFT JOIN TABLE_ONE T1 ON T1. ItemID = T2. ItemID WHERE T1.ItemID IS NULL
Query C:
SELECT ItemID FROM TABLE_ONE WHERE ItemID NOT IN (SELECT ItemID FROM TABLE_TWO)
Query D (Same result as Query C):
SELECT T1.ItemID FROM TABLE_ONE T1 LEFT JOIN TABLE_TWO T2 ON T1. ItemID = T2. ItemID WHERE T2.ItemID IS NULL
Results:
No any index in both tables:
A: return about 120000 records and spends 36 seconds
B: return about 120000 records and spends 35 seconds
C: return about 8200000 records and spends 1:23 seconds
D: return about 8200000 records and spends 1:25 seconds
Built clustered index on ItemID in both tables
A: return about 120000 records and spends 57 seconds
B: return about 120000 records and spends 57 seconds
C: return about 8200000 records and spends 1:40 seconds
D: return about 8200000 records and spends 1:43 seconds更多精彩文章及讨论,请光临枫下论坛 rolia.net
ItemID, other fields (8 million+ records)
TABLE_TWO
ItemID, other fields (150000+ records)
Query A:
SELECT ItemID FROM TABLE_TWO WHERE ItemID NOT IN (SELECT ItemID FROM TABLE_ONE)
Query B (Same result as Query A):
SELECT T2.ItemID FROM TABLE_TWO T2 LEFT JOIN TABLE_ONE T1 ON T1. ItemID = T2. ItemID WHERE T1.ItemID IS NULL
Query C:
SELECT ItemID FROM TABLE_ONE WHERE ItemID NOT IN (SELECT ItemID FROM TABLE_TWO)
Query D (Same result as Query C):
SELECT T1.ItemID FROM TABLE_ONE T1 LEFT JOIN TABLE_TWO T2 ON T1. ItemID = T2. ItemID WHERE T2.ItemID IS NULL
Results:
No any index in both tables:
A: return about 120000 records and spends 36 seconds
B: return about 120000 records and spends 35 seconds
C: return about 8200000 records and spends 1:23 seconds
D: return about 8200000 records and spends 1:25 seconds
Built clustered index on ItemID in both tables
A: return about 120000 records and spends 57 seconds
B: return about 120000 records and spends 57 seconds
C: return about 8200000 records and spends 1:40 seconds
D: return about 8200000 records and spends 1:43 seconds更多精彩文章及讨论,请光临枫下论坛 rolia.net