MySQL中多列索引中的列顺序 [英] Order of columns in a multi-column index in MySQL

查看:302
本文介绍了MySQL中多列索引中的列顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试理解定义多列索引时更好的方法:

I'm trying to understand what is better when defining multi-column indexes:


  • 将最具选择性的列放在第一位(更高的基数) ,速度?);或者

  • 首先选择较少选择性的列(较低的基数,用于索引压缩?)

或者也许这取决于我是在优化速度还是空间?

Or maybe it depends if I'm optimizing for speed or space?

推荐答案

列的顺序应该与顺序相匹配稍后查询列或MySQL不会使用它们。
这是你应该考虑的问题。

The order of the columns should match the order in which the columns are queried later or MySQL will not use them. This is the question you should really think about.

阅读更多 here

UPDATE:

关于基数的问题,请阅读这个
这与你的问题相似吗?它回答了吗?

For your question about cardinality maybe read this. Is this similar to your question? Does it answer it?

这篇关于MySQL中多列索引中的列顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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