-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Optimize key-range queries in pull queries (#6105) #7993
Conversation
Not ready for review |
b1df1da
to
776d97a
Compare
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.
Thanks, @patrickstuedi !
I has a few questions for you.
ksqldb-engine/src/main/java/io/confluent/ksql/planner/plan/KeyConstraint.java
Outdated
Show resolved
Hide resolved
...rc/main/java/io/confluent/ksql/execution/streams/materialization/ks/KsMaterializedTable.java
Outdated
Show resolved
Hide resolved
ksqldb-engine/src/main/java/io/confluent/ksql/physical/pull/PullPhysicalPlan.java
Show resolved
Hide resolved
2f7de81
to
a3d59b4
Compare
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.
Looking good. Just had a handful of comments.
ksqldb-engine/src/main/java/io/confluent/ksql/physical/pull/PullPhysicalPlan.java
Show resolved
Hide resolved
ksqldb-engine/src/main/java/io/confluent/ksql/physical/pull/PullPhysicalPlan.java
Show resolved
Hide resolved
ksqldb-engine/src/main/java/io/confluent/ksql/physical/pull/PullPhysicalPlanBuilder.java
Outdated
Show resolved
Hide resolved
...engine/src/main/java/io/confluent/ksql/physical/pull/operators/KeyedTableLookupOperator.java
Outdated
Show resolved
Hide resolved
...engine/src/main/java/io/confluent/ksql/physical/pull/operators/KeyedTableLookupOperator.java
Show resolved
Hide resolved
ksqldb-engine/src/main/java/io/confluent/ksql/planner/plan/QueryFilterNode.java
Outdated
Show resolved
Hide resolved
ksqldb-engine/src/main/java/io/confluent/ksql/planner/plan/QueryFilterNode.java
Outdated
Show resolved
Hide resolved
ksqldb-engine/src/main/java/io/confluent/ksql/planner/plan/QueryFilterNode.java
Outdated
Show resolved
Hide resolved
...engine/src/main/java/io/confluent/ksql/physical/pull/operators/KeyedTableLookupOperator.java
Show resolved
Hide resolved
ksqldb-engine/src/main/java/io/confluent/ksql/physical/pull/PullPhysicalPlan.java
Show resolved
Hide resolved
a3d59b4
to
31840ef
Compare
...ne/src/test/java/io/confluent/ksql/physical/pull/operators/KeyedTableLookupOperatorTest.java
Show resolved
Hide resolved
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.
Thanks @patrickstuedi! Reviewed it out of interest :) left some comments, none are blockers
ksqldb-engine/src/main/java/io/confluent/ksql/planner/plan/QueryFilterNode.java
Outdated
Show resolved
Hide resolved
ksqldb-engine/src/main/java/io/confluent/ksql/planner/plan/QueryFilterNode.java
Outdated
Show resolved
Hide resolved
ksqldb-engine/src/main/java/io/confluent/ksql/physical/pull/PullPhysicalPlan.java
Show resolved
Hide resolved
ksqldb-engine/src/test/java/io/confluent/ksql/planner/plan/QueryFilterNodeTest.java
Outdated
Show resolved
Hide resolved
...ne/src/test/java/io/confluent/ksql/physical/pull/operators/KeyedTableLookupOperatorTest.java
Show resolved
Hide resolved
10838f5
to
6cbccba
Compare
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.
This LGTM! You should wait for @AlanConfluent or @vvcephei's +1 as well as they have a bit more context into the code than I do.
ksqldb-engine/src/main/java/io/confluent/ksql/physical/pull/PullPhysicalPlanBuilder.java
Outdated
Show resolved
Hide resolved
ksqldb-engine/src/main/java/io/confluent/ksql/planner/plan/QueryFilterNode.java
Outdated
Show resolved
Hide resolved
...ional-tests/src/test/resources/rest-query-validation-tests/pull-queries-with-range-scan.json
Outdated
Show resolved
Hide resolved
...ional-tests/src/test/resources/rest-query-validation-tests/pull-queries-with-range-scan.json
Outdated
Show resolved
Hide resolved
...-streams/src/main/java/io/confluent/ksql/execution/streams/materialization/ks/KsLocator.java
Outdated
Show resolved
Hide resolved
81476e0
to
194f27d
Compare
ksqldb-engine/src/main/java/io/confluent/ksql/planner/plan/QueryFilterNode.java
Outdated
Show resolved
Hide resolved
ksqldb-engine/src/main/java/io/confluent/ksql/planner/plan/QueryFilterNode.java
Show resolved
Hide resolved
@@ -447,10 +444,49 @@ public Void visitComparisonExpression( | |||
final Object key = resolveKey(other, col.get(), metaStore, ksqlConfig, node); | |||
keyContents[col.get().index()] = key; | |||
seenKeys.set(col.get().index()); | |||
operatorType = node.getType(); |
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.
You're saying that currently, if we have a multi-column key, we can't do table-scan queries today? It seems like we ought to have a test for that kind of thing. It also seems like that restriction isn't strictly necessary.
I didn't meant to imply that. Table scan should work for this today. The validator above will check to see if any operation isn't an "=" and potentially make it a scan if it is. Currently, only if they're all "=" will it skip a table scan and do a key lookup. To handle range queries, this all still holds true, but we can additionally carve out the case of a single key column with range operator from the cases that were being handled by table scan, and now handle that by range query.
...ional-tests/src/test/resources/rest-query-validation-tests/pull-queries-with-range-scan.json
Show resolved
Hide resolved
...ional-tests/src/test/resources/rest-query-validation-tests/pull-queries-with-range-scan.json
Show resolved
Hide resolved
@@ -447,10 +444,49 @@ public Void visitComparisonExpression( | |||
final Object key = resolveKey(other, col.get(), metaStore, ksqlConfig, node); | |||
keyContents[col.get().index()] = key; | |||
seenKeys.set(col.get().index()); | |||
operatorType = node.getType(); |
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 believe the current code, if you have multiple key columns, will not behave correctly for a query like this:
KEY1 < 10 AND KEY2 = 5
operatorType will be set to the latest operator seen in the AST traversal, which is equals. It will, based on that, assume they're all equality, which was a simplifying assumption we could make before because we only allowed equality, but now isn't quite accurate. I think the current code would just do an equality lookup rather than range operator on one column. If we see this intermixing of operators, we should just fall back on table scan.
To keep track of that, I think we need to keep track of all of the operators. Only if they're all "=" can the lookup operator be equal. I think intermixing is a table scan and if it's a single column key, then range operators can result in lookup operators that are range. My comments above were meant to say that even if we have all "<" for a multi column key, we wouldn't want to do a range scan operation since it wouldn't make sense.
At the moment multi key columns only work for equality, so other operators should throw an error in that case.
I should have said fall back on table scan.
ksqldb-engine/src/main/java/io/confluent/ksql/physical/pull/PullPhysicalPlan.java
Show resolved
Hide resolved
2d78bd7
to
870ffbc
Compare
I think I commented on a version that is the same as your latest, but not after your rebase by mistake. This looks good. I don't think you handled windowed tables yet. If you're bold, you can try sticking it in this PR, but it would also be fine to do it in a followup. |
77798d4
to
4940bb8
Compare
implementation of KLIP-54
4940bb8
to
d7926fc
Compare
Description
Use range interface in state store for range pull queries, instead of doing a table scan
Testing done
no testing yet
Reviewer checklist