simon
2012-02-29 14:16:00 UTC
I have one join of 2 tables(first table - filtered index, has 6827
rows and second one has 1 million of rows).
Join is by identity column, which is clustered index in small table
and nonclustered in large table.
There is no order - so, I guess, merge join is not optimal here. But
query optimizer choose it.
CPU time is about 350 ms(and also execution time is near), and IO is
about 1900 logical reads.
Because one table is small and other is large, I would take nested
loop (for each value in small table, I would take index seek on large
table).
Now CPU is much faster, only 80 ms, but logical reads are more than 10
times greater (20000).
Since logical reads are from memory it doesn't affect the performance
a lot.
If I would clear cash, than loop join would be slower than merge
join.
But even if I execute: DBCC DROPCLEANBUFFERS, DBCC FREESYSTEMCACHE,
DBCC FREESESSIONCACHE, DBCC FREEPROCCACHE, I still have logical reads.
How can I remove pages from cache?
Anyway, when pages are in cache(that is probably most of the time),
then Loop join would be 5-times faster than merge. Should I use Hint
operator here?(and first table will always have small number of rows,
only second will grow).
So, should i focus more on CPU time when optimizing query(and ignore
logical reads since they are almost never physical) or should I focus
more on logical reads.
If I choose HASH JOIN in this case i get similar results as with merge
join(CPU time is little bigger, reads are the same).
br, Simon
rows and second one has 1 million of rows).
Join is by identity column, which is clustered index in small table
and nonclustered in large table.
There is no order - so, I guess, merge join is not optimal here. But
query optimizer choose it.
CPU time is about 350 ms(and also execution time is near), and IO is
about 1900 logical reads.
Because one table is small and other is large, I would take nested
loop (for each value in small table, I would take index seek on large
table).
Now CPU is much faster, only 80 ms, but logical reads are more than 10
times greater (20000).
Since logical reads are from memory it doesn't affect the performance
a lot.
If I would clear cash, than loop join would be slower than merge
join.
But even if I execute: DBCC DROPCLEANBUFFERS, DBCC FREESYSTEMCACHE,
DBCC FREESESSIONCACHE, DBCC FREEPROCCACHE, I still have logical reads.
How can I remove pages from cache?
Anyway, when pages are in cache(that is probably most of the time),
then Loop join would be 5-times faster than merge. Should I use Hint
operator here?(and first table will always have small number of rows,
only second will grow).
So, should i focus more on CPU time when optimizing query(and ignore
logical reads since they are almost never physical) or should I focus
more on logical reads.
If I choose HASH JOIN in this case i get similar results as with merge
join(CPU time is little bigger, reads are the same).
br, Simon