Exchange Table Subpartition With Data And Its All LOCAL Partition Indexes 子分区

You have a table called TAB1 which is AUTO PARTITION ON A DATE COLUMN and then SUB-PARTITOIN further.

Now you are trying to move data and its sub-partition LOCAL INDEXES from TAB1 to TAB3 using exchange partition.

You have a staging table as TAB2. All three tables TAB1 (main table) , TAB2 (staging table) and TAB3 (history table) have same table structure.

Now the question is Do you have to have same indexes structure with diff name on TAB2 and TAB3 as TAB1? If not then how do to exchange the partition?
 

SOLUTION

NOTE: In the images and/or the document content below, the user information and data used represents fictitious data from the Oracle sample schema(s) or Public Documentation delivered with an Oracle database product.  Any similarity to actual persons, living or dead, is purely coincidental and not intended in any manner. 

You need to have an index on the exchange table that indexes the same columns as the local index on the partitioned table.

Text: index mismatch for tables in ALTER TABLE EXCHANGE SUBPARTITION
Cause:
Ensure that the indexes for the two tables have indexes which follow this rule For every non partitioned index for the non partitioned table, there has to be an identical LOCAL index on the partitioned table and vice versa

Here's a testcase you can review
- drop any objects already created
drop table test_part cascade constraints;
drop table test_exch cascade constraints;

-- create range/list composite partitioned table
CREATE TABLE test_part (
  customer_id NUMBER(6),
  cust_first_name VARCHAR2(20),
  cust_last_name VARCHAR2(20),
  nls_territory VARCHAR2(30),
  credit_limit NUMBER(9,2))
PARTITION BY RANGE (credit_limit)
SUBPARTITION BY LIST (nls_territory)
SUBPARTITION TEMPLATE
  (SUBPARTITION east VALUES ('CHINA', 'JAPAN', 'INDIA', 'THAILAND'),
  SUBPARTITION west VALUES ('AMERICA', 'GERMANY', 'ITALY', 'SWITZERLAND'),
  SUBPARTITION other VALUES (DEFAULT))
(PARTITION p1 VALUES LESS THAN (1000),
 PARTITION p2 VALUES LESS THAN (2500),
 PARTITION p3 VALUES LESS THAN (MAXVALUE));

-- create local index on partitions
CREATE INDEX test_part_idx ON test_part(credit_limit, nls_territory)
STORAGE (INITIAL 1M MAXEXTENTS UNLIMITED)
LOCAL
(PARTITION p1,
 PARTITION p2,
 PARTITION p3
  (SUBPARTITION east, SUBPARTITION west, SUBPARTITION other));

-- create the exchange table and index


CREATE TABLE test_exch2 (
  customer_id NUMBER(6),
  cust_first_name VARCHAR2(20),
  cust_last_name VARCHAR2(20),
  nls_territory VARCHAR2(30),
  credit_limit NUMBER(9,2))
partition by list(nls_territory)
(partition east VALUES ('CHINA', 'JAPAN', 'INDIA', 'THAILAND'),
 partition west VALUES ('AMERICA', 'GERMANY', 'ITALY', 'SWITZERLAND'),
 partition other VALUES (DEFAULT));

CREATE INDEX test_exch2_idx ON test_exch2 (credit_limit, nls_territory);

alter table test_part exchange partition p1 with table test_exch2;

If you want to exchange out just a single subpartition of a partition (i.e. not the entire partition and all its subpartitions), then do this

-- create exchange table to hold the subpartition
CREATE TABLE test_exch (
  customer_id NUMBER(6),
  cust_first_name VARCHAR2(20),
  cust_last_name VARCHAR2(20),
  nls_territory VARCHAR2(30),
  credit_limit NUMBER(9,2))
/
CREATE INDEX test_exch_idx ON test_exch (credit_limit, nls_territory);

alter table test_part exchange subpartition P2_OTHER with table test_exch;


Make sure to use without validation, or it will try to validate each row in the exchange table should go into the partition you are trying to put it into , and that takes a long time

Now the question is Do I have to have same indexes structure with diff name on TAB2 and TAB3 as TAB1? If not then how do I exchange the partition?


In your testcase, the index name does have to be different on the exchange table
If you want your local index partitions to be usable after the exchange, you have to use including indexes clause, and you have one index on the exchange table for every local index on tab1 and yes, the index names have to be different.

相关推荐

  1. leetcode 659. 分割数组为连续序列

    2024-01-31 10:42:03       35 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-01-31 10:42:03       19 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-01-31 10:42:03       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-01-31 10:42:03       20 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-01-31 10:42:03       20 阅读

热门阅读

  1. 本地python部署onnx模型,使用c++通过http访问

    2024-01-31 10:42:03       34 阅读
  2. 初级通信工程师-移动通信系统

    2024-01-31 10:42:03       29 阅读
  3. 磁珠与电感的区别

    2024-01-31 10:42:03       38 阅读
  4. 蓝桥杯《走方格》

    2024-01-31 10:42:03       34 阅读
  5. 2024美赛数学建模赛题解读常用模型算法

    2024-01-31 10:42:03       31 阅读
  6. 一文了解如何发现并解决Redis热key与大key问题

    2024-01-31 10:42:03       41 阅读
  7. basic CNN

    basic CNN

    2024-01-31 10:42:03      28 阅读
  8. RabbitMQ安全防护,加固策略

    2024-01-31 10:42:03       36 阅读