The Iterator Model of Query Processing
The Volcano model, or iterator model, provides a standardized framework for executing complex relational algebra expressions. At its core, every operator in a query plan—such as Filter, Join, or Sort—implements a common interface. This interface consists of three fundamental methods: open(), next(), and close().
How the Iterator Pattern Functions
Query execution begins at the root of the operator tree, typically a projection or result-gathering operator, which calls next() on its child. This request propagates recursively down the tree until it reaches a leaf node, such as a table scan. The leaf node retrieves a tuple from storage and returns it up the chain. Each intermediate operator processes the tuple according to its logic—filtering, joining, or aggregating—before returning the final result to its own parent.
open(): Initializes the operator, allocates internal state, and prepares resources.
next(): Fetches the next tuple in the result stream or returns a completion signal.
close(): Releases resources and cleans up memory after the stream is exhausted.
Trade-offs and Performance Implications
The primary advantage of the Volcano model is modularity. Operators are decoupled, allowing the query optimizer to compose complex trees without requiring each operator to understand the internals of its children. However, the model introduces significant overhead due to function call frequency. In modern CPU architectures, calling a virtual function for every single tuple creates high branch misprediction rates and prevents effective instruction pipelining, often referred to as 'tuple-at-a-time' overhead.
Engineers often address these limitations by transitioning to vectorized execution, where batches of tuples are processed in a single function call, or code generation (JIT compilation), which transforms the entire operator tree into an optimized, executable machine code loop. Despite these modern alternatives, the simplicity and versatility of the iterator model remain the foundation of query evaluation systems worldwide.
