Categories
SQL

A Bit About Trivial Plans

A Trivial plan is created when SQL Server really doesn’t have any choice in how it’s going to execute. Here’s an example from the StackOverflow database with the indexes removed: There really isn’t any choice but a clustered index seek. It’s the only index and its about as effective as we can get given we’re filtering on […]

Categories
SQL

Optimising DISTINCT Clauses using EXISTS

The DISTINCT clause in a query can help us quickly remove duplicates from our results. Sometimes it can be beneficial to stop and ask why. Why do we need to use the clause, why are we receiving duplicates from our data? I see this typically due to a JOIN being used where we don’t really want all of those results. This could […]