Explore Library
Code Quiz

Partition Pruning Defeated by a Function

A wrapped partition key silently disables pruning, forcing a full scan across every partition.

Codesql
-- orders is RANGE-partitioned by order_date (one partition per year)
-- there is a secondary index on (status, customer_id)

SELECT o.customer_id, SUM(o.amount) AS total
FROM orders o
WHERE YEAR(o.order_date) = 2024
  AND o.status = 'shipped'
GROUP BY o.customer_id;

The plan shows every partition being scanned even though only 2024 data is needed. What is the bug?