Repository navigation
Description
Description
MatrixOne stores the original SELECT * text for a View and expands the star again against the current base-table schema every time the View is queried. Adding, dropping, or renaming a base-table column therefore changes the View's result-column set after creation, while the persisted View catalog still reports the old columns.
This differs from MySQL, which expands * when the View is created and keeps that selected column set stable. The MatrixOne behavior can change result metadata and break INSERT ... SELECT or clients that prepared/scanned the original result shape.
Environment
- Branch:
main - Commit:
b84a6627060539173f9ee243e8523792a3ad2200 - Deployment: local standalone MatrixOne (
etc/launch/launch.toml), 1 CN / 1 TN / 1 Log service, MySQL text protocol - Oracle: MySQL 8.0.45
Steps to reproduce
DROP DATABASE IF EXISTS view_star_dynamic;
CREATE DATABASE view_star_dynamic;
USE view_star_dynamic;
CREATE TABLE t(a INT PRIMARY KEY, b VARCHAR(5));
INSERT INTO t VALUES (1,'x'),(2,'yy');
CREATE VIEW v_star AS SELECT * FROM t;
CREATE VIEW v_explicit AS SELECT a,b FROM t;
ALTER TABLE t ADD COLUMN c INT DEFAULT 7;
DESC v_star;
SELECT * FROM v_star ORDER BY a;
SELECT c FROM v_star ORDER BY a;
CREATE TABLE target2(a INT,b VARCHAR(5));
INSERT INTO target2 SELECT * FROM v_star;
SELECT COUNT(*) FROM target2;Actual behavior
DESC v_star still reports the two creation-time columns a,b, but query binding re-expands the stored star and exposes the new column:
SELECT * FROM v_star;
a b c
1 x 7
2 yy 7
SELECT c FROM v_star;
c
7
7
The two-column insert then fails and leaves the target empty:
ERROR 20301 (HY000): invalid input: insert values does not match the number of columns
COUNT(*)
0
SHOW CREATE VIEW continues to show CREATE VIEW v_star AS SELECT * FROM t, so the query-time re-expansion is persistent.
Expected behavior
MySQL 8.0.45 expands the star in the stored View definition:
CREATE VIEW v_star AS
SELECT t.a AS a,t.b AS b FROM t
After adding c, SELECT * FROM v_star still returns only a,b, SELECT c FROM v_star returns unknown-column error 1054, and INSERT INTO target2 SELECT * FROM v_star succeeds with two rows.
The View's executable result shape, DESC, information_schema.columns, CTAS, prepared execution, and INSERT SELECT must agree on the same stable column set.
Stability and controls
- Reproducer: 3/3 fresh databases exposed
a,b,cthrough a View whose catalog contained onlya,b. - INSERT impact: 3/3 two-column
INSERT ... SELECT * FROM v_starstatements failed; every target remained at 0 rows. - CTAS impact:
CREATE TABLE copied AS SELECT * FROM v_starcreated and stored all three visible columns, confirming the extra column reaches materialization rather than being a client-print artifact. - Explicit-column control:
CREATE VIEW v_explicit AS SELECT a,b FROM tremained two columns and returned correct rows. - MySQL oracle: kept
a,b, rejected direct reference toc, and inserted two rows into the two-column target. - Explicit View-column-list boundary:
CREATE VIEW v_named(x,y) AS SELECT * FROM tbecomes unusable after ADD COLUMN with error 1353 because the dynamically expanded star has three expressions for two persisted names; MySQL remains usable. - Nested View boundary: a View-of-View created before the ALTER also dynamically exposed the new column while retaining two-column catalog metadata.
- DROP COLUMN boundary: MatrixOne dynamically removed the dropped column and continued querying the star View; MySQL marked the View invalid because its fixed selected column was removed.
- No source data was modified by rejected inserts; the session and service remained usable with no panic, restart, or hang.
Evidence
The minimal reproducer, three fresh-database repetitions, MySQL oracle, explicit-column control, CTAS, nested View, explicit View column list, DROP COLUMN, and failure-atomicity checks were executed on 2026-08-11 against the exact commit above.
Code analysis
Confirmed path:
genViewTableDefinpkg/sql/plan/build_ddl.gobinds the creation-time query and persists the two-columnTableDef, but storesctx.GetRootSql()unchanged inViewData.Stmt.QueryBuilder.bindViewinpkg/sql/plan/query_builder.goparses that storedCREATE VIEW ... SELECT * ...again for every query and rebinds it against the current base-table schema.
The persisted schema and query-time schema can consequently diverge. The fix should preserve the creation-time bound output-column set for star projections while still allowing supported dependency changes to refresh the types/defaults/nullability of those selected columns.
Regression coverage
After the product fix, add public BVT coverage under test/distributed/cases/view/ for:
- direct and nested
SELECT *Views after base-table ADD COLUMN; - explicit View column lists;
- ADD FIRST/AFTER ordering, RENAME, and DROP of selected/unselected columns;
DESC,information_schema.columns, direct SELECT, CTAS, and INSERT SELECT shape consistency;- prepared and ordinary execution after dependency DDL;
- rejected DML atomicity and session recovery.
Do not baseline the current dynamically changed result shape.
Related
- [Bug]: View metadata stays stale after source column type changes #26227 / PR fix: refresh persisted View metadata after dependency DDL #26876 covers refreshing metadata such as type, width, defaults, and nullability for columns already selected by a dependent View. This issue concerns the different invariant that a creation-time
SELECT *must not acquire newly added base columns or silently lose selected columns. - [Bug]: COM_QUERY plan cache returns deleted or replaced View data after DDL in another session #26882 covers stale COM_QUERY plans after View DROP/replace in another session; this reproduces with a fresh query in one session and is not a plan-cache invalidation failure.
Activity
fix view select star (#26964)
Ariznawlll commentedon Aug 17, 2026
测试版本
maine32c7dc95946c347710e706e70dfee2927bc84e0原问题验证
在 3 个全新数据库中创建
v_star AS SELECT * FROM t,随后ALTER TABLE t ADD COLUMN c。3/3 次DESC/SELECT *仍只有创建时的a,b,SHOW CREATE VIEW已保存展开后的列,INSERT INTO target2 SELECT * FROM v_star均成功并插入 2 行。Happy Path 覆盖
information_schema.columns:列集合保持a,b。INSERT ... SELECT *、View-of-View:均保持两列并返回正确数据。view_star_static_columns.sql覆盖。Unhappy Path 覆盖
SELECT c FROM v_star均按预期报column c does not exist。白盒验证
go test -mod=readonly ./pkg/sql/plan -run TestGenViewTableDefPersistsExpandedStarSelectList -count=1:通过。回归测试
已检查现有 BVT
test/distributed/cases/view/view_star_static_columns.sql,覆盖直接/嵌套 View、CTAS、INSERT SELECT、ADD FIRST/AFTER、RENAME、DROP 和错误路径。测试证据
/private/tmp/mo-26957-1.txt、-2.txt、-3.txt/private/tmp/mo-26957-extra-add.txt/private/tmp/mo-26957-extra-rename.txt测试结论
测试通过。
fix view select star (matrixorigin#26964)
fix view select star (matrixorigin#26964)
fix view select star (matrixorigin#26964)