MySQL VARCHAR Index Length
MySQL tables have a maximum index length of 767 bytes. This is per column, so a composite index cannot exceed 767 bytes in total. However, there are some exceptions to this rule:
In your specific case:
The index you created is not being used because it exceeds the maximum index length of 767 bytes. This is because MySQL assumes 3 bytes per UTF-8 character, and 512 characters * 3 bytes/character = 1536 bytes.
To resolve this issue, you can:
Reduce the length of the index to 255 characters or less.
ALTER TABLE products ADD INDEX (name(255));
Enable the innodb_large_prefix configuration option and use the DYNAMIC or COMPRESSED row format.
SET innodb_large_prefix = ON; ALTER TABLE products ROW_FORMAT=COMPRESSED;
Additional Notes:
The above is the detailed content of Why Isn\'t My MySQL VARCHAR(512) Index Being Used?. For more information, please follow other related articles on the PHP Chinese website!