Will mysql's negative conditional query use indexes?

Will mysql's negative conditional query, such as not in, use an index?

In fact, mysql will still try to make use of indexes. If there is an index on the column being queried, and the index covers the columns required by the query, MySQL may use the index to get the results instead of doing a full table scan.

For example, execute statementexplain select * from test_table where type not in ('login', 'register'); to view the execution plan, which uses the negative condition not in:
Insert image description here
As can be seen from the above output, this negative The query still uses the index.

Execute statementexplain select * from test_table where type in ('login', 'register');View the execution plan, which uses the forward condition in:
Insert image description here
As can be seen from the output, this forward condition query also uses index.

Guess you like

Origin blog.csdn.net/panghuangang/article/details/134972138