Repository navigation
fix: use JSON value identity in window partitions and correlated LIMIT - #31681
Conversation
Window PARTITION BY feeds compare their keys through pkg/compare.New, which fell back to a raw-byte strCompare for T_json, and the window operator's internal detector reused bytesPartition for the same type. JSON 1 and 1.0 therefore split window partitions (wrong ROW_NUMBER, COUNT and SUM), and the correlated pagination rewrite, which rejoins a ROW_NUMBER over the correlation keys by JSON equality, returned multiple rows per outer row. Both wrong results persisted through INSERT SELECT. Both identity paths now reuse the JSON value-identity detector that ORDER BY already applies: New() returns jsonCompare for T_json (matching NewOrder and the SQL = operator), and partition.Partition routes T_json to jsonOrderPartition. NULL/const-null/desc/cross-vector/ordinary-type contracts stay on the shared nullsCompare machinery and are locked by tests. Adds the distributed case json_value_identity_window_31636 with golden, covering window ROW_NUMBER/COUNT/SUM, correlated LIMIT 1 and OFFSET 1, INSERT SELECT persistence of both families, number spellings, objects, arrays and NULL, non-JSON controls, duplicate-PK failure atomicity and same-connection reuse after the error. Fixes #31636
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? |
|
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: d25dd030f018ee11b8bf0472058a1892723ec9e8
Assessment: approve
The change consistently applies JSON value identity across the affected partition paths. No actionable findings remain.
Model: gpt-6-astra / xhigh
Session: 01a13dcf-1517-7f90-b3f9-c5f9f9e7031b · slot 0 · generation 1
Validation:
-
All four owning/consumer packages passed: 937 named test/subtest results, with no failures or skips.
-
Independent boundary probe passed for NULL handling, selector order, accumulated boundaries and hash/comparator agreement.
-
Comparison benchmark completed with zero allocations for both JSON cases.
-
Preflight, native build and source/receipt/log audit passed. validation-audit.json retains the evidence mapping; source remained unchanged.
Limitations:
-
Public SQL validation relies on supplied BVT reports and successful frozen-head CI; raw BVT logs were unavailable and BVT was not rerun locally.
-
The comparison benchmark does not establish end-to-end query performance.
🚫 Left the queue1 h 5 min in the queue, with no time running CI. So far
Reason Pull request #31681 has been merged manually at d950fdc Hint You were too fast! Tick the box to put this pull request back in the merge queue (same as
Times in UTC · dashboard · how the merge queue works |
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #31636
What this PR does / why we need it:
Two SQL-visible symptoms came from comparing JSON partition keys by raw bytes:
PARTITION BYa JSON column split SQL-equal values:1and1.0landed in different window partitions and returned wrongROW_NUMBER,COUNTandSUM.ORDER BY ... LIMIT 1subquery, rewritten asROW_NUMBERover the correlation keys and joined back by JSON equality, returned multiple rows per outer row.Both wrong results persisted through
INSERT SELECT. Root cause: the non-ORDER comparatorpkg/compare.New()fell back to a raw-bytestrCompareforT_json(the colexec partition operator uses it to split window feeds), andpkg/partition.Partition()routedT_jsontobytesPartitionfor the window operator's internal identity detector.Fix: both paths now reuse the JSON value-identity detector that ORDER BY already applies (
jsonCompare/jsonOrderPartition), matching the SQL=operator and GROUP BY / DISTINCT semantics. NULL / const-null / desc / cross-vector / ordinary-type contracts stay on the sharednullsComparemachinery and are locked by tests;varcharkeeps byte identity.Adds the distributed BVT case
json_value_identity_window_31636(+ golden) covering window ROW_NUMBER/COUNT/SUM, correlated LIMIT 1 and LIMIT 1 OFFSET 1, real SELECT plus INSERT SELECT persistence for both families, number spellings (1,1.0,1e0), objects, arrays and NULL, non-JSON decimal/varchar controls, duplicate-PK failure atomicity and same-connection reuse after the error.Validation
run.sh -m run -n -g -o -i json_value_identity_window_31636 -r 100) against a fresh isolated instance:TOTAL: 33, SUCCESS: 33, SUCCESS RATE: 100%, exit code 0; the golden file is byte-stable before and after the run; the in-caseDuplicate entryerror occurs on the same JDBC connection and the following statements still pass (connection reuse).S1yields 11 rows, and the correlated INSERT hitsERROR 1062because the multi-row rewrite violates the primary key); fixed main returns SQL-correct values everywhere and the INSERT persists exactly 6 rows.81082d34: 937 tests green across the four owning packages (pkg/compare,pkg/partition,pkg/sql/colexec/partition,pkg/sql/colexec/window) via the CGo test wrapper, exit code 0.go vet,molint check,golangci-lint runover./pkg/compare/... ./pkg/partition/...all exit 0. Focused benchmark: JSON value-identity comparison costs 97.62 / 305.0 ns/op (0 allocs) versus the 7.69 / 7.66 ns/op raw-byte baseline.Notes
7597f979(RED00373844…, FIX95a41b9a…, identified by SHA andvcsstamps);7597f979 -> 81082d34adds only a test-only commit with a 0-line delta in the affected packages, so that evidence carries over, and the unit/static results above were rerun on the rebased source.makeexit codes for those binary builds were not independently preserved; this PR does not claim a verified rawmakepass code for them.