Repository navigation
fix(sql): publish typed and expression column defaults in metadata - #32276
Conversation
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.
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
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.
|
@Mergifyio queue |
✅ Merged into
|
What type of PR is this?
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.
columnDefaultValue(pkg/sql/plan/function/func_builtin.go) returned the persistedOriginStringfor every non-string default, soDECIMAL(10,4) DEFAULT 1.2published1.2instead of the stored1.2000, andBIT(8) DEFAULT b'00110011'publishedb'00110011'instead of the storedb'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 rawLiteral_Decimal128Val(lexer DECIMAL_VALUE), soDECIMAL(40,4) DEFAULT 18446744073709551616published the origin token while the executor widened and rescaled to18446744073709551616.0000— the renderer needed executor-parity decimal64→128→256 carrier widening.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, soDEFAULT (uuid())never surfaced MySQL'sDEFAULT_GENERATEDmarker even though the expression executed correctly.Exact changes
Approved design:
docs/design/20261105-column-default-metadata-publication.md(revision 6, SHA-25605dd30e100403f3ccd3c8e444b79a08505faabdc667f2b47dc13a95ce33734a8).pkg/sql/plan/function/func_builtin_column_default.go(new):renderTypedLiteralDefaultrenders literal-classified DECIMAL/BIT defaults from the foldedplan.Defaultat the declared type, includingDecimal64Val→dec128/dec256 andDecimal128Val→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:columnDefaultValuetakes the fullplan.Default, applies typed rendering for literal-classified DECIMAL/BIT defaults; newmo_show_visible_binmode 7 classifies a default asDEFAULT_GENERATED(expression) or empty (literal); mode range extended from [0,6] to [0,7].pkg/util/sysview/predefined.go: theDEFAULT_GENERATEDarm is layered into all four branches of the currentinformation_schema.COLUMNSidentity after the generated-column arm (auto-increment/generated keep precedence; varchar(24) bound holds); the pre-change identity is frozen asInformationSchemaColumnsPreDefaultGeneratedDDLand 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).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), BVTtest/distributed/cases/ddl/column_default_typed_metadata.sql+.result(45 statements).Issue-to-test proof
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 (18446744073709551616vs expected18446744073709551616.0000); exit 0,ok pkg/sql/plan/function 1.513safter the fix.go test -count=1 -run TestIssue31161ColumnDefaultMetadata ./pkg/tests/issues/— pre-fix only the uint64+1 decimal(40,4) metadata diverged; post-fixok pkg/tests/issues 10.910s, covering metadata + inserted values,i_likeclone, reconnect, and thebad_uuidCREATE rejection (error 20301 retained).go test -count=1 -timeout 15m ./pkg/sql/plan/function/...— 6 packages ok, zero FAIL.go vetover the touched packages — exit 0. Sysview, SHOW COLUMNS template (6/6), and bootstrap versions (incl. v4_0_7) suites pass.mo-service): replayed CREATE variants (quoted/plain/negative controls, uint64-boundary carriers), LIKE clone, invalid-INSERT rejection, and the unparenthesizedDEFAULT uuid()rejection probe (ERROR 20301, expected) via mysql client — all expectations met.method=genrsregenerated the.result(inspected line by line; purely additive diff for the newt_u64boundarysection), thenmethod=run— TOTAL 45, SUCCESS 45, FAILED 0.Residual risks
pkg/sql/plansuite remains for CI; focused package suites are green.692c8e17a6(12 commits behindorigin/mainat selection time); owner files showed no upstream changes.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 text0for the synthesized zero default ofctas_view.bit_col. The typed renderer intentionally publishes every BIT default in MySQL bit-literal form (b'0'), so the stale expectation failed withexpected "0", actual "b'0'". Repaired ine51f68b790by 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
Extrafor expression defaults —ddl/alter_table_expression_default.sql(desc t_def),mo_cloud/mo_cloud.sqlandsystem_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 defaultDEFAULT_GENERATED, so the stale rows failed withexpected [], actual [DEFAULT_GENERATED]. Repaired in0fb9c90a63by aligning the three.resultfiles with the designed output (test-only change).Local proof: fresh isolated cluster on this head's
mo-service— mo-testeralter_table_expression_default.sql15/15 PASS andcolumn_default_typed_metadata.sql45/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 threemysql.*_privtables returnsDEFAULT_GENERATEDfor theTimestamprows.SCA
static-check-analysisfailure (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 infunc_builtin.go, a''doc-comment pair infunc_builtin_column_default.go(rephrased to keep the comment ASCII), and comment/value column alignment infunc_builtin_column_default_test.goandissue_31161_test.go. Repaired in67c217e3df; formatting only, no behavior change.Local proof:
gofmt -lclean on the entire PR Go closure;go vet(CGo env) exit 0 andgolangci-lint run -c .golangci.yml --new-from-rev <merge-base>→0 issueson the four changed packagespkg/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:
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 onlycast_value_to_indexwas on the transparent-cast list, soenum('T','E') DEFAULT 1/2andset('') DEFAULT ''were misclassified as expression defaults and publishedDEFAULT_GENERATED, contradicting design invariant I3 (literal defaults stay empty) and MySQL. Added the three sibling wrapper names toisTransparentCastName(dtype/enum.sql,enum_2.test,mysql_compat_enum_set_numeric.sqlfailed on this)..resultrows still assumed an emptyExtraforCURRENT_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-changeinformation_schema.COLUMNSview 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_MoShowVisibleBinColumnDefaultTypedAndExtrafails 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'smo-service— direct SQL assertions (enum/set literal defaults → empty Extra,CURRENT_TIMESTAMP()→DEFAULT_GENERATED,SHOW CREATE TABLE information_schema.columnsbyte-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.testrow 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-flakysystem.statement_infotiming 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.gostood 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 in071d57e6d1(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 themo_show_visible_binNULL-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 -funcshows every function infunc_builtin_column_default.goat 100.0% (zero uncovered blocks), and the PR-modified lines offunc_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.