多少数据库索引太多了?

How many database indexes is too many?(多少数据库索引太多了?)
本文介绍了多少数据库索引太多了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个具有相当大 Oracle 数据库的项目(尽管我的问题同样适用于其他数据库).我们有一个网络界面,允许用户搜索几乎所有可能的字段组合.

I'm working on a project with a rather large Oracle database (although my question applies equally well to other databases). We have a web interface which allows users to search on almost any possible combination of fields.

为了加快这些搜索的速度,我们为我们认为用户通常会搜索的字段和字段组合添加了索引.但是,由于我们并不真正了解客户将如何使用该软件,因此很难确定要创建哪些索引.

To make these searches go fast, we're adding indexes to the fields and combinations of fields on which we believe users will commonly search. However, since we don't really know how our customers will use this software, it's hard to tell which indexes to create.

空间不是问题;我们有一个 4 TB 的 RAID 驱动器,我们只使用了其中的一小部分.但是,我担心索引过多可能会导致性能下降.因为每次添加、删除或修改行时都需要更新这些索引,所以我想在一个表上有几十个索引是个坏主意.

Space isn't a concern; we have a 4 terabyte RAID drive of which we are using only a small fraction. However, I'm worried about the possible performance penalties of having too many indexes. Because those indexes need to be updated every time a row is added, deleted, or modified, I imagine it'd be a bad idea to have dozens of indexes on a single table.

那么多少索引才算太多?10?25?50?或者我应该只涵盖真正、真正常见和明显的情况,而忽略其他一切?

So how many indexes is considered too many? 10? 25? 50? Or should I just cover the really, really common and obvious cases and ignore everything else?

推荐答案

这取决于表上发生的操作.

It depends on the operations that occur on the table.

如果有很多 SELECT 和很少的变化,索引所有你喜欢的......这些将(可能)加速 SELECT 语句.

If there's lots of SELECTs and very few changes, index all you like.... these will (potentially) speed the SELECT statements up.

如果表受到 UPDATE、INSERTs + DELETEs 的严重影响......这些将非常慢,因为有很多索引,因为每次发生这些操作之一时都需要修改它们

If the table is heavily hit by UPDATEs, INSERTs + DELETEs ... these will be very slow with lots of indexes since they all need to be modified each time one of these operations takes place

话虽如此,您显然可以将许多毫无意义的索引添加到一个不会做任何事情的表中.将 B 树索引添加到具有 2 个不同值的列将毫无意义,因为它在查找数据方面没有添加任何内容.列中的值越独特,它就越能从索引中受益.

Having said that, you can clearly add a lot of pointless indexes to a table that won't do anything. Adding B-Tree indexes to a column with 2 distinct values will be pointless since it doesn't add anything in terms of looking the data up. The more unique the values in a column, the more it will benefit from an index.

这篇关于多少数据库索引太多了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

SQL/MySQL: split a quantity value into multiple rows by date(SQL/MySQL:按日期将数量值拆分为多行)
SQL to Generate Periodic Snapshots from Transactions Table(用于从事务表生成定期快照的SQL)
SQL Server Graph Database - shortest path using multiple edge types(SQL Server图形数据库-使用多种边类型的最短路径)
How should make faster SQL Server filtering procedure with many parameters(如何让多参数的SQL Server过滤程序更快)
How can I generate an entity–relationship (ER) diagram of a database using Microsoft SQL Server Management Studio?(如何使用Microsoft SQL Server Management Studio生成数据库的实体关系(ER)图?)
Inserting NaN value into MySQL Database(将NaN值插入MySQL数据库)