liveBook · Manning

Partitioning key

As explained in 100 SQL Server Mistakes and How to Avoid Them

A partitioning key is the column or expression whose values determine the partition containing each table row.

A partitioning key is the column or expression whose values determine the partition containing each table row. In SQL Server, choosing it around real reporting filters enables partition elimination: the engine can skip irrelevant partitions instead of scanning the whole table. section 10.7 section 10.8

Mistake: choosing a key without checking how queries use it.

  • Filter directly on the key when possible. Combining CampaignID with an EventTime range allows elimination; using OR can force reads from every partition. section 10.8
  • Keep comparison types aligned. An EventTime DATETIME filter using DATE variables can require conversion and prevent elimination; DATETIME variables preserve the demonstrated behavior. section 10.8
  • Check parameterization. Simple parameterization can stop elimination; OPTION(RECOMPILE) and the demonstrated predicate workaround are available investigation points. section 10.8

ImpressionsArchive reporting query

A date-range query against the unpartitioned ImpressionsArchive reports 46,979 logical reads. The same EventTime range against ImpressionsArchivePartitioned reports 15,732 logical reads, illustrating the payoff when the partitioning key matches the filter.

How 100 SQL Server Mistakes and How to Avoid Them covers it

How deep it goes
Explains implementation and failure modes, including OR predicates, conversions, and parameterization, but stops short of broader design guidance.
Examples
Demonstrates EventTime ranges, ImpressionsArchive read counts, AND-versus-OR predicates, typed variables, and OPTION(RECOMPILE).
What it assumes
Assumes basic SQL Server querying and predicates while teaching partitioning objects and elimination behavior through T-SQL examples.
What you can do after
Diagnose/debug with it by checking whether predicates, data types, and parameterization allow SQL Server to eliminate partitions.
How it connects
Connects table partitioning with partition elimination, partition functions, partition schemes, data-type conversion, and simple parameterization.

Also explained in

Compare how 10 books explain partitioning key →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of 100 SQL Server Mistakes and How to Avoid Them. The section links point to the parts of the book it draws on.