Skip to main content

Operator

Trait Operator 

Source
pub trait Operator: Send {
    // Required methods
    fn open(&mut self) -> Result<()>;
    fn next(&mut self) -> Result<Option<RowRef>>;
    fn close(&mut self) -> Result<()>;
    fn schema(&self) -> &[ColumnInfo];
    fn name(&self) -> &str;

    // Provided methods
    fn estimated_rows(&self) -> Option<usize> { ... }
    fn ordering(&self) -> OrderingProperty { ... }
}
Expand description

Volcano-style iterator interface for query operators.

Each operator implements this trait to participate in the streaming execution pipeline. The execution follows the open-next-close pattern:

  1. open() - Initialize the operator (called once)
  2. next() - Get the next row (called repeatedly until None)
  3. close() - Release resources (called once at end)

§Thread Safety

Operators are Send to allow execution on different threads, but individual operators are not Sync - they maintain mutable state.

Required Methods§

Source

fn open(&mut self) -> Result<()>

Initialize the operator.

Called once before the first next() call. This is where child operators should be opened and any one-time initialization should occur.

Source

fn next(&mut self) -> Result<Option<RowRef>>

Get the next row from this operator.

Returns:

  • Ok(Some(row)) - A row is available
  • Ok(None) - No more rows (exhausted)
  • Err(e) - An error occurred

After returning None, subsequent calls should continue to return None.

Source

fn close(&mut self) -> Result<()>

Close the operator and release resources.

Called once after all rows have been consumed or when execution is terminated early. Child operators should also be closed.

Source

fn schema(&self) -> &[ColumnInfo]

Get the schema (column information) for this operator’s output.

Source

fn name(&self) -> &str

Get a descriptive name for this operator (for EXPLAIN).

Provided Methods§

Source

fn estimated_rows(&self) -> Option<usize>

Get an estimate of the number of rows this operator will produce.

Returns None if the estimate is not available. Used by the query planner for cost estimation.

Source

fn ordering(&self) -> OrderingProperty

Physical ordering guaranteed by this operator’s output.

Unknown is deliberately fail-closed: an executor must never discover ordering by rescanning the complete output merely to choose an algorithm.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§