Query Planning and Execution
The longest part of the book, and the one most performance questions land in: two optimizers, an executor, and the interconnect that moves tuples between segments.
-
Chapter 13
From SQL to Segments: Cloudberry Query Processing
The simple and extended query protocols, custom versus generic plans, and how the coordinator dispatches a finished plan to segment executors.
-
Chapter 14
Statistics and Selectivity Estimation in Cloudberry
How ANALYZE builds pg_statistic across segments, what extended and multivariate statistics add, and how selectivity estimates turn into row counts.
-
Chapter 15
The Postgres Planner in Cloudberry, Step by Step
Query tree structure, preprocessing, paths and costs, add_path pruning, and how the chosen path becomes an executable plan tree.
-
Chapter 16
Distributed Planning: Locus, Motion and Direct Dispatch
The cdbpathlocus model, how CdbMotionPath decides where data must move, cdbllize parallelization, distributed grouping and direct dispatch.
-
Chapter 17.1
ORCA Optimizer: Entry Points and Fallback Rules
When Cloudberry hands a query to ORCA and when it falls back to the Postgres planner — the entry path, unsupported features, and how to see the decision.
-
Chapter 17.2
Inside ORCA's Cascades Engine: Groups and Jobs
How ORCA's memo, groups, group expressions and job scheduler explore a search space, and what the optimization levels actually change.
-
Chapter 17.3
ORCA Transformation Rules and the Search Space
How xforms rewrite expressions into alternatives, which rules fire for joins and aggregates, and how to disable a transformation to test its effect.
-
Chapter 17.4
ORCA's Metadata Layer and Cost Model Explained
How ORCA pulls statistics through the metadata accessor and cache, derives its own cardinality estimates, and what its cost model actually charges for.
-
Chapter 17.5
DXL: Translating Queries Between ORCA and Cloudberry
The DXL interchange format — query to DXL, ORCA's plan back to a PlStmt, and how to dump and replay a minidump to reproduce a plan offline.
-
Chapter 17.6
Steering ORCA: GUCs, Traceflags and Minidumps
The optimizer GUCs that change ORCA's behaviour, the traceflags that expose what it did, and how to read the optimizer instead of guessing at it.
-
Chapter 18.1
The Cloudberry Executor: Framework and Lifecycle
ExecutorStart, ExecutorRun and ExecutorEnd, the plan-state tree, tuple slots, and the pull-based volcano model that drives every node.
-
Chapter 18.2
Executor Scan Nodes: Seq, Index, Bitmap and AO
How each scan node fetches tuples — sequential, index, index-only, bitmap, and the append-optimized and PAX scans unique to Cloudberry.
-
Chapter 18.3
Sort and Aggregate Nodes in the Cloudberry Executor
Tuplesort and its spill path, hash and group aggregation, the two-stage distributed aggregate, and where work_mem and statement_mem bite.
-
Chapter 18.4
Join Execution: Nested Loop, Hash and Merge Joins
How each join node executes, how hash joins batch and spill to disk, and what an MPP plan adds on top of the upstream PostgreSQL implementations.
-
Chapter 18.5
Expression Evaluation in the Cloudberry Executor
How expressions compile to an ExprState step program, how short-circuit jumps are patched, and where JIT compilation does and does not apply.
-
Chapter 18.6
Subplans, CTEs and the Rest of the Executor Nodes
SubPlan and InitPlan execution, CTE and recursive union nodes, Material, Limit, Window, and the remaining executor nodes in one place.
-
Chapter 18.7
Executor Nodes That Exist Only in Cloudberry
Motion, Split Update, Assert, Sequence, Partition Selector, Shared Scan and the other executor nodes that exist only in the MPP lineage.
-
Chapter 19.1
How Distributed Query Execution Works in Cloudberry
Slices, gangs, query executors, and the rules that decide how one plan becomes parallel work running on every segment at once.
-
Chapter 19.2
The Dispatcher: Gangs, Gang Reuse and Async Dispatch
How CdbDispatchPlan allocates gangs of query executors, ships the plan and snapshot over libpq, and collects results without blocking.
-
Chapter 19.3
Slice Tables: Mapping Plan Slices to Gangs
How the planner cuts a plan into slices at every Motion, and how the slice table maps each PlanSlice onto the gang that will run it.
-
Chapter 19.4
Motion Nodes: Gather, Broadcast and Redistribute
The five Motion types that reach the executor, what each one costs, and how to read Motion nodes in an EXPLAIN plan to spot data skew.
-
Chapter 19.5
The Cloudberry Interconnect: UDPIFC, TCP and Proxy
How segments actually move tuples between each other — the UDP interconnect with its own flow control, the TCP fallback, and the interconnect proxy.
-
Chapter 19.6
Parallel Retrieve Cursors and Endpoints in Cloudberry
How a parallel retrieve cursor lets a client pull results directly from every segment at once, bypassing the coordinator gather entirely.