Skip to content

fix: improve JDBC cursor, metadata, and auto-increment compatibility - #27315

Merged
mergify[bot] merged 40 commits into
matrixorigin:mainfrom
daviszhen:fix-issue-27286
Aug 23, 2026
Merged

mergify[bot] merged 40 commits into
matrixorigin:mainfrom
daviszhen:fix-issue-27286

Conversation

@daviszhen

@daviszhen daviszhen commented Aug 19, 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:

issue #27286

#27292, and #27295.

What this PR does / why we need it:

  • Accept MySQL read-only server-cursor executions and implement COM_STMT_FETCH with binary rows and cursor lifecycle cleanup.
  • Preserve MySQL JDBC metadata for TEXT-family capacities, temporal display precision, and YEAR.
  • Return the first generated AUTO_INCREMENT value for multi-row inserts and add regression coverage.

Validation: full pkg/frontend, pkg/incrservice, and pkg/sql/plan tests pass with the repository CGo test wrapper; focused frontend and incrservice race tests pass; git diff --check passes.

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

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

Codex automated review

Follow-up review of head 18d9195; the authored surface since my prior reviewed head c567391 is commit d1e8dbe ('fix prepared cursor persistence and statement generated IDs') plus an upstream merge with no conflict-resolution delta. Both of my remaining findings are resolved. (1) P1 parallel preinsert first-generated-ID: fixed via statement-wide coordination — genAutoIncrCol now publishes through proc.SetStatementLastInsertIDIfEarlier, a mutex-guarded min-publish on the shared BaseProcess (all parallel child procs share Base, verified in process2.go); remote CNs return their min in the remote terminal envelope and the client merges it with the same coordinator; prepareRetryTransition resets the value and restores the session baseline so a rolled-back attempt cannot win; the per-statement reset in doComQuery and the per-execute fill-callback rebind in Compile.Reset cover operator reuse. The new parallel race test, multi-batch INSERT...SELECT and all-manual BVT cases, and -race runs (-count=5) all pass. (2) P2 cursor query-result persistence bypass: fixed by reusing the DML RETURNING staged-writer lifecycle — the cursor output callback stages batches into fileservice, the meta is published only after transaction finalization succeeds and before the cursor wire response, and every error path (executeStmtWithResponse error, publish failure, ExecCtx.Close) aborts and deletes staged blocks; the canSaveQueryResult/limitResultSize gates and empty-result metadata (ses.rs set before execution) match the normal SELECT path. All my earlier blockers from rounds 3c63fdd/698e2b7/9ee0452/2b75043 (cursor protocol terminators, empty-cursor lifecycle, TEXT DDL round-trip and catalog recovery, temporal FSP incl. LOCALTIMESTAMP, multi-batch LAST_INSERT_ID, all-manual generated-key clearing, cursor memory accounting for array/decimal/geometry, zero-budget, LONGTEXT row-size overflow, SHOW COLUMNS rendering, legacy-EOF packet ordering, cursor advertisement before txn finalization) were fixed and accepted in prior rounds. Other reviewers' raised findings (aptend's budget/multi-batch/CASE-IF/dynamic-limit, XuPeng-SH's five blockers plus EOF-ordering and finalize-ordering, aunjgr's geometry accounting) are likewise all addressed per the review record and are not re-raised. Verification on this head: pkg/sql/colexec/preinsert (full, plus -race -count=5 on TestGenAutoIncr*), pkg/vm/process (full and -race), pkg/frontend (full), pkg/sql/plan (new control-flow TEXT-family test), and focused pkg/sql/compile remote-run tests all pass with the repository CGo wrapper. No blocking or non-blocking findings remain.

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

Deep re-review of exact head 56c8ce4edd81dcfed7817bfe2a53401de4a852e4. I read the complete review/comment/reply/thread history (all four inline threads are resolved), compared the increment since my prior reviewed head 698e2b7ea397c58af5e26fed1cf4c24198528c54, and re-audited the full cursor, JDBC metadata, and auto-increment diff.

The earlier blockers are closed in the integrated code: cursor retention is bounded and session-accounted (including array/decimal/geometry materialization, explicit zero and live budget changes), cursor execute/fetch now uses a single protocol-valid terminator after transaction finalization and preserves query-result staging, BIT fetches use binary encoding, cursor ownership is released across fetch/reset/close/reexecute/error/panic/session teardown, TEXT-family and temporal/YEAR metadata propagate through planner/protocol/show/recovery paths without LONGTEXT row-size overflow, and statement generated-key state is separated from session LAST_INSERT_ID and coordinated across batches/parallel/remote scopes and retries. I did not find a remaining blocking counterexample.

Verification on the exact head: affected packages (./pkg/frontend ./pkg/incrservice ./pkg/sql/colexec/preinsert ./pkg/sql/plan ./pkg/vm/process ./pkg/sql/compile ./pkg/container/types) pass under the required locally built thirdparties/CGo environment; focused cursor/generated-key race tests pass at -race -count=5; go vet passes for the same packages. The only git diff --check findings are the repository test-result format trailing spaces in existing tabular golden rows.

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

P1: gate remote auto-increment PRE_INSERT execution on a protocol version that can return statement_last_insert_id.

The previous cursor-response/finalization blocker is closed on this head. However, d1e8dbe adds StatementLastInsertID only to the JSON remote terminal envelope and does not bump or check the deployment MORPC version (latest is still v22). During a rolling upgrade, a new coordinator can send PRE_INSERT{HasAutoCol:true} to an old CN. That old CN generates the auto-increment value but its terminal envelope cannot return statement_last_insert_id, so the coordinator keeps the statement value at 0. INSERT ... SELECT generated keys therefore become wrong and scheduling-dependent in a mixed-version cluster.

