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

Resolves #860: Try planning an IN predicate as an OR of equalities. #861

Merged

Conversation

nschiefer
Copy link
Contributor

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.

@nschiefer
Copy link
Contributor Author

It occurred to me that I should probably catch the DNFTooLargeException in the asOr() branch, in case that gets thrown here.

@nschiefer
Copy link
Contributor Author

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.

@nschiefer nschiefer force-pushed the plan-in-as-or branch 2 times, most recently from f1c7399 to 4ce8f79 Compare March 25, 2020 15:10
…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.
@nschiefer nschiefer changed the base branch from master to fdb-record-layer-2.8.102 March 25, 2020 16:00
Copy link
Contributor

@alecgrieser alecgrieser left a 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.


// 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;
Copy link
Contributor

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?).

Copy link
Contributor Author

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.

@alecgrieser alecgrieser merged commit b109ede into FoundationDB:fdb-record-layer-2.8.102 Mar 25, 2020
nschiefer added a commit that referenced this pull request Apr 3, 2020
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants