Skip to content

[Bug]: information_schema.VIEWS reports aggregate views as updatable and returns CREATE VIEW as the definition #27655

Closed

Description

@Ariznawlll

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

main

Commit ID

a53f5a3

Other Environment Information

  • Deployment: local multi-CN (launch-multi-cn)
  • Server: 8.0.30-MatrixOne-v20260826

Actual Behavior

information_schema.VIEWS hard-codes every view as IS_UPDATABLE='YES', including aggregate views that MatrixOne rejects for DML. VIEW_DEFINITION also contains the complete CREATE VIEW ... statement rather than the view's SELECT definition.

The behavior was reproduced 3/3 with fresh databases and was identical on both CNs:

IS_UPDATABLE=YES
VIEW_DEFINITION=create view agg_v as select a,count(*) cnt from t group by a
UPDATE agg_v ... -> ERROR 20301: cannot insert/update/delete from view

Expected Behavior

  • A grouped/aggregate view is reported as IS_UPDATABLE='NO'.
  • VIEW_DEFINITION contains the SELECT statement defining the view, matching the documented MySQL information-schema contract.
  • Metadata and actual DML capability do not contradict each other.

Steps to Reproduce

DROP DATABASE IF EXISTS metadata_view_repro;
CREATE DATABASE metadata_view_repro;
USE metadata_view_repro;

CREATE TABLE t(a INT);
CREATE VIEW agg_v AS SELECT a,COUNT(*) cnt FROM t GROUP BY a;

SELECT TABLE_NAME,VIEW_DEFINITION,IS_UPDATABLE
FROM information_schema.VIEWS
WHERE TABLE_SCHEMA='metadata_view_repro';

UPDATE agg_v SET cnt=1;

Additional information

The current InformationSchemaViewsDDL in pkg/util/sysview/predefined.go returns tbl.rel_createsql and the literal 'YES'. This can mislead ORM and migration tools that use information_schema.VIEWS to decide whether a view is writable or to compare definitions.

Activity

  1. added this to the MO-202608 milestone on Aug 26, 2026
  2. added
    kind/bug
    on Aug 26, 2026
  3. added theissue type on Aug 26, 2026
  4. added
    ai-light
    on Oct 21, 2026
  5. Ariznawlll commented on Oct 21, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:7038c8520e5fc1ba456914b3c389ccedb69e22f7(执行时官方 main,包含修复 PR fix: correct information schema views metadata #27716;发布前 main 后续仅新增与本问题无关的 Top 算子提交)
    • 部署方式:隔离的 macOS arm64 本地服务,1 LogService / 1 TN / 2 CN;MySQL 协议分别连接两个 CN(16001、16002),使用全新数据目录和每轮独立数据库。
    • 测试日期:2026-10-21

    原问题验证

    按 issue 原始步骤创建 t(a,b),插入 (1,10),(1,20),(2,30),创建 agg_v AS SELECT a,COUNT(*) cnt FROM t GROUP BY a,并查询 information_schema.VIEWS。两个 CN 各独立执行 3 轮,共 6/6:agg_v.IS_UPDATABLE=NO,VIEW_DEFINITION 以 select 开头、含 COUNT(*) 和 GROUP BY,不再返回完整 CREATE VIEW;实际聚合结果均为 a=1,cnt=2、a=2,cnt=1。元数据字段均非 NULL。

    Happy Path 覆盖

    1. 同轮创建普通 direct_v AS SELECT a,b FROM t:其 VIEW_DEFINITION 同样为 SELECT 定义,而非 CREATE 语句;当前产品不支持对 view 写入,因此 IS_UPDATABLE=NO 与实际能力一致。两个 CN 各 3/3。
    2. 对基础表正常执行 UPDATE t SET b=11 WHERE a=1 AND b=10,最终行集精确为 (1,11),(1,20),(2,30),两个 CN 各 3/3;每轮删除独立数据库,6/6 清理完成。

    Unhappy Path 覆盖

    1. 对聚合 view 执行原始 UPDATE agg_v SET cnt=1:两个 CN 各 3/3 被拒绝,拒绝后的基础表仍精确为 (1,10),(1,20),(2,30),没有部分写入。另对普通 view 的 UPDATE 做了单次对照,返回 ERROR 20301: cannot insert/update/delete from view,因此没有把普通 view 错判为可更新。

    白盒验证

    独立运行 pkg/util/sysview 的 TestInformationSchemaViewsMetadata -count=3 通过;pkg/sql/plan/function 的 TestViewDefinitionFunctionRegistration、TestViewDefinitionFromPersistedData、TestBuiltInViewDefinition、TestBuiltInViewCheckOption 均以 -count=3 通过。此 issue 的原始缺陷可通过公开 SQL 完整触发,未另做故障注入或 race;初版 QA 脚本对 COUNT 字母大小写的假设导致一次测试脚本失败,已改用大小写无关的断言,该次不计入产品结果。

    回归测试

    修复 PR #27716 已合入 main,包含公开 SQL/BVT 成对用例 information_schema_views_metadata.sql / .result,覆盖聚合/普通 view 元数据、DML 拒绝和更多定义解析边界。PR 的 Linux 多 CN BVT 与 CI Required 为 SUCCESS;我本地未另跑完整 BVT suite,也未向 MOTR 重复添加同一公开 SQL 用例。

    测试证据

    • 本次独立 SQL 运行结果:16001 3/3、16002 3/3;每轮元数据 NO/SELECT、聚合结果 1:2,2:1、拒绝后行集不变、基础表更新和清理均通过。隔离服务已正常停止,两个端口释放。
    • PR 多 CN BVT job 的日志包含上述 information_schema_views_metadata.sql,job SUCCESS;CI Required SUCCESS。

    测试结论

    测试通过。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ai-lightkind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions