-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
distsql: support left outer lookup joins #25644
Conversation
Please ignore the first commit, which corresponds to #25628. |
0a958a4
to
b3c0481
Compare
Reviewed 9 of 9 files at r1. pkg/sql/distsqlrun/joinreader.go, line 399 at r2 (raw file):
pkg/sql/distsqlrun/joinreader.go, line 421 at r2 (raw file):
I didn't notice this in the other PR, but we'll need to fix this before merging it. Comments from Reviewable |
Review status: 6 of 11 files reviewed at latest revision, 2 unresolved discussions. pkg/sql/distsqlrun/joinreader.go, line 399 at r2 (raw file): Previously, petermattis (Peter Mattis) wrote…
I see, thanks. I replaced the set with a pkg/sql/distsqlrun/joinreader.go, line 421 at r2 (raw file): Previously, petermattis (Peter Mattis) wrote…
OK to handle this in a follow-up PR to keep the code reviews simpler? Comments from Reviewable |
b3c0481
to
fbb1cea
Compare
Review status: 3 of 18 files reviewed at latest revision, 2 unresolved discussions, some commit checks failed. pkg/sql/distsqlrun/joinreader.go, line 421 at r2 (raw file): Previously, solongordon (Solon) wrote…
Yes, fine to handle the batching in a follow-on PR, though I'm assuming it will be the next thing worked on. Not batching the primary index lookups is a huge hit on performance. pkg/sql/distsqlrun/joinreader.go, line 465 at r4 (raw file):
The downside to an Comments from Reviewable |
Review status: 3 of 18 files reviewed at latest revision, 3 unresolved discussions, some commit checks failed. pkg/sql/distsqlrun/joinreader.go, line 421 at r2 (raw file): Previously, petermattis (Peter Mattis) wrote…
Yup, coming up next. pkg/sql/distsqlrun/joinreader.go, line 465 at r4 (raw file): Previously, petermattis (Peter Mattis) wrote…
My thinking was that the Comments from Reviewable |
Review status: 3 of 18 files reviewed at latest revision, 1 unresolved discussion, some commit checks failed. pkg/sql/distsqlrun/joinreader.go, line 442 at r4 (raw file):
Not your code: do you know what the purpose of this is? Looks like pkg/sql/distsqlrun/joinreader.go, line 465 at r4 (raw file): Previously, solongordon (Solon) wrote…
I might be misreading the code, but it seems to me that they only way for Comments from Reviewable |
Review status: 3 of 18 files reviewed at latest revision, 2 unresolved discussions, some commit checks failed. pkg/sql/distsqlrun/joinreader.go, line 465 at r4 (raw file): Previously, petermattis (Peter Mattis) wrote…
I think there are two problems actually. The simpler one is that The more complicated one is the index lookup might return multiple index rows for one input row (say if the lookup is on only a prefix of the index columns.) In that case, Comments from Reviewable |
Review status: 3 of 18 files reviewed at latest revision, 2 unresolved discussions, some commit checks failed. pkg/sql/distsqlrun/joinreader.go, line 465 at r4 (raw file): Previously, solongordon (Solon) wrote…
Ah, got it. Thanks for the explanation. Might be useful to add some comments to make this clearer. Comments from Reviewable |
Review status: 3 of 18 files reviewed at latest revision, 2 unresolved discussions, some commit checks failed. pkg/sql/distsqlrun/joinreader.go, line 442 at r4 (raw file): Previously, petermattis (Peter Mattis) wrote…
Agreed, fixed. pkg/sql/distsqlrun/joinreader.go, line 465 at r4 (raw file): Previously, petermattis (Peter Mattis) wrote…
Will do. Comments from Reviewable |
cd088b2
to
5caa34d
Compare
The dependent PR has now been merged so this should be better reviewable now. PTAL. |
Code Reviewed 15 of 15 files at r5. pkg/sql/distsqlrun/joinreader.go, line 413 at r5 (raw file):
This gets called once per batch, right? You could save on allocations by pre-allocating this array once, in the setup code of the joinReader if it's a LeftOuterJoin, and zeroing it in this function. But I suppose in the common case, we would hope that Take it or leave it! pkg/sql/logictest/testdata/logic_test/lookup_join, line 230 at r5 (raw file):
You mentioned above that there are a few reasons why we can't track un-emitted rows, like when the index scan returns no rows vs the when index scan returns multiple rows. Are all of those cases tested sufficiently here? In my experience, outer joins have a lot of edge cases - we should make sure those are all tested for this new method of executing them. Comments from Reviewable |
Review status: all files reviewed at latest revision, 2 unresolved discussions. pkg/sql/distsqlrun/joinreader.go, line 413 at r5 (raw file): Previously, jordanlewis (Jordan Lewis) wrote…
Yeah, true. It's such a small allocation that I'm tempted to opt for more allocations over more code complexity. (Also now we know we could avoid a heap allocation by changing the length arg from pkg/sql/logictest/testdata/logic_test/lookup_join, line 230 at r5 (raw file): Previously, jordanlewis (Jordan Lewis) wrote…
Good call. I'll at least add one for the case where the lookup yields multiple rows, some emitted and some not. Comments from Reviewable |
5caa34d
to
635b43c
Compare
I found an annoying bug while adding tests. If a query had an ON filter on the right side of the join (the index), the left side would not be emitted if all the right rows were filtered out. This was due to the way filters were originally implemented in lookup joins. If the logical plan had a filter on the right side scan, it was just added as a post-processing filter on the joinReader. This meant rows got filtered out in the emit stage, too late for the left join logic to know. (Also it made an ON filter indistinguishable from a WHERE filter.) I handled this by specifying index filters explicitly in the |
61e8bda
to
b3ef8e2
Compare
Ouch, glad you caught that. On the plus side, as you note, the code is much easier to read now. Just making sure - Review status: 0 of 7 files reviewed at latest revision, all discussions resolved. pkg/sql/distsqlrun/joinreader.go, line 64 at r6 (raw file):
comment on this field would be nice. "indexFilter is the part of the ON condition that applies to the index being probed. Probed index rows that fail the indexFilter do not count as matches, and will not be emitted" or something. pkg/sql/logictest/testdata/logic_test/lookup_join, line 104 at r6 (raw file):
It's unfortunate that the new plan diagram doesn't contain the filter. I wouldn't want to hold up this PR on that fact, but I think we definitely need to reinstate the filter into the plan diagram by looking at the new filter expr you added in the diagram creation code. pkg/sql/logictest/testdata/logic_test/lookup_join, line 228 at r6 (raw file):
sorry, bell hooks! i didn't mean to kick you out. you belong in this pantheon. Comments from Reviewable |
Right, I tested out the Review status: 0 of 7 files reviewed at latest revision, 3 unresolved discussions. Comments from Reviewable |
Review status: 0 of 7 files reviewed at latest revision, 3 unresolved discussions. pkg/sql/logictest/testdata/logic_test/lookup_join, line 104 at r6 (raw file): Previously, jordanlewis (Jordan Lewis) wrote…
Yeah, agree, I'll make an issue for this. I actually originally added it but the column indices were confusing since they only referred to the right side, so I'll figure this out separately. Comments from Reviewable |
joinReader now supports left outer lookup joins. This required adding a new joinReaderSpec field for specifying the join type. I also needed to rejigger the way that the joinReader applies filters to the index in lookup joins. Previously this was handled by planning the filter as a post-processing step. However, when executing a left join we need to know earlier if an index row is filtered out so we can potentially emit an unmatched left row. Now the filter is specified explicitly in the JoinReaderSpec and applied immediately after the index lookup. Release note (sql change): The experimental lookup join feature now supports left outer joins.
b3ef8e2
to
e4d965a
Compare
Review status: 0 of 7 files reviewed at latest revision, 3 unresolved discussions. pkg/sql/distsqlrun/joinreader.go, line 64 at r6 (raw file): Previously, jordanlewis (Jordan Lewis) wrote…
Done. Btw it's not necessarily part of the ON cond. For inner joins it could be a WHERE condition which got pushed down. Comments from Reviewable |
bors r+ |
25644: distsql: support left outer lookup joins r=solongordon a=solongordon joinReader now supports left outer lookup joins. This required adding a new joinReaderSpec field for specifying the join type. Release note (sql change): The experimental lookup join feature now supports left outer joins. 25819: sql: Allow computed-ness to be removed from a column r=bobvawter a=bobvawter This change adds a new SQL command, `ALTER TABLE t ALTER COLUMN c DROP STORED`, which removes the `ComputedExpr` from that column's definition. This new command is in support of the generalized `ALTER COLUMN TYPE` feature. Release note (sql change): Stored, computed columns can be converted to regular columns by running `ALTER TABLE t ALTER COLUMN c DROP STORED`. 25844: sql: fix CANCEL/PAUSE/RESUME QUERIES/JOBS/SESSIONS with non-canonical types r=knz a=knz Fixes #25842 Prior to this patch, the various control statement were announcing via their type checking rules that they accepted non-canonical value types (i.e. wrapped via DOidWrapper to give them a different postgres type OID), however their execution code did not support non-canonical types and would panic if presented with such a value. This patch fixes the behavior by properly unwrapping the values. Release note (bug fix): CockroachDB no longer crashes if the control statements (`CANCEL`/`PAUSE`/`RESUME`) are given values using special PostgresSQL types (e.g. `NAME`). Co-authored-by: Solon Gordon <solon@cockroachlabs.com> Co-authored-by: Bob Vawter <bob@cockroachlabs.com> Co-authored-by: Raphael 'kena' Poss <knz@cockroachlabs.com>
Build succeeded |
joinReader now supports left outer lookup joins. This required adding a
new joinReaderSpec field for specifying the join type.
Release note (sql change): The experimental lookup join feature now
supports left outer joins.