Greenplum for Data Engineers
Greenplum and its forks as a data engineer runs them — segment mirrors, choosing a distribution key, data and processing skew, motions in EXPLAIN, heap and append-optimized tables, partitions on column tables, VACUUM and ANALYZE after loads, parallel loading, spill files and resource groups, GPORCA.
10 questions
JuniorTheoryVery commonGreenplum offers heap, append-optimized row and append-optimized column tables — which fits which warehouse table?
Greenplum offers heap, append-optimized row and append-optimized column tables — which fits which warehouse table?
Heap for small tables with frequent UPDATE, DELETE or single-row inserts, like load control tables. Append-optimized for data loaded in batches and rarely changed; column-oriented and compressed for wide facts whose queries read a few columns.
Open full question →Common mistakes
- ✗Making every table append-optimized column, then running frequent single-row UPDATE and DELETE against it
- ✗Choosing column orientation for tables whose queries read whole rows, where it only multiplies files
- ✗Running several batch UPDATE or DELETE jobs on the same append-optimized table at once
Follow-up questions
- →How does Greenplum delete a row from an append-optimized table, and when does that space come back?
- →Why can old partitions of one fact table use column storage with compression while the current one stays heap?
MiddleDesignVery commonA sales mart is moving into Greenplum (48 segments). orders has 2 billion rows: order_id, customer_id (NULL for the 15% of guest orders), order_date, a six-value status and is_paid. order_items has 9 billion rows and joins orders on order_id in almost every report. customers has 40 million rows and joins orders on customer_id; currency_rates has 3,000 rows. Most reports filter by a date range. A colleague proposes DISTRIBUTED BY (order_date) for orders, so a day's report touches one segment, and DISTRIBUTED BY (is_paid) for order_items. Choose the distribution for each table, say what is wrong with the proposal, and how you would check a candidate key before moving 9 billion rows.
A sales mart is moving into Greenplum (48 segments). orders has 2 billion rows: order_id, customer_id (NULL for the 15% of guest orders), order_date, a six-value status and is_paid. order_items has 9 billion rows and joins orders on order_id in almost every report. customers has 40 million rows and joins orders on customer_id; currency_rates has 3,000 rows. Most reports filter by a date range. A colleague proposes DISTRIBUTED BY (order_date) for orders, so a day's report touches one segment, and DISTRIBUTED BY (is_paid) for order_items. Choose the distribution for each table, say what is wrong with the proposal, and how you would check a candidate key before moving 9 billion rows.
Distribute orders and order_items on order_id: unique, even, and the biggest join runs with no motion. Replicate currency_rates; put customers on customer_id and accept a motion on that join. A date key sends each day to one segment; a boolean uses two at most.
Common mistakes
- ✗Distributing by the date column that queries filter on, so each day's load and each day's report land on one segment
- ✗Choosing a low-cardinality key such as a status or a boolean, which can use at most as many segments as it has values
- ✗Picking a join key with many NULLs, which sends every NULL row to the same segment
Follow-up questions
- →When would you distribute
customersoncustomer_idinstead of replicating it, given the 40 million rows? - →Why must both join columns have the same data type for a collocated join in Greenplum?
JuniorTheoryCommonWhat do Gather, Redistribute and Broadcast Motion, and slices, mean in a Greenplum EXPLAIN plan?
What do Gather, Redistribute and Broadcast Motion, and slices, mean in a Greenplum EXPLAIN plan?
A motion moves rows between segments over the interconnect: Gather sends results to the coordinator, Redistribute rehashes rows to segments by a key, Broadcast copies every row to all segments. Motions cut the plan into slices that run in parallel.
Open full question →Common mistakes
- ✗Reading a Redistribute or Broadcast Motion as free, when it means rows crossing the network before the next step
- ✗Overlooking a Broadcast Motion over a large table, which copies all of it to every segment
- ✗Treating the final Gather Motion as a problem, though every query that returns rows to the client ends with one
Follow-up questions
- →When would the planner choose to broadcast one side of a join rather than redistribute both?
- →What does a
48:1or48:48after a motion name tell you?
JuniorTheoryCommonIn Greenplum, a primary segment fails during the nightly load — what happens to the load, to queries and to the cluster?
In Greenplum, a primary segment fails during the nightly load — what happens to the load, to queries and to the cluster?
The coordinator's fault prober marks the primary down and promotes its mirror. Transactions running at that moment roll back, so the load must be re-run. The cluster keeps serving, but unbalanced, until gprecoverseg restores the pair and gprecoverseg -r the roles.
Common mistakes
- ✗Expecting a running load or query to survive the failover, instead of planning a re-run
- ✗Leaving the cluster on its promoted mirrors, where one host now carries extra primaries and sets the speed of every query
- ✗Assuming the coordinator's standby takes over by itself the way segment mirrors do
Follow-up questions
- →Why should a nightly load into Greenplum be safe to re-run from the start, and how would you make it so?
- →What changes for the cluster when a whole host fails under group mirroring versus spread mirroring?
MiddleDebuggingCommonIn Greenplum, the table is evenly distributed, yet one segment does most of the join's work — diagnose it
In Greenplum, the table is evenly distributed, yet one segment does most of the join's work — diagnose it
Not data skew: events is even. The join redistributes it on partner_id, and the 1.39 billion rows with partner_id = 0 all hash to seg17, which works alone. That is processing skew: handle the hot value apart, or aggregate before the motion.
Common mistakes
- ✗Checking only rows per segment of the stored table and concluding there is no skew
- ✗Redistributing the table on the hot join key, which turns processing skew into permanent data skew
- ✗Adding memory or hardware instead of removing the hot value from the redistributed stream
Follow-up questions
- →What do
gp_toolkit.gp_skew_coefficientsandgp_toolkit.gp_skew_idle_fractionsmeasure, and why would neither have caught this? - →How would pre-aggregating
eventsbypartner_idbefore the join change the rows each segment receives?
MiddleDebuggingCommonGreenplum reports slowed down over a month of nightly loads, and a plan now broadcasts the biggest fact — diagnose
Greenplum reports slowed down over a month of nightly loads, and a plan now broadcasts the biggest fact — diagnose
The loads go into tables that already have statistics, so auto-stats never fire again: the planner still sees 1.15M rows in fact_clicks and broadcasts it. Run ANALYZE after each load. The daily DELETE bloats heap sales_daily: VACUUM it, or swap partitions.
Common mistakes
- ✗Assuming automatic statistics keep up with loads into a table that already has statistics
- ✗Reloading days with DELETE and INSERT into a heap table and never vacuuming it
- ✗Expecting VACUUM to collect the column statistics ANALYZE gathers, or ANALYZE to reclaim dead rows
Follow-up questions
- →How does VACUUM treat deleted rows in an append-optimized table differently from a heap table?
- →Why does reloading a day by swapping in a freshly loaded partition avoid both bloat and the DELETE?
SeniorDesignCommonEach night 1.5 TB of CSV files land on two ETL hosts and must reach a Greenplum fact table partitioned by day (48 segments). Today a Python job streams them with COPY ... FROM STDIN: it takes six hours, the coordinator's network link sits at 100%, and one malformed row aborts a whole file, so the job restarts from scratch. Another team also needs to load Parquet files from S3 into the same warehouse. Design the loading path: how the data gets into the segments, how bad rows are handled without losing the night, how a reloaded day replaces the old one safely, and what must run after the load so the next morning's reports plan well.
Each night 1.5 TB of CSV files land on two ETL hosts and must reach a Greenplum fact table partitioned by day (48 segments). Today a Python job streams them with COPY ... FROM STDIN: it takes six hours, the coordinator's network link sits at 100%, and one malformed row aborts a whole file, so the job restarts from scratch. Another team also needs to load Parquet files from S3 into the same warehouse. Design the loading path: how the data gets into the segments, how bad rows are handled without losing the night, how a reloaded day replaces the old one safely, and what must run after the load so the next morning's reports plan well.
Serve files with gpfdist on the ETL hosts and read them via an external table: every segment pulls in parallel, past the coordinator; S3 via PXF. LOG ERRORS SEGMENT REJECT LIMIT sets bad rows aside. Load a staging table, swap it in as the day's partition, then ANALYZE.
Common mistakes
- ✗Loading bulk data with COPY through the coordinator, which turns one process and one network link into the bottleneck
- ✗Letting a single bad row abort a whole file instead of isolating rejected rows in an error log with a limit
- ✗Deleting and re-inserting a day in the live table instead of loading a staging table and swapping the partition
Follow-up questions
- →What does a
SEGMENT REJECT LIMITin percent protect you from that a row count does not? - →How does the number of gpfdist processes and files limit how many segments read in parallel?
MiddleTheoryOccasionalA Greenplum column-oriented table has 200 columns and daily partitions for three years — why does that hurt, and what instead?
A Greenplum column-oriented table has 200 columns and daily partitions for three years — why does that hurt, and what instead?
Each column of each partition is a separate file on every segment: 200 columns × 1,095 days is about 219,000 files per segment, which costs planning, catalog and file-open work. Partition by month instead, with fewer, fuller partitions, and set storage per partition.
Open full question →Common mistakes
- ✗Partitioning a column-oriented table as finely as possible without counting columns × partitions files per segment
- ✗Expecting pruning to make the partition count free, though planning and catalog work grow with it
- ✗Adding a second partition level, which multiplies the file count again
Follow-up questions
- →What decides the right partition grain for a fact table: query filters, retention, or partition size?
- →Why might the current month stay heap while older months become column-oriented and compressed?
SeniorPerformanceOccasionalA Greenplum report on a partitioned fact slowed down, and EXPLAIN now names the Postgres-based planner — why, and what to do?
A Greenplum report on a partitioned fact slowed down, and EXPLAIN now names the Postgres-based planner — why, and what to do?
GPORCA plans a query only when it supports every feature in it, otherwise Greenplum falls back to the Postgres-based planner and loses GPORCA's partition elimination and join choices. Find the feature with optimizer_trace_fallback, rewrite around it, and keep root statistics fresh.
Common mistakes
- ✗Tuning the Postgres planner's settings while GPORCA plans the query, though GPORCA ignores them
- ✗Not checking the optimizer line of EXPLAIN after changing a report query or a table definition
- ✗Analyzing only new leaf partitions and leaving GPORCA with stale or missing root partition statistics
Follow-up questions
- →When can turning GPORCA off for a session be the right call, and what would you check first?
- →Why can GPORCA eliminate partitions at run time in a join, when the partition values come from the other table?
SeniorDebuggingOccasionalA nightly Greenplum ELT insert fails with «workfile per query size limit exceeded» while dashboards run — diagnose
A nightly Greenplum ELT insert fails with «workfile per query size limit exceeded» while dashboards run — diagnose
The query spilled past its workfile limit, almost all on seg9: the window redistributes on user_id and sorts per user, so 910M rows of -1 land on one segment. Unlimited spill only fills seg9's disk. Handle -1 apart, and give etl its own resource group.
Common mistakes
- ✗Raising or removing the workfile limit, which moves the failure to a full disk on the hot segment
- ✗Blaming the stored table's distribution when the skew comes from redistributing on a hot window partition key
- ✗Running ELT and dashboards in one default resource group, where they compete for the same memory and concurrency slots
Follow-up questions
- →How would you find which operator of the plan spilled, and on which segments, while the query is still running?
- →Why can stale statistics on
eventsmake a hash join or aggregate spill even without a hot key?