-
Notifications
You must be signed in to change notification settings - Fork 220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: introduce next-gen planner & optimizer #702
Conversation
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
- fix filter-true/false rule - remove incorrect pushdown for proj-filter Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Looks great to me! Will take a look soon. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally LGTM, thanks for your great work! It looks like the planner has not been fully integrated with the current query processing code path. Is there a tracking issue / TODO list for this?
impl std::fmt::Display for ColumnRefId { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
// TODO: now ignore database and schema | ||
write!(f, "${}.{}", self.table_id, self.column_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should make ColumnRefId more generic (e.g. Vec<String>
) so as to represent a column in subquery. e.g. subquery.table1.x
. I'll do this probably when refactoring binder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I gave up taking subquery into account. It's a little complicated. 🤯
Not yet. I'll create a tracking issue soon. A rough plan is to:
|
Sounds great. I'll start working on the new binder soon. Constructing executors from egg AST also doesn't look hard. |
Signed-off-by: Runji Wang <wangrunji0408@163.com>
ready to merge? |
Really blow my mind! |
Well, to be honest, I still had some concerns about the capability of DSL for a productional database system. https://twitter.com/fuyufjh/status/1509182041828790274?s=20&t=LBlWsQKaNTiU2QBXbDtGBg |
I think these kinds of DSL are suitable to describe the high-level structural trait of a rule. The rest detailed and complex logic is usually left to the native language. In fact, this combination is a common pattern in the Programming Language field (e.g. lex, yacc...). Because functional, declarative languages are good at language processing, while low-level procedural languages are more efficient. In this term, although Rust has pattern matching, we found it's not expressive enough for optimizer rules. So in my opinion, some kinds of metaprogramming are still needed, whatever it is macro, codegen, or DSL. PS. When I was writing the rules of this PR, I felt like I was writing LISP, not Rust. Then I began to realize why LISP is so powerful. Greenspun's tenth rule 😇 |
Thank you very much for your work! Looks amazing! |
This PR introduces a brand new optimizer based on egg, a powerful crate to build cascades-style optimizers in Rust.
With egg, we can define a complex rewrite rule using pattern matching in a few lines:
As a result, the new optimizer is super small but complete.
In about 600 lines of code (+ 200 lines for test), it implements the following optimizations:
and resolves two annoying problems in the old planner:
and maintaining them during optimization
As a comparison, the current planner + optimizer has nearly 4100 lines of code (+ 600 lines for test) with a similar feature set.
In my opinion, the egg framework is definitely a game changer for building database optimizers.
If it proves to work well in RisingLight, we can consider migrating it to RisingWave in the future.