Skip to content

Fix mixed JSON and numeric comparisons - #30707

Merged
mergify[bot] merged 8 commits into
matrixorigin:mainfrom
iamlinjunhong:codex/loom/develop/c28ce3081c3bed5186197a904bea1b2e02b3fbc8fc16db146231dcf582e6807f
Oct 22, 2026
Merged

mergify[bot] merged 8 commits into
matrixorigin:mainfrom
iamlinjunhong:codex/loom/develop/c28ce3081c3bed5186197a904bea1b2e02b3fbc8fc16db146231dcf582e6807f

Conversation

@iamlinjunhong

@iamlinjunhong iamlinjunhong commented Oct 21, 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:

The reporter should verify the issue after merge.

What this PR does / why we need it:

Comparing JSON_EXTRACT with a number currently casts the JSON value to the numeric operand's type. Heterogeneous documents can abort the query, and narrowing can make JSON 1.5 equal integer 1. Prepared comparisons and optimizer key rewrites can introduce the same loss of meaning.

This change preserves JSON categories and fractional values for mixed JSON/numeric comparisons in both operand orders, including prepared execution. It retains concrete numeric range errors, FLOAT32 rounding, exact decimal handling, SQL/JSON NULL behavior, and explicit CAST behavior. Mixed predicates remain residual expressions when hash, index, composite-key, range, or OR-to-IN rewrites would lose their typed semantics. New overloads are guarded by MORPC v127 capability checks, including placement, transport, and persisted-expression admission.

Mixed JSON/numeric ASOF equality now checks full candidate eligibility before selecting the nearest timestamp, so a rejected candidate cannot hide an earlier valid match. Real keys remain coarse grouping keys; otherwise a constant physical key provides one group. This path uses build-right on a single coordinator and retains the complete right input. Pure-key ASOF behavior is unchanged.

Mixed JSON/numeric equality cannot prove a shared partition identity or a single physical value. Correlated LIMIT/OFFSET and window shapes requiring that identity are explicitly rejected with the existing NYI error instead of returning wrong results; ordinary numeric keys, explicit CAST keys, LIMIT 0, and root EXISTS without OFFSET keep their safe behavior. Simple correlated COUNT/SUM aggregate the complete raw match set per outer row. ONLY_FULL_GROUP_BY rejects ambiguous projections constrained by mixed equality, including prepared parameters whose runtime comparison domain is not fixed; explicit JSON casts retain their fixed-domain behavior.

Validation:

  • Original Linux cgroup watcher cancellation timeouts are tracked in [Bug]: Linux race UT cgroup watcher cancellation times out in IdleStop and Events #30757. Three focused race/tag/CGO passes on the original PR head and three on clean official main satisfy the prescribed flaky-candidate protocol; controls ran on Linux/arm64 and do not establish an amd64 reproduction or a confirmed pre-existing cause. One failed-jobs rerun was requested for run 39574779715.

  • Rebased on official main 32591dcf3757a0ae4c2dec52cfd8d98761bd3454; upstream VIEWS retains v126 and JSON comparisons require v127. Fresh protocol composition/predecessor tests, protobuf/compile/function/planner owning packages, authenticated SQL regression and incremental lint passed. Prior unchanged ASOF lifecycle/race and exact BVT case evidence is reused.

  • Typed proof tests and authenticated SQL regressions cover both operand orders, NULL-safe equality, window and pagination boundaries, explicit CAST and noncorrelated controls, COUNT/SUM results, and direct/prepared ONLY_FULL_GROUP_BY rejection with legal fixed-domain controls.

  • The previous head validation retained an unreproduced authorization-test count observation (expected 4, observed 3) from the first owning-package run. The exact authorization test passed three consecutive diagnostic iterations (8.081s), followed by a complete issues package passing all 196 root tests (901.594s) on the previous head. No pre-existing-defect attribution is made.

  • Final planner owning package, focused optimizer regressions, vet, and lint passed. Regression coverage includes composite keys, fractional range bounds, secondary indexes, and mixed OR expressions.

  • Final JSON extract BVT passed 324/324 twice on the same owned instance, with teardown verified between runs. ASOF BVT passed 74/74 twice.

  • Scalar/prepared, protocol/capability, compiler, colexec, and hashjoin owning checks passed. Earlier race checks and deterministic in-scan cancellation/reuse checks (100 iterations) passed for the unchanged hashjoin implementation.

  • Real MySQL binary prepared execution passed integer-to-float-to-NULL-to-integer reuse. Budget failure, partial preparation, cancellation, cleanup, and account assertions passed.

