Skip to content

fix(sql): preserve FIELD binary domains and prepared CASE types - #30096

Merged
mergify[bot] merged 31 commits into
matrixorigin:mainfrom
ck89119:issue-25301-from-scratch-main
Oct 21, 2026
Merged

mergify[bot] merged 31 commits into
matrixorigin:mainfrom
ck89119:issue-25301-from-scratch-main

Conversation

@ck89119

@ck89119 ck89119 commented Oct 13, 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:

Fixes #25301

What this PR does / why we need it:

FIELD compared binary strings through Unicode case folding. For example, FIELD(_binary X'FF', _binary X'FE', _binary X'FF') returned 1 instead of 2. The proposed behavior compares raw bytes for a resolved binary subject, preserving text comparison, NULL handling, first-match ordering, and numeric dispatch.

The complete scope includes selector/relational declaration ownership, immutable prepared CASE type history, statement-wide numeric reprepare, cache admission, failure publication, retry, migration, ordinary SQL and expression DEFAULTs. Transport types, source domains, consumer comparison domains, and result declarations remain separate. History-bearing handles cannot migrate because the existing payload cannot preserve their history.

Versioned design and authorization

  • Frozen D2 design and D3 counterexamples retain their bytes and historical status.
  • A second user go ahead, after retry/cost counterexamples were explained, selected fail-closed retry and optimization before delivery. The decision record preserves exact hashes, authorization provenance, alternatives and limits. The first authorization does not retroactively accept subsequently discovered risks.
  • Review19 implementation checkpoint: 76ecbfcdbf; historical validation source: e89a5a65edf396d85ec5aa2e4ae6d1ff9e69b165 against 79298b10e2114246c6ef41bde709dbbb4a20bca4.
  • Review20 source: 8cc91d1ede8ff40fa4e2d8483c4f9773e512d1c3, after merging fixed mo/main 743e749a1e33d6c845bb73999e8c82d297a2b657. The full PR against that base is 40 files, 15 non-generated production Go files and 2,027 production changed lines; this is not a one-line-cleanup review.
  • Author authorization/self-review is not independent reviewer approval. CHANGES_REQUESTED reviews are not dismissed; the earlier missing-artifact concern is distinct from correctness/design approval.

Implemented closure

  1. History-bearing compile retry deep-captures catalog-generation facts and validates dependencies before rebinding with old history. Changed object/version/database/publication facts fail closed; resolution errors propagate. The error maps to 20631/HY000, not MySQL 1615. Automatic driver reprepare is not promised. Unchanged dependencies preserve history; the next ordinary EXECUTE owns generation rebuilding/publication.
  2. Ordinary TEXT binding uses a stateless proof from authoritative declarations and existing forwarding contracts. Prepared/default/provenance/ambiguous projection paths retain the full resolver. TABLE_SCAN projections require a matching TEXT self-reference; no persistent memo or extra producer whitelist is introduced.
  3. Actual Compile.clear() clears buildPlanFunc; intentionally cached Release retains retry capability. Deterministic private-clear tests do not inspect pooled objects or depend on GC.
  4. Review20 corrects the previous blanket “genuine CASE” exclusion. A selected VARCHAR paired with a weaker binary literal must remain character-oriented ("你a": length 2, reverse 61E4BDA0), including expression DEFAULTs. CASE/IF is not universally transparent: real binary columns, equal-rank binary contributors, explicit BINARY/NULL casts, COLLATE and allocating-result owners remain boundaries. Existing witness traversal now carries binding-local rank/owner facts, not retained expression graphs, persisted flags or per-row traversal. Numeric roles reuse IntegerArgumentTarget, preserving upstream TIMESTAMPADD SECOND fractional normalization.
  5. 23 DEFAULT controls retain actual CREATE TABLE, original→whole-plan-copy equality, wire roundtrip/copy, actual Eval and full-expression immutability. Numeric DEFAULT targets, NULL/empty values and genuine binary owners are covered; the original LPAD control was not weakened.

Validation and explicit limits

