Cardinality, and in particular, Selectivity are important items to consider when designing the indexes and the WHERE clause of your queries.
First let’s start by defining them. Cardinality is the number of unique or distinct values that can exist in a column. For example, a column used to store Gender is likely to have only 2 possible values to choose from, Male and Female. This means the cardinality is 2 since there are only 2 possible values. Low cardinality is not ideal since it will lead to high selectivity.... read more
I sometimes get the question, what is the difference between DISTINCT and GROUP BY?
The answer is, it depends. What I mean is, it depends on what you’re trying to accomplish. If you’re just trying to get rid of duplicate rows then both functions generate the same execution plan and both get rid of duplicate rows. So if all you’re trying to do is get rid of duplicate rows then there is no real difference between the two.... read more
When SQL is running on a server with multiple processors, it has the option to use multiple processors to satisfy a single query. This is referred to as Parallelism.
This sounds great and wonderful but as we all know, there is no free lunch. Everything has a price associated with it and parallelism is no exception. Parallelism’s cost has to do with the additional CPU required to manage and synchronize all the sub-tasks associated with parallelism.... read more
By enabling SET STATISTICS TIME ON, you are instructing SQL to return the parse, compile and execution time of each statement. This information can be very useful when tuning your queries. This is particularly true when your query runtime is under 1 second as the Query Analyzer timer (bottom-right of query window) is only accurate to the second and also displays network time to return the results to the client. SET STATISTICS TIME ON is different in that it only includes server time to process the query. This, after all, is the only part you need to worry about when tuning your queries.... read more