Performance and compatibility limits: mixed ASOF scans candidates in O(sum LgRg), worst-case O(LR) without real keys. It uses O(1) additional best-candidate state and retains O(R) right-side rows under existing memory accounts. The single-coordinator path disables build-left and temporal-index optimizations and can reach memory limits sooner than the previous distributed/build-left path. Broadcast does not automatically spill: an over-budget build returns the existing controlled error and cleans up. MORPC v127 is required for these new comparison expressions. Real multi-CN ASOF and rolling-upgrade behavior were not exercised; remote CI results are not claimed here.

@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 21, 2026
@matrix-meow matrix-meow added the size/XXL Denotes a PR that changes 2000+ lines label Oct 21, 2026
@XuPeng-SH

XuPeng-SH commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 69630b23b906c17518ca445b094481984f4329e2

Review completed. Read the assessment.

@XuPeng-SH

XuPeng-SH commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-xupeng · superseded

Commit: 69630b23b906c17518ca445b094481984f4329e2

already-reviewed

@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: 69630b23b906c17518ca445b094481984f4329e2

Assessment: request_changes

The shared comparator and reuse of existing ASOF ownership are coherent, but the optimizer exclusions are incomplete: correlated pagination can silently discard valid matches.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1517-7f90-b3f9-c5f9f9e7031b · slot 0 · generation 1

  • P1 pkg/sql/plan/flatten_subquery.go:2949: With o(f FLOAT) containing 16777216 and i(id INT, j JSON) containing (1,'16777216') and (2,'16777217'), execute SELECT (SELECT i.id FROM i WHERE i.j=o.f ORDER BY i.id LIMIT 1 OFFSET 1) FROM o.
    Impact: The result should be 2. Both JSON values match the FLOAT32 peer, but correlated pagination partitions by their distinct raw JSON values. OFFSET removes both singleton partitions, producing NULL. Extend the mixed-domain exclusion to correlated partition proofs and preserve per-outer-row pagination through a safe execution path; add a SQL regression.
    Evidence: The new equality binding retains uncast operands. collectCorrelatedPaginationPartitionKeys at lines 4769–4785 still accepts this equality and extracts the inner JSON key; rewriteCorrelatedPagination applies ROW_NUMBER/OFFSET before restoring the predicate. The base cast both operands to FLOAT32, keeping these rows together. The added scalar test explicitly confirms 16777217 equals FLOAT32 16777216. Source tracing and pagination-witness.log establish the counterexample; MatrixOne SQL was not executed locally.

Validation:

  • Reviewed all 42 changed files and surrounding scalar, prepared, optimizer, protocol, compiler and hashjoin owners, including cleanup and failure tests.

  • Source remained clean at the assigned HEAD. git diff --check passed: checks/1792562584865414234-3.json and diff-check.log.

  • Isolation preflight passed with matching source fingerprint: checks/1792562739660831165-3.json and preflight-source.log.

  • Standalone pagination counterexample model passed: checks/1792562776470299418-3.json and pagination-witness.log. This is mathematical validation, not a production SQL test.

  • Retained the source trace, proposed SQL regression and receipt/log reconciliation in /home/xupeng/.local/state/mo-bot/jobs/a12e1133964e03177ce61ebf/attempt-1/review-evidence.json.

Limitations:

  • Local Go tests stopped before compilation: libmo.so was absent and the repository build owner rejected incompatible primary-worktree native inputs. Receipt checks/1792562596914855574-3.json matches planner-owner.log; this is an environment diagnostic.

  • Frozen CI metadata reports successful build, UT, SCA, coverage and BVT checks, but local_validation is empty and raw author/CI execution artifacts were not supplied. Issue #30539's body was also absent.

  • No performance measurements were independently available. Mixed comparisons lose key-based shortcuts; mixed ASOF retains O(R) right input on one coordinator and can require O(L*R) work. Real rolling-upgrade behavior was not exercised.

@iamlinjunhong
iamlinjunhong force-pushed the codex/loom/develop/c28ce3081c3bed5186197a904bea1b2e02b3fbc8fc16db146231dcf582e6807f branch from 198e066 to 8d246f4 Compare October 21, 2026 16:49
@iamlinjunhong

