From ec9d57cecc098b72a2382dd4de3817bb18fbdc12 Mon Sep 17 00:00:00 2001 From: Boudewijn van Groos Date: Wed, 25 Mar 2026 18:58:45 +0100 Subject: [PATCH] fix: nested views not working (#7857) Signed-off-by: Boudewijn van Groos --- src/catalog/src/table_source.rs | 6 +++- .../standalone/common/view/create.result | 31 ++++++++++++++++++- tests/cases/standalone/common/view/create.sql | 8 ++++- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/src/catalog/src/table_source.rs b/src/catalog/src/table_source.rs index 132e02fe14..8aabf64e99 100644 --- a/src/catalog/src/table_source.rs +++ b/src/catalog/src/table_source.rs @@ -151,7 +151,11 @@ impl DfTableSourceProvider { let catalog_list = Arc::new(DummyCatalogList::new(self.catalog_manager.clone())); let logical_plan = self .plan_decoder - .decode(Bytes::from(view_info.view_info.clone()), catalog_list, true) + .decode( + Bytes::from(view_info.view_info.clone()), + catalog_list, + false, + ) .await .context(DecodePlanSnafu { name: &table.table_info().name, diff --git a/tests/cases/standalone/common/view/create.result b/tests/cases/standalone/common/view/create.result index 1c6e0ee50b..76b9838628 100644 --- a/tests/cases/standalone/common/view/create.result +++ b/tests/cases/standalone/common/view/create.result @@ -30,6 +30,10 @@ CREATE VIEW test_view as SELECT * FROM public.numbers; Affected Rows: 0 +CREATE VIEW test_view2 as SELECT * FROM test_view; + +Affected Rows: 0 + --- View already exists ---- CREATE VIEW test_view as SELECT * FROM public.numbers; @@ -51,6 +55,7 @@ SHOW TABLES; | numbers | | test_table | | test_view | +| test_view2 | +------------------+ SHOW FULL TABLES; @@ -61,6 +66,7 @@ SHOW FULL TABLES; | numbers | LOCAL TEMPORARY | | test_table | BASE TABLE | | test_view | VIEW | +| test_view2 | VIEW | +------------------+-----------------+ -- psql: \dv @@ -124,17 +130,19 @@ SELECT * FROM INFORMATION_SCHEMA.TABLES ORDER BY TABLE_NAME, TABLE_TYPE; |greptime|information_schema|tables|LOCALTEMPORARY|ID|ID|ID|ID|ID|ID||ID|Fixed|ID|ID|ID|DATETIME|DATETIME||utf8_bin|ID|||Y| |greptime|public|test_table|BASETABLE|ID|ID|ID|ID|ID|ID|mito|ID|Fixed|ID|ID|ID|DATETIME|DATETIME||utf8_bin|ID|||N| |greptime|public|test_view|VIEW|ID|ID|ID|ID|ID|ID||ID|Fixed|ID|ID|ID|DATETIME|DATETIME||utf8_bin|ID|||N| +|greptime|public|test_view2|VIEW|ID|ID|ID|ID|ID|ID||ID|Fixed|ID|ID|ID|DATETIME|DATETIME||utf8_bin|ID|||N| |greptime|information_schema|views|LOCALTEMPORARY|ID|ID|ID|ID|ID|ID||ID|Fixed|ID|ID|ID|DATETIME|DATETIME||utf8_bin|ID|||Y| +++++++++++++++++++++++++ -- SQLNESS REPLACE (\s\d+\s) ID -- SQLNESS REPLACE (\s[\-0-9T:\.]{15,}) DATETIME -SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'VIEW'; +SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'VIEW' ORDER BY TABLE_NAME; +---------------+--------------+------------+------------+----------+-------------+-----------------+--------------+------------------+----------------+--------+---------+------------+------------+-----------+----------------+---------------------+---------------------+------------+-----------------+----------+----------------+---------------+-----------+ | table_catalog | table_schema | table_name | table_type | table_id | data_length | max_data_length | index_length | max_index_length | avg_row_length | engine | version | row_format | table_rows | data_free | auto_increment | create_time | update_time | check_time | table_collation | checksum | create_options | table_comment | temporary | +---------------+--------------+------------+------------+----------+-------------+-----------------+--------------+------------------+----------------+--------+---------+------------+------------+-----------+----------------+---------------------+---------------------+------------+-----------------+----------+----------------+---------------+-----------+ | greptime | public | test_view | VIEW |ID |ID |ID |ID |ID |ID | |ID | Fixed |ID |ID |ID |DATETIME |DATETIME | | utf8_bin |ID | | | N | +| greptime | public | test_view2 | VIEW |ID |ID |ID |ID |ID |ID | |ID | Fixed |ID |ID |ID |DATETIME |DATETIME | | utf8_bin |ID | | | N | +---------------+--------------+------------+------------+----------+-------------+-----------------+--------------+------------------+----------------+--------+---------+------------+------------+-----------+----------------+---------------------+---------------------+------------+-----------------+----------+----------------+---------------+-----------+ SHOW COLUMNS FROM test_view; @@ -169,10 +177,31 @@ SELECT * FROM test_view LIMIT 10; | 9 | +--------+ +SELECT * FROM test_view2 LIMIT 10; + ++--------+ +| number | ++--------+ +| 0 | +| 1 | +| 2 | +| 3 | +| 4 | +| 5 | +| 6 | +| 7 | +| 8 | +| 9 | ++--------+ + DROP VIEW test_view; Affected Rows: 0 +DROP VIEW test_view2; + +Affected Rows: 0 + DROP TABLE test_table; Affected Rows: 0 diff --git a/tests/cases/standalone/common/view/create.sql b/tests/cases/standalone/common/view/create.sql index b82704d3a9..91149f44f4 100644 --- a/tests/cases/standalone/common/view/create.sql +++ b/tests/cases/standalone/common/view/create.sql @@ -16,6 +16,8 @@ CREATE OR REPLACE VIEW test_table as SELECT * FROM public.numbers; CREATE VIEW test_view as SELECT * FROM public.numbers; +CREATE VIEW test_view2 as SELECT * FROM test_view; + --- View already exists ---- CREATE VIEW test_view as SELECT * FROM public.numbers; @@ -48,7 +50,7 @@ SELECT * FROM INFORMATION_SCHEMA.TABLES ORDER BY TABLE_NAME, TABLE_TYPE; -- SQLNESS REPLACE (\s\d+\s) ID -- SQLNESS REPLACE (\s[\-0-9T:\.]{15,}) DATETIME -SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'VIEW'; +SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'VIEW' ORDER BY TABLE_NAME; SHOW COLUMNS FROM test_view; @@ -58,8 +60,12 @@ SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'test_view'; SELECT * FROM test_view LIMIT 10; +SELECT * FROM test_view2 LIMIT 10; + DROP VIEW test_view; +DROP VIEW test_view2; + DROP TABLE test_table; SELECT * FROM test_view LIMIT 10;