大家帮我看看这个mysql索引创建的问题
不好意思没分了。表字段如下,全是INT,省略了无关字段:
id
site
status
category
bool1
bool2
bool3
bool4
后4个是bool值,非0即1。
id 是个PRIMARY, 因为要和其他表外连接。现在考虑给其他字段创索引,但因查询条件不同,想不出怎么才能建立适合所有查询的索引,我要进行的查询包括:
1. 选出符合site和status的记录(所谓符合site和status即SELECT id FROM table WHERE site=xxx AND status=xxx)
2. 选出符合status,bool1,category的记录,或者不考虑category,只选出符合status,bool1的记录
3. 选出符合status,bool2,category的记录,或者不考虑category,只选出符合status,bool2的记录
4. 选出符合status,bool3,category的记录,或者不考虑category,只选出符合status,bool3的记录
5. 选出符合status,bool4,category的记录,或者不考虑category,只选出符合status,bool4的记录
我该如何建立索引,才能兼顾这5中查询?mysql要求每个字段只能出现在一个索引里,因此不可能建立5个这样的索引:
(site, status)
(status,bool1,category)
(status,bool2,category)
(status,bool3,category)
(status,bool4,category)