mysql select query optimization and how limit works in mysql

前端 未结 1 2024
小蘑菇
小蘑菇 2021-02-09 21:55

I am using mysql database which has only one table \"data\" with 17,151257 rows.This table has a column string

1条回答
  •  灰色年华
    2021-02-09 22:35

    Regular indexing can't be used to improve that query. MySQL indexes are B-trees, which means they can find a prefix of the indexed column very quickly. But since your LIKE query has % at the beginning, there's no unique prefix to search for. So every row has to be scanned to match against the pattern.

    However, MySQL also supports full-text searching. This creates an index of all the words in the column, and it can find these words quickly. See the documentation for details.

    If you use LIMIT 10, it will stop scanning as soon as it finds the first 10 rows that satisfy the conditions. Unless you also use ORDER BY -- then it has to find all the rows so that it can sort them before selecting the first 10.

    0 讨论(0)
提交回复
热议问题