Skip to content

[Bug]: View metadata drops source defaults and breaks View CTAS inserts #26232

Closed

Description

@Ariznawlll

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

main

Commit ID

7cb78aa

Other Environment Information

- MatrixOne: 8.0.30-MatrixOne-v1.3.0
- MySQL reference: 8.0.45

Actual 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

  • DESC and information_schema.columns report 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/SET type, 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

  1. added this to the MO-202607 milestone on Jul 27, 2026
  2. added
    kind/bug
    on Jul 27, 2026
  3. added theissue type on Jul 27, 2026
  4. added
    severity/s0
    and removed on Aug 3, 2026
  5. added a commit that references this issue on Aug 8, 2026
    08770e1
  6. slyunnn commented on Aug 12, 2026

    @slyunnn

    Regression and extended verification for #26232 (2026-08-12)

    Follow-up to fix(plan): preserve source defaults in view metadata (#26729).

    Verification environment

    • MatrixOne main: 9a7c98b8f3aa07fad24b411d54c7a9f6cb3a8731
      • fix(plan): enforce index metadata invariants safely (#26982)
    • Fix commit: 08770e1beeb23239c91165492f2fe85243a3c66a
      • fix(plan): preserve source defaults in view metadata (#26729)
    • MOTR branch: test/issue-26232-view-default-ctas
    • MOTR commit: e6179d6eab83b66651684c654515788561db3c49
    • Topology: local single-node MatrixOne service.

    What was covered

    • Original regression:

      • Source NOT NULL DEFAULT columns projected through a View.
      • Result: OK. View metadata preserves direct source defaults.
    • Happy path:

      • Direct projection and aliased projection with explicit View column names.
      • Result: OK. Integer default 7 and string default 'seed' are retained.
    • Unhappy path:

      • A semantic expression (qty + 1) over a source column with a default.
      • Result: OK. The expression output does not inherit the source default.
    • CTAS behavior:

      • CREATE TABLE ... AS SELECT from the direct View, followed by an insert omitting non-nullable columns.
      • Result: OK. The CTAS target accepted the insert and used executable target defaults.

    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 0 and an empty string, respectively.

    MOTR / BVT coverage

    • Existing upstream coverage:

      • pkg/tests/issues/issue_26232_test.go
    • Added MOTR coverage:

      • suites/14_issue_regression/t/issue_26232_view_default_ctas.test
      • suites/14_issue_regression/r/issue_26232_view_default_ctas.result
    • Record: 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.

  7. added 3 commits that reference this issue on Sep 17, 2026
    26068d8
    7fb2f14
    6fc4d1d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s0

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions