-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
opt: introduce optimizer expression trees and build them from TypedExprs #20557
Conversation
c17d0ab
to
1ed8c89
Compare
Review status: 0 of 9 files reviewed at latest revision, 6 unresolved discussions, all commit checks successful. pkg/sql/opt/expr.go, line 18 at r1 (raw file):
Either pull in some of the additional commentary from pkg/sql/opt/expr.go, line 19 at r1 (raw file):
I imagine we'll have to export pkg/sql/opt/opt_test.go, line 55 at r1 (raw file):
Time to copy over the help text from pkg/sql/opt/tree_print.go, line 30 at r1 (raw file):
The name pkg/sql/opt/tree_print.go, line 34 at r1 (raw file):
pkg/sql/opt/testdata/build-scalar, line 11 at r1 (raw file):
Are the 2 blank lines intentional? If yes, you're not consistent below. Comments from Reviewable |
I'm sorry but the commit message doesn't cut it. So:
|
What types? The types in the code should be documented in the code, not in commit messages.
The commit message already includes this paragraph:
|
That's a high bar to clear and not one that I would personally impose. |
Okay let me try that for you:
|
Also it is a mistake to place the It should go to |
Note that I insist that a competent reviewer must be able to check and understand this code without looking at opttoy and even know that it exists. There are a few more shortcomings, I have more comments coming soon. |
Where are we going to find such an engineer? Or are you going to wipe knowledge of There are definite shortcomings to the code and some design decisions that won't be clear without additional context. IMO, the hurdles you appear to be putting up will not be justified by the benefit (if any) they provide. On the downsides of the hurdles are significant. Clearly you feel very strongly about this and I imagine discussing in PR comments will be fraught. Let's find time to discuss in person. |
Reviewed 8 of 9 files at r1. pkg/sql/opt/build.go, line 1 at r1 (raw file):
This file belongs to a new package pkg/sql/opt/build.go, line 80 at r1 (raw file):
Document these two constants. pkg/sql/opt/expr.go, line 1 at r1 (raw file):
This file belongs to a new package pkg/sql/opt/expr.go, line 24 at r1 (raw file):
Extend the comment to remind the reader what are scalar properties. pkg/sql/opt/misc.go, line 19 at r1 (raw file):
This function should be added in a separate commit. pkg/sql/opt/operator.go, line 1 at r1 (raw file):
This file belongs to a new package pkg/sql/opt/operator.go, line 26 at r1 (raw file):
Every operator below pkg/sql/opt/operator.go, line 82 at r1 (raw file):
This is a misnomer. Make this pkg/sql/opt/operator.go, line 87 at r1 (raw file):
Detail what this struct is for in comments, as well as its members. pkg/sql/opt/operator.go, line 92 at r1 (raw file):
Explain this in comments. pkg/sql/opt/operator.go, line 103 at r1 (raw file):
Explain what this does and why it exists. pkg/sql/opt/scalar.go, line 26 at r1 (raw file):
You could define a scalar-specific pkg/sql/opt/scalar.go, line 40 at r1 (raw file):
the capitals here and below are inconsistent with the other operators. This needs to either be made consistent, or extensively documented both here and the commit message to justify the inconsistency. pkg/sql/opt/scalar.go, line 99 at r1 (raw file):
These various constructors must be commented / explained further. pkg/sql/opt/tree_print.go, line 1 at r1 (raw file):
This file belongs to a new package Comments from Reviewable |
@petermattis it's very clear to me that any of Jordan, Nathan, Toby or Justin must be able to review and understand this code without looking at opttoy. If they don't (or can't) we have a serious organisatory problem. |
I am happy to add more comments and make things more understandable (within reason).
I don't yet have a picture of how this should be divided into packages; I would rather keep things in one place for now and move things out later (not to mention that having |
Review status: 8 of 9 files reviewed at latest revision, 21 unresolved discussions, all commit checks successful. pkg/sql/opt/misc.go, line 19 at r1 (raw file): Previously, knz (kena) wrote…
Huh? These are all new files, and you chose this one-line-wrapper as something that needs its own commit? pkg/sql/opt/tree_print.go, line 30 at r1 (raw file): Previously, petermattis (Peter Mattis) wrote…
I was thinking of moving this to Comments from Reviewable |
ok we can think about separate packages later, I agree. |
Updated the commit message, PTAL. I will address the rest of the comments later today. Review status: 8 of 9 files reviewed at latest revision, 22 unresolved discussions, some commit checks pending. Comments from Reviewable |
FWIW I have read the code and I recognize in it what the RFC defines and that it aligns with the overall directions. @jordanlewis can you do quality control on it? |
1c1cc24
to
d49013e
Compare
Updated. Moved tree printer in Review status: 0 of 9 files reviewed at latest revision, 20 unresolved discussions. pkg/sql/opt/build.go, line 80 at r1 (raw file): Previously, knz (kena) wrote…
Done. pkg/sql/opt/expr.go, line 18 at r1 (raw file): Previously, petermattis (Peter Mattis) wrote…
Added a few more comments and TODO. A lot of the comments in opttoy pertain to things that are not here yet, like relational operators and auxiliary subexpressions. I don't want to talk about those yet, they will just be confusing for now. pkg/sql/opt/expr.go, line 19 at r1 (raw file): Previously, petermattis (Peter Mattis) wrote…
Yeah, I don't have a clear picture yet of what will be public. It doesn't need to be public for the index constraints thing so we should be good for now. pkg/sql/opt/expr.go, line 24 at r1 (raw file): Previously, knz (kena) wrote…
Done, and added a comment for the scalarProps type. pkg/sql/opt/operator.go, line 26 at r1 (raw file): Previously, knz (kena) wrote…
Done. pkg/sql/opt/operator.go, line 82 at r1 (raw file): Previously, knz (kena) wrote…
Done. pkg/sql/opt/operator.go, line 87 at r1 (raw file): Previously, knz (kena) wrote…
Done. pkg/sql/opt/operator.go, line 92 at r1 (raw file): Previously, knz (kena) wrote…
Done. pkg/sql/opt/operator.go, line 103 at r1 (raw file): Previously, knz (kena) wrote…
Done. pkg/sql/opt/opt_test.go, line 55 at r1 (raw file): Previously, petermattis (Peter Mattis) wrote…
Done. pkg/sql/opt/scalar.go, line 26 at r1 (raw file): Previously, knz (kena) wrote…
Done. pkg/sql/opt/scalar.go, line 40 at r1 (raw file): Previously, knz (kena) wrote…
I don't know any reason for this, made them all lowerase. pkg/sql/opt/scalar.go, line 99 at r1 (raw file): Previously, knz (kena) wrote…
Done. pkg/sql/opt/testdata/build-scalar, line 11 at r1 (raw file): Previously, petermattis (Peter Mattis) wrote…
Fixed. pkg/sql/opt/tree_print.go, line 34 at r1 (raw file): Previously, petermattis (Peter Mattis) wrote…
Done. Comments from Reviewable |
Review status: 0 of 9 files reviewed at latest revision, 22 unresolved discussions. pkg/sql/opt/build.go, line 145 at r3 (raw file):
Isn't the function already resolved by this point? I would have imagined we would need to resolve the function before typing. Answering my own question: looks like this is just the method you call to get the resolved function. I suppose we could add a pkg/sql/opt/scalar.go, line 86 at r3 (raw file):
Let's comment this field as long as you're on a commenting spree. pkg/sql/opt/scalar.go, line 105 at r3 (raw file):
pkg/sql/opt/testdata/build-scalar, line 45 at r3 (raw file):
Something seems messed up here. The about should read pkg/sql/opt/testdata/build-scalar, line 51 at r3 (raw file):
Very pretty! Comments from Reviewable |
@jordanlewis To expand on this request - it would be useful to get your review as someone who hasn't looked at opttoy in detail. There may be things which seem "obvious" to us but are not. There is no rush though. Thanks! |
Review status: 0 of 9 files reviewed at latest revision, 22 unresolved discussions, some commit checks pending. pkg/sql/opt/build.go, line 145 at r3 (raw file): Previously, petermattis (Peter Mattis) wrote…
We don't hold on to the FunctionDefinition in pkg/sql/opt/scalar.go, line 86 at r3 (raw file): Previously, petermattis (Peter Mattis) wrote…
Done. pkg/sql/opt/scalar.go, line 105 at r3 (raw file): Previously, petermattis (Peter Mattis) wrote…
Done. pkg/sql/opt/testdata/build-scalar, line 45 at r3 (raw file): Previously, petermattis (Peter Mattis) wrote…
Oh, this is bad, thank you for noticing! Fixed (and improved the treeprinter test). Comments from Reviewable |
edb158c
to
f4e3a75
Compare
Review status: 0 of 9 files reviewed at latest revision, 17 unresolved discussions, some commit checks failed. pkg/sql/opt/build.go, line 145 at r3 (raw file): Previously, RaduBerinde wrote…
We do hold onto the Comments from Reviewable |
Review status: 0 of 10 files reviewed at latest revision, 17 unresolved discussions. pkg/sql/opt/build.go, line 145 at r3 (raw file): Previously, petermattis (Peter Mattis) wrote…
Ah, got it. Done, PTAL Comments from Reviewable |
@RaduBerinde @knz I am planning to review this soon! |
a7b4cd3
to
1d7f79b
Compare
Reviewed 2 of 9 files at r4, 7 of 8 files at r5. pkg/sql/opt/build.go, line 76 at r5 (raw file):
Where did 16 come from? Why is that a good choice? pkg/sql/opt/expr.go, line 61 at r5 (raw file):
Don't you mean operatorClass interface? pkg/sql/opt/misc.go, line 19 at r5 (raw file):
This seems like a basic function that would be useful for other packages too. Maybe it belongs in util? (Maybe this was Raphael's intention in asking for a separate commit?) Anyway, misc.go isn't a very informative name.... pkg/sql/opt/opt_test.go, line 18 at r5 (raw file):
Why not just augment logic_test.go with the build-scalar command? It seems like a lot of this code is repeated from that file. pkg/sql/opt/opt_test.go, line 85 at r5 (raw file):
I thought currently only build-scalar was supported (this comment should be fixed) pkg/sql/opt/scalar.go, line 115 at r5 (raw file):
pkg/sql/opt/scalar.go, line 135 at r5 (raw file):
What should it refer to instead? pkg/sql/opt/testdata/build-scalar, line 51 at r3 (raw file): Previously, petermattis (Peter Mattis) wrote…
+1 pkg/sql/opt/testdata/build-scalar, line 6 at r5 (raw file):
Why is this test case repeated? pkg/util/treeprinter/tree_printer.go, line 52 at r5 (raw file):
pkg/util/treeprinter/tree_printer.go, line 114 at r5 (raw file):
Comments from Reviewable |
TFTR! Review status: 1 of 9 files reviewed at latest revision, 26 unresolved discussions. pkg/sql/opt/build.go, line 76 at r5 (raw file): Previously, rytaft wrote…
It's an arbitrary choice, just amortizing some allocations. pkg/sql/opt/expr.go, line 61 at r5 (raw file): Previously, rytaft wrote…
Done. pkg/sql/opt/opt_test.go, line 18 at r5 (raw file): Previously, rytaft wrote…
First, logic test is in a separate package and this test should be able to use unexported pkg/sql/opt/opt_test.go, line 85 at r5 (raw file): Previously, rytaft wrote…
Removed the comment (the supported commands are described in the beginning). pkg/sql/opt/scalar.go, line 115 at r5 (raw file): Previously, rytaft wrote…
Done. pkg/sql/opt/scalar.go, line 135 at r5 (raw file): Previously, rytaft wrote…
Removed the TODO pkg/sql/opt/testdata/build-scalar, line 6 at r5 (raw file): Previously, rytaft wrote…
Fixed pkg/util/treeprinter/tree_printer.go, line 52 at r5 (raw file): Previously, rytaft wrote…
Done. pkg/util/treeprinter/tree_printer.go, line 114 at r5 (raw file): Previously, rytaft wrote…
Done. pkg/sql/opt/misc.go, line 19 at r5 (raw file): Previously, rytaft wrote…
Sigh.. removed it. Comments from Reviewable |
Reviewed 2 of 9 files at r6, 7 of 7 files at r7. pkg/sql/opt/scalar.go, line 135 at r5 (raw file): Previously, RaduBerinde wrote…
It would help to keep the info about what pkg/util/treeprinter/tree_printer.go, line 52 at r5 (raw file): Previously, RaduBerinde wrote…
you changed it to Comments from Reviewable |
Adding a helper that can be used to print hierarchical structures (to be used with optimizer expressions). Release note: None
Review status: 1 of 9 files reviewed at latest revision, 18 unresolved discussions. pkg/sql/opt/scalar.go, line 135 at r5 (raw file): Previously, rytaft wrote…
Done. pkg/util/treeprinter/tree_printer.go, line 52 at r5 (raw file): Previously, rytaft wrote…
Sorry, fixed. Comments from Reviewable |
Reviewed 1 of 8 files at r8, 7 of 7 files at r9. Comments from Reviewable |
Reviewed 1 of 9 files at r4, 8 of 8 files at r8, 7 of 7 files at r9. pkg/sql/opt/expr.go, line 20 at r9 (raw file):
I would benefit from examples here as an outsider. I imagine a scalar expression is what our current "expression tree" represents. What is a relational expression precisely? Does it correspond to what we call a "statement" or is it more limited than that? Can you give some examples? I see below that you're planning to do that later - that's okay then. pkg/sql/opt/expr.go, line 22 at r9 (raw file):
Also would be nice to have examples here -of course they maintain properties. Nearly everything in software does! What is an expression property? pkg/sql/opt/expr.go, line 37 at r9 (raw file):
This is good - could you add a For example line to the other fields? When code gets this generic, I think it's very helpful to provide copious examples. pkg/sql/opt/operator.go, line 75 at r9 (raw file):
nit: For consistency with the camel cased ones above consider pkg/sql/opt/operator.go, line 95 at r9 (raw file):
What is Oh now I see it is around to get the number of operators! Please add a comment that this must come last. Comments from Reviewable |
This change brings in a subset of https://github.com/petermattis/opttoy/tree/master/v3 This change introduces: - the expr tree: cascades-style optimizers operate on expression trees which can represent both scalar and relational expressions; this is a departure from the way we represent expressions and statements (sem/tree) so we need a new tree structure. - scalar operators: initially, we focus only on scalar expressions. - building an expr tree from a sem/tree.TypedExpr. - opt version of logic tests See the RFC in cockroachdb#19135 for more context on the optimizer. This is the first step of an initial project related to the optimizer: generating index constraints from scalar expressions. This will be a rewrite of the current index constraint generation code (which has many problems, see cockroachdb#6346). Roughly, the existing `makeIndexConstraints` will call into the optimizer with a `TypedExpr` and the optimizer will return index constraints. Release note: None
TFTRs! Review status: all files reviewed at latest revision, 21 unresolved discussions, all commit checks successful. pkg/sql/opt/expr.go, line 20 at r9 (raw file): Previously, jordanlewis (Jordan Lewis) wrote…
Yeah, I will add more information when we support relational expressions. I figured it'd be confusing to explain things that aren't implemented. pkg/sql/opt/expr.go, line 22 at r9 (raw file): Previously, jordanlewis (Jordan Lewis) wrote…
Fixed the comment a bit, PTAL. I'm not sure what more to say. There will be more information when we support more kinds of expressions. pkg/sql/opt/expr.go, line 37 at r9 (raw file): Previously, jordanlewis (Jordan Lewis) wrote…
Added a line for children. The scalarProps type is pretty well defined. pkg/sql/opt/operator.go, line 75 at r9 (raw file): Previously, jordanlewis (Jordan Lewis) wrote…
This is consistent with pkg/sql/opt/operator.go, line 95 at r9 (raw file): Previously, jordanlewis (Jordan Lewis) wrote…
Done. This is a very common pattern. Comments from Reviewable |
This change brings in a subset of
https://github.com/petermattis/opttoy/tree/master/v3
This change introduces:
the expr tree: cascades-style optimizers operate on expression
trees which can represent both scalar and relational expressions;
this is a departure from the way we represent expressions and
statement (sem/tree) so we need a new tree structure.
scalar operators: initially, we focus only on scalar expressions.
building an expr tree from a sem/tree.TypedExpr.
opt version of logic tests
See the RFC in #19135 for more context on the optimizer.
This is the first step of an initial project related to the optimizer:
generating index constraints from scalar expressions. This will be a
rewrite of the current index constraint generation code (which has
many problems, see #6346). Roughly, the existing
makeIndexConstraints
will call into the optimizer with aTypedExpr
and the optimizer will return index constraints.
Release note: None