为提高效率,提问时请提供以下信息,问题描述清晰可优先响应。
【DM版本】: dm8
【操作系统】:centos7
【CPU】:
【问题描述】*:
现在有两张表:icc_contacts和icc_contacts_group_bind,其中icc_contacts大概有300多万的数据,icc_contacts_group_bind大概有400多万的数据。
icc_contacts表的索引如下:
icc_contacts_group_bind的索引如下:
执行sql如下:
select t0.id ,t0.code,t0.create_time,t0.group_ids,t0.types,t0.is_virtual,t0.name,t1.group_id
from icc_contacts t0
left join icc_contacts_group_bind t1 on t0.id=t1.contacts_id
where t0.types=0 and t0.is_virtual=0
order by t0.code desc
fetch first 10 rows only;
上面sql的执行时间是9s左右,执行计划如下图所示:
尝试将排序从t0.code降序调整为t0.code升序排序,效果不明显。
尝试调整HJ_BUF_SIZE的大小为300,也没有效果
只有减少查询的列,只保留t0.id和t1.group_id后,执行时间减少到6.2秒左右。
想请教下各位大佬还有没有其他的优化手段,
1 types和is_virtual列的过滤性怎么样
查看一下值分布select types,is_virtual,count() from icc_contacts
group by types,is_virtual
如果值没有过滤性,建了索引也不会走
2 code的索引是asc,那么排序也升序order by t0.code asc
3 尝试加个hint看下
select /+ TOP_ORDER_OPT_FLAG(1)*/ t0.id ,t0.code,t0.create_time........
创建一个code降序的聚集索引试试:
create cluster index 索引名 on 表名(code desc);
您好,首先通过你的执行计划来看应该有点不正确,可以在对这两个表收集一下统计信息。通过执行计划来看,T0表是走了CSCN全表扫描,由于你的索引(你说name,types,is_virtual组成一个联合索引)应该是前导列为name所以没有使用上索引。
这里我建议可以types,is_virtual组成一个组合索引,这里性能应该会有一定提升,具体哪个咧作为第一列建议从业务和数据分布出发来定