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

Extracting negated IN filters #2790

Open
MMcM opened this issue Jun 28, 2024 · 1 comment
Open

Extracting negated IN filters #2790

MMcM opened this issue Jun 28, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@MMcM
Copy link
Contributor

MMcM commented Jun 28, 2024

FDBInQueryTest.testNotInQueryParameterBad has a filter

Query.not(Query.field("num_value_3_indexed").in("valueThrees"))

giving a plan

Scan(<,>) | [MySimpleRecord] | Not(num_value_3_indexed IN $valueThrees)

If we make this slightly more complicated, so that there is an applicable index

Query.and(
    Query.field("str_value_indexed").equalsParameter("valueStr"),
    Query.not(Query.field("num_value_3_indexed").in("valueThrees")))

it becomes

Index(MySimpleRecord$str_value_indexed [EQUALS $valueStr]) | Not(num_value_3_indexed IN $valueThrees)

along the same lines.

However, if we now enable allowNonSargedInBindings mode with

setMaxNumReplansForInToJoin(-1)

it becomes

Index(MySimpleRecord$str_value_indexed [EQUALS $valueStr]) | Not(num_value_3_indexed EQUALS $__in_num_value_3_indexed__0) WHERE __in_num_value_3_indexed__0 IN $valueThrees

which is wrong.

The fundamental problem is that at some point the InExtractor started believing that NotComponent was okay to descend through for the purpose of hoisting the IN list. This mistake was masked by its considering the broken plan but never returning it, on the grounds that it was more work than the residual predicate. But after #1999, with the proper configuration, it can now escape.

There are probably other expressions for which In extraction is not appropriate.

@MMcM MMcM added the bug Something isn't working label Jun 28, 2024
@normen662
Copy link
Contributor

Hi, I believe this is a duplicate of #1112.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants