Expression

Trait Expression 

Source
pub trait Expression:
    Send
    + Sync
    + Debug {
Show 15 methods // Required methods fn evaluate(&self, row: &Row) -> Result<bool>; fn evaluate_fast(&self, row: &Row) -> bool; fn with_aliases( &self, aliases: &FxHashMap<String, String>, ) -> Box<dyn Expression>; fn prepare_for_schema(&mut self, schema: &Schema); fn is_prepared(&self) -> bool; fn clone_box(&self) -> Box<dyn Expression>; // Provided methods fn get_column_name(&self) -> Option<&str> { ... } fn can_use_index(&self) -> bool { ... } fn get_comparison_info(&self) -> Option<(&str, Operator, &Value)> { ... } fn get_and_operands(&self) -> Option<&[Box<dyn Expression>]> { ... } fn get_or_operands(&self) -> Option<&[Box<dyn Expression>]> { ... } fn get_like_prefix_info(&self) -> Option<(&str, String, bool)> { ... } fn collect_comparisons(&self) -> Vec<(&str, Operator, &Value)> { ... } fn is_unknown_due_to_null(&self, _row: &Row) -> bool { ... } fn as_any(&self) -> &dyn Any { ... }
}
Expand description

Expression trait for boolean expressions used in WHERE clauses

All expressions evaluate a row and return true/false to indicate whether the row matches the condition.

Required Methods§

Source

fn evaluate(&self, row: &Row) -> Result<bool>

Evaluate the expression against a row

Returns Ok(true) if the row matches, Ok(false) if it doesn’t, or an error if evaluation fails.

Source

fn evaluate_fast(&self, row: &Row) -> bool

Fast evaluation without detailed error handling

This is optimized for the hot path in query processing. Returns false on any error condition.

Source

fn with_aliases( &self, aliases: &FxHashMap<String, String>, ) -> Box<dyn Expression>

Create a copy of this expression with column aliases resolved

The aliases map maps alias names to original column names. If a column in the expression matches an alias, it will be replaced with the original name in the returned expression.

Source

fn prepare_for_schema(&mut self, schema: &Schema)

Prepare the expression for a specific schema

This pre-computes column indices for fast row access during evaluation. Should be called before evaluating many rows with the same schema.

Source

fn is_prepared(&self) -> bool

Check if this expression has been prepared for a schema

Source

fn clone_box(&self) -> Box<dyn Expression>

Clone the expression into a boxed trait object

Provided Methods§

Source

fn get_column_name(&self) -> Option<&str>

Get the column name this expression operates on (if single column)

Source

fn can_use_index(&self) -> bool

Check if this expression can potentially use an index

Source

fn get_comparison_info(&self) -> Option<(&str, Operator, &Value)>

Extract equality comparison info for index lookups

Returns (column_name, operator, value) if this is a simple comparison expression. This is used for primary key lookups and index lookups without requiring downcasting.

Source

fn get_and_operands(&self) -> Option<&[Box<dyn Expression>]>

Get child expressions if this is an AND expression

Returns Some with a slice of child expressions for AND expressions, None for other expression types. Used for expression pushdown optimization.

Source

fn get_or_operands(&self) -> Option<&[Box<dyn Expression>]>

Get child expressions if this is an OR expression

Returns Some with a slice of child expressions for OR expressions, None for other expression types. Used for OR index union optimization.

Source

fn get_like_prefix_info(&self) -> Option<(&str, String, bool)>

Get LIKE prefix info for index range scanning

For LIKE expressions with prefix patterns (e.g., ‘John%’), returns:

  • column_name: The column being matched
  • prefix: The prefix before the first wildcard (e.g., “John”)
  • negated: Whether this is NOT LIKE

Returns None for patterns with leading wildcards or non-LIKE expressions.

Source

fn collect_comparisons(&self) -> Vec<(&str, Operator, &Value)>

Collect all simple comparisons from this expression tree

For AND expressions, recursively collects comparisons from all branches. For comparison expressions, returns itself. Used for index pushdown optimization.

Source

fn is_unknown_due_to_null(&self, _row: &Row) -> bool

Check if the expression result would be UNKNOWN (NULL) for this row

In SQL’s three-valued logic, comparisons with NULL return UNKNOWN. For filtering purposes, UNKNOWN is treated as false. However, NOT(UNKNOWN) should remain UNKNOWN, not become true.

This method helps detect when a false result is actually UNKNOWN due to NULL, so that NOT expressions can handle three-valued logic correctly.

Default implementation returns false (expression is never unknown due to NULL).

Source

fn as_any(&self) -> &dyn Any

Get a reference to the expression as Any for downcasting

Trait Implementations§

Source§

impl Clone for Box<dyn Expression>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Implementors§