Repository navigation
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? |
|
This pull request is merged. |
|
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: 0a41bce2ebe278d394c3343b2d8ea3ccb8a5e093
Assessment: request_changes
The guard fixes the reported residual-filter ordering, but it introduces a wrong-result regression when an IVF INCLUDE query also has a distance-range predicate. The retained SQL sort does not enforce a bound that the outer planner has already moved into reader parameters.
Model: gpt-6.1-terra / max
Session: 01a22b07-00b6-7e32-b0a1-3099d0b867c7 · slot 1 · generation 39
- P1
pkg/sql/plan/pushdown.go:837: A default-mode IVF query filters an included column and also constrains the same distance expression used by ORDER BY, for examplecategory = 20 AND l2_distance(v, '[0,0]') >= 5.
Impact: The indexed query can return rows that violate the distance predicate. An INSERT ... SELECT using that query can persist those incorrect rows.
Evidence: The outer IVF rewrite removes the distance predicate from the base scan and stores it in IndexReaderParam.DistRange. When this guard declines Top-K, the entries scan has no reader OrderBy or Limit, so reader.SetIndexParam returns without enforcing that range; the generated entries SQL contains no copy of it. In a one-list, one-CN MySQL probe, the pre-index and forced-scan controls returned IDs 5 and 6, while the candidate's IVF query returned 1 and 2. Replacing only pushdown.go with the base version returned 5 and 6 through IVF. Preserve an enforcing distance predicate when declining reader Top-K, for example in the entries SQL or another applicable filter.
Validation:
-
Private-runtime preflight and native-input audit passed; the current CGo library was built in the diagnostic directory.
-
The focused planner run selected and passed the committed guard tests and the unfiltered control. Its added distance-range assertion failed as described: checks/1796122138967344377-3.json and review-range.stdout.log.
-
The public SQL counterexample failed on the candidate: checks/1796122288565370798-3.json and review-public.stdout.log. The same fixture passed with the base planner file overlaid: checks/1796122392429227041-3.json and review-public-base.stdout.log.
-
The supplied CI snapshot reports successful Ubuntu unit tests and multi-CN BVT.
Limitations:
-
The SQL counterexample used an isolated one-CN embedded cluster; the base comparison overlaid only the changed planner implementation onto the assessed head.
-
The author's reported full planner and repeated mo-tester runs were not independently repeated.
|
Follow-up eb9c7d2: ordinary INCLUDE queries now qualify unresolved business predicates before the candidate limit. In a fresh default session on the final binary, IN (2,7) returned IDs 21,24,27,30; a genuine Go driver prepared group_id=? returned 21,24,27. Both INSERT SELECT destinations matched their unindexed controls on an independent connection. The full planner package and 42/42 statements of the SQL regression passed. The four explicitly requested single-round POST comparisons remain approximate; no ordinary-query mismatches in the 148-comparison matrix. No index rebuild or storage format change. |
LeftHandCold
left a comment
There was a problem hiding this comment.
Changes needed on 4.2-dev: the prior distance-range wrong-result finding is not closed by this head. The new residual fallback does help non-serializable conditions, but a serializable INCLUDE equality plus a bound on the same vector distance takes a different path. The ordinary business-row WHERE must remain enforced somewhere even when reader Top-K is declined.
The previous SQL replay and one-file control actually returned IDs 1,2 vs 5,6 on the preceding head. On this SHA I re-traced range extraction, residual fallback, entries SQL generation and the reader guard; I did not rerun that SQL. The 42/42 targeted BVT does not exercise this conjunction. Please add an ordinary, unhinted, single-list case asserting the actual IDs against the exact scan (including a committed INSERT … SELECT if possible), not just plan shape or row count.
|
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: eb9c7d220efc85e031a53c290ec0649063c0a554
Assessment: request_changes
The change reuses the existing prefilter and reader paths, and it fixes the tested business-filter cases. The previously reported distance-range regression remains open: an ordinary indexed query can return and persist rows that fail its WHERE clause.
Model: gpt-6.1-terra / max
Session: 01a22b07-00b6-7e32-b0a1-3099d0b867c7 · slot 1 · generation 39
- P1
pkg/sql/plan/pushdown.go:837: An ordinary IVF INCLUDE query has a serializable included-column equality and a distance predicate, for example category = 20 AND l2_distance(v, '[0,0]') >= 5, followed by ORDER BY that distance LIMIT 2.
Impact: The indexed SELECT can return rows outside the requested distance range, and INSERT ... SELECT can commit those incorrect rows. With one IVF list and no distance ties, the current head returned and persisted IDs [1,2] instead of [5,6].
Evidence: The outer rewrite extracts the distance predicate into IndexReaderParam.DistRange, but the new fallback at apply_indices_ivfflat.go:1355 only applies when a business predicate remains unserialized. This guard then declines reader Top-K for the included-column filter. The entries SQL does not independently apply the distance range, and reader.SetIndexParam ignores it without an OrderBy and Limit. The same public SQL probe passed with the two planner files overlaid from the frozen base. Preserve or enforce the range before the candidate limit, or decline the IVF rewrite for this shape, and cover the SELECT and committed INSERT results with a regression test.
Validation:
-
Private-runtime preflight passed; native prerequisites were built from inputs matching the frozen head.
-
Four focused planner tests passed, including the changed residual-filter and entries Top-K tests; planner-focused.log, receipt 1796133067214830792-4.json.
-
A one-CN public SQL probe passed the original equality, IN, prepared-parameter and committed INSERT cases; feature-probe.log, receipt 1796133151497208261-4.json.
-
The distance-range SQL probe failed on the current head with [1,2] versus the unindexed and forced controls [5,6]; range-probe.log, receipt 1796132735355634463-4.json. The same probe passed using frozen-base planner files; range-base.log, receipt 1796132844290646830-4.json.
-
git diff --check passed; receipt 1796133182012306488-3.json.
Limitations:
- The local SQL probes used a single embedded CN. Full mo-tester comparison, multi-CN behavior and performance were not independently rerun; the supplied local_validation list contains no receipts for the author-reported broader runs.
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #33585
What this PR does / why we need it:
On 4.2-dev, IVF INCLUDE could rank entries before applying the business filter. The nearest nonqualifying rows could consume an entire page. There was also a wrong-result path when an indexed query combined an included column with a distance range. In the one-list example from review, both SELECT and a committed INSERT … SELECT returned IDs 1 and 2 even though the WHERE clause required IDs 5 and 6.
The entries query now checks candidate eligibility before each LIMIT, including when reading exact primary-key chunks. The current request supplies the distance function and thresholds, so alternating L2 and squared L2 on a warm index preserves the correct units. SQL evaluates the distance predicate at its original precision. NULL vectors cannot take slots in the internal candidate query. Quantized or asynchronously maintained entries fall back to the original relational plan for extracted distance bounds. The planner retains the original WHERE on a declined rewrite.
Unfiltered queries and supported centroid-prefix probes keep the storage Top-K optimization. Queries with a residual distance or business condition may score more entries to produce the correct page. There is no additional SQL round trip or change to the index format.
The Ubuntu/x86 UT failure occurred during fixture writes in TestS3FSPrefetchBoundsStagedFullFiles. Setup formerly shared the worker's five-second deadline. The smaller fixture still fills all four slots and exercises two overflow objects. Each synchronization wait has its own deadline.
Verification
167a1a9199. A native service built from4b119ed955matched the pre-index reference for 9 SQL cases and 18 precision/quantization cases. A second connection saw committed IDs 5 and 6. EXPLAIN ANALYZE confirmed reader Top-K on the unfiltered query.The pre-existing default NULL ordering and signed-zero primary-key issues are tracked separately in #33586 and #33587.