Skip to content

fix: preserve prepared table-function domains through consumers and CTAS - #29369

Merged
XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/fix-29349-29351-systemic
Sep 24, 2026
Merged

XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/fix-29349-29351-systemic

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • BUG
  • Improvement
  • Test and CI

Which issue(s) this PR fixes

Fixes #29306
Fixes #29307
Fixes #29311
Fixes #29313
Fixes #29314

Supersedes #29349 and #29351 by combining their prepared-argument fixes with the downstream consumer, CTAS, and protocol closures.

Root cause and changes

Prepared values cross SQL and MySQL protocol boundaries as bytes/text while some consumers need the assignment or packet domain. The original fixes specialized direct calls but left downstream plans, internally reparsed CTAS inserts, cached execution, and mixed-CN dispatch with stale or incompatible domains.

  • Rebind GENERATE_SERIES consumers and result metadata at execution. Parameterized series gets a fresh runtime compilation because endpoint fractions and steps can change DATETIME scale without changing packet type. Real COM_STMT DATE/DATETIME packets keep temporal domain at series endpoints.
  • Refresh only inferred CTAS columns after specialization, map target-only columns correctly, reject incompatible inferred nullability/default changes, carry semantic parameter values through CTAS retry, and clear the sidecar on compile release/reset.
  • Bind direct prepared UNNEST JSON arguments to an old-operator-compatible JSON domain without a 65,535-byte TEXT cast. Keep HLL/bitmap state in a lossless internal binary domain, and preserve ENUM/SET numeric provenance.
  • Keep CEIL/FLOOR precision scalar through the private integer conversion. Introduce MORPC v95 placement and sender/receiver checks for this executor behavior; a new coordinator keeps affected work local while an older CN is present.

The external MySQL protocol and persisted catalog/storage formats do not change. The approved rev4 design is docs/design/20260924-prepared-argument-domains.md (SHA-256 7079eb07827ac8f81d87cd146d33a290b963ee4389cfba4ff495d56f4e33ce0f). An earlier independent code review passed after its prior rebase; the current rebased head received a separate final review.

Validation

Evidence was gathered on the equivalent pre-rebase patch 99e419e925; git range-diff maps all five PR commits unchanged to head 348d4e2f6d on main ac46f1a09b. The sole new base change is in pkg/sql/colexec/external and does not intersect this PR.

  • mo-cgo-test with -p 2 -count=1: pkg/defines, pkg/pb/plan, pkg/sql/plan, pkg/sql/compile, pkg/sql/colexec/table_function, pkg/frontend, and pkg/embed all passed.
  • Focused regression checks passed for CTAS column order/defaults and retry cleanup, >65 KiB JSON and bitmap state, same binary statement across temporal scales, real DATE/DATETIME COM_STMT packets, and v94/v95 remote precision placement/send/receive gates.
  • Normal mo-tester comparison (-n -g -o -p) passed twice on one ready instance for issue_29311_binary_state.sql (26/26), issue_29313_enum_set_aggregate.sql (16/16), issue_29314_scalar_precision.sql (33/33), and prepared_table_functions.sql (37/37). Created tables were absent after teardown.
  • make build-with-prebuilt-native, incremental go vet, and incremental golangci-lint (0 issues) passed; git diff --check and gofmt clean.
  • Rolling mixed-CN check: a v94 CN initialized the cluster, then a v95 CN joined; SQL succeeded on both. A 4.2M-row table crossed the 512-block multi-CN threshold, and a prepared CEIL precision query on the v95 coordinator returned the expected sum. This external check did not record the identity of the worker that ran the query; the v94/v95 placement and fail-closed remote protocol branches are covered by the focused compile test.

