Search before asking
- I had searched in the issues and found no similar issues.
Description
Cannot hit rollup even if the if expr contains the rollup dimension.
Reproduce the problem:
create database db1;
use db1;
-- create table
CREATE TABLE `tbl` (
`dt` date NULL COMMENT "dt",
`is_dau` tinyint(4) NULL COMMENT "is_dau",
`is_intention` tinyint(4) NULL COMMENT "is_intention",
`city_id` int(11) NULL COMMENT "city_id",
`device_id` bitmap BITMAP_UNION NULL COMMENT "device_id"
) ENGINE=OLAP
AGGREGATE KEY(`dt`, `is_dau`, `is_intention`, `city_id`)
PARTITION BY RANGE(`dt`)
(PARTITION p20220101 VALUES [('1970-01-01'), ('2022-04-10')),
PARTITION p20220411 VALUES [('2022-04-10'), ('2022-04-11')),
PARTITION p20220412 VALUES [('2022-04-11'), ('2022-04-12')))
DISTRIBUTED BY HASH(`city_id`) BUCKETS 10
PROPERTIES (
"replication_num" = "1",
"in_memory" = "false",
"storage_format" = "V2"
);
-- load data
insert into tbl values ('2022-04-11', 1, 1, 1, to_bitmap(1));
insert into tbl values ('2022-04-11', 0, 1, 2, to_bitmap(2));
insert into tbl values ('2022-04-11', 1, 1, 2, to_bitmap(3));
insert into tbl values ('2022-04-11', 0, 1, 3, to_bitmap(4));
insert into tbl values ('2022-04-11', 1, 1, 3, to_bitmap(5));
insert into tbl values ('2022-04-11', 0, 1, 4, to_bitmap(6));
insert into tbl values ('2022-04-11', 1, 1, 4, to_bitmap(7));
insert into tbl values ('2022-04-11', 0, 1, 5, to_bitmap(8));
insert into tbl values ('2022-04-11', 1, 1, 5, to_bitmap(9));
-- add rollup
ALTER TABLE db1.tbl ADD ROLLUP rollup1 (dt, is_intention, city_id, device_id);
The following sql can hit rollup1
, as expected:
select city_id,
count(distinct device_id)
from db1.tbl
where dt='2022-04-11' and is_intention=1
group by city_id;
-- explain sql: rollup: rollup1
The following sql fails to hit rollup1
:
select city_id,
count(distinct if(is_intention=1,device_id,NULL))
from db1.tbl
where dt='2022-04-11'
group by city_id;
-- explain sql: rollup: tbl
Solution
Can hit rollup.
Are you willing to submit PR?
- Yes I am willing to submit a PR!
Code of Conduct
- I agree to follow this project's Code of Conduct
暂无答案!
目前还没有任何答案,快来回答吧!