有表A(a1,a2,a3,a4)
a1为PK ,a2建有索引,a3建有索引,a4为数值型
表的数据量为3M条记录语句1:select count(*) from A where A.a1 like '10001_____' 语句2: select count(*) from A where A.a1 like '10001_____' and A.a2=xxx and A.a3=yyy语句1取出的数值是语句2的12倍,花的时间语句1 是语句2的1/50,这让我难以理解,请大家不吝赐教
a1为PK ,a2建有索引,a3建有索引,a4为数值型
表的数据量为3M条记录语句1:select count(*) from A where A.a1 like '10001_____' 语句2: select count(*) from A where A.a1 like '10001_____' and A.a2=xxx and A.a3=yyy语句1取出的数值是语句2的12倍,花的时间语句1 是语句2的1/50,这让我难以理解,请大家不吝赐教
先看看你的两个语句的执行计划
然后分析一下你的表
analyze table tablename compute;
再看看你的表的执行计划
感觉你的第二个语句用的RBO,没有用到CBO
2、建复合索引,第二个语句的查询现在要扫描3个索引。效力低