(
scx: &StatementContext,
mut query: Query<Aug>,
lifetime: QueryLifetime,
)
| 129 | /// applying the returned `RowSetFinishing`. |
| 130 | #[mz_ore::instrument(target = "compiler", level = "trace", name = "ast_to_hir")] |
| 131 | pub 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 | /// |
no test coverage detected