Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you look at the query plans, you'll notice that significantly fewer rows (judging by the thickness of the arrows) are returned by the second query.</p> <p>This leads me to wonder if you've correctly populated the <code>compareHash</code> column. I.e. if all 200 columns were correctly included in the hash.</p> <p>If anything, I would expect the second query to return <em>more</em> rows, since hashing the character data will force the comparison to be case-sensitive. The default collation in sql server would perform a case-insensitive comparison for your first query over the varchar values.</p> <p>While this has more to do with correctness, you usually want to compare approaches that yield the same answer when comparing performance.</p> <hr> <p>Correctness aside, another observation is that in the first query, the data is sorted and then a streaming aggregate is applied. In the second query, a hash table is built and the second table is used to probe the hash table. You could try to force the sorted streaming aggregate plan in the second query by adding <code>OPTION (ORDER GROUP)</code> at the end of your query and see if that changes execution time, but I doubt it will improve it.</p> <p>My guess is that the original varchar data has some natural ordering that sql server is taking advantage of in the first query.</p> <p>If you're open to creating an index on the <code>compareHash</code> columns, you'll probably see significant performance gains in the second query since it'll use a merge-join.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload