多个相同列索引的 Oracle 性能

发布于 2024-07-25 05:13:26 字数 127 浏览 9 评论 0原文

我正在使用一个新的 Oracle 数据库,其中一个表具有以下索引:

  • 索引 1:ColA、ColB
  • 索引 2:ColA

第二个索引是否冗余,这会对性能产生负面影响吗?

I'm Working with a new Oracle DB, with one table having the following indexes:

  • Index 1: ColA, ColB
  • Index 2: ColA

Is the second index redundant, and Will this have a negative impact on performance?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

℡Ms空城旧梦 2024-08-01 05:13:26

Google 是我最好的朋友:

http://www.orafaq.com/node/926

主要这篇文章的要点是:

If 2 indexes ( I1 and I2 ) exist for a table and
   the number of columns in Index I1 is less or equal to the number of column in index I2 and
   index I1 has the same columns in the same order as leading columns of index I2 
Then
   If index I1 is UNIQUE then
      If index I2 is used to support Foregh Key or for Index Overload then
         Do Nothing
      Else
         Index I2 can be DROPPED
      End If
   Else
      Index I1 can be DROPPED
   End If
End If

我同意这一点!
事实上,在谷歌中搜索“重复索引”会有不同的答案。

Google is my best friend :

http://www.orafaq.com/node/926

The main point of this article is :

If 2 indexes ( I1 and I2 ) exist for a table and
   the number of columns in Index I1 is less or equal to the number of column in index I2 and
   index I1 has the same columns in the same order as leading columns of index I2 
Then
   If index I1 is UNIQUE then
      If index I2 is used to support Foregh Key or for Index Overload then
         Do Nothing
      Else
         Index I2 can be DROPPED
      End If
   Else
      Index I1 can be DROPPED
   End If
End If

And I'm agree with that !
In fact, search "duplicate indexes" in Google to have different kind of answer.

青柠芒果 2024-08-01 05:13:26

第二个索引是不同的,并且本身并不冗余。

这个查询怎么样:

SELECT DISTINCT ColA FROM TABLE WHERE ColA IS NOT NULL;

Oracle 可以完全从索引 2 回答这个问题。现在,索引 2 预计会比索引 1 小(更少的块)。这意味着,对于上述查询来说,它是一个更好的索引。

如果您的应用程序从未执行过比 Index1 更适合 Index2 的查询,那么它对于您的应用程序来说是多余的。

索引始终是性能权衡。 当执行插入、更新或删除时,需要做额外的工作来维护每个附加索引。

索引提供的性能提高是否足以弥补这一点? 取决于您的应用程序和数据使用情况。

The second index is different and is not redundant per se.

How about this query:

SELECT DISTINCT ColA FROM TABLE WHERE ColA IS NOT NULL;

Oracle can answer this question entirely from Index 2. Now, index 2 would be expected to be small (less blocks) than index 1. This means, it is a better index for the above query.

If your application never does a query that suits Index2 better than Index1, then it is redundant for your application.

Indexes are always a performance tradeoff. When an insert, update or delete is performed there is extra work to do in order to maintain each additional index.

Is this more than compensated for by the increased performance provided by the index? Depends on your application and data usage.

心凉 2024-08-01 05:13:26

第二个索引有点多余 - 任何使用 Index2 的操作都可以使用索引 1。此外,由于还有另一个索引需要更新,写入速度会稍微慢一些。

也就是说,Index2 并不完全多余,因为它可能会更快一点,因为索引本身可能会小得多。

The second index is sort of redundant - any operation that uses Index2 could use Index 1. Also, writes will be slightly slower since there is another index to update.

That said, Index2 is not entirely redundant as it could be a bit faster since the index itself is probably going to be significantly smaller.

流心雨 2024-08-01 05:13:26

如果您的统计信息过时,优化器可能会在需要索引 1 时选择索引 2。 (当然,对优化器的提示可以解决这个问题。)

there is a chance that if your statistics go out of date, the optimizer might choose index 2 when index 1 is needed. (a hint to the optimizer would solve that, of course.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文