Skip to content

test(sql): lock normalized signed-zero set operations - #30184

Merged
XuPeng-SH merged 63 commits into
matrixorigin:mainfrom
iamlinjunhong:fix/30155-setop-signed-zero
Oct 29, 2026
Merged

XuPeng-SH merged 63 commits into
matrixorigin:mainfrom
iamlinjunhong:fix/30155-setop-signed-zero

Conversation

@iamlinjunhong

@iamlinjunhong iamlinjunhong commented Oct 14, 2026 •

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:

What this PR does / why we need it:

MatrixOne treats -0 and +0 as equal, and set operations follow that equality. We do not match MySQL 8.0.46, which keeps opposite signed zeros as separate set members.

main already behaves this way. The hash key canonicalizes FLOAT/DOUBLE values in keycodec.CanonicalFloat32Bits / CanonicalFloat64Bits: both zeros map to 0, and every NaN sign/payload maps to one canonical NaN. As a result, UNION / INTERSECT / EXCEPT return 1/1/0 for opposite zeros, and NaN is a single set member.

Following review, the earlier approach (set-only float keys, ScalarSet* reaggregation, protocol gates, RFC) is withdrawn. The branch now carries main's tree plus regression tests:

  • TestSetOperationSignedZeroNormalized: for FLOAT and DOUBLE, in both arm orders, UNION 1, UNION ALL 2, INTERSECT 1, INTERSECT ALL 1, EXCEPT 0, EXCEPT ALL 0, plus the literal -0e0 INTERSECT/EXCEPT 0e0 cases.
  • TestFloat32CodecContract: adds the missing FLOAT64 negative-zero assertion next to the existing FLOAT32 zero and NaN payload cases.

Validation: both tests pass locally, and go vet on the two packages is clean.

@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 →

@mergify mergify Bot added the kind/bug Something isn't working label Oct 14, 2026
@matrix-meow matrix-meow added the size/L Denotes a PR that changes [500,999] lines label Oct 14, 2026
@iamlinjunhong
iamlinjunhong force-pushed the fix/30155-setop-signed-zero branch from 73912ed to d48be22 Compare October 14, 2026 13:46
@XuPeng-SH

XuPeng-SH commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: d48be22e128ef9f3de3e0ff924533ab9626d867e

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-local · review

Commit: d48be22e128ef9f3de3e0ff924533ab9626d867e

Assessment: request_changes

Reviewed the complete fourteen-file delta and affected consumers. Reusing physical equality keys is a sound way to isolate signed-zero set semantics. However, integration with correlated-query handling and predicate pushdown introduces two confirmed regressions.

Model: gpt-6-astra / xhigh

Session: 01a12d8f-7dea-77c2-a565-38d45b5564e4 · slot 0 · generation 0

  • P2 pkg/sql/plan/query_builder.go:4868: On t(a INT,b INT,f DOUBLE), execute SELECT a FROM t o WHERE EXISTS (SELECT f FROM t i WHERE i.a=o.a AND i.b=o.b UNION SELECT f FROM t i WHERE i.a=o.a AND i.b=o.b). Identical arms using i.a>o.a also trigger the regression.
    Impact: Previously supported queries now fail with error 20102. Prepared versions also fail when both arms select the integer constant 1. Preserve these correlation shapes when retaining float or prepared arms.
    Evidence: All six public SQL probes pass with exact merge-base overlays. The candidate fails float/prepared multiple-predicate and range-predicate cases; single-equality controls pass. The new collapse restrictions expose flatten_subquery.go:4388–4404, which accepts only one matching equality identity per arm. Results are retained in public-base.log and public-head.log.

  • P2 pkg/sql/plan/query_builder.go:4861: On t(k INT PRIMARY KEY,d DOUBLE), execute SELECT k,d FROM (SELECT k,d FROM t UNION SELECT k,d FROM t) u WHERE k=1.
    Impact: Adding float physical keys activates the blanket filter-pushdown barrier, converting a selective primary-key lookup into full scans and hash aggregation. Preserve pushdown for predicates proven invariant under the equality key, including this predicate on the untouched integer column.
    Evidence: With 4,096 finite rows, EXPLAIN PHYPLAN ANALYZE changes from one scanned row and 37 bytes of reported memory on base to two 4,096-row scans, an 8,192-input-row aggregate, and 761,904 bytes on HEAD. The integer-only control remains one scanned row and 25 bytes. The filter stays above aggregation because pushdown.go:944 rejects pushdown whenever PhysicalEqualityKeyList is populated. See perf-base.log and perf-head.log.

