为提高效率,提问时请提供以下信息,问题描述清晰可优先响应。
【DM版本】:8
【操作系统】:centos7
【CPU】:
【问题描述】:
create table iretrieve_120.ALARM_INFO
(
info_id VARCHAR2(36) not null,
station_num NUMBER,
alarm_type VARCHAR2(36),
alarm_sub_type VARCHAR2(36),
ctctime DATE,
content CLOB,
operator_type VARCHAR2(2),
groups VARCHAR2(50),
operate_user_id NUMBER,
analysis_status VARCHAR2(1),
analysis_type VARCHAR2(1),
audit_status VARCHAR2(2),
create_by VARCHAR2(50),
create_time TIMESTAMP(6),
update_time TIMESTAMP(6),
update_by VARCHAR2(50),
del_flag VARCHAR2(1) default '0',
tips VARCHAR2(512),
train VARCHAR2(512),
construct_flag NUMBER default 0
)
索引:
sql:select ai.alarm_type,to_char(ai.ctctime,'yyyy-mm') as 'date',ai.analysis_status,ai.analysis_type,count() as "count" from alarm_info ai where ai.del_flag='1' and ai.ctctime between to_date('2023-12-01 00:00:00','yyyy-MM-dd HH24:mi:ss') and to_date('2024-12-01 00:00:00','yyyy-MM-dd HH24:mi:ss') and ai.alarm_type in (.....) and ai.alarm_sub_type in (......) and ai.station_num in (......)
and nvl(ai.operator_type,'0') in (....) and nvl(ai.analysis_status,'0') in (....)
group by ai.alarm_type,to_char(ai.ctctime,'yyyy-mm'),ai.analysis_status,ai.analysis_type;
oracle:
解释计划:
达梦:三分钟起步
解释计划:
达梦:去除条件in或者in的参数很少
解释计划:
执行计划不是告诉你了吗?第二次全表扫了。
select /+ enable_in_value_list_opt(8)/ai.alarm_type 这样试试,或者取6
蹲
条件列数据索引过滤性很差,数据重复太多,此查询不适合走索引,走hash更优,删除索引或用/+no_index(ai,alerm_info_stat_index)/禁用索引。
/*+ HAGR_HASH_SIZE(10000000) HAGR_BUF_SIZE(1024) HAGR_BUF_GLOBAL_SIZE(40000) new_motion(1) parallel(8) */
收集表统计信息看看,不要走索引DBMS_STATS.GATHER_TABLE_STATS('IRETRIEVE_120','ALARM_INFO',null,100,TRUE,'FOR ALL COLUMNS SIZE AUTO',16);
蹲个坑