Thinking Out Loud

August 14, 2013

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

Filed under: 11g,oracle — mdinh @ 3:57 am

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
About these ads

1 Comment »

  1. SCOTT> select * from t partition(p0);
    ID NAME
    ———- ——————–
    1 one

    SCOTT> select * from t partition(pmax);
    ID NAME
    ———- ——————–
    2 two

    ???

    Comment by zws — February 7, 2014 @ 7:28 am | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

The Rubric Theme. Create a free website or blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 294 other followers

%d bloggers like this: