开发者

mysql composite indeces should i be using them

I got question on开发者_开发知识库 index strategies for mysql - mainly when to use a composite index

I have a fairly common relational db scenario, heres my table set up:

Maintable - table consisting of "products" including brandid, merchantid 

So I create a table to store the brands and merchants

Brandtable - brandname, brandid
Merchanttable - merchantname, merchantid

When I query the Maintable I sometimes query for brandid, sometimes for merchantid and sometimes both. What is best to use in this scenario, a single index on each column, or composite index made up of both?

Also if I wanted to include brandname and merchantname in a fulltext search, how would I achieve this?

Cheers :)


In this case you should use a separate index for each column. MySQL can only use a composite index if your queries involve the leftmost columns in that composite index.

e.g., if you have a composite index of (brandid,merchantid), that index will be considered if you query on brandid or brandid and merchantid. Not if you only query on merchantid

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