Repository navigation
Description
Is there an existing issue for the same bug?
- I have checked the existing issues.
Branch Name
main
Commit ID
Other Environment Information
- MatrixOne: 8.0.30-MatrixOne-v1.3.0
- MySQL reference: 8.0.45Actual Behavior
A view over a source column with a non-NULL default drops the default from
its persisted column metadata. A CTAS target created from that view therefore
has a NULL default for a non-nullable column and cannot insert a row that
omits the column.
For this source definition, MatrixOne reports DEFAULT 7 on source_t.qty
but NULL on v_source_t.qty and ctas_view.qty:
CREATE TABLE source_t (
id INT PRIMARY KEY,
qty INT NOT NULL DEFAULT 7
);
INSERT INTO source_t (id) VALUES (1);
CREATE VIEW v_source_t AS SELECT id, qty FROM source_t;
CREATE TABLE ctas_view AS SELECT id, qty FROM v_source_t;
DESC source_t;
DESC v_source_t;
DESC ctas_view;
INSERT INTO ctas_view (id) VALUES (2);The final insert fails three out of three runs with:
ERROR 20301 (HY000): invalid input: invalid default value for column 'qty'
The view query itself returns the correct existing value (qty = 7).
Expected Behavior
View metadata should preserve the source default where the projected column
is a direct column reference. A CTAS target created from the view should have
a usable default for omitted non-nullable columns, consistent with the
reference behavior.
Reference behavior
MySQL 8.0.45 reports DEFAULT 7 for v_source_t.qty. Its CTAS target from the View has a usable default (0) and accepts INSERT INTO ctas_view (id) VALUES (2).
The View default and the CTAS target default therefore have separate observable contracts: the View must preserve the source default text, while the CTAS target must have a valid default that permits omission of the non-nullable column. The CTAS default text must not be assumed to equal the source default without an explicit reference-engine rule.
Revised implementation scope
This issue depends on #26226 and must consume its planner-local OutputColumnProvenance result. It must not add another source-column resolver based on output names, expression strings, or catalog re-queries.
A View output may inherit a default only when its captured provenance is a valid single source and that source ColDef has a default. Direct projections, aliases, explicit View column names, and transparent single-source query boundaries preserve that eligibility. Constants, functions, arithmetic, aggregates, set operations, recursive CTEs, and outputs without a unique bound source do not inherit a default.
Multi-table queries must resolve the exact bound source column and must never infer a default from an unqualified or duplicated column name.
Acceptance criteria
DESCandinformation_schema.columnsreport the source default for eligible direct or transparently propagated View columns.- SELECT aliases and explicit View column names do not change default inheritance.
- Nullable columns, explicit
DEFAULT NULL, string defaults, and expression defaults preserve their catalog text according to the existing default contract. - Non-source expressions and provenance-clearing boundaries produce no inherited source default.
- The [Bug]: View projection loses ENUM/SET ordering and CTAS type metadata #26226
ENUM/SETtype, ordering, and raw-value behavior remains unchanged when a source column also has a default. - The public source-table -> View -> CTAS -> omitted-column INSERT path succeeds, and View metadata plus CTAS behavior are checked independently.
Dependencies
Implementation order: #26226 -> #26232 -> #26227. After this issue is complete, #26227 must use the same authoritative View schema-generation path when dependency DDL requires persisted metadata refresh.
Activity
fix(plan): preserve source defaults in view metadata (#26729)
slyunnn commentedon Aug 12, 2026
Regression and extended verification for #26232 (2026-08-12)
Follow-up to
fix(plan): preserve source defaults in view metadata(#26729).Verification environment
9a7c98b8f3aa07fad24b411d54c7a9f6cb3a8731fix(plan): enforce index metadata invariants safely (#26982)08770e1beeb23239c91165492f2fe85243a3c66afix(plan): preserve source defaults in view metadata (#26729)test/issue-26232-view-default-ctase6179d6eab83b66651684c654515788561db3c49What was covered
Original regression:
NOT NULL DEFAULTcolumns projected through a View.Happy path:
7and string default'seed'are retained.Unhappy path:
qty + 1) over a source column with a default.CTAS behavior:
CREATE TABLE ... AS SELECTfrom the direct View, followed by an insert omitting non-nullable columns.Findings
The original issue was not reproduced on current
main.View metadata inherits a default only for outputs with a unique direct source-column provenance. Aliases and explicit
View column names preserve that eligibility; expressions do not.
View-default metadata and CTAS defaults have distinct contracts: the CTAS target must have a valid executable default,
but it is not required to copy the View/source default text. In this verification, the omitted CTAS integer and string
columns used target defaults
0and an empty string, respectively.MOTR / BVT coverage
Existing upstream coverage:
pkg/tests/issues/issue_26232_test.goAdded MOTR coverage:
suites/14_issue_regression/t/issue_26232_view_default_ctas.testsuites/14_issue_regression/r/issue_26232_view_default_ctas.resultRecord: 14/14 statements passed.
Replay: 14/14 statements passed.
The MOTR files were added to preserve the public SQL behavior separately for direct View metadata, aliases, expression
provenance clearing, and CTAS omitted-column inserts. No MatrixOne service source code was modified.
Final conclusion
#26232 is fixed on current
main.The independent MOTR branch has been pushed and is ready for inclusion in the daily regression PR.
fix(plan): preserve source defaults in view metadata (matrixorigin#26729
fix(plan): preserve source defaults in view metadata (matrixorigin#26729
fix(plan): preserve source defaults in view metadata (matrixorigin#26729