为提高效率,提问时请提供以下信息,问题描述清晰可优先响应。
【DM版本】:8
【操作系统】:mac
【CPU】: m1 pro
【问题描述】*:
select
person_id,
max(modify_time)
from
ehr_org_person_history a
where
org_id = '8876686154421706446'
AND modify_time <= '2025-06-01 23:59:59.999'
and del_flag = 1
and is_outer = 0
and state > 0
group by
person_id;
sql 如上,数据库数据有41万条,根据条件过滤后也有40万条,但是根据分组后只有9万条的数据。该sql语句执行时长为400ms 以上,请问该如何优化。
可以发下ehr_org_person_history表的表结构sql,不要截图
执行计划和ET看下。
可以试试加这俩索引,没效果再删了
CREATE INDEX idx_ehr_org_person_history_main
ON ehr_org_person_history (
org_id,
modify_time DESC,
del_flag,
is_outer,
state,
person_id
);
CREATE INDEX idx_ehr_org_person_history_order
ON ehr_org_person_history (
number,
order_no,
person_id
);
没有过滤性,只能全表扫描,可以考虑手动加并行
修改dm.ini,开启手动并行,并重启服务
PARALLEL_POLICY = 2