Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我应该使用mysql复合索引吗_Mysql_Indexing_Full Text Search_Composite - Fatal编程技术网

我应该使用mysql复合索引吗

我应该使用mysql复合索引吗,mysql,indexing,full-text-search,composite,Mysql,Indexing,Full Text Search,Composite,我对mysql的索引策略有疑问——主要是何时使用复合索引 我有一个相当常见的关系数据库场景,下面是我的表设置: Maintable - table consisting of "products" including brandid, merchantid 所以我创建了一个表来存储品牌和商家 Brandtable - brandname, brandid Merchanttable - merchantname, merchantid 当我查询main表时,我有时查询brandid,有时查

我对mysql的索引策略有疑问——主要是何时使用复合索引

我有一个相当常见的关系数据库场景,下面是我的表设置:

Maintable - table consisting of "products" including brandid, merchantid 
所以我创建了一个表来存储品牌和商家

Brandtable - brandname, brandid
Merchanttable - merchantname, merchantid
当我查询main表时,我有时查询brandid,有时查询merchantid,有时两者都查询。在这种情况下,最好使用哪种方法,在每一列上使用一个索引,或者使用由这两个列组成的复合索引

另外,如果我想在全文搜索中包括brandname和merchantname,我将如何实现这一点


干杯:)

在这种情况下,您应该为每一列使用单独的索引。只有当查询涉及复合索引中最左边的列时,MySQL才能使用该复合索引


e、 例如,如果您的复合索引为
(brandid,merchantid)
,则在查询
brandid
brandid
merchantid
时,将考虑该索引。如果您只查询
merchantid

,这一点非常清楚。我刚刚习惯了索引的世界,一开始要想了解它是相当复杂的。为简洁的答案欢呼:)