我有一个表,它有一个主键,它是一个整数,然后是一个用于按类型搜索的列,它是一个 varchar。让我们说 content_id 和 content_type。
SELECT * FROM TABLE_A WHERE content_type='abc'
varchar content_type 的长度为 255。我正在考虑为它建立索引以加快 SELECT 查询。这会提高性能吗?即使它的长度为 255,如果只使用 5 个字符而不是整个 255 个字符,这会对性能产生影响吗?
最佳答案
content_type
上的索引应该使您的查询更快:
select * from table_a where content_type = 'whatever';
select * from table_a where content_type like 'whatever%';
但它不会使您的查询更快:
select * from table_a where content_type like '%whatever%';
如果您只使用 255 个可用字符中的 5 个也没关系。
关于mysql - 数据库设计 : Index Varchar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5732096/