• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

数据库索引:是好事还是坏事还是浪费时间?

用户头像
it1352
帮助1

问题说明

这里经常建议添加索引,以解决性能问题.

Adding indexes is often suggested here as a remedy for performance problems.

(我只在说阅读和查询,我们都知道索引会使写入变慢).

(I'm talking about reading & querying ONLY, we all know indexes can make writing slower).

多年来,我在DB2和MSSQL上都尝试了很多方法,结果总是令人失望.

I have tried this remedy many times, over many years, both on DB2 and MSSQL, and the result were invariably disappointing.

我的发现是,无论索引有多明显",它都会使事情变得更好.事实证明,查询优化器更智能,而我明智地选择的索引几乎总是使事情变得更糟.

My finding has been that no matter how 'obvious' it was that an index would make things better, it turned out that the query optimiser was smarter, and my cleverly-chosen index almost always made things worse.

我应该指出,我的经验主要与小表(<100'000行)有关.

I should point out that my experiences relate mostly to small tables (<100'000 rows).

任何人都可以提供一些有关索引选择的实用指南吗?

Can anyone provide some down-to-earth guidelines on choices for indexing?

正确的答案应该是一系列建议,例如:

The correct answer would be a list of recommendations something like:

  • 从不/总是索引少于/多于NNNN记录的表
  • 从不/始终考虑使用多字段键上的索引
  • 从不/始终使用聚集索引
  • 在单个表上永远不会/永远不会使用超过NNN索引
  • [我想学习的某些魔术条件]永远不会/总是添加索引

理想情况下,答案将提供一些启发性的例子.

Ideally, the answer will give some instructive examples.

正确答案

#1

索引有点像化疗...太多了,它杀死了您...太少了,您就死了...以错误的方式做了,您死.您必须知道使它不会杀死您的数量,频率和种类.

Indexes are kind of like chemotherapy...too much and it kills you...too little and you die...do it the wrong way and you die. You gotta know just how much, how often, and what kind to make it not kill you.

您的硬件,平台,环境,负载均起作用.因此,回答您的问题.

Your hardware, platform, environment, load all play a role. So to answer your questions..

是的,也许有时.

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcfigie
系列文章
更多 icon
同类精品
更多 icon
继续加载