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

Function plan_root_query

src/sql/src/plan/query.rs:131–182  ·  view source on GitHub ↗
(
    scx: &StatementContext,
    mut query: Query<Aug>,
    lifetime: QueryLifetime,
)

Source from the content-addressed store, hash-verified

129/// applying the returned `RowSetFinishing`.
130#[mz_ore::instrument(target = "compiler", level = "trace", name = "ast_to_hir")]
131pub fn plan_root_query(
132 scx: &StatementContext,
133 mut query: Query<Aug>,
134 lifetime: QueryLifetime,
135) -> Result<PlannedRootQuery<HirRelationExpr>, PlanError> {
136 transform_ast::transform(scx, &mut query)?;
137 let mut qcx = QueryContext::root(scx, lifetime);
138 let PlannedQuery {
139 mut expr,
140 scope,
141 order_by,
142 limit,
143 offset,
144 project,
145 group_size_hints,
146 } = plan_query(&mut qcx, &query)?;
147
148 let mut finishing = RowSetFinishing {
149 limit,
150 offset,
151 project,
152 order_by,
153 };
154
155 // Attempt to push the finishing's ordering past its projection. This allows
156 // data to be projected down on the workers rather than the coordinator. It
157 // also improves the optimizer's demand analysis, as the optimizer can only
158 // reason about demand information in `expr` (i.e., it can't see
159 // `finishing.project`).
160 try_push_projection_order_by(&mut expr, &mut finishing.project, &mut finishing.order_by);
161
162 if lifetime.is_maintained() {
163 expr.finish_maintained(&mut finishing, group_size_hints);
164 }
165
166 let typ = qcx.relation_type(&expr);
167 let typ = SqlRelationType::new(
168 finishing
169 .project
170 .iter()
171 .map(|i| typ.column_types[*i].clone())
172 .collect(),
173 );
174 let desc = RelationDesc::new(typ, scope.column_names());
175
176 Ok(PlannedRootQuery {
177 expr,
178 desc,
179 finishing,
180 scope,
181 })
182}
183
184/// Attempts to push a projection through an order by.
185///

Callers 7

plan_viewFunction · 0.85
describe_selectFunction · 0.85
plan_select_innerFunction · 0.85
plan_explain_timestampFunction · 0.85
describe_subscribeFunction · 0.85
plan_subscribeFunction · 0.85

Calls 11

transformFunction · 0.85
plan_queryFunction · 0.85
is_maintainedMethod · 0.80
finish_maintainedMethod · 0.80
relation_typeMethod · 0.80
collectMethod · 0.45
mapMethod · 0.45
iterMethod · 0.45
cloneMethod · 0.45
column_namesMethod · 0.45

Tested by

no test coverage detected