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
Resolves #860: Try planning an IN predicate as an OR of equalities. #861
Resolves #860: Try planning an IN predicate as an OR of equalities. #861
Conversation
It occurred to me that I should probably catch the |
...rd-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/RecordQueryPlanner.java
Show resolved
Hide resolved
Re: DNF explosion, it looks like this part of the planner doesn't use the full normalization logic, although I'm not sure why. I added a test with a very large CNF (large enough to cause a stack overflow) to make sure this doesn't change. |
f1c7399
to
4ce8f79
Compare
...rd-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/RecordQueryPlanner.java
Outdated
Show resolved
Hide resolved
4ce8f79
to
4791a9d
Compare
…qualities. If the planner detects that it can't implement an IN predicate using an in-join (for example, because of an incompatible sort order), it tries to rewrite it as an OR predicate instead. This attempt is controlled by a configuration object, which also includes the IndexScanPreference.
4791a9d
to
0546106
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.
I think it's mostly cosmetic, except for some things I call out as "for a later day" which are maybe more work. I could be persuaded to drop essentially all of these.
...rd-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/RecordQueryPlanner.java
Outdated
Show resolved
Hide resolved
.../src/main/java/com/apple/foundationdb/record/query/plan/RecordQueryPlannerConfiguration.java
Show resolved
Hide resolved
...rd-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/RecordQueryPlanner.java
Show resolved
Hide resolved
...-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/planning/InExtractor.java
Show resolved
Hide resolved
|
||
// If we don't change this when shouldAttemptFailedInJoinAsOr() is true, then we _always_ pick the union plan, | ||
// rather than the in join plan. | ||
int score = getConfiguration().shouldAttemptFailedInJoinAsOr() ? 0 : 1; |
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.
Hmm, interesting. Should the logic in the join filter that chooses between the Union
and the InJoin
be changed then (maybe ignoring the score if we can't trust it?).
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.
Possibly. I'm a bit worried about doing so because I don't really know what the score
is trying to capture. If we think that's lower risk, I'm for it.
.../src/test/java/com/apple/foundationdb/record/provider/foundationdb/query/FDBInQueryTest.java
Outdated
Show resolved
Hide resolved
.../src/test/java/com/apple/foundationdb/record/provider/foundationdb/query/FDBInQueryTest.java
Outdated
Show resolved
Hide resolved
.../test/java/com/apple/foundationdb/record/query/plan/RecordQueryPlannerConfigurationTest.java
Outdated
Show resolved
Hide resolved
PR #861 added a new transformation to the RecordQueryPlanner that attempts to transform an IN predicate into an equivalent OR of equality predicates when the planner determines that it cannot implement the IN predicate as an IN-join because of an incompatible sort order. However, the equivalent OR predicate is too complex for the simple normalizer normalizeAndOr() if there are other predicates on the original filter. In this case, the predicates are not normalized and so the union planner is unable to produce the desired union plan. This change adds a more sophisticated normalizer to handle this case.
If the planner detects that it can't implement an IN predicate using an in-join (for example, because of an incompatible sort order), it tries to rewrite it as an OR predicate instead.
See #860 for a description of the specific problem that this solves.
The implementation is a bit hacky and ends up relying on pieces of the new planner to make decisions. This might not be great hygiene, but it seemed like the right tool for determining when to use one plan or another.