Skip to content
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

Merged
merged 2 commits into from Nov 2, 2020

Conversation

seut
Copy link
Member

@seut seut commented Oct 27, 2020

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.

@seut seut requested review from mfussenegger and removed request for mfussenegger October 27, 2020 11:24
@seut seut marked this pull request as draft October 27, 2020 16:04
@seut
Copy link
Member Author

seut commented Oct 27, 2020

moved back to draft mode, as I completely forgot to add the filters to the execution (filter projections) 🤦

@seut seut force-pushed the s/pk-filter branch 2 times, most recently from 3b50f69 to 514fe79 Compare October 29, 2020 16:27
@seut seut marked this pull request as ready for review October 30, 2020 07:12
server/src/main/java/io/crate/planner/operators/Get.java Outdated Show resolved Hide resolved
server/src/main/java/io/crate/planner/operators/Get.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) {
Copy link
Member

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 ?

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member Author

@seut seut Oct 30, 2020

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.

Copy link
Member Author

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?

Copy link
Member

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 👍

@@ -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) {
Copy link
Member

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 ?

Copy link
Member Author

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?

Copy link
Member

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.
@seut seut added the ready-to-merge Let Mergify merge the PR once approved and checks pass label Nov 2, 2020
@mfussenegger
Copy link
Member

As a follow up - we should probably tweak the explain output so that the query part is visible?

@seut
Copy link
Member Author

seut commented Nov 2, 2020

As a follow up - we should probably tweak the explain output so that the query part is visible?

Ah good point, will do.

@mergify mergify bot merged commit ab5e0a4 into master Nov 2, 2020
@mergify mergify bot deleted the s/pk-filter branch November 2, 2020 15:51
seut added a commit that referenced this pull request Nov 20, 2020
Add the query symbol to the print output of the GET operators so
`explain` statements will show them.

Follow up of #10708.
seut added a commit that referenced this pull request Nov 20, 2020
Add the query symbol to the print output of the GET operators so
`explain` statements will show it.

Follow up of #10708.
seut added a commit that referenced this pull request Nov 20, 2020
Add the query symbol to the print output of the GET operators so
`explain` statements will show it.

Follow up of #10708.
seut added a commit that referenced this pull request Nov 20, 2020
Add the query symbol to the print output of the GET operators so
`explain` statements will show it.

Follow up of #10708.
seut added a commit that referenced this pull request Nov 20, 2020
Add the query symbol to the print output of the GET operators so
`explain` statements will show it.

Follow up of #10708.
mergify bot pushed a commit that referenced this pull request Nov 20, 2020
Add the query symbol to the print output of the GET operators so
`explain` statements will show it.

Follow up of #10708.
mfussenegger added a commit that referenced this pull request Jan 8, 2024
#10708 changed the EqualityExtractor
to allow in-exact matches, this change wasn't reflected by the update
and delete planner, until #14361
tried to fix it, but it didn't account for AND clauses without
references.
mergify bot pushed a commit that referenced this pull request Jan 8, 2024
#10708 changed the EqualityExtractor
to allow in-exact matches, this change wasn't reflected by the update
and delete planner, until #14361
tried to fix it, but it didn't account for AND clauses without
references.
mergify bot pushed a commit that referenced this pull request Jan 8, 2024
#10708 changed the EqualityExtractor
to allow in-exact matches, this change wasn't reflected by the update
and delete planner, until #14361
tried to fix it, but it didn't account for AND clauses without
references.

(cherry picked from commit 8251d26)
mergify bot pushed a commit that referenced this pull request Jan 9, 2024
#10708 changed the EqualityExtractor
to allow in-exact matches, this change wasn't reflected by the update
and delete planner, until #14361
tried to fix it, but it didn't account for AND clauses without
references.

(cherry picked from commit 8251d26)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-to-merge Let Mergify merge the PR once approved and checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PRIMARY KEY lookup with additional filters
2 participants