开发者

impact of index in SQL query

开发者 https://www.devze.com 2023-01-19 10:43 出处:网络
Suppose there are two indexes on a table index1 on col1,col2 index2 on col3 Please tell me, whether in below case index will help?

Suppose there are two indexes on a table

  1. index1 on col1,col2
  2. index2 on col3

Please tell me, whether in below case index will help?

.. where col开发者_高级运维1,col4
.. where col3,col4
.. where col1,col3 
.. where col1,col2,col3,col4

*note,

  1. i wrote where clause only without specifying the conditions. Only used column are mentioned
  2. I am using DB2. So as per my knowledge column sequence would not matter.
  3. col4 is not having any index.


  • where col1,col4 - can use prefix col1 from index 1.
  • where col3,col4 - can use index 2.
  • where col1,col3 - can use either index2 or prefix col1 from index 1.
  • where col1,col2,col3,col4 - can use either index


The columns mentioned in where clause, if indexed, then those indexes will be used. For eg:- in your "Where col1, col4", col1 is indexed and hence it will be used. Similarly for other conditions. For columns which both indexes are available, then both of them might be used. For eg:- in your 3rd and 4th where clauses.

0

精彩评论

暂无评论...
验证码 换一张
取 消