Understanding SQL Server Density Vectors
A density vector helps estimate how selective indexed data can be. SQL Server stores these values inside statistics. The value named all density is small when many distinct values exist. It is larger when repeated values are common. This calculator turns those ideas into clear maths.
Why Density Matters
Query plans depend on row estimates. A poor estimate can choose a slow join, weak index, or heavy memory grant. Density gives the optimizer a compact clue. It tells how many rows may match equality predicates across leading key columns. For one column, density is based on its distinct count. For two columns, it uses distinct pairs. Longer prefixes follow the same idea.
Formula Based Logic
The core formula is simple. All density equals one divided by distinct values. Estimated matching rows equal total rows multiplied by density. A residual filter can reduce the estimate further. An optional actual row value helps show error. The error is useful when comparing a statistic with real query output.
Using Four Key Columns
This page supports four leading key prefixes. That matches many practical indexes. You can enter column names, combined distinct counts, and average key length values. The tool then builds a density vector table. It also prepares SQL style notes, so the numbers feel close to database work.
Good Input Practices
Use combined distinct values for each prefix. Prefix two means distinct combinations of column one and column two. Prefix three includes the first three columns. Do not enter separate distinct counts when the prefix needs combined counts. Use values from statistics, profiling queries, or trusted reports.
Reading Results
Low density means high selectivity. High density means more duplicates. A final estimate below one is rounded up for planning notes, because at least one row may be expected for a matching key. The table also shows magnitude and spread indicators. These help compare prefixes quickly.
Limits and Care
Density is not a full histogram. It does not fully model skew, correlation, or filtered predicates. SQL Server may combine density with histograms and other rules. Use this calculator for learning, checking, and documenting estimates. Always test important database changes with real execution plans before any production rollout starts.