MySQL 索引以及何时将它们分组 [英] MySQL indexes and when to group them

查看:46
本文介绍了MySQL 索引以及何时将它们分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我仍在努力寻找在 MySQL 中使用 INDEXES 的最佳方法.你怎么知道什么时候把它们合并在一起,什么时候把它们分开?

I'm still trying to get my head around the best way to use INDEXES in MySQL. How do you know when to merge them together and when to have them separate?

以下是来自 Wordpress 帖子表的索引.看看 post_name、post_parent 和 post_author 如何是单独的条目?然后他们有 type_status_date 这是 4 个字段的混合?

Below are the indexes from the Wordpress posts table. See how post_name, post_parent and post_author are seperate entries? And then they have type_status_date which is a mixture of 4 fields?

http://img215.imageshack.us/img215/5976/screenshot20120426at431.

我不明白这背后的逻辑?谁能给我指点一下?

I don't understand the logic behind this? Can anyone enlighten me?

推荐答案

MySQL 通常一次不能使用多个索引.这意味着,例如,当您有一个对两个字段进行过滤或排序的查询时,您会将它们放入同一个索引中.

MySQL cannot normally use more than one index at a time. That means, for instance, that when you have a query that filters or sorts on two fields you put them both into the same index.

WordPress 可能有一个常见的查询,可以对 post_typepost_status post_date 进行过滤和/或排序.对它们代表什么进行有根据的猜测,这可能是 WordPress 的 Post 列表页面的核心查询.所以这三个字段被放到了同一个索引中.

WordPress likely has a common query that filters and/or sorts on post_type, post_status and post_date. Making an educated guess as to what they stand for, this would likely be the core query for WordPress's Post listing pages. So the three fields are put into the same index.

这篇关于MySQL 索引以及何时将它们分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