Back to questions
JuniorTheoryCommon
How does a massively parallel (MPP) warehouse like Greenplum spread one table across its nodes?
MPP is shared-nothing: a coordinator plans, each segment holds a share of every table. A distribution key hashes rows to segments; a small table can be replicated to all, or rows spread randomly. A join on that key runs locally; otherwise rows move.
- Confusing the distribution key, which places rows on segments, with the partition key, which splits a table by value
- Thinking an MPP segment owns whole tables rather than a share of every table
- Assuming every join is local, without checking whether both sides share the distribution key
- When would you choose
DISTRIBUTED REPLICATEDin Greenplum orDISTSTYLE ALLin the Redshift warehouse? - What makes a column a bad distribution key even when it is the most common join key?
What it looks like in Greenplum (and its forks Arenadata DB and Greengage DB) and in Redshift:
-- Greenplum: the fact is hashed on the join key
CREATE TABLE sales (sale_id bigint, customer_id bigint, amount numeric)
DISTRIBUTED BY (customer_id);
-- small dimension: a copy on every segment
CREATE TABLE regions (region_id int, name text)
DISTRIBUTED REPLICATED;
-- no good key: spread evenly, regardless of value
CREATE TABLE raw_clicks (payload jsonb)
DISTRIBUTED RANDOMLY;Redshift names the same ideas DISTSTYLE KEY (with a DISTKEY), ALL and EVEN, and AUTO picks the style itself; node slices play the role of segments.
A join of sales with another table distributed on customer_id runs on every segment over its own rows. When the keys differ, the plan shows a motion: one or both sides are redistributed on the join key, or the small side is broadcast to every segment.