Search before asking
Version
3.1.4
What's Wrong?
- mtmv not choosed when useing GROUPING SETS and select fileds has a alias
- mtmv not choosed when useing GROUPING SETS and CET and select from CET with filter grouping_id fileds
What You Expected?
sql2 and sql5 should choose the mtmv mv_table_a
How to Reproduce?
create database if not exists test;
drop table if exists test.table_a force;
CREATE TABLE test.table_a (
g varchar(20) NULL,
value_1 bigint NULL,
date_1 varchar(20) NULL
) ENGINE=OLAP
DUPLICATE KEY(g)
AUTO PARTITION BY LIST (date_1)()
PROPERTIES ("replication_allocation" = "tag.location.default: 1");
insert into test.table_a select 'g1' g,300 value_1,'2025-10-22' as date_1;
drop materialized view if exists test.mv_table_a;
CREATE MATERIALIZED VIEW mv_table_a BUILD IMMEDIATE REFRESH AUTO ON COMMIT
PARTITION by(date_1) DISTRIBUTED BY HASH(g) BUCKETS 17 PROPERTIES ('replication_num'='1')
as select date_1,g,sum(value_1) from test.table_a a group by date_1,g;
-- sql 1
--choose mv_table_a
explain
SELECT date_1,grouping_id(date_1),g,sum(value_1) x FROM test.table_a a group by GROUPING SETS ((g),(date_1,g));
--sql 2
--not choose mv_table_a, just add alias l for date_1 base on sql 1
-- FailSummary: View struct info is invalid, View dimensions doesn't not cover the query dimensions
explain
SELECT date_1 l,grouping_id(date_1),g,sum(value_1) x FROM test.table_a a group by GROUPING SETS ((g),(date_1,g));
--sql 3
--choose mv_table_a, just remove grouping_id base on sql 2
explain
SELECT date_1 l,g,sum(value_1) x FROM test.table_a a group by GROUPING SETS ((g),(date_1,g));
--sql 4
--choose mv_table_a
explain
with temp as(SELECT date_1,grouping_id(date_1) AS g_id,g,sum(value_1) x FROM test.table_a group by GROUPING SETS ((g),(date_1,g)))
select * from temp;
--sql 5
--FailSummary: View struct info is invalid, Rewrite compensate predicate by view fail, RewrittenPlan output logical properties is different with target group
explain
with temp as( SELECT date_1,grouping_id(date_1) AS g_id,g,sum(value_1) x FROM test.table_a group by GROUPING SETS ((g),(date_1,g)))
select * from temp where g_id=1;
Anything Else?
No response
Are you willing to submit PR?
Code of Conduct
Search before asking
Version
3.1.4
What's Wrong?
What You Expected?
sql2 and sql5 should choose the mtmv mv_table_a
How to Reproduce?
create database if not exists test;
drop table if exists test.table_a force;
CREATE TABLE test.table_a (
gvarchar(20) NULL,value_1bigint NULL,date_1varchar(20) NULL) ENGINE=OLAP
DUPLICATE KEY(
g)AUTO PARTITION BY LIST (
date_1)()PROPERTIES ("replication_allocation" = "tag.location.default: 1");
insert into test.table_a select 'g1' g,300 value_1,'2025-10-22' as date_1;
drop materialized view if exists test.mv_table_a;
CREATE MATERIALIZED VIEW mv_table_a BUILD IMMEDIATE REFRESH AUTO ON COMMIT
PARTITION by(date_1) DISTRIBUTED BY HASH(g) BUCKETS 17 PROPERTIES ('replication_num'='1')
as select date_1,g,sum(value_1) from test.table_a a group by date_1,g;
-- sql 1
--choose mv_table_a
explain
SELECT date_1,grouping_id(date_1),g,sum(value_1) x FROM test.table_a a group by GROUPING SETS ((g),(date_1,g));
--sql 2
--not choose mv_table_a, just add alias
lfor date_1 base on sql 1-- FailSummary: View struct info is invalid, View dimensions doesn't not cover the query dimensions
explain
SELECT date_1 l,grouping_id(date_1),g,sum(value_1) x FROM test.table_a a group by GROUPING SETS ((g),(date_1,g));
--sql 3
--choose mv_table_a, just remove grouping_id base on sql 2
explain
SELECT date_1 l,g,sum(value_1) x FROM test.table_a a group by GROUPING SETS ((g),(date_1,g));
--sql 4
--choose mv_table_a
explain
with temp as(SELECT date_1,grouping_id(date_1) AS g_id,g,sum(value_1) x FROM test.table_a group by GROUPING SETS ((g),(date_1,g)))
select * from temp;
--sql 5
--FailSummary: View struct info is invalid, Rewrite compensate predicate by view fail, RewrittenPlan output logical properties is different with target group
explain
with temp as( SELECT date_1,grouping_id(date_1) AS g_id,g,sum(value_1) x FROM test.table_a group by GROUPING SETS ((g),(date_1,g)))
select * from temp where g_id=1;
Anything Else?
No response
Are you willing to submit PR?
Code of Conduct