物化视图改写失败

为了更快的定位您的问题,请提供以下信息,谢谢
【详述】物化视图改写失败
【背景】做过哪些操作?
【业务影响】测试中,无影响
【是否存算分离】否
【StarRocks版本】例如:3.2.3
【集群规模】例如:3fe(1 follower+2observer)+3be(fe与be混部)
【机器信息】CPU虚拟核/内存/网卡,例如:48C/64G/万兆
【联系方式】为了在解决问题过程中能及时联系到您获取一些日志信息,请补充下您的联系方式,例如:社区群4-小李或者邮箱,谢谢
【附件】
异步物化视图
CREATE MATERIALIZED VIEW test.project_record_area_code_base
DISTRIBUTED BY HASH(cdate)
PROPERTIES (
‘query_rewrite_consistency’=‘LOOSE’
) as
SELECT
area_code AS areacode,
COUNT(called_num) AS monthCount1,
COUNT(DISTINCT called_num) AS monthCount2,
COUNT(CASE WHEN call_duration > 0 THEN called_num ELSE NULL END),
COUNT(CASE WHEN call_duration >= 20 THEN called_num ELSE NULL END) AS monthCount4,
COUNT(DISTINCT CASE WHEN call_duration > 0 THEN called_num ELSE NULL END) AS monthCount5,
COUNT(DISTINCT CASE WHEN call_duration >= 20 THEN called_num ELSE NULL END) AS monthCount6,
COUNT(CASE WHEN end_result = 4 THEN called_num ELSE NULL END) AS monthCount7,
COUNT(DISTINCT CASE WHEN sms_content LIKE CONCAT(’%’,8,’%’) THEN called_num ELSE NULL END) AS monthCount10,
cdate
FROM project_record_dayPartitionTest record
LEFT JOIN project p ON p.id = project_id
WHERE cdate <= date(date_sub(current_timestamp(),1))
GROUP BY area_code,cdate;

sql1:
explain SELECT
area_code AS areacode,
COUNT(called_num) AS monthCount1,
COUNT(DISTINCT called_num) AS monthCount2,
cdate
FROM project_record_dayPartitionTest record
LEFT JOIN project p ON p.id = project_id
WHERE cdate <= date(date_sub(current_timestamp(),0))
GROUP BY area_code,cdate;
可以触发查询改写
explain1.data (4.1 KB)

sql2
explain SELECT
area_code AS areacode,
COUNT(called_num) AS monthCount1,
COUNT(DISTINCT called_num) AS monthCount2,
COUNT(CASE WHEN call_duration > 0 THEN called_num ELSE NULL END),
cdate
FROM project_record_dayPartitionTest record
LEFT JOIN project p ON p.id = project_id
WHERE cdate <= date(date_sub(current_timestamp(),0))
GROUP BY area_code,cdate;
无法触发查询改写

sql2只是比sql1 多了个COUNT(CASE WHEN call_duration > 0 THEN called_num ELSE NULL END), 这个语句在异步物化视图里面有的
explain.data (1.9 KB)

sql2的 trace logs mv

这个应该是改成成功了吧,但是explain显示好像不正确,显示改写失败

最后发现使用了 count(distinct )导致改写失败,第一个sql是出发了另一个mv