On the previous remote head f464d449bc, shared build and Ubuntu/x86 UT passed. ARM64 SCA found a missing rows.Err/Close in a test, fixed here. Both multi-CN BVT jobs failed during Quay MinIO image pulls before SQL (#29367; infrastructure fix #29370). UT Coverage timed out in Checkout MatrixOne source before tests, a recurrence of #28411; downstream Coverage lacked that producer and calculated no verdict. The new head's CI must be evaluated separately.

Rollback: revert this PR's five commits; no data migration is required.

Latest-main rebase and current validation

Rebased onto matrixorigin/main@44e5226a21 (including #29370). New head: 315ef452135f21335ff7e79281700cbd6ba127d2. The complete binary diff against main is byte-for-byte identical to the diff before rebase, and git diff --check passes. Focused post-rebase CGo tests passed in pkg/sql/plan, pkg/sql/compile, pkg/frontend, and pkg/embed, including prepared series consumers, >65 KiB UNNEST, CTAS column mapping, precision protocol, temporal COM_STMT binding, and specialized-domain execution. The old BVT failures are not SQL test verdicts; CI on this new head is pending.

@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 kind/bug Something isn't working kind/enhancement kind/test-ci labels Sep 24, 2026
@matrix-meow matrix-meow added the size/XL Denotes a PR that changes [1000, 1999] lines label Sep 24, 2026
@XuPeng-SH
XuPeng-SH force-pushed the codex/fix-29349-29351-systemic branch from f464d44 to 348d4e2 Compare September 24, 2026 16:16
@XuPeng-SH
XuPeng-SH requested a review from fengttt as a code owner September 24, 2026 16:16

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

深度审查结论:未发现需要阻塞合并的正确性问题。

已核对参数域特化及下游消费者、CTAS 推导列与内部 INSERT 重建、UNNEST/HLL/bitmap/ENUM/SET、CEIL/FLOOR 标量精度与 MORPC v95 兼容门槛,以及参数副本在重试、释放和复用时的生命周期。另用本地 CTAS 边界探针验证了直接参数、算术表达式、COALESCE、generate_series 消费者和过滤条件,均通过。

当前 head 315ef452135f 的已启用 CI 检查均通过。我建议合并。

@XuPeng-SH
XuPeng-SH merged commit 5d80e0b into matrixorigin:main Sep 24, 2026
29 checks passed
XuPeng-SH added a commit that referenced this pull request Sep 25, 2026
## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes #29317
Fixes #29318

## What this PR does / why we need it:

Prepared SQL `EXECUTE` transported user variables as text and allowed
provisional marker casts/numeric-prefix conversion to choose the wrong
comparison domain for all-parameter `GREATEST`/`LEAST` and `FIELD`.
Binary `FIELD` operands could also fall through to `DOUBLE` comparison.

- Restore each SQL variable's source type at these variadic comparison
operands before rebinding the complete tuple. Keep actual string
operands as string boundaries; restore numeric literal peers only when
the tuple has no actual string operand.
- Route binary/text-only `FIELD` tuples through the existing
byte-preserving, case-insensitive string implementation. Leave COM_STMT
protocol typing and explicit SQL casts unchanged.
- Pin the planner-generated vector-index overfetch `LEAST()` arithmetic
to explicit `UINT64`, so execute-time variadic rebinding cannot
reinterpret a prepared LIMIT as signed or decimal. Cover saturation
boundaries and decimal inputs.
- Add planner/function unit coverage and a public SQL BVT for mixed
numeric/text values, binary NUL/case behavior, NULL, statement reuse,
explicit casts, and numeric literal peers.

Validation on base `2f25834093` (isolated local MatrixOne service):
original three issue reproductions fail before the change and match
direct SQL after it. `pkg/sql/plan` and `pkg/sql/plan/function` full CGo
test suites pass. New BVT: 37/37 statements pass. Earlier GPT-6 Astra
medium independent final review: no blockers. The subsequent two
unsigned-overfetch commits have focused planner regression coverage and
are included in the current final review.

## Latest-main rebase and current validation

Rebased onto
`matrixorigin/main@e914d98` (including
#29369); new head `4876d85a92c2ef099bfd559771bd18abc7de3354`. Main moved
`ParamValue` from `plan` to `executor`; the conflict resolution keeps
the existing `plan.ParamValue` alias and relocates this PR's
`SourceType` comment to the defining type in
`pkg/util/executor/options.go`. `git range-diff` confirms all behavioral
patches are retained; the other eight file diffs are byte-for-byte
identical. `git diff --check` passes.

Focused post-rebase CGo tests passed for prepared variadic source
domains, unsigned/decimal vector overfetch boundaries, `FIELD` type
handling, and the newly merged prepared `generate_series` consumers. The
`pkg/sql/compile` CGo test binary also compiled and linked successfully.
Full CI on this head is pending.

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/enhancement kind/test-ci size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

2 participants