The validation record, especially section 8, documents final-source inputs, commands, counterexamples, failure generations, coverage and public-result review. Earlier sections retain their original source attribution.

  • Go1.27.1, darwin/arm64, verified native provenance and bounded parallelism. One complete final-source five-package atomic run passed: planner/frontend/compile/function/AST. Changed executable coverage: 35/36=97.2% this round, 1011/1086=93.1% full PR. Vet passed; new-diff golangci-lint reported 0 issues. Molint exited 0 with 22 existing owner/source-equivalent diagnostics, not zero diagnostics or an executed baseline lint run. Supported prebuilt-native service build passed.
  • Original dtype expectations passed 93/93 before generation. New SQL's 21 rows matched independent MySQL byte-for-byte; result changes were reviewed before normal comparisons. Final single-CN normal runs: dtype 104/104 twice, history 492/492 twice, FIELD 97/97, variadic 104/104, TimestampAdd 99/99. All seven reports have zero failures/ignored/abnormal and empty error files. Dtype retains strict @metacmp(true) (SQL > document > global); its existing MULTICN section is preserved but not claimed executed. The owned service/ports and temporary databases were cleaned up.
  • Known numeric-DEFAULT boundary: with the original _binary '' fallback, selected non-NULL text now returns 2 in actual DML. A NULL row selecting the empty fallback still fails with 20203 instead of MySQL's 0. A full fixed-upstream Go overlay independently reproduces the empty-string-to-int failure in IF and COALESCE; setup/build failures are not counted as semantic evidence. The public mixed-NULL table uses independently checked _binary '0' (2/0/1), while the original failure, MySQL 2/0/0, current negative probe and original empty-literal non-NULL regression remain preserved. Changing that fallback is not a claim that the original NULL failure is fixed.
  • Failed candidates remain classified: declaration/COLLATE/LPAD counterexamples, an F public DEFAULT failure despite F's earlier green suites, and G's first low-disk spill-budget failure. Cache cleanup occurred only after confirming no users/open files, recovering about 53GiB; the unchanged resource test and a fresh complete five-package run then passed. No quota/assertion was weakened or failed profile stitched into acceptance.
  • Historical review19 measurements, not new G measurements: five exact lifecycle tests each passed 100 race repetitions; complete frontend/compile race passed 28.064s/16.777s. Depth32 binder medians were 206127 → 319042 → 214939 ns/op, approximately 96.1 → 160.0 → 96.1 KB/op, 1209 → 1485 → 1209 allocations. The approximately 63.9KB/276-allocation excess was removed, but timing remained +4.3% over upstream, not parity. First-bind/type-progress/numeric-mode/CTE/dependency-count evidence retains its original scope; dependency facts are not a byte quota or whole-statement linearity proof. No new performance or race result is implied by the unchanged fast path.

No full-repository, Proxy/MULTICN, restart/old-CN, actual concurrent-DDL physical retry, wire20631 injection, mixed-version semantic equivalence or post-push CI pass is claimed. Serialization does not make old FIELD executors implement new behavior. Broader conditional charset/result-domain normalization (including selected nonempty binary literals), existing CONCAT/explicit-CHAR/cross-explicit/unbounded-BINARY differences and the documented numeric-DEFAULT fallback limit remain outside this narrow correction; they do not exclude the selected-VARCHAR case fixed above. No expansion into partitioning, procedures, UDFs or warning compatibility. No unrelated CI reruns are requested or awaited.

SCA follow-up (2026-10-20)

  • Latest head 1ec4f5c5085c637c132c4b9cea9d0487a47736a5 merges fixed mo/main 0fb05134c76148fe7fd42a6bd54d37038df9510e ([codex] fix(colexec): avoid speculative XFS join spill allocation #30637). The PR's 28 Go files and public SQL/results are byte-identical to the validated review20 source; there is no additional product or SCA-rule workaround.
  • The failed ARM64 SCA job checked old head 1e2475f09e. Its only annotation is self-hosted runner lost communication, while Static Code Analysis never reported a terminal result; the raw-log endpoint returns BlobNotFound. This does not establish a lint finding or a specific OOM/network cause. Existing issue [Bug]: ARM64 SCA self-hosted runner loses communication during analysis #27742 tracks this failure class; no duplicate issue/comment was added.
  • After the merge, local incremental vet/lint passed for eight packages (golangci-lint 0 issues; molint retains 22 fixed-base owner/source-equivalent diagnostics). One normal atomic run passed spillio/hashbuild/spillutil/compile: 4001 pass events including subtests, no failures/skips. Merge-delta executable coverage is 11/14=78.6%. Upstream Linux UT/SCA evidence retains its own tested-source attribution; this Darwin run is not Linux/XFS verification.
  • The newer SCA was already running, so the obsolete failed job was not rerun concurrently. This merge/push triggers latest-head CI; neither runner root-cause repair nor a post-push CI pass is claimed. Independent CHANGES_REQUESTED remains unchanged.

Review follow-up (2026-10-21)

  • Fixed the three conditional-declaration counterexamples: a binary user variable competes at declaration rank; an independently owned TEXT LPAD result is not automatically binary; LIMIT/HAVING consume the logical CASE declaration instead of its temporary binary transport. Genuine binary/explicit-CAST/COLLATE controls remain intact.
  • Closed the same LIMIT/HAVING path through real PREPARE/EXECUTE, including history-free CASE producers and true/false/true executions. An intermediate candidate passed ordinary SQL but failed prepared scopes; that evidence was retained rather than accepted.
  • Fixed the separately reported CAST-history defect using the existing explicit-cast classification. Actual PREPARE/initExecuteStmtParam/Eval covers SIGNED, DECIMAL, CHAR and nested CHAR-to-SIGNED; changing only the pinned parameter transport preserves FIELD results 0/2/2 and H identity/revision.
  • Final source ac5777821b54fc6ce7e54bbf94d02d2ccdaf598b includes the merge of fixed upstream 76e152a1dd02b7875829027117a6f6344d1f8d33. Five owning packages passed (39,815 test/subtest PASS events, 3 existing skips); incremental executable-line coverage is 42/43 (97.7%), full-PR coverage 1037/1111 (93.3%). Vet and incremental golangci-lint passed (0 issues); molint emitted 20 fixed-base owner/source-equivalent diagnostics, not a clean baseline lint execution. Native prerequisites were rebuilt and provenance verified.
  • Original dtype expectations passed 104/104 before generation. All 34 new public SQL rows match an independent MySQL oracle. Reviewed generated output is one additive hunk with old metadata and MULTICN bytes unchanged. Normal BVT comparisons: dtype 139/139 twice, prepared history 492/492 twice, FIELD 97/97, variadic 104/104, TimestampAdd 99/99; no failures/ignored/abnormal cases. Owned services were stopped and test databases cleaned.
  • The existing numeric DEFAULT NULL-to-empty-binary fallback still raises 20203 (selected non-NULL TEXT now returns 2); no general charset/result-metadata, topology, restart, mixed-version, physical-retry, fresh race or performance-parity claim is added. Frozen design/authorization history is unchanged.

Evidence and explicit limits: validation section 9. Author validation does not replace independent review; existing changes-requested reviews are not dismissed. Post-push CI is not awaited or claimed successful.

@mergify mergify Bot added the kind/bug Something isn't working label Oct 13, 2026
@matrix-meow matrix-meow added the size/XXL Denotes a PR that changes 2000+ lines label Oct 13, 2026
@XuPeng-SH

XuPeng-SH commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: a0e585b3090302fc57d9a8eabbe954b98d6d1aee

"interrupted"

@XuPeng-SH

XuPeng-SH commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: a0e585b3090302fc57d9a8eabbe954b98d6d1aee

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: a0e585b3090302fc57d9a8eabbe954b98d6d1aee

Assessment: request_changes

The FIELD byte-comparison fix has a reasonable owner, but the complete change introduces a substantial prepared-type history and lifecycle refactor without traceable design-first approval. Implementation approval stops at that mandatory gate. The earlier NULLIF DEFAULT concern is addressed in the current source and regression test.

Model: gpt-6-astra / xhigh

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

  • P2 pkg/sql/plan/prepared_field_types.go:33: Prepared execution now retains CASE/parameter type history across executions, changes specialization-cache admission and generation resets, propagates history through retries, and prevents connection migration while that history exists.
    Impact: Design requirement: this materially changes state, lifecycle, and compatibility contracts. Provide or link an exact versioned design and its approval covering ownership, publication/reset/retry transitions, migration behavior, alternatives, resource bounds, common-path costs, and acceptance tests before implementation approval.
    Evidence: The delta changes 1,861 non-generated production lines. Concrete integration points include prepared_binding.go:1022, computation_wrapper.go:2007, and routine.go:857. The supplied PR evidence contains no design revision or approval, and the related binary-string/runtime-specialization documents do not describe these new contracts. .agents/skills/mo-dev/references/feature-design-review.md explicitly includes architectural refactors labeled as fixes and requires reviewers to 'stop the implementation approval path' when the design gate fails. This is a missing required design artifact, not an asserted runtime defect.

Validation:

  • Verified the frozen head/base, clean source, complete 32-file inventory, supplied patch contents, production-line count, and diff whitespace.

  • Checked the prior NULLIF finding: the no-QueryBuilder branch now records provenance, and TestExpressionDefaultNullIfStringSource evaluates the actual planned DEFAULT expression with relevant controls.

  • The frozen exact-head CI snapshot reports successful build, Ubuntu UT, SCA, coverage, and both BVT groups. These results do not establish design approval.

  • Reconciled checks/1792388736105813727-3.json with review-design-audit.log under /home/xupeng/.local/state/mo-bot/jobs/734797fed1d2c23d5dbc1ed4/attempt-1. Scope and evidence are retained in review-evidence.json.

Limitations:

  • Full downstream correctness, lifecycle, performance, and test-hunk review remains unfinished under the mandatory design-first gate.

  • No product tests ran locally. local_validation is empty; raw CI logs and author execution receipts were not supplied.

  • No performance regression is asserted. The new general-binding traversals, optional second optimization, and history-dependent cache checks need explicit design-level cost analysis.

  • The linked issue’s full text was not supplied.

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

审查 head a0e585b3090302fc57d9a8eabbe954b98d6d1aee,基准 main def799e1260dd547cae2e0e54323ea20ec1b7685。已审查完整 32 文件 diff、相关测试,以及 FIELD 分派、字符串声明来源、prepared 类型快照、缓存命中、代际失效、编译重试、关闭与连接迁移调用链。当前未确认 P0/P1/P2/P3 问题,结论为 APPROVE。

上轮 DEFAULT/NULLIF 问题已修复:无 QueryBuilder 的成功绑定分支现在也调用 rememberPreparedFieldNullIfDomain;TestExpressionDefaultNullIfStringSource 直接执行 CREATE TABLE 规划出的 DEFAULT 表达式,覆盖多字节文本、二进制来源、嵌套 NULLIF、真正 CASE 声明、空值及 NULL 输入。该回归测试本轮通过。已读取上轮 review、快照中的全部 review comments 和 PR conversation;未发现作者对应回复,本次批准依据是旧问题已修复且当前无确认问题。

本地验证:补齐仓库自带 C 依赖后,planner、function、frontend 中 FIELD 类型历史、来源、数值模式、依赖、缓存、重试、迁移和 DEFAULT 定向测试通过;通用字符串绑定相关的 collation、CTAS 宽度、prepared 用户变量及 BinaryString 测试通过。迁移与执行竞争用例 TestPreparedFieldHistoryCacheAndMigration 的 race 检查通过。AST 包编译通过,该筛选下没有匹配测试。git diff --check 通过,源码工作区无改动。未运行完整服务或分布式 SQL 集成测试,也未独立进行 MySQL 差分测试或性能基准测试。

派发 CI 快照共 31 项,全部结束:14 success、15 skipped、2 neutral,无失败或待运行项;mergeable 为 true,mergeable_state 为 behind。

aptend
aptend previously requested changes Oct 19, 2026

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

Reviewed exact head a0e585b3090302fc57d9a8eabbe954b98d6d1aee, actual base/merge-base def799e1260dd547cae2e0e54323ea20ec1b7685, all history/replies and the complete 32-file scope. Independent decision: REQUEST_CHANGES at the mandatory design-first gate; no runtime defect is asserted by this review.

The complete change is not just FIELD byte comparison: 1,861 non-generated production lines introduce retained CASE/parameter type history across executions, revision-sensitive cache admission, failure-sensitive generation reset/publication, compile-retry propagation and connection-migration suppression. I traced those scope owners in planner/frontend and read both existing prepared-specialization/argument-domain documents in full. Neither documents these new lifecycle/compatibility contracts; the PR does not provide/link a versioned design for them.

This is not a request for a separate human approval badge, RFC conversion or separate design PR. Please provide/link the scope-specific versioned design (or extend the existing contract), covering invariants/alternatives, snapshot ownership and bounds, publication/reset/retry/failed-metadata transitions, cache identity, migration behavior and common-path/two-pass costs with measurable acceptance criteria. I can then perform a distinct design phase before implementation approval. The repository's mo-self-review / feature-design-review contract requires stopping implementation approval while that technical artifact is missing.

The earlier NULLIF DEFAULT concern is addressed in current source: the no-QueryBuilder successful branch records source provenance and a planned-DEFAULT regression exists. I do not re-raise it. Exact-head CI39200730764 is successful. No local product-test pass or complete downstream correctness review is claimed: native preflight diagnosed missing libmo/rejected primary reuse; design-gate failure stopped further implementation validation.

Unhappy-path question Required design closure
Q1 — ownership/bounds Retained type snapshots and temporary binder graphs: ownership, publication and retention bound.
Q2 — failures/transitions Binding/metadata failure, pending reset, retry and migration linearization.
Q3 — accumulation/reuse Generation/cache reset and migration lifetime, plus incremental common-path/second-bind cost and acceptance evidence.

Comment thread pkg/sql/plan/prepared_field_types.go Resolved
@XuPeng-SH

XuPeng-SH commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-xupeng · done

Commit: f2b418d1bfe604a1825419b3abf6affe0f53d09b

Review completed. Read the assessment.

@XuPeng-SH

XuPeng-SH commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: f2b418d1bfe604a1825419b3abf6affe0f53d09b

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-xupeng · review

Commit: f2b418d1bfe604a1825419b3abf6affe0f53d09b

Assessment: request_changes

D2/D3 address the missing-design concern, but schema-change retry, history cleanup, and ordinary-SQL cost decisions remain unresolved. The earlier NULLIF DEFAULT omission is fixed in the current source and regression test.

Model: gpt-6-astra / xhigh

Session: 01a14d34-4e51-79a3-a62d-6c9c16279dc8 · slot 0 · generation 0

  • P2 pkg/frontend/computation_wrapper.go:3034: A prepared FIELD(CASE WHEN ? THEN n_name ELSE ? END,'A','a') captures VARCHAR history, then a definition-change retry binds n_name as VARBINARY.
    Impact: The retry retains the old text comparison domain and can return 1 instead of 2. Validate the captured dependency generation before reusing history, or carry a correctly rebuilt private generation through retries. Add regression coverage for both metadata-freezing states and the following EXECUTE.
    Evidence: The callback unconditionally passes preparedRetry.fieldTypes into rebinding. prepared_field_types.go:349 reuses the CASE fact by ordinal; parameter reprepare does not validate catalog dependencies. Compile.validateRetryResultMetadata checks output columns, which remain unchanged for FIELD, and frontend invalidation happens after Run. D3 documents a binder/retry-helper counterexample with these results; that diagnostic was not independently rerun here.

  • P2 pkg/frontend/prepared_execution.go:193: A history-bearing runtime Compile is evicted or deallocated and returned to the reuse pool.
    Impact: The new history snapshot remains reachable through buildPlanFunc after handle cleanup. Clear the callback at the actual pool-return boundary, preserving intentional prepared-Compile caching, and add a deterministic cleanup regression.
    Evidence: The new fieldTypes capture enters preparedExecutionBuildPlanFunc. releaseRuntimeCompile calls SetIsPrepare(false) and Release; doCompileRelease reaches reuse.Free and Compile.clear, which never clears buildPlanFunc. The callback-cleanup omission predates this PR, but this change attaches retained history to that path. This establishes unwanted retention, not unlimited growth or OOM.

  • P2 docs/design/CLAUDE_PREPARED_FIELD_TYPE_HISTORY_DESIGN_D3.md:78: Ordinary SQL nests string functions such as REVERSE over VARCHAR, without FIELD, CASE, or prepared history.
    Impact: The design leaves the additional common-path cost unresolved. Choose and document either an optimization that avoids repeated subtree resolution or an explicit accepted cost budget with measurable acceptance criteria before implementation approval.
    Evidence: base_binder.go invokes bindStringSourceDeclaration generally and creates a fresh resolver at line 6382; its memo is local, so nested consumers revisit inner expressions. D2 identifies potentially quadratic cumulative work. D3 reports substantial overhead for 32 nested REVERSE calls and explicitly leaves acceptance versus optimization undecided. Those benchmark numbers are author-reported, not independently measured here.

Validation:

  • Static audit passed: exact head/base, clean source, supplied patch equality apart from terminal newlines, git diff --check, D2 hash, and unchanged product/test inputs since a0e585b. Receipt: attempt-1/checks/1792400882870336172-3.json; log: attempt-1/review-scope-audit-v2.log under the assigned job directory.

  • The initial audit rejected only a terminal-newline difference; its failed receipt and review-scope-audit.log were retained separately.

  • Read D2/D3 and frozen review comments; traced history binding, retry metadata checks, terminal invalidation, and pool cleanup. Verified the prior NULLIF fix and its targeted DEFAULT regression in source.

  • Retained review-record.json and review-evidence.json. The frozen CI snapshot reports successful build, Ubuntu UT, coverage, and BVT checks; these do not close the identified design issues.

Limitations:

  • The design phase fails. Full downstream correctness, test-hunk, performance, race, and topology review remains unfinished under the repository mo-self-review rule that failed design 'short-circuits full implementation polishing'.

  • No local product tests or benchmarks ran. local_validation is empty; raw author diagnostic logs and execution receipts were not supplied, so reported outcomes are not claimed as independently verified passes.

  • The linked issue's full text was not supplied.

@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: f2b418d1bfe604a1825419b3abf6affe0f53d09b

Assessment: request_changes

D2/D3 close the previous missing-design-document concern. Immutable history owned by the prepared handle is reasonable, but changed-schema retries violate generation consistency, terminal cleanup retains history, and ordinary-SQL binding costs remain unresolved. The design gate does not pass.

Model: gpt-6-astra / xhigh

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

  • P2 pkg/frontend/computation_wrapper.go:3034: Establish history for FIELD(CASE WHEN ? THEN n_name ELSE ? END, 'A', 'a'), then rebuild through a definition-change retry after n_name changes from VARCHAR to VARBINARY, with unchanged parameters and value 'a'.
    Impact: The retry reapplies the old text CASE declaration and can return 1 instead of the fresh binary result 2. Validate captured dependencies before applying history; either terminate with the existing reprepare error or implement a consistent private retry generation.
    Evidence: prepared_field_types.go reuses CASE facts by ordinal and checks parameter compatibility without checking changed schema. Compile's result-metadata guard accepts unchanged FIELD output metadata; frontend invalidation occurs after execution. D3 section 1 reports the matching binder/retry counterexample. Independently traced this source path; no end-to-end concurrent-DDL reproduction was run.

  • P2 pkg/frontend/prepared_execution.go:193: A history-bearing prepared statement captures fieldTypes in its retry callback, then deallocation or cache replacement returns its Compile to the pool.
    Impact: The newly retained history maps outlive their terminal owner. Clear buildPlanFunc when Compile actually returns to the pool, while preserving callbacks for intentionally cached prepared compiles.
    Evidence: PrepareStmt.Close clears fieldTypes and releases the runtime Compile through SetIsPrepare(false)/Release. The pool invokes Compile.clear(), which leaves buildPlanFunc intact; NewCompile also does not clear it. The callback captures preparedRetry.fieldTypes. The callback-reset omission predates this PR, but the added history reference introduces this unclosed lifetime. This establishes retention, not unbounded leakage.

  • P2 pkg/sql/plan/base_binder.go:4763: Ordinary SQL binds nested string transformations such as 32 REVERSE layers over VARCHAR, without FIELD or prepared history.
    Impact: Validation requirement: close the common-path cost gate before approval. Retain reproducible paired binder benchmark inputs, commands and terminal logs, and either mitigate the repeated analysis or record an explicit acceptable cost boundary.
    Evidence: The new call reaches per-consumer resolver creation and recursive source traversal. D3 reports depth-32 binding increasing from 212654 to 327094 ns/op, with 63873 additional bytes and 276 allocations, and explicitly leaves acceptance unresolved. These are author-reported measurements; local_validation contains no corresponding receipts. Functional CI does not establish this performance contract.

Validation:

  • Static audit passed: exact head/base, clean source, 34 changed files, 1861 production changed lines, D2 hash, and git diff --check. Reconciled receipt /home/xupeng/.local/state/mo-bot/jobs/e503527c16c8803a2fd27ef7/attempt-1/checks/1792401102360902761-4.json with review-audit.log and review-source-ledger.json.

  • Verified that product and test files are unchanged from a0e585b; this increment adds only D2/D3.

  • The previous NULLIF DEFAULT concern is addressed by the no-QueryBuilder annotation and its regression test.

  • Frozen evidence records successful current-head build, unit tests, coverage and BVT checks. Raw CI logs and author probe receipts were not supplied; these statuses do not close the findings.

  • Retained detailed design assessment and evidence boundaries in attempt-1/review-notes.md.

Limitations:

  • The failed design gate stops implementation approval; exhaustive downstream implementation/test-hunk review remains deferred.

  • No local Go, native, runtime, MySQL or benchmark tests were executed. No environment setup failure was treated as a product failure.

  • The linked issue body was absent from the supplied evidence; its contract was assessed through the frozen PR, design documents and source.

aunjgr
aunjgr previously requested changes Oct 19, 2026

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

Request changes on f2b418d. The current design/implementation gate remains failed, not merely undocumented.

I read D2 and D3 and verified that production pkg/ content is unchanged from D3's tested snapshot a0e585b.

  1. Retry correctness: buildPlanForCompileRetry still binds with captured preparedRetry.fieldTypes and returns only the new plan. After a genuine VARCHAR→VARBINARY dependency change, the old CASE declaration can therefore retain the old FIELD comparison result. D3's actual-binder/executor control obtains 1 with old history versus 2 with fresh history; FIELD's unchanged integer result metadata means the Compile metadata guard does not reject it. Invalidating the cache after execution cannot repair the current result. Choose and approve a coherent fail-closed/reprepare or private retry-generation contract, then implement and validate it.
  2. Ordinary hot-path cost: D3 measures increased allocations and roughly 54% binding time in a 32-level ordinary REVERSE chain with no FIELD/history. This is not a zero-cost opt-in path. The design has no accepted budget for that growth; optimize it or explicitly settle the measured tradeoff and required bounds before approval.
  3. Terminal ownership: D2/D3 identify buildPlanFunc retaining the captured history/session when a Compile actually returns to the reuse pool. Close this at the real pool-clear owner, while preserving intentional prepared-Compile caching. This is a missing terminal reference release, not a claim of an infinite leak or OOM.

The recorded user go-ahead does not decide the subsequently discovered retry policy and cost questions. Passing CI and current-version DEFAULT round trips remain useful but do not close these counterexamples. I reuse the source-identical diagnostic evidence rather than claim a fresh local reproduction; implementation approval stops at this failed design gate, not an exhaustive pass over the remaining implementation.

@XuPeng-SH

XuPeng-SH commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 1ec4f5c5085c637c132c4b9cea9d0487a47736a5

Review completed. Read the assessment.

@XuPeng-SH

XuPeng-SH commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 1ec4f5c5085c637c132c4b9cea9d0487a47736a5

"interrupted"

@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: 1ec4f5c5085c637c132c4b9cea9d0487a47736a5

Assessment: request_changes

Reviewed the complete 40-file delta and supplied review concerns. Immutable prepared-history ownership, fail-closed retry, and compile cleanup are reasonable designs. However, parameter seeding bypasses the established explicit-CAST classification, causing a reproduced wrong-result defect despite all five owning package suites passing.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1586-7a01-9000-d45e20995cf8 · slot 1 · generation 1

  • P1 pkg/sql/plan/prepared_field_types.go:276: Prepare SELECT FIELD(CASE WHEN ? THEN ? ELSE NULL END,'A','a'), CAST(? AS SIGNED). Execute with (1,NULL,"1"), then (1,"a","1"), then (1,"a",1), changing only the third parameter's transport from VAR_STRING to LONGLONG on the last execution.
    Impact: The unrelated explicitly cast parameter incorrectly triggers statement-wide reprepare, discarding CASE history. FIELD changes from 2 to 1 although its inputs are unchanged. Preserve inherited CAST contracts using the existing explicit-cast classification and add a regression through actual PREPARE binding.
    Evidence: seedParameters checks only SyntaxExplicitCast, but the production PREPARE plan represents SIGNED, DECIMAL and CHAR casts with CAST1 and no such flag. isExplicitPreparedCast already recognizes this representation. The retained TestReviewPinnedFieldBehavior probe exercised initExecuteStmtParam and expression evaluation: FIELD returned 0,2,1 and history revision changed 2→3. SIGNED, nested CHAR→SIGNED, and DECIMAL variants all failed. See pinned-behavior.jsonl, review_pinned_behavior_test.go, review-behavior-overlay.json and checks/1792500361416669372-4.json (exit 1).

Validation:

  • Verified frozen HEAD and unchanged tracked source/build-copy files. Reconciled commands, source fingerprints, exit receipts and log hashes in /home/xupeng/.local/state/mo-bot/jobs/4dfa3d755dbd6827178f7a8f/attempt-1/review-evidence-manifest.json.

  • Isolation preflight passed. Recovered missing native prerequisites through make cgo in the diagnostic checkout; repository native-provenance verification passed. The initial missing-library setup failure executed no tests.

  • Full plan, frontend, compile, plan/function and parsers/tree suites passed: 39,746 passing test/subtest events and 3 skips. Receipt checks/1792500213134176823-3.json matches full-packages.jsonl. Focused checks separately passed 569 events.

  • Reviewer probes reproduced the CAST-history defect in three variants. Their source overlays and logs are retained; production source was not modified.

  • All 36 changed implementation/test files match author checkpoint 8cc91d1. Frozen CI reports successful UT, SCA, coverage, Connector/J reset and BVT checks; these do not cover the demonstrated gap.

Limitations:

  • The reproducer uses production binding and expression evaluation through frontend fixtures, not a live wire-protocol server.

  • No local race or distributed SQL rerun. Author raw race, SQL-harness and benchmark logs were unavailable for independent reconciliation.

  • Author measurements report restored baseline allocations but approximately 4.3% residual latency overhead for deeply nested TEXT binding; performance parity was not established.

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

@XuPeng-SH

XuPeng-SH commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: ac5777821b54fc6ce7e54bbf94d02d2ccdaf598b

Review completed. Read the assessment.

@XuPeng-SH

XuPeng-SH commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: ac5777821b54fc6ce7e54bbf94d02d2ccdaf598b

"interrupted"

@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: ac5777821b54fc6ce7e54bbf94d02d2ccdaf598b

Assessment: approve

Reviewed the complete 40-file delta and supplied review concerns. Immutable prepared-history ownership, metadata-gated publication, fail-closed dependency retries, and pool cleanup form a coherent design using existing owners. The NULLIF DEFAULT and explicit-CAST history defects are addressed. No actionable unresolved findings remain.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1586-7a01-9000-d45e20995cf8 · slot 1 · generation 1

Validation:

  • Verified frozen HEAD/base, patch equality, changed-file hashes, whitespace, and unchanged source checkout. Isolation preflight and repository-owned native build/provenance verification passed.

  • Focused planner, frontend, compile, and function validation passed: 44 root tests and 552 test/subtest passes, including CAST history, declaration boundaries, DEFAULT serialization, retry failures, and cleanup.

  • Migration/history race validation passed once and for 100 repetitions. Full frontend and compile race suites passed with 9,973 test/subtest passes and one existing unrelated skip.

  • Paired merge-base/current benchmarks confirmed identical allocations at REVERSE depths 1/8/32. Median latency changes were +8.4%/-1.7%/+0.7%; a longer reversed-order shallow comparison measured -4.5%. The earlier allocation regression is closed; latency parity is not claimed.

  • Reconciled 13 prerequisite/test/benchmark checks against commands, source identities, exit receipts, and retained logs. Evidence index and detailed review: /home/xupeng/.local/state/mo-bot/jobs/cc854fb425aa915edf991ef0/attempt-1/review-evidence-manifest.json and review-notes.md. Final reconciliation receipt: checks/1792519339188421477-3.json.

  • The frozen exact-head CI snapshot reports successful build, Ubuntu UT, SCA, coverage, Connector/J reset, and both BVT groups.

Limitations:

  • local_validation is empty. Raw CI and author validation artifacts were unavailable; their reported results are distinguished from independently reconciled local checks.

  • No local live-MySQL differential, distributed SQL rerun, mixed-version/restart test, or concurrent-DDL physical-retry wire injection was performed. Accepted migration refusal and retry-error behavior remain explicit compatibility tradeoffs.

  • Benchmarks used a shared CPU and establish neither universal latency parity nor workload throughput. The linked issue body was absent; its contract was assessed through the frozen PR, comments, design, and source.

@mergify

mergify Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-21 00:32 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-10-21 01:26 UTC · at c119c68881942a7c6e8fcdb44fa222d13625939f · squash

This pull request spent 53 minutes 19 seconds in the queue, including 52 minutes 27 seconds running CI.

Required conditions to merge

This branch was previously deployed

1 inactive deployment
ci — 2ca5f37c Deployed Oct 21, 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.

[Bug]: binary string functions use character semantics instead of byte semantics

6 participants