I confirmed the missing compatibility gate with a temporary focused regression: set MOProtocolVersion to MORPCVersion22, convert a PreInsert with HasAutoCol=true to a remote pipeline instruction, and require rejection. The test fails because convertToPipelineInstruction returns nil error. The temporary test was removed after verification.

Please introduce the next negotiated MORPC version (or force the generated-ID-owning PRE_INSERT onto a compatible/coordinator path below that version), gate both remote construction/decode as appropriate, and test old-version rejection/fallback plus new-version remote ID propagation. JSON unknown-field compatibility only protects new-server/old-client decoding; it cannot make an old remote server produce the newly required terminal value.

# Conflicts:
#	pkg/sql/plan/legacy_tinytext_test.go
@daviszhen

Copy link
Copy Markdown
Contributor Author

已处理本轮 P1 并更新 PR:

  • 保留 MORPCVersion23 的既有字符串 provenance 合约,新增 MORPCVersion24 作为远程 PRE_INSERT{HasAutoCol:true} / statement_last_insert_id 的协商版本,并更新 latest protocol。
  • 在远程 pipeline 构造和服务端 decode 两侧增加版本门控;协议低于 v24 时拒绝生成 ID 的远程 PRE_INSERT,避免旧 CN 执行后无法回传 statement ID。
  • 增加旧版本拒绝、普通 PRE_INSERT 兼容、新版本构造/decode,以及 terminal envelope 传递 StatementLastInsertID 的回归测试。
  • 已合并最新 upstream/main(dd040ad691)。本地 pkg/sql/compile 全包测试通过。

请再次 review。

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

Deep re-review of exact head 84fea3d. The previous rolling-upgrade blocker is fixed: MORPC v25 gates remote auto-increment PRE_INSERT execution, the sender/decoder checks are symmetric, and the focused old/new protocol test passes. One test-stability blocker remains in the latest commit.

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

Deep review of exact head c6b2eb3b89497570e6e67768f5c8ef2423372137.

The cursor protocol/lifecycle, JDBC metadata propagation, generated-ID local/parallel/retry/remote paths, and unhappy-path ownership checks are otherwise closed. Focused tests, all affected owning-package tests, amplified race tests, and full -race runs for frontend/compile/preinsert/process pass.

P2 — test/distributed/cases/plan_cache/plan_cache.test:4: the latest stabilization evaluates NOW() once into @plan_cache_now, so the repeated cached statements no longer contain a real-time expression. The expected count = 4 is now tautological because every input is intentionally identical; a regression that incorrectly folds/caches NOW() across executions would still pass. Please preserve deterministic coverage of per-execution current-time evaluation—for example, a focused frontend/plan-cache test that drives proc.Base.UnixTime through known values—while testing the new default FSP=0 behavior separately.

@daviszhen

Copy link
Copy Markdown
Contributor Author

Deep review of exact head c6b2eb3b89497570e6e67768f5c8ef2423372137.

The cursor protocol/lifecycle, JDBC metadata propagation, generated-ID local/parallel/retry/remote paths, and unhappy-path ownership checks are otherwise closed. Focused tests, all affected owning-package tests, amplified race tests, and full -race runs for frontend/compile/preinsert/process pass.

P2 — test/distributed/cases/plan_cache/plan_cache.test:4: the latest stabilization evaluates NOW() once into @plan_cache_now, so the repeated cached statements no longer contain a real-time expression. The expected count = 4 is now tautological because every input is intentionally identical; a regression that incorrectly folds/caches NOW() across executions would still pass. Please preserve deterministic coverage of per-execution current-time evaluation—for example, a focused frontend/plan-cache test that drives proc.Base.UnixTime through known values—while testing the new default FSP=0 behavior separately.

  • 合并最新 upstream/main,解决协议相关代码冲突。

  • 保留 MORPC v25 的 UPDATE changed-row counting,将远程 LAST_INSERT_ID 协议升级为 MORPC v26。

  • 修复 plan cache reviewer comment:

    • BVT 恢复每次执行真实的 NOW(6);
    • 删除一次性缓存的 @plan_cache_now;
    • 更新预期结果,验证每次执行时间不会被错误复用。
  • 新增确定性 UT,通过改变 proc.Base.UnixTime 验证同一 NOW() overload 每次执行读取新的 statement time。

  • 本地相关 Go 测试已通过,提交 911228f 已推送到 PR。

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

Reviewed exact head 911228f. The outstanding deterministic NOW()/plan-cache concern is closed by TestBuiltInCurrentTimestampReadsStatementTimePerExecution, which reuses an overload while varying Base.UnixTime. The exact head preserves the cursor, JDBC metadata, and statement generated-ID lifecycle fixes. No blocking issue found.

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

Approved exact HEAD 911228f after deep re-review.

The final plan-cache coverage blocker is closed: the distributed case again executes real NOW(6) expressions repeatedly, while TestBuiltInCurrentTimestampReadsStatementTimePerExecution deterministically reuses one overload ID across two statement timestamps and verifies execution-time values. The merge with current main also correctly moves remote statement LAST_INSERT_ID propagation to MORPC v26 because v25 is now owned by UPDATE changed-row counting; old-version rejection and v26 propagation checks are symmetric.

Revalidated focused cursor packet/commit-failure/geometry accounting, generated-ID local/parallel/process semantics, remote protocol gating, and current-time execution tests. Exact-head CI is green. No blocking issue found.

@mergify

mergify Bot commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-23 09:11 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged — 2026-08-23 09:11 UTC · at 911228f9d73e2dd026f331a741ba2a919ef348d2 · squash

This pull request spent 21 seconds in the queue, including 2 seconds running CI.

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

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/enhancement size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants