简体   繁体   English

MySQL-InnoDB为varchar编制索引或为多个varchar编制索引

[英]MySQL - InnoDB indexing varchar or indexing multiple varchars

Hello everyone i am planing to create table with 10 columns, which should be at least 10,000,000 rows, and inside of it, i would have column description - VARCHAR(600) and index on it. 大家好,我打算创建具有10列的表,该表应至少为10,000,000行,并且在其中,我将具有列description - VARCHAR(600)和其上的索引。

So the question is, would it be faster to query LIKE on that column - VARCHAR(600), or it would be faster to split the description in 6 columns with 100 characters and indexing them with LIKE and OR .. 因此,问题是,在该列上查询LIKE会更快(VARCHAR(600)),还是将描述分为100个字符的6列并用LIKEOR索引会更快。

For example: description - VARCHAR(600) INDEX 例如: description - VARCHAR(600) INDEX

SELECT `id` FROM `table` WHERE `description` LIKE "%something%"

or it would be faster to split description in 6 columns like desc1 , desc2 ,.. desc6 with VARCHAR(100) INDEX - each of them and use following query: 或者它会更快分裂description在6列像desc1desc2 ,.. desc6VARCHAR(100) INDEX -它们每一个和使用以下查询:

SELECT `id` FROM `table` WHERE `desc1` LIKE "%something%" OR `desc1` LIKE "%something%" OR `desc3` LIKE "%something%" OR `desc4` LIKE "%something%" OR `desc5` LIKE "%something%" OR `desc6` LIKE "%something%"

Just wondering before i start creating the database.. 在我开始创建数据库之前就想知道。

Best regards and Thanks to everyone! 最好的问候,并感谢大家!

It makes no difference at all . 根本没有区别。 . . well, very little. 好,很少。 The query is going to have to do a full table scan, because the like pattern starts with a wildcard ("%"). 该查询将必须进行全表扫描,因为like模式以通配符(“%”)开头。

If you care about performance, you should probably rephrase the problem as a full-text search. 如果您关心性能,则可能应该将该问题重新表述为全文搜索。 Start with the documentation . 文档开始。

If you must use LIKE '%something%' (that is, LIKE with leading wildcard), then 如果必须使用LIKE '%something%' (即,带前导通配符的LIKE ),则

  • A single column. 一列。 (Less work than 6 LIKEs , plus ORs ) Also, what would you do about something that happens to be spread across two chunks? (较少的工作比6所LIKEs ,加上ORs )。另外,你会怎么做有关something恰好是在两个块传播的?
  • No index on that column (because of the leading wildcard, the index would not be use) 该列上没有索引(由于前导通配符,将不使用该索引)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM