查询 sql 期望可以使用前缀索引,但是 profile 结果中 ShortKeyFilterRows 的值为 0

【详述】
查询表的建表语句为

CREATE TABLE ads_autopilot_os_all_event_case_report_daily_order_1
(
case_id VARCHAR(30) ,
event_name VARCHAR(200) ,
case_first_date date,
relative_day int,
event_date date,
count bigint,
sum double,
unique bigint )
PARTITION BY(event_date)
DISTRIBUTED BY HASH(case_id)
ORDER BY(case_id)

sql 查询语句为:select * from ads_autopilot_os_all_event_case_report_daily_order_1 where event_date between date ‘2023-10-01’ and date ‘2025-06-30’ and case_id = ‘case-8kkwcl1bd’ and case_first_date between ‘2023-10-01’ and ‘2024-08-15’ and relative_day between 0 and 319 and event_name = ‘active’ order by case_first_date, relative_day;

我另外创建一个表,采用如下的建表语句
CREATE TABLE ads_autopilot_os_all_event_case_report_daily (
case_id varchar(30),
event_name varchar(200),
case_first_date varchar(10),
relative_day int,
event_date date,
count bigint,
sum double,
unique bigint
)
DUPLICATE KEY (case_id, event_name, case_first_date, relative_day)
PARTITION BY (event_date)
DISTRIBUTED BY HASH(case_id)
使用同样的 sql 从这个表查询,profile 结果中 ShortKeyFilterRows 值就为 2,969,832,151。

而且从查询性能上,从 ads_autopilot_os_all_event_case_report_daily_order_1 查询的性能和 ads_autopilot_os_all_event_case_report_daily 并没有太大差异,这是为啥呢?

【业务影响】无
【是否存算分离】是存算分离
【StarRocks版本】3.3.3
【集群规模】1fe ( 700m CPU, 4Gi 内存)+ 1cn(3000m CPU, 10GI 内存), k8s 部署
【联系方式】never_wencan@163.com
【附件】
profile_from_ ads_autopilot_os_all_event_case_report_daily_order_1.txt (24.3 KB)
profiiel_from_ ads_autopilot_os_all_event_case_report_daily.txt (24.1 KB)
explain_from_ads_autopilot_os_all_event_case_report_daily_order_1.txt (23.3 KB)
explain_from_ads_autopilot_os_all_event_case_report_daily.txt (32.6 KB)

我也遇到同样问题,请问你找到原因了吗

第一个SQL通过其他如zoneMap索引、谓词下推过滤掉了:

第二个sql多跑几次试试,看看过滤规则都是一样的吗

1赞

我查看了我的profile,也是通过zonemap过滤掉了数据。请问下主键表什么时候会走zonemap,什么时候会走前缀索引呢?

如果过滤条件里,只有SortKey的第一列,默认是走Zonemap的,如果想走ShortKeyIndex,可以修改下be.conf enable_short_key_for_one_column_filter=true

// If your sort key cardinality is very high,
// You could enable this config to speed up the point lookup query,
// otherwise, StarRocks will use zone map for one column filter
CONF_mBool(enable_short_key_for_one_column_filter, "false");
1赞

您好,想问下这个参数在哪个版本可以生效呀,我在官方文档里面没有找到orz

你用的这个版本,有这个参数

大佬好,我在3.3.14版本里面配置这个参数好像没有起作用T-T