Repository navigation
[4.2-dev] Require exact membership before scalar IVF PRE Top-K - #33514
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? |
|
Queue requested — the merge queue status continues in this comment ↓. |
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: cb68ff3d2eb4bb614725fb26ab25151088e665fd
Assessment: request_changes
The required-domain approach fixes the demonstrated scalar PRE Bloom collision by reusing the existing membership pipeline. Expanding that pipeline to scalar predicates also exposes two primary-key type defects and an 8 MiB limit that rejects previously successful queries. The exactness fix needs to preserve those cases.
Model: gpt-6.1-terra / max
Session: 01a22aff-bb68-7e31-ae71-ee4ab48ad9d0 · slot 0 · generation 45
-
P2
pkg/sql/plan/apply_indices_ivfflat.go:1703: A scalar IVF PRE query has more than 100 qualifying TIMESTAMP primary keys and runs in a non-UTC session time zone.
Impact: The exact membership predicate can identify different timestamps, silently omitting qualifying rows or returning an empty Top-K result.
Evidence: The newly required non-integer path formats timestamps in UTC in pkg/vectorindex/sqlexec/bloomfilter.go:292, but the internal SQL executor uses the session time zone at pkg/vectorindex/sqlexec/sqlexec.go:192. In an indexed SQL test with 101 qualifying keys, the candidate returned no rows at +08:00 while the unindexed reference and the original planner returned row 1; the UTC control also returned row 1. Generate literals in the executor's time zone or use a time-zone-independent exact representation. -
P2
pkg/sql/plan/apply_indices_ivfflat.go:1687: A scalar IVF PRE query has more than 100 qualifying DECIMAL(65,0) primary keys.
Impact: A valid query that previously completed now fails with "ivf_search: unsupported pk type 34".
Evidence: The mandatory non-integer path calls AppendVectorSQLLiteral, whose decimal cases cover Decimal64 and Decimal128 but not Decimal256. An indexed SQL test with 101 DECIMAL(65,0) keys failed on the candidate and returned the expected row with the original planner. Add Decimal256 support or use another exact membership representation for this supported key type. -
P2
pkg/sql/plan/apply_indices_ivfflat.go:1703: A scalar IVF PRE predicate produces non-integer primary keys whose encoded exact predicate exceeds 8 MiB.
Impact: Previously valid queries fail even when their former results were correct; the failure depends on the size of the eligible domain, not the requested Top-K.
Evidence: The PR discloses the existing exact-predicate limit, but this change applies it to scalar PRE queries that previously used the optional path. In an indexed SQL test with 45,000 qualifying VARCHAR keys of 197 bytes each and all rows eligible, the original planner and an unindexed reference returned row 1; the candidate failed with "exact primary-key filter exceeds 8388608 bytes". Preserve exact PRE semantics for broad domains, for example through an exact membership representation or a correct scan fallback.
Validation:
-
Private execution preflight passed: checks/1796038852598415064-3.json.
-
Focused planner, IVF membership, and exact-filter Go tests passed: checks/1796039167973089171-3.json and focused-recovered.log.
-
The indexed Bloom-collision SQL control passed on the candidate and reproduced the missing row with the original planner: checks/1796039934108922731-3.json, checks/1796039963293920985-3.json, and the corresponding ivf-sql-collision logs.
-
Indexed TIMESTAMP and DECIMAL SQL probes failed on the candidate and passed with the original planner overlaid on the same checkout: checks/1796039379626380184-3.json, checks/1796039531411409844-3.json, and the corresponding ivf-sql logs.
-
The 45,000-key SQL probe failed on the candidate and passed with the original planner: checks/1796039664634820636-3.json, checks/1796039696282510798-3.json, and the corresponding ivf-sql-large logs.
-
Receipt, log, source-fingerprint, baseline-file, and discussion-key checks are recorded in review-evidence-audit.json.
Limitations:
-
The SQL probes used an embedded single-CN cluster with one IVF list; this review did not run a multi-CN test.
-
The full changed BVT suite and the PR-reported full package suites were not independently rerun; their raw local-validation logs were not supplied.
-
The first focused test attempt failed during offline dependency setup. It passed after the assigned module cache was populated.
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: cfacc1a37a3b14a75376823c295c73398b9219ef
Assessment: approve
The fix uses the existing PRE membership and join path, with bounded exact-key batches and global ranking across batches. The earlier timestamp, Decimal256 and oversized-predicate findings are resolved. Broad string-key PRE queries have a substantial measured latency cost; the author disclosed that trade-off and the available mode=force alternative. POST remains the default unless PRE is selected or enabled for the session.
Model: gpt-6.1-terra / max
Session: 01a22b07-00b6-7e32-b0a1-3099d0b867c7 · slot 1 · generation 39
Validation:
-
Isolation preflight and native-input provenance checks passed: checks/1796056276209520461-3.json and checks/1796056355253226794-3.json.
-
Focused planner tests and the full ivfflat and sqlexec package tests passed: checks/1796057500675596033-3.json and checks/1796057437146452041-3.json.
-
Public SQL probes passed for the original Bloom collision, timestamp and decimal keys, a 45,000-key domain, BIT, binary, escaped string, UUID, composite and subnormal floating-point keys: checks/1796056838736568501-3.json, checks/1796057405570237404-3.json and checks/1796057586011458475-3.json.
-
An 8,200-key query with OFFSET returned the expected page through both CN entry points: checks/1796057227678003734-3.json.
-
git diff --check passed: checks/1796057449950484401-3.json.
Limitations:
-
In a single-CN, 45,000-row all-qualifying string-key fixture, median PRE latency was 32 ms with merge-base production-file overlays and 588 ms on the candidate; each median used five timed runs after warm-up. This is a workload-scoped regression, not a production latency estimate.
-
The two-CN probe did not establish that the internal entries scan used a remote route.
-
The author-reported mo-tester logs were not supplied, and the exact mo-tester fixtures were not independently rerun. The separate volatile-predicate short-page issue is pre-existing and tracked in #33531.
🚫 Left the queue · pull request dequeued17 min in the queue, with no time running CI. So far
Reason Pull request #33514 has been dequeued Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.
To get back in the queue
Merge conditions not met when it left the queue
Tick the box to put this pull request back in the merge queue (same as
2 merge conditions met
Times in UTC · dashboard · how the merge queue works |
## What type of PR is this? - [x] BUG - [x] Improvement ## Which issue(s) this PR fixes: issue #33549 ## What this PR does / why we need it: #33514 established exact IVF PRE membership before ranking. On wide VARCHAR primary keys, it also expanded complete typed key vectors into SQL literals and ran the optimizer and entries scan for every list of literals. The optimizer accounted for 54% of sampled CPU in the 8,193-key reproduction. The inner executor also returned all matching entries before the Go merge took the Top-K. - Send bounded primary-key vectors through prepared parameters. Evaluate exact membership before the SQL Top-K, then merge up to LIMIT + OFFSET candidates per chunk across all lists. - Bind compact, sorted key sets through the existing typed IN expression when the column's equality and ZoneMap ordering support it. Preserve pruning on selective queries. - Keep the caller's statement snapshot and observe pipeline cancellation. Publish the merged keys and aligned INCLUDE values after all chunks succeed. Remove the superseded literal conversion and predicate batching. ### Validation Local Linux amd64 measurements against `34b63d7261`, two runs per side, eight timed samples per mode and key count per run. Each query returned the expected Top-10. Values are ranges of the run medians in milliseconds. | Eligible 1,021-byte keys | Base PRE | PR PRE | | ---: | ---: | ---: | | 8,192 | 231–260 | 30–32 | | 8,193 | 242–276 | 22.8–23.2 | FORCE remained in the 1.4–2.0 ms range. With persisted 48,000-row controls, the 2-key BIGINT median was 1.58–2.07 vs 1.59–1.61 ms. The 2-key VARCHAR median was 1.57–1.72 vs 1.73–1.92 ms, with overlapping sample ranges. The 100-key BIGINT and VARCHAR controls retained block pruning and the 5,000-key integer control retained docfilter. - 507 assertions passed across 11 IVF BVT cases, including a binary-key page spanning chunks with OFFSET, excluded nearer rows and an empty domain. - A two-CN native run crossed the byte budget with 17 MiB of binary keys and matched an independent order and page oracle. Transactional visibility and rollback checks passed. - Local UT race across eight packages, gofmt, go vet and diff-scoped golangci passed. The pinned molint diagnostics match the base.
What type of PR is this?
Which issue(s) this PR fixes
Fixes #33504 on 4.2-dev. Separate from the flush/replay problem in #33149.
What this PR does / why we need it
Scalar PRE membership is a correctness condition, not an optional optimization: a Bloom false positive can take the place of an eligible row before Top-K. Keep exact membership for this domain. In particular, preserve the original scalar and vector predicates when producing eligible keys. A sync IVF candidate implies the direct vector IS NOT NULL test, not arbitrary predicates mentioning that vector.
The follow-up fixes the review findings on cb68ff3:
Verification
Floating PK review follow-up (cfacc1a)
The previous revision could turn a tiny DOUBLE into zero or overflow Decimal256 for a large DOUBLE when parsing bare fixed-point PK literals. Encode the shortest round-trip text for the source width as a quoted string explicitly cast to FLOAT/DOUBLE. No change to batching, ranking, or storage.
Same SQL on 1944c90 vs the fix: 171 eligible out of 340 distinct keys, all four lists probed. Small DOUBLE: unhinted PRE returned zero rows in 5/5 trials, now IDs 1–10 in 5/5; large negative DOUBLE: error 20301 in 5/5, now IDs 1–10 in 5/5. On a new connection after COMMIT, the small-DOUBLE insert-select changed from an empty destination to exactly IDs 1–10. A seven-table differential run covering FLOAT, DOUBLE, adjacent representable keys, and 100/101/171/340 candidates passed all 36 query and 7 committed-readback checks. The updated repository SQL regression failed 2 assertions on the old revision and passed 46/46 twice on the fix; full sqlexec/ivfflat/plan tests, incremental lint, vet and binary build passed. The independent, pre-existing volatile-predicate short page is tracked in #33531.
Release trade-off
Exact string PRE is still not performance-neutral. On the fixed build, a small in-memory-like test with almost every row eligible and 1,021-byte keys gave median 289 / 302 ms for 8,192 / 8,193 keys vs 9.9 / 9.8 ms for the same query on the exact relational path (single CN, 3 vCPU limit, six alternating timed trials after warm-up, identical ordered results). This is a path comparison, not a before/after throughput claim. For very broad domains, a per-query
BY RANK WITH OPTION 'mode=force'selects the exact relational alternative. No assertion of multi-CN or production performance certification.