There is a sentence in the MySQL document that I don't quite understand.

in the
mysql document:
https://dev.mysql.com/doc/ref.

I don"t quite understand some of the following sentences. I"d like to ask you for help

The index may also be used even if the ORDER BY does not match the index exactly, as long as all unused portions of the index and all extra ORDER BY columns are constants in the WHERE clause. If the index does not contain all columns accessed by the query, the index is used only if index access is cheaper than other access methods.

how to understand the sentence "as long as"?
my personal understanding is:

as long as the columns that do not appear in order by and the columns that do not appear in order by are constant in the where statement, do you mean that columns that do not appear in the index are constant in the where statement

especially the extra order by column in all extra ORDER BY columns .

Mar.18,2022

SELECT * FROM t1
  WHERE key_part1 = constant
  ORDER BY key_part2;

here all extra ORDER BY columns are constants in the WHERE clause actually means that the key_part1, official document interprets the key_part1 from different angles. It is an extra column for an index that is dead, and an extra column for order by. Can understand when the index can be used to optimize sorting.

Menu