Validation:

  • Artifacts: /home/xupeng/.local/state/mo-bot/jobs/cf9b4aade4ab97927e6c6434/attempt-1. evidence-audit.json reconciles seven execution receipts with commands, source fingerprints, logs and overlay inputs. Final audit receipt 1792012368798373316-4.json exits 0; source remains unchanged.

  • Isolation preflight passed. Native provenance verified 192 current source inputs and 62 artifacts against the retained repository build-owner receipt and log.

  • Focused function, planner, group/spill and compile/remote-codec tests passed: receipt 1792012253239799077-3.json.

  • TestSetOperationSignedZero passed. Independent correlation probes passed on base and exposed four candidate failures: receipts 1792012264966570110-3.json and 1792012269810977520-3.json.

  • Both physical-work comparisons completed successfully: receipts 1792012294035663064-3.json and 1792012294734351744-3.json.

  • Frozen exact-head CI reports successful UT, static analysis, shared build, proxy/pessimistic multi-CN BVT and coverage.

Limitations:

  • The full linked issue body, raw CI logs and retained author validation artifacts were not supplied; local_validation was empty.

  • Local public SQL probes used one CN. Codec and compilation checks do not constitute a local multi-CN runtime run.

  • Performance evidence measures execution-plan work and memory, not sustained latency or concurrency. Full repository, BVT and race suites were not rerun locally.

@fengttt fengttt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about NaN? Is that handled correctly?

In any case, I think the fix should be in one (or 2) functions, float32/64 compare.

Those cryptic ScalaSetXXX should not exist at all. And preserve or not, is not important.

@iamlinjunhong

Copy link
Copy Markdown
Contributor Author

In response to review 5647929299, checked at exact head 71a54d811b38c333b87531a8542477cb450713fd against base 4769417cdce5531c9771644eca49f1e71d8f654c.

NaN: the set-key functions preserve the existing canonical NaN class. Only the exact negative-zero bit pattern takes their special branch; every NaN reaches Float32Codec.CanonicalBits / CanonicalFloat64Bits, yielding 0x7fc00000 / 0x7ff8000000000000. The function tests cover positive/negative NaN payloads for both widths; TestFloat32CodecContract additionally covers signaling NaN encodings. Those named cases passed in this exact head's coverage run. This reuses recorded execution, not a new local run or a claim about additional MySQL NaN behavior. The overall producer's unrelated package-budget failure remains tracked separately in #31146.

Why comparison-only changes are insufficient: shared types/compare.go and keycodec/keycodec.go are byte-identical between the two revisions. ORDER BY comparators are not the owner of resident hash equality: the FLOAT hash path canonicalizes signed zero through the codec. Merely changing those comparators leaves the reported set membership unchanged. Changing the shared canonicalization to distinguish zeros instead changes GROUP BY/aggregate equality too, which the original #30155 scope explicitly excludes. The set-specific numerical difference is already in two key functions.

There is also a separate planning boundary: base utils.go:getUnionSelects collapses textually identical UNION arms before binding, and query_builder.go then takes ordinary single-arm DISTINCT. That route bypasses a set-only comparison/key change. Retaining typed arms exposed actual previously-supported correlation regressions, established by the independent baseline/head review; they are PR-caused regressions, not unrelated feature requests. The bounded ScalarSet composition repairs those cases while preserving separate outer occurrences, empty/NULL membership and the existing 1242 scalar-cardinality error. The current exact-head report passes the public correlation cases, TestScalarSetRetainsCardinalityOwner and TestScalarSetFallbackResourceLifecycle.

Under the recorded acceptance boundary—set-only compatibility, unchanged ordinary equality, and repair of regressions made reachable by the fix—this PR does not implement a global comparator rewrite or remove the fallback without an equivalent replacement. Those proposed changes are not being reported as fixed. A smaller equivalent implementation is not ruled out, but comparison-only edits have not established one; no remaining NaN failure or replacement preserving the correlation/cardinality/resource contracts is demonstrated here. No code or test changes are made for this response.

iamlinjunhong and others added 2 commits October 26, 2026 15:43
Review (fengttt) rejected preserving the zero sign in set membership:
MatrixOne equality treats -0 and +0 as equal, and main already
canonicalizes both (and every NaN encoding) in the hash key through
keycodec.CanonicalFloat32Bits/CanonicalFloat64Bits. UNION, INTERSECT
and EXCEPT therefore already return 1/1/0 for opposite zeros, which is
the intended behavior; MySQL's 2/0/1 is not a compatibility target.

This merge takes main's tree, dropping the set-only float keys, the
ScalarSet* reaggregation path, the protocol gates and the RFC.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
FLOAT and DOUBLE -0/+0 are one set member for UNION, INTERSECT and
EXCEPT (and the ALL variants), in either arm order; UNION ALL keeps
both rows. The hash key test also covers FLOAT64 negative zero next to
the existing FLOAT32 zero and NaN payload cases.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@iamlinjunhong

Copy link
Copy Markdown
Contributor Author

