Oliiii | J'en profile pour rappeler l'importance d'utiliser les Join.
Si la query tourne sur une petite table de 8 records ca ne change rien, mais j'ai fais le test sur un table de 10Mil rows:
Code :
SELECT a.* FROM Stock a LEFT JOIN Stock b ON a.numero = b.numero AND b.Type = 'Lym' WHERE a.Type = 'DNA' AND b.Type IS NULL /* Table 'Stock'. Scan count 10, logical reads 39528, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0. Table 'Worktable'. Scan count 0, logical reads 0, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0. SQL Server Execution Times: CPU time = 12828 ms, elapsed time = 8887 ms. */
|
Code :
SELECT * FROM Stock WHERE Stock.Type='DNA' AND Stock.numero NOT IN ( SELECT numero FROM Stock WHERE Stock.Type='Lym'); /* Table 'Stock'. Scan count 18, logical reads 10118584, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0. Table 'Worktable'. Scan count 0, logical reads 0, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0. Table 'Worktable'. Scan count 0, logical reads 0, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0. SQL Server Execution Times: CPU time = 4299639 ms, elapsed time = 1174512 ms. */
|
On passe de 12sec a 20mins (sur un quad core) |