Skip to content

fix: allow prepared JSON ordering params - #25527

Merged
XuPeng-SH merged 11 commits into
matrixorigin:mainfrom
LeftHandCold:agent/fix-json-extract-prepare-param
Jul 14, 2026
Merged

XuPeng-SH merged 11 commits into
matrixorigin:mainfrom
LeftHandCold:agent/fix-json-extract-prepare-param

Conversation

@LeftHandCold

@LeftHandCold LeftHandCold commented Jul 8, 2026 •

Copy link
Copy Markdown
Collaborator

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #25502

What this PR does / why we need it:

Prepared JSON ordering predicates such as json_expr >= ? were rejected during binding because the dynamic parameter kept its default text type while JSON ordering is only supported through numeric comparison.

This change detects direct dynamic parameters on either side of JSON ordering operators, casts the JSON expression to float64, and assigns the parameter the same type. Literal string comparisons remain rejected.

Tested with:

go test -count=1 -mod=mod ./pkg/sql/plan -run TestBindFuncExprImplByPlanExpr_JsonOrderingWithDynamicParam

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

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

Self-review结果:PR #25527 仅涉及 prepare 参数解析/JSON 顺序比较绑定与新增 UT。已核对 binder/执行链路闭环与失败路径,未发现阻塞级缺陷(按 mo-self-review 结论为可合入)。建议 approve。

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

LGTM: 自审通过,无阻塞级发现。

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

Request changes

High: the new FLOAT64 normalization returns wrong results for valid JSON numbers

adjustJsonOrderingDynamicParamType casts both operands to FLOAT64. The binary protocol preserves a MYSQL_TYPE_LONGLONG / unsigned integer parameter as its exact decimal text, but the generated casts then round both that text and an exact JSON integer.

Concrete regression:

SELECT JSON_EXTRACT('{"v":9007199254740992}', '$.v') < ?
-- binary parameter: MYSQL_TYPE_LONGLONG, value 9007199254740993

The predicate must be true. With this patch both casts produce 9007199254740992 as float64, so it evaluates to false. The same loss occurs for high-precision decimal JSON values. This conflicts with the existing pkg/container/bytejson/bytejson_compare_test.go contract that values beyond the exact float range must not collapse, and with the PR issue's MySQL-compatibility goal.

The fix needs an exact comparison path rather than choosing an approximate common type. Preserve the parameter's JSON/numeric representation through execute and compare JSON numeric scalars exactly (including int64, uint64, and decimal), or add a dedicated exact JSON ordering comparator. Do not coerce both sides to FLOAT64.

Please add protocol-level regression coverage for the adjacent 2^53 integers above, a high-precision decimal pair, NULL, invalid MYSQL_TYPE_VAR_STRING, and both operand orders. The current tests only prove that the binder emits casts and that "1" can be cast; they do not execute the complete prepared comparison semantics.

I also ran the PR's added plan/colexec/frontend tests plus the relevant JSON exact-comparison and cast tests locally.

@mergify mergify Bot added the kind/feature label Jul 12, 2026
…json-extract-prepare-param

# Conflicts:
#	pkg/sql/plan/function/func_compare_test.go
#	pkg/sql/plan/function/function_id.go
#	pkg/sql/plan/function/function_id_test.go

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

Previous precision blocker is fixed in the latest head.

The new path no longer collapses JSON ordering through FLOAT64: direct prepared params are normalized via __mo_json_ordering_param, binary-protocol values keep their exact text representation, and JSON ordering now compares exact JSON numeric scalars (including adjacent >2^53 integers, uint64 edge values, decimals, null, invalid input, and both operand orders) instead of approximate float casts.

I re-checked the binder/operator/runtime chain and I don't see a remaining high-confidence correctness blocker in this PR.

@mergify

mergify Bot commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-07-14 12:42 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-07-14 13:44 UTC · at 2fffa7ac93959cb3fd23ea5f3d184e9daa0c83a6

This pull request spent 1 hour 1 minute 34 seconds in the queue, with no time running CI.

Waiting for
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-skipped = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-success = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
    • check-success = Matrixone Utils CI / Coverage
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
    • check-success = Matrixone CI / SCA Test on Linux/arm64
All conditions
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-skipped = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-success = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
    • check-success = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
    • check-success = Matrixone CI / SCA Test on Linux/arm64
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]
  • github-review-decision = APPROVED [🛡 GitHub branch protection]

Reason

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

Failing checks:

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.

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

  • Requeue this pull request

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

kind/bug Something isn't working kind/feature kind/test-ci size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants