Skip to content

[4.1-dev] Fix nullable IN-list runtime semantics#25468

Open
LeftHandCold wants to merge 3 commits into
matrixorigin:4.1-devfrom
LeftHandCold:codex/fix-25346-null-in-runtime-41
Open

[4.1-dev] Fix nullable IN-list runtime semantics#25468
LeftHandCold wants to merge 3 commits into
matrixorigin:4.1-devfrom
LeftHandCold:codex/fix-25346-null-in-runtime-41

Conversation

@LeftHandCold

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #25346

Follow-up to #25426.

What this PR does / why we need it:

The previous zonemap fix made block pruning conservative for nullable IN lists, but the SQL path can still fail before row-level filtering. Planner constant folding converts IN list literals into a folded vector. Vector.InplaceSortAndCompact() sorts the vector payload without moving the null bitmap, so ('keep', NULL) can become a vector where the null bitmap no longer points at the same value. The runtime in operator then skips the wrong RHS slot while building its hash map, and WHERE k IN ('keep', NULL) can filter out matching keep rows.

This PR fixes the full path for 4.1-dev:

  • keeps folded nullable IN-list vectors unsorted/uncompacted so values and null bitmap stay aligned;
  • makes vectorized IN / NOT IN return SQL UNKNOWN for no-match rows when the RHS contains NULL;
  • keeps nullable folded vectors conservative in zonemap/readutil pruning instead of relying on sorted first/last entries;
  • adds tests for operator three-valued logic, folded predicate execution, nullable folded vectors in zonemap pruning, and varchar/fixed-type nullable zonemap AnyIn.

Validated with the issue-shaped SQL on a dev node:

SELECT COUNT(*) FROM t WHERE k IN ('keep', NULL);
-- 2

SELECT COUNT(*) FROM t WHERE k NOT IN ('zzz', NULL);
-- 0

Local checks:

go test ./pkg/sql/plan/function -count=1
go test ./pkg/sql/colexec -count=1
go test ./pkg/vm/engine/readutil -count=1
go test ./pkg/vm/engine/tae/index -count=1
go test ./pkg/sql/plan/rule -count=1
go test ./pkg/sql/plan -run 'Test.*Fold|Test.*In|Test.*Filter' -count=1

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working kind/test-ci size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants