Partitioning & Sharding: Mistakes
Module: Schema Design & Advanced DDL
Partitioning without including partition key in queries
Always include partition key in WHERE clause to enable partition pruning
Partition by date but query without date filter. Database scans all partitions. No benefit. Solution: Include partition key in WHERE clause. Query with date filter only scans relevant partitions.
High
graph TD
A[Query without partition key] --> B[Scan ALL partitions]
B --> C[No performance benefit]
D[Query with partition key] --> E[Partition pruning]
E --> F[Scan only relevant partition]
F --> G[10-100x faster]
style C fill:#FFB6C6
style G fill:#90EE90
Creating too many small partitions
Keep partitions manageable size (10-100M rows), not too many
Partition by day creates 365 partitions per year. Planning overhead increases. Query optimizer slower. Solution: Partition by month or quarter. Balance between partition size and number of partitions.
Medium
Forgetting to create indexes on each partition
Create indexes on each partition separately for best performance
Partition table but forget indexes. Queries still slow. Solution: CREATE INDEX on each partition. Smaller indexes on smaller partitions are faster.
High