How to use index in select statement?

前端 未结 8 623
误落风尘
误落风尘 2020-12-12 12:42

Lets say in the employee table, I have created an index(idx_name) on the emp_name column of the table.

Do I need to explicitly specify the index name in

8条回答
  •  暖寄归人
    2020-12-12 13:09

    How to use index in select statement?
    this way:

       SELECT * FROM table1 USE INDEX (col1_index,col2_index)
        WHERE col1=1 AND col2=2 AND col3=3;
    


    SELECT * FROM table1 IGNORE INDEX (col3_index)
    WHERE col1=1 AND col2=2 AND col3=3;
    


    SELECT * FROM t1 USE INDEX (i1) IGNORE INDEX (i2) USE INDEX (i2);
    

    And many more ways check this

    Do I need to explicitly specify?

    • No, no Need to specify explicitly.
    • DB engine should automatically select the index to use based on query execution plans it builds from @Tudor Constantin answer.
    • The optimiser will judge if the use of your index will make your query run faster, and if it is, it will use the index. from @niktrl answer

提交回复
热议问题