索引是否在SQL中吮吸? [英] Do indexes suck in SQL?

查看:94
本文介绍了索引是否在SQL中吮吸?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个包含大量行的表,其中一个我想索引的列可以包含20个值中的一个。
如果我在列上放一个索引它会很大吗?

Say I have a table with a large number of rows and one of the columns which I want to index can have one of 20 values. If I were to put an index on the column would it be large?

如果是这样,为什么?如果我将数据分成数据到20个表中,每个值对应一个列,索引大小将是微不足道的,但索引效果是相同的。

If so, why? If I were to partition the data into the data into 20 tables, one for each value of the column, the index size would be trivial but the indexing effect would be the same.

推荐答案

索引(或索引)不吸引人。很多非常聪明的人在过去的几十年里花了相当多的时间来确保这一点。

Indexes (or indices) don't suck. A lot of very smart people have spent a truly remarkable amount of time of the last several decades ensuring that this is so.

然而,你的模式缺乏相同的数量专业知识和努力,确实可能非常糟糕。

Your schema, however, lacking the same amount of expertise and effort, may suck very badly indeed.

在所描述的情况下,分区等同于应用聚簇索引。如果表以其他方式排序(或以任意顺序排列),则索引必须占用更多空间。根据平台,非聚集索引的大小可能会减小,因为行的排序相对于索引值会增加。

Partitioning, in the case described is equivalent to applying a clustered index. If the table is sorted otherwise (or is in arbitrary order) then the index necessarily has to occupy much more space. Depending on the platform, a non-clustered index may reduce in size as the sortedness of the rows with respect to the indexed value increases.

YMMV。

这篇关于索引是否在SQL中吮吸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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