MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / plan_order_by_exprs

Function plan_order_by_exprs

src/sql/src/plan/query.rs:2906–2927  ·  view source on GitHub ↗

Plans a slice of `ORDER BY` expressions. See `plan_order_by_or_distinct_expr` for details on the `output_columns` parameter. Returns the determined column orderings and a list of scalar expressions that must be mapped onto the underlying relation expression.

(
    ecx: &ExprContext,
    order_by_exprs: &[OrderByExpr<Aug>],
    output_columns: &[(usize, &ColumnName)],
)

Source from the content-addressed store, hash-verified

2904/// Returns the determined column orderings and a list of scalar expressions
2905/// that must be mapped onto the underlying relation expression.
2906pub(crate) fn plan_order_by_exprs(
2907 ecx: &ExprContext,
2908 order_by_exprs: &[OrderByExpr<Aug>],
2909 output_columns: &[(usize, &ColumnName)],
2910) -> Result<(Vec<ColumnOrder>, Vec<HirScalarExpr>), PlanError> {
2911 let mut order_by = vec![];
2912 let mut map_exprs = vec![];
2913 for obe in order_by_exprs {
2914 let expr = plan_order_by_or_distinct_expr(ecx, &obe.expr, output_columns)?;
2915 // If the expression is a reference to an existing column,
2916 // do not introduce a new column to support it.
2917 let column = match expr {
2918 HirScalarExpr::Column(ColumnRef { level: 0, column }, _name) => column,
2919 _ => {
2920 map_exprs.push(expr);
2921 ecx.relation_type.arity() + map_exprs.len() - 1
2922 }
2923 };
2924 order_by.push(resolve_desc_and_nulls_last(obe, column));
2925 }
2926 Ok((order_by, map_exprs))
2927}
2928
2929/// Plans an expression that appears in an `ORDER BY` or `DISTINCT ON` clause.
2930///

Callers 3

plan_query_innerFunction · 0.85
plan_select_from_whereFunction · 0.85
plan_subscribeFunction · 0.85

Calls 5

pushMethod · 0.45
arityMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected