How many database indexes is too many?

后端 未结 17 2082
终归单人心
终归单人心 2020-12-07 08:09

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

相关标签:
17条回答
  • 2020-12-07 08:53

    How many columns are there? I have always been told to make single-column indexes, not multi-column indexes. So no more indexes than the amount of columns, IMHO.

    0 讨论(0)
  • 2020-12-07 08:56

    In data warehousing it is very common to have a high number of indexes. I have worked with fact tables having two hundred columns and 190 of them indexed.

    Although there is an overhead to this it must be understood in the context that in a data warehouse we generally only insert a row once, we never update it, but it can then participate in thousands of SELECT queries which might benefit from indexing on any of the columns.

    For maximum flexibility a data warehouse generally uses single column bitmap indexes except on high cardinality columns, where (compressed) btree indexes can be used.

    The overhead on index maintenance is mostly associated with the expense of writing to a great many blocks and the block splits as new rows are added with values that are "in the middle" of existing value ranges for that column. This can be mitigated by partitioning and having the new data loads aligned with the partitioning scheme, and by using direct path inserts.

    To address your question more directly, I think it is probably fine to index the obvious at first, but do not be afraid of adding more indexes on if the queries against the table would benefit.

    0 讨论(0)
  • 2020-12-07 08:59

    It is totally based on the columns which are being used in Where Clause. And as the Thumb of Rule, we must have indexes on Foreign Key Columns to avoid DEADLOCKS. AWR report should analyze periodically to understand the need of indexes.

    0 讨论(0)
  • 2020-12-07 09:00

    I made some simple tests on my real project and real MySql database. I already answered in this topic: What is the cost of indexing multiple db columns?

    But I think it will be better if I quote it here:

    I made some simple tests using my real project and real MySql database.

    My results are: adding average index (1-3 columns in an index) to a table - makes inserts slower by 2.1%. So, if you add 20 indexes, your inserts will be slower by 40-50%. But your selects will be 10-100 times faster.

    So is it ok to add many indexes? - It depends :) I gave you my results - You decide!

    0 讨论(0)
  • 2020-12-07 09:02

    If you do mostly reads (and few updates) then there's really no reason not to index everything you'll need to index. If you update often, then you may need to be cautious on how many indexes you have. There's no hard number, but you'll notice when things start to slow down. Make sure your clustered index is the one that makes the most sense based on the data.

    0 讨论(0)
  • 2020-12-07 09:03

    An index imposes a cost when the underlying table is updated. An index provides a benefit when it is used to spped up a query. For each index, you need to balance the cost against the benefit. How much slower does the query run without the index? How much of a benefit is running faster? Can you or your users tolerate the slow speed when the index is missing?

    Can you tolerate the additional time it takes to complete an update?

    You need to compare costs and benefits. That's particular to your situation. There's no magic number of indexes that passes the threshold of "too many".

    There's also the cost of the space needed to store the index, but you've said that in your situation that's not an issue. The same is true in most situations, given how cheap disk space has become.

    0 讨论(0)
提交回复
热议问题