ORACLE中重命名分区

发布于 2024-08-16 12:01:03 字数 89 浏览 8 评论 0原文

如果我们使用 ALTER TABLE RENAME PARTITION 语句重命名 Oracle 表中的现有分区,是否需要使用新更改的分区名称重新创建本地分区索引?

if we use the ALTER TABLE RENAME PARTITION statement to rename the existing partitions in an Oracle table, do we need to recreate the local partitioned indexes with newly changed partition names?

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

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

发布评论

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

评论(2

溺渁∝ 2024-08-23 12:01:03

不会,重命名分区不会影响本地分区索引。您可以轻松测试:

--create table
CREATE TABLE t (
  c1 DATE,
  c2 NUMBER(3))
partition by range (c1) (
  partition t_nov values less than (
    to_date('01-12-2009 00:00:00', 'DD-MM-YYYY HH24:MI:SS')
  ),
  partition t_dec values less than (
    to_date('01-01-2010 00:00:00', 'DD-MM-YYYY HH24:MI:SS')
  )
)
/

--create index
create index idx_t on t (c1) local (partition t_nov, partition t_dec);

--insert some rows
insert into t values (sysdate, 1);
insert into t values (sysdate, 1);
insert into t values (sysdate, 1);
insert into t values (sysdate, 1);
insert into t values (sysdate, 1);
insert into t values (sysdate, 1);
insert into t values (sysdate, 1);
insert into t values (sysdate, 1);
insert into t values (sysdate, 1);
insert into t values (sysdate, 1);

--gather statistics
exec dbms_stats.gather_table_stats('SYSTEM', 'T');

--set autotrace on, to determine that index is used
set autotrace on

--select indexed column 
select c1 from t where c1 < sysdate+1;

--------------------------------------------------------------------------------------------------
| Id  | Operation                | Name  | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
--------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT         |       |    11 |    88 |     1   (0)| 00:00:01 |       |       |
|   1 |  PARTITION RANGE ITERATOR|       |    11 |    88 |     1   (0)| 00:00:01 |     1 |   KEY |
|*  2 |   INDEX RANGE SCAN       | IDX_T |    11 |    88 |     1   (0)| 00:00:01 |     1 |   KEY |
--------------------------------------------------------------------------------------------------

--rename partition
alter table t rename partition t_dec to t_december;
Table altered.


select c1 from t where c1 < sysdate+1;

--------------------------------------------------------------------------------------------------
| Id  | Operation                | Name  | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
--------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT         |       |    11 |    88 |     1   (0)| 00:00:01 |       |       |
|   1 |  PARTITION RANGE ITERATOR|       |    11 |    88 |     1   (0)| 00:00:01 |     1 |   KEY |
|*  2 |   INDEX RANGE SCAN       | IDX_T |    11 |    88 |     1   (0)| 00:00:01 |     1 |   KEY |
--------------------------------------------------------------------------------------------------

重命名分区后索引仍然使用

No, renaming partitions does not affect locally partitioned indexes. You can easily test that:

--create table
CREATE TABLE t (
  c1 DATE,
  c2 NUMBER(3))
partition by range (c1) (
  partition t_nov values less than (
    to_date('01-12-2009 00:00:00', 'DD-MM-YYYY HH24:MI:SS')
  ),
  partition t_dec values less than (
    to_date('01-01-2010 00:00:00', 'DD-MM-YYYY HH24:MI:SS')
  )
)
/

--create index
create index idx_t on t (c1) local (partition t_nov, partition t_dec);

--insert some rows
insert into t values (sysdate, 1);
insert into t values (sysdate, 1);
insert into t values (sysdate, 1);
insert into t values (sysdate, 1);
insert into t values (sysdate, 1);
insert into t values (sysdate, 1);
insert into t values (sysdate, 1);
insert into t values (sysdate, 1);
insert into t values (sysdate, 1);
insert into t values (sysdate, 1);

--gather statistics
exec dbms_stats.gather_table_stats('SYSTEM', 'T');

--set autotrace on, to determine that index is used
set autotrace on

--select indexed column 
select c1 from t where c1 < sysdate+1;

--------------------------------------------------------------------------------------------------
| Id  | Operation                | Name  | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
--------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT         |       |    11 |    88 |     1   (0)| 00:00:01 |       |       |
|   1 |  PARTITION RANGE ITERATOR|       |    11 |    88 |     1   (0)| 00:00:01 |     1 |   KEY |
|*  2 |   INDEX RANGE SCAN       | IDX_T |    11 |    88 |     1   (0)| 00:00:01 |     1 |   KEY |
--------------------------------------------------------------------------------------------------

--rename partition
alter table t rename partition t_dec to t_december;
Table altered.


select c1 from t where c1 < sysdate+1;

--------------------------------------------------------------------------------------------------
| Id  | Operation                | Name  | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
--------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT         |       |    11 |    88 |     1   (0)| 00:00:01 |       |       |
|   1 |  PARTITION RANGE ITERATOR|       |    11 |    88 |     1   (0)| 00:00:01 |     1 |   KEY |
|*  2 |   INDEX RANGE SCAN       | IDX_T |    11 |    88 |     1   (0)| 00:00:01 |     1 |   KEY |
--------------------------------------------------------------------------------------------------

The index is still used, after renaming the partition

帅哥哥的热头脑 2024-08-23 12:01:03

重命名分区不会影响本地分区索引,因此您无需重建索引。

Renaming partitions does not affect locally partitioned indexes, so you will not need to rebuild your indexes.

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