Indexing for BINARY LIKE operations in MySQL

后端 未结 1 1498
长发绾君心
长发绾君心 2021-01-21 22:04

I know that varchar_pattern_ops exists in Postgresql for fast, index-based searches in a LIKE query, but is there any similar functionality for MySQL?<

1条回答
  •  遥遥无期
    2021-01-21 22:45

    Do the fact that MySQL indexes the left side of a string.

    Then a string column can use the index if the query use wildcard right side :

     SELECT * FROM your_table WHERE field LIKE "text%" # can use an index
    

    but remember that for index there is a limit of 767 bytes

    From Mysql DOC

    A B-tree index can be used for column comparisons in expressions that use the =, >, >=, <, <=, or BETWEEN operators. The index also can be used for LIKE comparisons if the argument to LIKE is a constant string that does not start with a wildcard character.

    https://dev.mysql.com/doc/refman/8.0/en/index-btree-hash.html

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