Repository navigation
fix: strengthen filter pushdown and PK pruning - #25596
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Blocking findings:
- High - NaN breaks the new typed range merge and can prune valid rows.
compareBasePKValues now obtains a total order for floats through types.CompareValue/cmp.Compare, but SQL predicates and the block-search functions use IEEE comparisons, where every ordered comparison with NaN is false. For a FLOAT64 PK containing 1 and 2, pk >= CAST('NaN' AS DOUBLE) OR pk >= 1 is semantically pk >= 1; the OR merge treats NaN as the minimum bound and produces pk >= NaN, whose sorted search returns no offsets. I reproduced the exact [0,1] -> nil false-negative locally.
Please reject NaN bounds/IN members from PK pruning and fail open (infinity remains ordered), or introduce comparison/search semantics that preserve SQL's unordered behavior end to end. Add scalar AND/OR and IN regressions for float32/float64, covering sorted block, unsorted block, and workspace/memory paths.
- High - malformed IN type mismatch fails open on persisted blocks but filters out workspace rows.
validBlockPKSearchFilter accepts any non-null IN vector without checking filter.Oid == filter.Vec.GetType().Oid. buildBlockPKSearchFuncs later guards the block path by input type, but NewMemPKFilter uses the same weak validation and immediately encodes the mismatched vector. With an INT64 PK and a VARCHAR IN vector containing "1", the block path keeps all rows while MemPKFilter.FilterVector marks the matching INT64 workspace row as skipped. I reproduced skipMask.Count() == 1; malformed/unsupported data therefore still causes false-negative pruning.
Use one shared validation contract before either filter is constructed: IN must match the PK OID; PREFIX_IN must match the explicitly supported compound/varlen domain. A mismatch must make both block and memory filters invalid. Add a regression that executes both paths from the same malformed BasePKFilter.
- Blocking CI - static analysis rejects the four new
fmt.Errorfcalls.
pkg/vm/engine/readutil/pk_filter_base.go:401,428,432,441 violates MatrixOne's moerr rule. The arm64 SCA job already fails with Use moerr instead. Replace all four errors with appropriate moerr constructors and remove the fmt import.
Verified locally on head 09aa3b78f17ce32d3870a7cb6490a23105ffc25c:
- existing unit tests for
vector,readutil,logtailreplay, andsql/planpass (the standalonetypestest binary is blocked locally by the externallibusearch_c.dylibruntime path); go test -racepasses forreadutil,logtailreplay, andsql/plan;- the two focused negative regressions above both fail exactly as described;
- no additional leak, hang, or unbounded-growth issue was confirmed in the changed paths.
|
Addressed all blocking findings in
Additional unhappy-path closure:
Validation completed locally:
|
gouhongshen
left a comment
There was a problem hiding this comment.
Blocking findings on 6260242:
-
High — block-filter dedup can panic on a valid constant LiteralVec. blockFilterConstantSet accepts a vector whenever its logical Length matches LiteralVec.Len, then calls GetConstantValue once per logical row (expr_opt.go:420-428). A CONSTANT vector with logical length > 1 has exactly one physical value: MustFixedColNoTypeCheck intentionally returns a one-element slice for it (vector/tools.go:27-33). Therefore a list-vs-constant-Vec IN comparison indexes row 1 and panics during planning. Do not index a constant vector by its logical row: reduce it to its single value (or simply decline semantic dedup for constants), and add a regression using NewConstFixed(..., length=2) as LiteralVec.
-
High — the new global dedup pass regresses planner complexity from bounded linear passes to O(B^2 * K) for B block filters containing K-element IN predicates. Every pair first performs structural comparison; Expr_Vec takes the proto-marshalling fallback, then the semantic path unmarshals both vectors and rebuilds value maps (expr_opt.go:377-434, 510-520). This runs after index application for every scan. exprStructuralHash already exists specifically to bucket dedup without this repeated work (expr_hash.go:24-32), but is not used here. Precompute a canonical key once per filter and use hash buckets plus exact collision checking; add a large-IN / many-block-filter regression or benchmark.
-
P2 — sameGeneratedCompoundFilter treats two compound predicates as equal solely by operation and target column, without comparing RHS (expr_opt.go:475-492). It is used both while rebuilding stats block filters and in final dedup. The stated single-generated-predicate invariant is neither encoded nor checked, so two distinct compound IN/range predicates can silently lose one pruning constraint. Dedup must retain structural/semantic equality, or carry an explicit generation identity; please add a negative test with different compound RHS.
The PK-filter cleanup handoff in the latest commit was checked through reader reset/Close and looks sound. I am requesting changes for the planner panic and the avoidable planner-scale regression.
|
Addressed in 3a8fc3c.
Validation: |
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #25592
Fixes #25593
Fixes #25594
Fixes #25595
Related to #25588
What this PR does / why we need it:
Makes filter pushdown both safer and more effective across planner, block-filter, primary-key read-filter, partition-state, and iterator paths.
Validation
go test ./pkg/container/types ./pkg/container/vector ./pkg/vm/engine/readutil ./pkg/vm/engine/disttae/logtailreplay ./pkg/sql/plango test -race ./pkg/container/types ./pkg/container/vector ./pkg/vm/engine/readutil ./pkg/vm/engine/disttae/logtailreplaygo vet ./pkg/container/types ./pkg/container/vector ./pkg/vm/engine/readutil ./pkg/vm/engine/disttae/logtailreplay ./pkg/sql/planmake buildtest/distributed/cases/optimizer/blockfilter.test(55/55 passed)Performance notes
Selective composite-key and prefix-range queries can now prune more blocks and partition-state rows, while iterator upper bounds stop scans early. The implementation avoids per-row maps and unnecessary expression/vector copies in hot paths. Unresolved optimizer limitations that can still cause conservative fallback are tracked in #25588.