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
Add support for PK lookup if additional filters are combined by AND #10708
Conversation
moved back to draft mode, as I completely forgot to add the filters to the execution (filter projections) 🤦 |
3b50f69
to
514fe79
Compare
server/src/main/java/io/crate/execution/dsl/projection/EvalProjection.java
Outdated
Show resolved
Hide resolved
var toCollect = new LinkedHashSet<>(boundOutputs); | ||
Consumer<Reference> addRefIfMatch = ref -> { | ||
if (ref.ident().tableIdent().equals(tableRelation.relationName()) | ||
&& docKeyColumns.contains(ref.column()) == false) { |
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 also don't quite understand why this check is necessary. toCollect
is a set, so duplicates won't be added anyways?
Is this under the assumption that the symbol might not be needed because it is only used in the docKeys part? I'm not sure if that assertion is safe. Couldn't the query still use columns from docKeyColumns
?
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.
Maybe it would make sense to use something like SymbolVisitors.intersection(query, allPossibleTableOutputs, toCollect::add);
?
I think that would handle functions better. If you have a SELECT substr(x, ...) WHERE .. (pk = 1 AND substr(x, ..)
it wouldn't add x
to the outputs I think.
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.
Yep right, good catch. This logic which is intended to only add a filter projection when needed (other columns than DocKeys are part of the query) was not correct. I'll push a new safe logic.
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.
Pushed a fixup before I saw your recent suggestion with the intersection. If you still think I should go in this direction instead, please shout.
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.
And related to WHERE .. (pk = 1 AND substr(x, ..)
, as the RevVisitor
traverses the tree x
will be added to the outputs. This query works as expected. Do I miss anything?
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 thought something along the lines of
create table tbl (id int primary key, x int);
select x from tbl where id = 1 and (_seq_no = 1 or x = 1)
But that is forbidden.
Or
select x from tbl where id = 1 and (id = 3 or x = 1);
but that works. So all good 👍
server/src/main/java/io/crate/planner/statement/DeletePlanner.java
Outdated
Show resolved
Hide resolved
server/src/test/java/io/crate/integrationtests/SeqNoBasedOCCIntegrationTest.java
Outdated
Show resolved
Hide resolved
server/src/test/java/io/crate/integrationtests/WherePKIntegrationTest.java
Show resolved
Hide resolved
@@ -40,4 +42,14 @@ public static void assertThrows(Executable executable, Matcher<? super Throwable | |||
assertThat(t, matcher); | |||
} | |||
} | |||
|
|||
public static void assertThrows(Executable executable, Class<? extends Throwable> type, String subString) { |
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.
Isn't this the same as org.junit.jupiter.api.Assertions.assertThrows
?
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.
On the methods I know of/found, the given message is used as a prefix for a failure output instead of matching the thrown exception message. Or do other assertThrows
implementation exists which I'm not aware of?
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.
Oh right 👍
If filters are combined by AND operators in addition to filters on primary key columns, the optimized PK lookup plan is used now. Closes #10298.
As a follow up - we should probably tweak the |
Ah good point, will do. |
Add the query symbol to the print output of the GET operators so `explain` statements will show them. Follow up of #10708.
Add the query symbol to the print output of the GET operators so `explain` statements will show it. Follow up of #10708.
Add the query symbol to the print output of the GET operators so `explain` statements will show it. Follow up of #10708.
Add the query symbol to the print output of the GET operators so `explain` statements will show it. Follow up of #10708.
Add the query symbol to the print output of the GET operators so `explain` statements will show it. Follow up of #10708.
Add the query symbol to the print output of the GET operators so `explain` statements will show it. Follow up of #10708.
If filters are combined by AND operators in addition to filters
on primary key columns, the optimized PK lookup plan is used now.
Closes #10298.