Re:Results of the SQL Performance Quiz
by jcampbell1 on Thursday February 20, 2014 @02:54PM
(#7273129)
I took the latter interpretation. The "correct" solution uses the fact the first query can be solved by selecting 0 rows from the base table.
At least on MSSQL, I would expect a query plan like so:
And the optimizer will choose this over a full table scan so long as the 1+2+3 < full table scan. I don't know the threshold for that, but is is certainly more than 100 rows out 1M+, and the planner will have an estimate of selectivity that will inform plan selection.[1] Important caveat. I interpret this line,
Current situation, selecting about hundred rows out of a million:
....to mean selection of 100 rows from the base table, rather than projection of 100 rows in the result, post-aggregation.
But if he really means a SELECT statement that returns 100 rows, then we have no idea how selective the WHERE clause is, and my answer changes to "The query will be much slower (impact >10%)".