大家帮我看看这个mysql索引创建的问题

iProgram 2005-08-09 11:22:04
不好意思没分了。表字段如下,全是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)
...全文
125 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
w_tao8029 2005-11-02
  • 打赏
  • 举报
回复
boolean型的列没有必要放在索引里面,因为boolean型的值不是0就是1,加不加索引,区别不大,用(site, status)或者(site, status,category )就可以了,

56,940

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