IN clause not using index

后端 未结 2 1951
无人共我
无人共我 2021-01-22 06:00

Here is the table definition

CREATE TABLE `dt_prdtime` (
  `TCompany` varchar(3) NOT NULL DEFAULT \'\',
  `TPerCode` varchar(8) NOT NULL,
  `TBegDateTime` dateti         


        
2条回答
  •  情书的邮戳
    2021-01-22 06:01

    Neither MyISAM, nor InnoDB, is likely to use an index when "too much" of the table needs to be fetched.

    IN (5,6) may mean 2/12ths of the table needs to be scanned? Or maybe the data is biased such that those two months have more than their share of rows?

    The reason the optimizer might eschew the index in cases like this...

    When using such an index, it needs to spend a lot of time bouncing between the index (one BTree) and the data.

    When not using the index, it simply cruises through the data, ignoring 10/12ths of the rows. This may actually be faster.

提交回复
热议问题