Skip to content

fix: support prepared UNNEST and GENERATE_SERIES arguments - #29349

Closed
XuPeng-SH wants to merge 1 commit into
matrixorigin:mainfrom
XuPeng-SH:fix/29307-29306-prepared-table-functions
Closed

XuPeng-SH wants to merge 1 commit into
matrixorigin:mainfrom
XuPeng-SH:fix/29307-29306-prepared-table-functions

Conversation

@XuPeng-SH

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • BUG

Which issue(s) this PR fixes:

Fixes #29307
Fixes #29306

What this PR does / why we need it:

SQL PREPARE transports user variables as TEXT, so table-function binders can choose the wrong argument domain before EXECUTE supplies the actual values. This caused prepared UNNEST to reject JSON text and prepared GENERATE_SERIES to treat integer endpoints as datetimes.

  • Cast direct UNNEST parameter markers to the function's JSON/path/boolean argument types.
  • Specialize copied prepared GENERATE_SERIES plans at execution from the first endpoint's runtime type, updating argument casts and output schema together. Keep the cached prepared plan reusable across integer and temporal executions.
  • Cast remaining markers when the first GENERATE_SERIES endpoint already has a known integer or temporal domain.
  • Add planner tests and a SQL BVT with expected rows and metadata for repeated execution, changed values, signed/unsigned integers, text and typed datetimes, and mixed placeholders/literals.

Validation:

  • mo-cgo-test -count=1 -timeout=10m ./pkg/sql/plan — passed.
  • go vet -mod=readonly ./pkg/sql/plan — passed.
  • golangci-lint run -c .golangci.yml --new-from-rev 2f258340935018feb88221af7430fa5707e1bcc2 ./pkg/sql/plan — 0 issues.
  • make build-with-prebuilt-native — passed.
  • ./run.sh -g -o -p test/distributed/cases/prepare/prepared_table_functions.sql (mo-tester) — 37/37 passed twice on one fresh isolated MatrixOne instance, with no failures, ignored, or abnormal cases.
  • Independent incremental review — 0 unresolved blockers.

Scope: static analysis and package tests covered pkg/sql/plan; the BVT covered the SQL frontend and table-function execution path. CI remains to run on this PR. Revert this commit to roll back.

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

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

Reviewed exact head a8f95b8 against base 2f25834 using GPT-6 High. No blocking finding identified. Reviewed all seven changed files and traced UNNEST argument casts, GENERATE_SERIES runtime domain selection, copied-plan schema propagation into consumers, prepared reuse, and existing argument-error paths. This is an ordinary bug fix and does not trigger the feature-design gate. Reused successful current-head CI run 35991520279, including build, Linux UT/SCA/coverage, and both active multi-CN BVT jobs, plus author-reported focused planner and repeated SQL regression results. I did not run additional local tests. Combined integration with related open prepared-argument PRs #29351, #29350, and #29345 was not tested. COMMENT only because this PR is self-authored.

@XuPeng-SH

Copy link
Copy Markdown
Contributor Author

Follow-up: #29369 combines this PR with #29351 and addresses the downstream aggregate/UNION, CTAS, fixed-start temporal scale, and >65 KiB UNNEST gaps found during deep review. Please review/merge #29369 instead of this head; keeping this PR open until the replacement CI settles.

@XuPeng-SH XuPeng-SH closed this Sep 24, 2026
XuPeng-SH added a commit that referenced this pull request Sep 24, 2026
…TAS (#29369)

## What type of PR is this?

- [x] BUG
- [x] Improvement
- [x] 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@44e5226` (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.

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 size/M Denotes a PR that changes [100,499] lines

Projects

None yet

2 participants