Quantcast
Channel: Thinking Out Loud
Viewing all articles
Browse latest Browse all 666

ORA-14098: index mismatch for tables in ALTER TABLE EXCHANGE PARTITION

$
0
0

Does having the code make troubleshooting easier?

Here is an example code:

create table t (
  id int,
  name varchar2(30)
)
partition by range (id) (
partition p0 values less than (10),
partition pmax values less than (maxvalue)
);
alter table t add constraint pk_t primary key(id);
insert into t values(1,'one');
insert into t values(11,'eleven');

create table t_stage (
  id int,
  name varchar2(30)
);
alter table t_stage add constraint pk_t_stag primary key(id);
insert into t_stage values(2,'two');
commit;

alter table t exchange partition pmax with table t_stage including indexes without validation update global indexes;

LAX:(HR@db01)> alter table t exchange partition pmax with table t_stage including indexes without validation update global indexes;
alter table t exchange partition pmax with table t_stage including indexes without validation update global indexes
                                                 *
ERROR at line 1:
ORA-14098: index mismatch for tables in ALTER TABLE EXCHANGE PARTITION

What do you think is wrong? No peeking!

 

 

 

dallas-cowboys-cheerleaders

 

 

 

FOCUS! Let’s look at the data.

LAX:(HR@db01)> select * from t;

        ID NAME
---------- ------------------------------
         1 one
        11 eleven

LAX:(HR@db01)> select * from t_stage;

        ID NAME
---------- ------------------------------
         2 two

Table Partition

select t.table_name, p.partition_name, partition_position, high_value
from user_tab_partitions p, user_tables t
where t.table_name in (‘T’,'T_STAGE’)
and t.table_name=p.table_name(+)
order by partition_position asc;

TABLE_NAME                     PARTITION_NAME                 PARTITION_POSITION HIGH_VALUE
------------------------------ ------------------------------ ------------------ ------------------------------
T                              P0                                              1 10
T                              PMAX                                            2 MAXVALUE
T_STAGE

Index Partition

select i.table_name, i.index_name ix, p.index_name pix, p.partition_name, partition_position, high_value
from user_ind_partitions p, user_indexes i
where i.table_name in (‘T’,'T_STAGE’)
and i.index_name=p.index_name(+)
order by partition_position asc;

There is no index partition.

TABLE_NAME                     IX                             PIX                            PARTITION_NAME                 PARTITION_POSITION HIGH_VALUE
------------------------------ ------------------------------ ------------------------------ ------------------------------ ------------------ ------------------------------
T                              PK_T
T_STAGE                        PK_T_STAG

Check for FK on table:

select constraint_name, constraint_type, table_name, r_constraint_name, status, bad, rely, validated, index_name, delete_rule from user_constraints
where r_constraint_name in (select constraint_name from user_constraints where table_name=’T');

Drop PK and recreate with local index:

alter table T drop constraint PK_T;
alter table T add constraint PK_T primary key(ID) using index local;

Exchange partition:
alter table t exchange partition pmax with table t_stage including indexes without validation update global indexes;

LAX:(HR@db01)> select * from t;

        ID NAME
---------- ------------------------------
         1 one
         2 two

LAX:(HR@db01)> select * from t_stage;

        ID NAME
---------- ------------------------------
        11 eleven

select i.table_name, i.index_name ix, p.index_name pix, p.partition_name, partition_position, high_value
from user_ind_partitions p, user_indexes i
where i.table_name in (‘T’,'T_STAGE’)
and i.index_name=p.index_name(+)
order by partition_position asc;

Index now partitioned:

TABLE_NAME                     IX                             PIX                            PARTITION_NAME                 PARTITION_POSITION HIGH_VALUE
------------------------------ ------------------------------ ------------------------------ ------------------------------ ------------------ ------------------------------
T                              PK_T                           PK_T                           P0                                              1 10
T                              PK_T                           PK_T                           PMAX                                            2 MAXVALUE
T_STAGE                        PK_T_STAG

Any INVALID index?

select index_name, table_name, status from user_indexes where status <> ‘VALID’;

INDEX_NAME                     TABLE_NAME                     STATUS
------------------------------ ------------------------------ --------
PK_T                           T                              N/A


Viewing all articles
Browse latest Browse all 666

Trending Articles