@fengttt You're right, and thanks for pushing back. The PR was chasing MySQL 8.0.46's signed-zero set membership (2/0/1), and that one decision is what pulled in the set-only keys and the ScalarSet* machinery. All of that is gone now.

MatrixOne equality treats -0 and +0 as equal, and main already normalizes in exactly one place: keycodec.CanonicalFloat32Bits / CanonicalFloat64Bits map both zeros to 0 and every NaN encoding to one canonical NaN. So UNION / INTERSECT / EXCEPT already return 1/1/0, and NaN is a single set member. Joins, by contrast, reject NaN via StrHashMap.SetRejectNaN.

The branch is now main plus regression tests that lock this behavior (2 files, +81). Could you take another look?

@XuPeng-SH

XuPeng-SH commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: ea8981a438be31366f58bf173b66a060f6a00fda

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-local · review

Commit: ea8981a438be31366f58bf173b66a060f6a00fda

Assessment: approve

Reviewed the complete two-file delta, affected owners and review concerns. No actionable findings remain. The tests preserve MatrixOne's existing normalized signed-zero semantics using the authoritative codec and shared SQL fixture. The earlier ScalarSet implementation is withdrawn; no production behavior or runtime cost changes.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1586-7a01-9000-d45e20995cf8 · slot 1 · generation 1

Validation:

  • Verified the frozen HEAD, clean source and complete 81-line test-only patch. Reviewed FLOAT/DOUBLE canonicalization, existing NaN coverage, SQL entry points, test oracles, timeout and cleanup ownership.

  • Reconciled exact-head CI run 40287595749. The SQL regression produced 15 named passing test/subtest events in race-enabled execution; its root completed in 1.33 seconds. All owning SQL-integration batches completed successfully.

  • Verified keycodec was selected without test filtering in the successful full-package race stage. Exact-head static analysis checked both changed packages; vet and lint succeeded with zero issues.

  • Recovered attempt-1 logs and seven command/source/exit receipts without repeating tests. Final reconciliation passed: attempt-2/checks/1793005914795943886-3.json. Evidence and scope are recorded in validation-ledger.json and review-record.json under /home/xupeng/.local/state/mo-bot/jobs/9df7e1a3901fc2b9e29a45a4/attempt-2.

Limitations:

  • Reused verified exact-head CI; no local native tests or separate BVT run was repeated. The retained summary omits the named codec-test event, but its unfiltered owning-stage execution and successful completion are recorded.

  • This locks MatrixOne's existing behavior; it does not implement MySQL's differing signed-zero set membership.

@aptend aptend left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed exact head ea8981a438be31366f58bf173b66a060f6a00fda against merge-base 83c1e23526fc0ed31188abd7fc2ca87cd3a6d4b3, including the change from my previous reviewed head, all 41 historical reviews, 11 inline comments/replies, 33 discussion comments and all five threads. No blocking findings remain.

The complete current diff is two test files (+81). The production tree matches the declared base: the earlier set-only key/ScalarSet implementation and its related artifacts have been withdrawn. The tests lock the accepted existing MatrixOne normalized-zero membership contract; they do not implement MySQL's different signed-zero membership.

Validation:

  • Full keycodec suite passed locally: 26 roots / 68 test-and-subtest executions, including the new FLOAT64 negative-zero assertion.
  • TestSetOperationSignedZeroNormalized passed twice in one process on the shared single-CN fixture.
  • My temporary independent probe confirmed that the same INSERT inputs actually retain opposite IEEE zero signs for both FLOAT and DOUBLE through binary-prepared queries, and verified schema cleanup between repetitions. Both probe rounds passed; the overlay was removed.
  • Audited and reused exact-head CI run 40287595749: all 15 named SQL test/subtest events and the owning race-enabled SQL-integration batches pass; configured static analysis for both changed packages succeeds. Skipped coverage/BVT jobs are not counted as executed.

No production behavior or new concurrency/resource mechanism is introduced by this final patch.

@mergify

mergify Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

🚫 Left the queue

35 min in the queue, with no time running CI.

So far

  • ✅ Entered the queue Thu 29 Oct, 03:49 · rule main · triggered by rule Automatic queue on approval for main
  • ⏹️ Testing stopped · in place
  • 🚫 Left the queue 04:24 · 1ab113f

Reason

Pull request #30184 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.

The author needs to enable "Allow edits from maintainers" on this pull request.

Hint

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Merge conditions: 2 of 3 met

This pull request

Condition Required by
✅ #review-threads-unresolved = 0 GitHub branch protection
✅ github-review-approved GitHub branch protection

The batch, tested in place

Condition Required by
❌ any of: check-neutral = CI Required, check-skipped = CI Required, check-success = CI Required GitHub branch protection

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

Times in UTC · dashboard · how the merge queue works

This branch was previously deployed

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

Labels

dequeued kind/bug Something isn't working kind/test-ci size/S Denotes a PR that changes [10,99] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants