Skip to content

fix(sql): publish typed and expression column defaults in metadata - #32276

Merged
mergify[bot] merged 8 commits into
matrixorigin:mainfrom
gouhongshen:agent/issue-31161-main-51045356
Nov 6, 2026
Merged

mergify[bot] merged 8 commits into
matrixorigin:mainfrom
gouhongshen:agent/issue-31161-main-51045356

Conversation

@gouhongshen

@gouhongshen gouhongshen commented Nov 5, 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:

Related to #31161

What this PR does / why we need it:

Root causes

Two metadata-publication paths discarded type/expression information that default execution retains. Inserted values were always correct; only introspection metadata was wrong.

  1. Typed literal defaults rendered from origin text. columnDefaultValue (pkg/sql/plan/function/func_builtin.go) returned the persisted OriginString for every non-string default, so DECIMAL(10,4) DEFAULT 1.2 published 1.2 instead of the stored 1.2000, and BIT(8) DEFAULT b'00110011' published b'00110011' instead of the stored b'110011'. String defaults were already scanner-decoded; numeric/BIT carriers were never rendered from the resolved type. Integer literals above uint64 bind target-free as raw Literal_Decimal128Val (lexer DECIMAL_VALUE), so DECIMAL(40,4) DEFAULT 18446744073709551616 published the origin token while the executor widened and rescaled to 18446744073709551616.0000 — the renderer needed executor-parity decimal64→128→256 carrier widening.
  2. Expression defaults carried no EXTRA marker. information_schema.COLUMNS.EXTRA (pkg/util/sysview/predefined.go) and the SHOW COLUMNS templates (pkg/sql/plan/build_show.go) computed EXTRA only for auto-increment and generated columns, so DEFAULT (uuid()) never surfaced MySQL's DEFAULT_GENERATED marker even though the expression executed correctly.

Exact changes

Approved design: docs/design/20261105-column-default-metadata-publication.md (revision 6, SHA-256 05dd30e100403f3ccd3c8e444b79a08505faabdc667f2b47dc13a95ce33734a8).

  • pkg/sql/plan/function/func_builtin_column_default.go (new): renderTypedLiteralDefault renders literal-classified DECIMAL/BIT defaults from the folded plan.Default at the declared type, including Decimal64Val→dec128/dec256 and Decimal128Val→dec256 widening with sign extension, a single rescale, and the same width checks as the executor's assignment casts; every unrecognized shape falls back to the origin text.
  • pkg/sql/plan/function/func_builtin.go: columnDefaultValue takes the full plan.Default, applies typed rendering for literal-classified DECIMAL/BIT defaults; new mo_show_visible_bin mode 7 classifies a default as DEFAULT_GENERATED (expression) or empty (literal); mode range extended from [0,6] to [0,7].
  • pkg/util/sysview/predefined.go: the DEFAULT_GENERATED arm is layered into all four branches of the current information_schema.COLUMNS identity after the generated-column arm (auto-increment/generated keep precedence; varchar(24) bound holds); the pre-change identity is frozen as InformationSchemaColumnsPreDefaultGeneratedDDL and registered in the adapter, metadata gate, and migration gate; delivery folds into the existing consolidated 4.0.7 COLUMNS upgrade entry via the dynamic current-DDL reference (4.0.7 is unreleased).
  • pkg/sql/plan/build_show.go: the same EXTRA arm is added to the SHOW COLUMNS / SHOW FULL COLUMNS templates (account-scoped and unscoped).
  • Tests: pkg/sql/plan/function/func_builtin_column_default_test.go (typed-renderer UTs incl. six decimal-carrier widening cases), pkg/tests/issues/issue_31161_test.go (end-to-end oracle: tables a–i, uint64-boundary decimal carriers, LIKE clone, reconnect re-asserts, invalid-INSERT and bad_uuid rejection pins), pkg/util/sysview/predefined_test.go + view_columns_history_test.go (frozen-generation pins), pkg/sql/plan/function/func_builtin_test.go (mode-range message), BVT test/distributed/cases/ddl/column_default_typed_metadata.sql + .result (45 statements).

Issue-to-test proof

  • UT red→green: go test -count=1 -run 'Test_BuiltIn_MoShowVisibleBinColumnDefault' ./pkg/sql/plan/function/ — exit 1 with exactly 5 carrier-case FAILs on the pre-fix tree (18446744073709551616 vs expected 18446744073709551616.0000); exit 0, ok pkg/sql/plan/function 1.513s after the fix.
  • SQL oracle red→green: go test -count=1 -run TestIssue31161ColumnDefaultMetadata ./pkg/tests/issues/ — pre-fix only the uint64+1 decimal(40,4) metadata diverged; post-fix ok pkg/tests/issues 10.910s, covering metadata + inserted values, i_like clone, reconnect, and the bad_uuid CREATE rejection (error 20301 retained).
  • Full function suite: go test -count=1 -timeout 15m ./pkg/sql/plan/function/... — 6 packages ok, zero FAIL. go vet over the touched packages — exit 0. Sysview, SHOW COLUMNS template (6/6), and bootstrap versions (incl. v4_0_7) suites pass.
  • Live isolated cluster (fixed mo-service): replayed CREATE variants (quoted/plain/negative controls, uint64-boundary carriers), LIKE clone, invalid-INSERT rejection, and the unparenthesized DEFAULT uuid() rejection probe (ERROR 20301, expected) via mysql client — all expectations met.
  • BVT: mo-tester method=genrs regenerated the .result (inspected line by line; purely additive diff for the new t_u64boundary section), then method=run — TOTAL 45, SUCCESS 45, FAILED 0.

Residual risks

  • Generalized edges beyond the issue's recorded MySQL 8.3 evidence (attributed compositions, precision above 38, scale-0 rounding, scientific/boolean/signed spellings, folded functions) are anchored by inserted-value consistency and MatrixOne planner/executor semantics; no live MySQL reference was reachable on the validation host.
  • Full pkg/sql/plan suite remains for CI; focused package suites are green.
  • Branch base is pinned at 692c8e17a6 (12 commits behind origin/main at selection time); owner files showed no upstream changes.
  • Out of scope by design: binary charset rendering ([Bug]: BINARY VARBINARY BLOB columns falsely report a character set in information_schema #31160), generated columns, ON UPDATE EXTRA, FLOAT/DOUBLE and hex-on-integer rendering.

CI repair (2026-11-06)

  • UT Coverage failure TestIssue26232ViewDefaultAndCTASContracts (run 42112811776, job 127545392446): the issue-26232 CTAS contract test still expected the pre-change raw origin text 0 for the synthesized zero default of ctas_view.bit_col. The typed renderer intentionally publishes every BIT default in MySQL bit-literal form (b'0'), so the stale expectation failed with expected "0", actual "b'0'". Repaired in e51f68b790 by aligning the test expectation with the designed rendering (test-only change).

  • Local proof: mo-cgo-test -count=1 -v -run '^(TestIssue26232ViewDefaultAndCTASContracts|TestIssue31161ColumnDefaultMetadata)$' ./pkg/tests/issues/ — both PASS, ok pkg/tests/issues 7.896s.

  • BVT COMPOSE PESSIMISTIC failure (run 42119318088, job 127572602832, 7 statements): three pre-existing BVT expectations still assumed an empty Extra for expression defaults — ddl/alter_table_expression_default.sql (desc t_def), mo_cloud/mo_cloud.sql and system_variable/system_variables.sql (DESC mysql.columns_priv/procs_priv/tables_priv, Timestamp DEFAULT CURRENT_TIMESTAMP()). The designed SHOW COLUMNS EXTRA arm marks every expression default DEFAULT_GENERATED, so the stale rows failed with expected [], actual [DEFAULT_GENERATED]. Repaired in 0fb9c90a63 by aligning the three .result files with the designed output (test-only change).

  • Local proof: fresh isolated cluster on this head's mo-service — mo-tester alter_table_expression_default.sql 15/15 PASS and column_default_typed_metadata.sql 45/45 PASS; for the six box-format DESC statements the EXPECT/ACTUAL row blocks are byte-identical (local mo-tester build additionally flags a pre-existing, PR-unrelated RSMetaData header annotation difference [1,0,0] vs [12,-1,0] on 30–34 statements per file incl. untouched ones — CI's mo-tester build does not compare it), and direct mysql-client DESC of the three mysql.*_priv tables returns DEFAULT_GENERATED for the Timestamp rows.

  • SCA static-check-analysis failure (run 42127152069, job 127594967934, Linux/arm64): the gofmt linter flagged 4 PR files (3 shown + 1 hidden by max-same-issues) — const-block comment alignment in func_builtin.go, a '' doc-comment pair in func_builtin_column_default.go (rephrased to keep the comment ASCII), and comment/value column alignment in func_builtin_column_default_test.go and issue_31161_test.go. Repaired in 67c217e3df; formatting only, no behavior change.

  • Local proof: gofmt -l clean on the entire PR Go closure; go vet (CGo env) exit 0 and golangci-lint run -c .golangci.yml --new-from-rev <merge-base> → 0 issues on the four changed packages pkg/sql/plan/function, pkg/sql/plan, pkg/util/sysview, pkg/tests/issues (linter 2.14.0, same as CI).

  • BVT multi-CN COMPOSE PESSIMISTIC failure (run 42135150377, job 127625016017, 23 statements), two classes:

    1. Classifier bug (code fix, 96771eb33f): the planner wraps persisted ENUM/SET literal defaults in the value-to-index cast family — cast_index_value_to_index (integer enum), cast_set_value_to_index / cast_set_index_value_to_index (string/integer set) — but only cast_value_to_index was on the transparent-cast list, so enum('T','E') DEFAULT 1/2 and set('') DEFAULT '' were misclassified as expression defaults and published DEFAULT_GENERATED, contradicting design invariant I3 (literal defaults stay empty) and MySQL. Added the three sibling wrapper names to isTransparentCastName (dtype/enum.sql, enum_2.test, mysql_compat_enum_set_numeric.sql failed on this).
    2. Stale BVT expectations (test-only): pre-existing .result rows still assumed an empty Extra for CURRENT_TIMESTAMP()/NOW()/now()/uuid() expression defaults (database/system_table.result, dml/show/show_create_table.result, dtype/uuid_type_and_uuid_func.result, pessimistic_transaction/vector/vector.result) and the pre-change information_schema.COLUMNS view text (dml/show/show.result, zz_accesscontrol/account_restricted.result; the view cell gains the mode-7 arm in all four UNION branches, 18896 → 19220 chars). Aligned with the designed output.
  • Local proof: focused UT Test_BuiltIn_MoShowVisibleBinColumnDefaultTypedAndExtra fails on the new enum/set wrapper rows without the fix (expected , but get DEFAULT_GENERATED ×3), passes with it (ok pkg/sql/plan/function 1.969s); fresh isolated cluster on this head's mo-service — direct SQL assertions (enum/set literal defaults → empty Extra, CURRENT_TIMESTAMP() → DEFAULT_GENERATED, SHOW CREATE TABLE information_schema.columns byte-identical to the new expectation with 4 mode-7 arms), and mo-tester on all nine affected files: the four space-format files 100% green (64/64, 24/24, 39/39, 74/74), show.test row 295 passes outright, remaining box-format diffs are only the known pre-existing local-mo-tester RSMetaData annotation quirk with byte-identical value rows, plus one @bvt:issue#17811-gated known-flaky system.statement_info timing check that CI skips.

  • Coverage gate failure (run 42144788179, job 127673641986): PR modified-line coverage was 55.63% against the 75% gate — func_builtin_column_default.go stood at 52.46% because the integer/bool/float32 literal carriers, the signed/unsigned integer→decimal helpers, the width/scale overflow rejections, the decimal256 const-vector decode failures, the BIT literal carriers, and the classifier guard branches were reachable only through BVT or not at all. Repaired in 071d57e6d1 (test-only): direct table-driven UTs for every literal carrier kind across decimal64/128/256, the canonical sign-chain peel and negative typed rendering, the admission-composition guards, the quoted-span and signed-numeric-literal scanners, and the mo_show_visible_bin NULL-mode and decode-error paths (incl. mode 7).

  • Local proof: mo-cgo-test -count=1 -timeout=1200s -coverprofile=... ./pkg/sql/plan/function — ok pkg/sql/plan/function 29.698s; go tool cover -func shows every function in func_builtin_column_default.go at 100.0% (zero uncovered blocks), and the PR-modified lines of func_builtin.go (NULL-mode error, mode-7 decode error) are covered; remaining uncovered lines in that file are pre-existing error paths outside this PR's diff.

information_schema.COLUMNS and SHOW COLUMNS rendered DECIMAL/BIT literal
defaults from their persisted origin text (1.2 instead of 1.2000 for
DECIMAL(10,4); b'00110011' instead of b'110011' for BIT(8)), and
expression defaults such as DEFAULT (uuid()) carried no EXTRA marker,
while inserted values were always correct.

- add renderTypedLiteralDefault: literal-classified DECIMAL/BIT defaults
  render the resolved value from the folded plan.Default at the declared
  type, with executor-parity decimal64->128->256 widening (sign extend,
  rescale once, width-checked); unrecognized shapes keep the origin text
- add mo_show_visible_bin mode 7: DEFAULT_GENERATED for expression
  defaults, empty for literal defaults
- layer the DEFAULT_GENERATED arm into the current information_schema
  COLUMNS identity (all four branches), freeze the pre-change identity
  as a recognized historical generation, and update the recognition
  seams (adapter, metadata gate, migration gate)
- add the same EXTRA arm to the SHOW COLUMNS / SHOW FULL COLUMNS
  templates
- delivery folds into the existing consolidated 4.0.7 COLUMNS upgrade
  entry through the dynamic current-DDL reference

Design: docs/design/20261105-column-default-metadata-publication.md (r6)

Related to matrixorigin#31161
…rendering

The typed column-default renderer now publishes every BIT default in the
MySQL bit-literal form (zero renders b'0'), independent of the original
spelling. The issue-26232 CTAS contract test still expected the pre-change
raw origin text "0" for the synthesized zero default of ctas_view.bit_col,
which failed UT Coverage on the merged head. Update the expectation to the
designed b'0' rendering; no production code changes.

Local proof: mo-cgo-test -count=1 -v -run
'^(TestIssue26232ViewDefaultAndCTASContracts|TestIssue31161ColumnDefaultMetadata)$'
./pkg/tests/issues/ -> both PASS, ok 7.896s.
…DESC

The typed column-default publication marks expression defaults with
DEFAULT_GENERATED in SHOW COLUMNS/DESC Extra per the approved design.
Align three pre-existing BVT expectations that still assumed an empty
Extra: alter_table_expression_default (desc t_def), mo_cloud and
system_variables (DESC mysql.columns_priv/procs_priv/tables_priv).
The Coverage gate rejected the PR at 55.63% modified-line coverage
(threshold 75%): func_builtin_column_default.go stood at 52.46% because
the integer/bool/float32 literal carriers, the signed/unsigned integer
to decimal conversion helpers, the width/scale overflow rejections, the
decimal256 const-vector decode failures, the BIT literal carriers, and
the classifier guard branches were only reachable through BVT or not at
all.

Add direct table-driven UTs for every literal carrier kind across
decimal64/128/256, the canonical sign-chain peel and negative typed
rendering, the unsigned-decimal admission composition guards, the
quoted-span and signed-numeric-literal scanners, and the
mo_show_visible_bin NULL-mode and decode-error paths (including mode
7). Local statement coverage of the new renderer file is 100% for every
helper, and the modified lines of func_builtin.go are fully covered.
@XuPeng-SH

XuPeng-SH commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 071d57e6d157f4a208ad5a291db525f73a827f2c

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: 071d57e6d157f4a208ad5a291db525f73a827f2c

Assessment: approve

No actionable defects found. The fix reuses assignment-cast and catalog-publication owners, preserves historical view recognition, and avoids new durable state. Typed-shape mirrors respect the planner dependency boundary.

Model: gpt-6.1-sol / max

Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0

Validation:

  • Reviewed the complete 22-file delta, discussion, linked issues and affected owners/consumers.

  • Reused frozen-head CI success for build, Ubuntu UT, arm64 SCA, coverage and both BVT groups.

  • Isolation preflight passed: checks/1793942720607297013-2.json; preflight.log.

  • Static audit passed: checks/1793943046734478021-2.json; source-audit.log. Verified frozen constructor composition, recognition seams, SHOW templates, result edits, case/result ordering and gofmt.

  • Saved review-plan.md, discussion-assessment.json and validation-index.json. Source remains unchanged.

Limitations:

  • No local Go/SQL runtime, live MySQL or released-binary upgrade rerun. Supplied CI has terminal results without per-test logs; author local-run summaries lack retained raw logs. Upgrade CI jobs were skipped.

  • Parenthesized signed numeric defaults retain the documented ambiguity with formatter-added parentheses in persisted origins.

@gouhongshen

Copy link
Copy Markdown
Contributor Author

@Mergifyio queue

@mergify

mergify Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

✅ Merged into main as dfc3ab0 at 08:51 UTC

3 h 14 min in the queue, 1 h 9 min of it CI.

So far

3 merge conditions met
  • #review-threads-unresolved = 0 · required by GitHub branch protection
  • github-review-approved · required by GitHub branch protection
  • any of · required by GitHub branch protection:
    • check-success = CI Required
    • check-neutral = CI Required
    • check-skipped = CI Required

Times in UTC · dashboard · how the merge queue works

@mergify mergify Bot added the queued label Nov 6, 2026

This branch was previously deployed

1 inactive deployment
ci — dd818564 Deployed Nov 6, 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.

3 participants