fn plan_order_by_or_distinct_expr(
ecx: &ExprContext<'_>,
expr: &Expr<Aug>,
output_columns: &[(usize, &ColumnName)],
) -> Result<HirScalarExpr, PlanError>Expand description
Plans an expression that appears in an ORDER BY or DISTINCT ON clause.
The output_columns parameter describes, in order, the physical index and
name of each expression in the SELECT list. For example, [(3, "a")]
corresponds to a SELECT list with a single entry named “a” that can be
found at index 3 in the underlying relation expression.
There are three cases to handle.
- A simple numeric literal, as in
ORDER BY 1. This is an ordinal reference to the specified output column. - An unqualified identifier, as in
ORDER BY a. This is a reference to an output column, if it exists; otherwise it is a reference to an input column. - An arbitrary expression, as in
ORDER BY -a. Column references in arbitrary expressions exclusively refer to input columns, never output columns.