How to Achieve Pruning When Querying by Non-Partitioned Columns in PostgreSQL 0 ▲ Haki Benita 138 days ago · 17 min read3414 words · Tech · hide · Fediverse post One of the most valuable things about partitioned tables is pruning - the database's ability to eliminate entire partitions based on a query predicate. Under conventional wisdom, pruning can only be achieved when querying by the partition key - this makes choosing the right key extremely difficult. However, if your data follows certain patterns, using some clever tricks you can achieve pruning even when filtering by non-partition key columns. In this article, I demonstrate how to achieve partition pruning when filtering by non-partition key columns. image by abstrakt design Table of Contents Table Partition Partition Pruning for Key Columns Local Indexes Global Indexes Pruning on Non-Partition Key Columns Talking to the Optimizer The constraint_exclusion Parameter Introducing Outliers Handling Outliers Gaps and Islands The Backstory Final Thoughts Table Partition Imagine you run a popular website with many users. Your product team wants to gain some insight into how the system is… Commenting on Bubbles has been removed. Why? If you want to talk about this post, write to the author, use the comments on their blog if it has them, or reply with a "RE:" post on your own blog. Suggestions? feedback@bubbles.town