Ravi Sir's Cards › AWS
DISTKEY and SORTKEY
This revision card explains DISTKEY and SORTKEY. It starts from the need that wrong distribution causes broadcast joins and slow scans. It describes DISTKEY co-locates join keys across nodes; SORTKEY orders data for zone-map pruning on filters. The how-to section notes DIST on common join key; SORT on frequent filter (date); ANALYZE after load. An example on the card is orders DIST customer_id SORT order_date cuts join+filter time sharply.
Read card text
What this card says
Why do we need it?
Wrong distribution causes broadcast joins and slow scans.
What is it?
DISTKEY co-locates join keys across nodes; SORTKEY orders data for zone-map pruning on filters.
DISTKEY / SORTKEY
How to do it
DIST on common join key; SORT on frequent filter (date); ANALYZE after load.
Example
orders DIST customer_id SORT order_date cuts join+filter time sharply.