Module sql::plan::query[][src]

Expand description

SQL Querys are the declarative, computational part of SQL. This module turns Querys into HirRelationExprs - a more explicit, algebraic way of describing computation. Functions named plan_* are typically responsible for handling a single node of the SQL ast. Eg plan_query is responsible for handling sqlparser::ast::Query. plan_* functions which correspond to operations on relations typically return a HirRelationExpr. plan_* functions which correspond to operations on scalars typically return a HirScalarExpr and a ScalarType. (The latter is because it’s not always possible to infer from a HirScalarExpr what the intended type is - notably in the case of decimals where the scale/precision are encoded only in the type). Aggregates are particularly twisty. In SQL, a GROUP BY turns any columns not in the group key into vectors of values. Then anywhere later in the scope, an aggregate function can be applied to that group. Inside the arguments of an aggregate function, other normal functions are applied element-wise over the vectors. Thus SELECT sum(foo.x + foo.y) FROM foo GROUP BY x means adding the scalar x to the vector y and summing the results. In HirRelationExpr, aggregates can only be applied immediately at the time of grouping. To deal with this, whenever we see a SQL GROUP BY we look ahead for aggregates and precompute them in the HirRelationExpr::Reduce. When we reach the same aggregates during normal planning later on, we look them up in an ExprContext to find the precomputed versions.

Structs

This is used to collect aggregates and table functions from within an Expr. See the explanation of aggregate handling at the top of the file for more details.

Stores planned CTEs for later use.

A bundle of unrelated things that we need for planning Exprs.

The state required when planning a Query.

Common information used for DELETE and UPDATE plans.

Describes how to execute a SELECT query.

Enums

Specifies how long a query will live. This impacts whether the query is allowed to reason about the time at which it is running, e.g., by calling the now() function.

Functions

Cast a relation from one type to another using the specified type of cast.

Coerces a list of expressions such that all input expressions will be cast to the same type. If successful, returns a new list of expressions in the same order as the input, where each expression has the appropriate casts to make them all of a uniform type.

Evaluates an expression in the AS OF position of a TAIL statement.

Builds a plan that adds the default values for the missing columns and re-orders the datums in the given rows to match the order in the target table.

Plans a slice of expressions.

Plans an expression in a GROUP BY clause.

Plans a slice of ORDER BY expressions.

Plans an expression that appears in an ORDER BY or DISTINCT ON clause.

Plans a top-level query, returning the HirRelationExpr describing the query plan, the RelationDesc describing the shape of the result set, a RowSetFinishing describing post-processing that must occur before results are sent to the client, and the types of the parameters in the query, if any were present.

Plans a ROWS FROM expression.

Plans an expression coalescing multiple table functions. Each table function is followed by its row ordinality. The entire expression is followed by the coalesced row ordinality.

Plans a table function that appears alone, i.e., that is not part of a ROWS FROM clause that contains other table functions. Special aliasing rules apply.

Plans a table function.

Plans a SELECT query with an intrusive ORDER BY clause.

Resolves the name to a set of function implementations.

A general implementation for name resolution on AST elements.

Attempts to push a projection through an order by.