一个表有两个列col1,col2
需要对col1,col2进行查询
例如:
select * from table where col1>a and col2<b索引策略1:
Create index ind1 on table(col1)
Create index ind2 on table(col2)
索引策略2
Create index ind3 on table(col1,col2)
这两种索引策略哪个效率高?本人以为策略2的效率高些, 因为策略1需要首先根据col1的条件索引到符合的行,然后再对col2的条件筛选出最后的结果集,需要次2次IO操作
策略2只需要根据索引表中同时满足col1和col2条件的索引值直接定位到数据块的物理地址,只需1次IO操作。大家各抒己见了。
需要对col1,col2进行查询
例如:
select * from table where col1>a and col2<b索引策略1:
Create index ind1 on table(col1)
Create index ind2 on table(col2)
索引策略2
Create index ind3 on table(col1,col2)
这两种索引策略哪个效率高?本人以为策略2的效率高些, 因为策略1需要首先根据col1的条件索引到符合的行,然后再对col2的条件筛选出最后的结果集,需要次2次IO操作
策略2只需要根据索引表中同时满足col1和col2条件的索引值直接定位到数据块的物理地址,只需1次IO操作。大家各抒己见了。
如果索引结果集很大,合并就慢了,还不如直接扫描表,CBO可能是这样吧好像只有
select * from table where col1= a and col2 =b
col1,col2没有主键和唯一键,才会实现吧
当然效率肯定不如索引策略2