Comparison
Clustering keyvsSort key
Clustering key
the table is partitioned by day and sorted within each day by customer, so filtering on a customer skips most blocks inside the partition.
The column data is physically ordered by within a partition, so per-block statistics become selective. It is the second-order layout decision after partitioning, and it is what makes filters on high-cardinality columns cheap without creating a folder per value. Ordering is not free: it is maintained by rewrite, so a clustered table needs periodic maintenance to stay clustered as data is appended.
Full entry →Sort key
the rows are stored in date order, so a range query reads a contiguous run of blocks instead of touching all of them.
The column or columns a table's rows are physically ordered by. Sorting improves both skipping and compression, since adjacent similar values compress far better, so it often reduces bytes scanned twice over. Choosing more than two or three sort columns rarely helps, because ordering is lexicographic and the later columns only discriminate within already-narrow ranges.
Full entry →