Copy link
Copy Markdown
Contributor Author

Rebased onto official main 60ad9a14fc6eda33b10ce74226078de3cffd24b2 in commit 8d246f44c6fb74c1cf6cdbbc7dcc9a0e0d46260f and resolved the MORPC allocation mechanically. Main retains v127 for IndexSearchScan search knobs; mixed JSON/numeric comparison admission, transport, and persisted-expression gates now consistently use v128, with v127 predecessor rejection and v128 acceptance covered.

Post-rebase validation passed: compile protocol tests, planner and locking regressions, complete pkg/sql/plan and pkg/tests/issues packages with -vet=all -count=1, and incremental lint (0 issues).

@XuPeng-SH

XuPeng-SH commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-xupeng · superseded

Commit: 8d246f44c6fb74c1cf6cdbbc7dcc9a0e0d46260f

Codex backend disconnected

@XuPeng-SH

XuPeng-SH commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 8d246f44c6fb74c1cf6cdbbc7dcc9a0e0d46260f

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: 8d246f44c6fb74c1cf6cdbbc7dcc9a0e0d46260f

Assessment: approve

Reviewed the complete 43-file delta and affected callers. The design is coherent: shared comparison logic preserves JSON categories and numeric domains, while planner guards prevent unsafe physical-key and partition deductions. ASOF reuses the existing operator with full candidate eligibility checks. Current code and regressions close the prior locking, pagination, window and grouping findings. No actionable defects remain.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1517-7f90-b3f9-c5f9f9e7031b · slot 0 · generation 1

Validation:

  • Verified the frozen HEAD, clean source checkout and patch content. Reviewed implementation, tests, SQL expected results, compatibility gates and resource ownership separately.

  • Isolation preflight passed. Rejected incompatible retained native artifacts, rebuilt through the repository build target, and verified 194 current native inputs plus output hashes.

  • Passed 42 distinct root tests, including all 26 new or changed test roots. Coverage includes scalar/prepared comparisons, selection masks, optimizer guards, protocol admission, ASOF placement/execution, cancellation, reuse, budget failure and authenticated two-transaction locking.

  • An additional authenticated SQL probe confirmed primary-key range filtering preserves scalar comparison results for JSON strings and booleans.

  • Current-candidate benchmarks: 1,024-row integer comparisons took 27.9–45.3 microseconds with zero allocations; exact decimal comparisons took 179–446 microseconds with 6,150–12,288 allocations. ASOF scans took approximately 18.5 microseconds for 32 candidates and 590 microseconds for 1,024, with zero reported allocations.

  • The frozen exact-head CI snapshot records successful build, Ubuntu UT, arm64 SCA, coverage, proxy BVT and pessimistic multi-CN BVT checks. Skipped checks were not counted as passes.

  • Commands, source fingerprints, terminal receipts and retained logs were independently reconciled in /home/xupeng/.local/state/mo-bot/jobs/d3d82006741fea42a94994e1/attempt-1/review-evidence.json. Final audit receipt checks/1792605995002631030-5.json exited 0; earlier diagnostic failures were not counted as product validation.

Limitations:

  • The linked issue body was not supplied; its behavioral contract was assessed from the frozen PR description, comments and regression cases.

  • Raw CI case logs were not supplied. No local multi-CN or rolling-upgrade run was performed; local compatibility checks cover placement, transport and persisted-expression admission at MORPC v128.

  • Benchmarks measure this candidate only. Mixed ASOF retains O(R) build input and performs O(sum LgRg) candidate work, potentially O(LR), on one coordinator; controlled budget failure is tested.

@XuPeng-SH

Copy link
Copy Markdown
Contributor

@Mergifyio refresh

@mergify

mergify Bot commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

refresh

✅ Pull request refreshed

@mergify mergify Bot added the queued label Oct 21, 2026
@mergify

mergify Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-21 23:53 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-10-22 01:51 UTC · at c232b6d2a1b5a94ac624c4954586569841c1e153 · squash

This pull request spent 1 hour 57 minutes 55 seconds in the queue, including 1 hour 2 minutes 28 seconds running CI.

Required conditions to merge

This branch was previously deployed

1 inactive deployment
ci — 3ebfd068 Deployed Oct 22, 2026 by mergify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants