数据库索引:是好事还是坏事还是浪费时间?
问题说明
这里经常建议添加索引,以解决性能问题.
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.
正确答案
索引有点像化疗...太多了,它杀死了您...太少了,您就死了...以错误的方式做了,您死.您必须知道使它不会杀死您的数量,频率和种类.
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
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
希伯来语的空格句子标记化错误
it1352 06-22 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20