sql: Refactor MapFilterProject, MfpPlan, and SafeMfpPlan to have parameter with trait#36759
Conversation
|
Triggered the random query subset of Nightly: https://buildkite.com/materialize/nightly/builds/16607 |
ggevay
left a comment
There was a problem hiding this comment.
LGTM, if Nightly is green
| expr.visit_pre(|e| { | ||
| if let MirScalarExpr::Column(i, _name) = e { | ||
| reference_count[*i] += 1; | ||
| expr.visit_pre(&mut |e| { |
There was a problem hiding this comment.
Minor thing: originally, this was MSE's visit_pre, which is written iteratively (the worklist stuff) to avoid recursion limit issues, while the new code is calling the Visit trait's visit_pre, which is Stacker-based. So, we now could newly panic on a recursion limit error. I'm wondering if the Visit trait's implementation could also be changed to be iterative.
(And the same at the below visit_pre call.)
There was a problem hiding this comment.
There are a bunch of deprecated things here... is there any reason not to move everything to iterative work?
There was a problem hiding this comment.
#36852 takes a cut at iterative visitors. This took me longer than I expected, mostly because post-order mutable traversal requires unsafe rust.
In the meantime, I made it so we can override visit_pre. It should go away once we have the iterative refactor, though.
…t to indicate necessary interface
88e78df to
14f9369
Compare
|
I'm not sure this is important enough to be considered a bug, but it's definitely a regression, the query worked fine before, now errors: with this .td file: |
|
Thanks, @def- ! We'll fix this as a followup, as part of some more visitor changes. |
|
Unless things are different in SLT from TD, I think this is a bug in the parser. Stack frame courtesy #36888. |
|
Oops, you're right, this already failed before! My bad. |
…meter with trait (#36759) ### Motivation Second PR pulled from #36544. ### Description `MapFilterProject` (and its friends, `MfpPlan` and `SafeMfpPlan`---the "MFP" family) are used at both the MIR and LIR level. To separate LIR cleanly from MIR, we need to be able to work with MFPs at both levels. This change parameterizes these types and introduces a trait `OptimizableExpr` that allows us to work independently of the MIR type. It is not the _prettiest_ trait, but I don't see how to work around this (without a much more intensive overhaul of how we process MFP-like structures in LIR). See also: https://linear.app/materializeinc/issue/SQL-319/mfp-like-structures-in-lir-are-optimized-late. ### Verification Pure refactor, CI green.
|
No worries! Absolutely could have been me. 😁 If this is something we'd like to keep track of, would it make sense to keep a file of known failing (but interesting and maybe eventually shouldn't fail) tests? |
|
We have bugs for a bunch of them on github's database-issues. No one seems to have cared much, even when they regressed in the past. |
### Motivation Closes MaterializeInc/database-issues#3733. Closes MaterializeInc/database-issues#3516. #36759 (comment) MaterializeInc/database-issues#9996 ### Description Changes `VisitChildren` to have `children()` and `children_mut()` functions. Changes `Visitor` to use these for iterative traversals. NB that mutable post-traversal requires unsafety: we need an `&mut` for the children and an `&mut` for the parent when we're done. This is sound---Rust allows it when your stack is the call stack, but not your own data structure. So: this is somewhat unsavory code. ### Verification Green CI. NB maintaing safety in `VisitChildren` means slightly changing visit order: if we're going to work via `children_mut()`, we can no longer yield all subqueries before the term itself. This seems to have affected precisely one SLT, which I've rewritten.
Motivation
Second PR pulled from #36544.
Description
MapFilterProject(and its friends,MfpPlanandSafeMfpPlan---the "MFP" family) are used at both the MIR and LIR level. To separate LIR cleanly from MIR, we need to be able to work with MFPs at both levels.This change parameterizes these types and introduces a trait
OptimizableExprthat allows us to work independently of the MIR type. It is not the prettiest trait, but I don't see how to work around this (without a much more intensive overhaul of how we process MFP-like structures in LIR). See also: https://linear.app/materializeinc/issue/SQL-319/mfp-like-structures-in-lir-are-optimized-late.Verification
Pure refactor, CI green.