大家好,问个相关索引的问题
例如有一个表 TableA
有列: Column1,Column2,Column3,Column4,Column5,Column6,
其中Primary Key 为Column1,Column2,Column3
此表已经有一个索引idx1:(Column1,Column2,Column3)
如果再增加索引如  idx2:(Column1,Column2,Column3,Column4)
                  idx3:(Column1,Column2,Column3,Column5)
我想问一下现在这个情况,会有三个索引块吗?(索引页?)
当插入数据时是否会在其三个索引块上都写创建相应的索引项?
数据库是如何进行查询的?
是否和查询的where clause有关?

解决方案 »

  1.   

    举个列子再:table1 和table2 表结构相同,pk: Column1,Column2, 聚集索引为Column1,Column2.
    table1 比table2 多一个非聚集索引 idx_columnAselect columnA from table1 where columnA = '1'select columnA from table2 where columnA = '1'以上两查询语句性能差别比较大:12%-88%,前者使用到了索引idx_columnA,后者只是扫描唯一的聚集索引。
    select columnB from prtftp_dtl where columnA = '1'select columnB from prtftp_dtl2 where columnA = '1'以上两查询语句性能相同50%-50%,两者都使用了唯一的聚集索引。
    select columnA from prtftp_dtl where column1 = 'x' and columnA = '1'select columnA from prtftp_dtl2 where column1 = 'x' columnA = '1'以上两查询语句性能也相同50%-50%,前者使用了非聚集索引,后者使用了聚集索引。我想知道的是,sql server到底是更具什么规则来选择查询哪个索引?
    (我是通过sql的查询计划来认定调用的哪个索引的:Index Seek 相当于非聚集索引,而Clustered Index Scan相当于聚集索引,不知道是否这个理解有误)