将列添加到 Oracle 中的现有索引
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8378571/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Adding columns to existing index in Oracle
提问by bonsvr
I have a relatively large table (81M rows) and an index on it.
我有一个相对较大的表(81M 行)和一个索引。
I want to add a column to the existing index.
我想向现有索引添加一列。
I searched for it on Google, but I couldn't find a way for it.
我在谷歌上搜索它,但我找不到方法。
I've read somewherethat the only way to add a column to an index is to drop and recreate it.
我在某处读到过将列添加到索引的唯一方法是删除并重新创建它。
However, here it saysit's common practice to add columns to existing index. (Although the author doesn't recommend it.)
但是,这里说将列添加到现有索引是常见的做法。(虽然作者不推荐。)
So, is it possible to add columns to existing index and if possible is it good practice?
那么,是否可以将列添加到现有索引中,如果可能的话,这是一种好习惯吗?
回答by Justin Cave
It is not possible to add a new column to an existing index without dropping and recreating the index.
在不删除和重新创建索引的情况下,不可能向现有索引添加新列。
When Jonathan Lewis is talking about "adding a column to an existing index", he's talking about dropping the existing index and creating a new index. Note in his example, both the "original index" and "modified index" are listed with a CREATE INDEX
statement. There are no ALTER INDEX
statements in the example that would add a new column without dropping the old column.
当 Jonathan Lewis 谈论“向现有索引添加列”时,他谈论的是删除现有索引并创建新索引。请注意,在他的示例中,“原始索引”和“修改后的索引”都与一条CREATE INDEX
语句一起列出。ALTER INDEX
示例中没有任何语句会在不删除旧列的情况下添加新列。
Whether it is a good idea to drop & recreate the index with an additional column depends on a number of factors. As Jonathan Lewis points out, there are various situations where adding additional columns will affect the clustering factor of the index and cause some existing queries to perform more poorly. Without knowing anything about your system or the index we're talking about, it's impossible to advise.
删除并重新创建带有附加列的索引是否是个好主意取决于许多因素。正如 Jonathan Lewis 指出的那样,在各种情况下,添加额外的列会影响索引的聚集因子并导致一些现有查询的性能更差。在不了解您的系统或我们正在谈论的索引的情况下,无法提供建议。