Skip to Main Content
  • Questions
  • How to tackle 'ORA-14024: number of partitions of LOCAL index must equal that of the underlying table' error?

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Samuel.

Asked: October 19, 2016 - 8:27 pm UTC

Last updated: October 20, 2016 - 1:43 am UTC

Version: 11gR2

Viewed 10K+ times! This question is

You Asked

Hi,

I have created a plsql program which does the following.

1) Create Backup tables using script from dbms_metadata.get_ddl utility.
2) Insert records from Main tables into backup tables.
3) Rename indexes on Main table
3) Create Indexes (With same name as Main table) and Constraints on backup tables.

Some of the tables have partitions defined on them. So, when the indexes are getting created I get the following error.

"ORA-14024: number of partitions of LOCAL index must equal that of the underlying table"

How do I overcome this error?

and Connor said...

That normally happens when you are explicitly naming partitions. Here's an example


SQL> drop table t purge;

Table dropped.

SQL>
SQL> create table t ( x int, y int )
  2  partition by range ( x )
  3  interval (100)
  4  (
  5    partition p1 values less than ( 0 )
  6  );

Table created.

SQL>
SQL> insert into t
  2  select rownum, rownum
  3  from dual
  4  connect by level <= 1000;

1000 rows created.

SQL>
SQL> commit;

Commit complete.

SQL>
SQL> select partition_name from user_tab_partitions where table_name = 'T';

PARTITION_NAME
---------------------------------
SYS_P18344
SYS_P18343
SYS_P18342
SYS_P18341
SYS_P18340
SYS_P18339
SYS_P18338
SYS_P18337
SYS_P18336
SYS_P18335
SYS_P18334
P1

12 rows selected.

SQL>
SQL> create index IX on T ( y  )
  2  local
  3  (
  4      partition p1,
  5      partition p2,
  6      partition p3,
  7      partition p4,
  8      partition p5,
  9      partition p6,
 10      partition p7,
 11      partition p8,
 12      partition p9,
 13      partition p10,
 14      partition p11,
 15      partition p12
 16  )
 17  ;

Index created.



So far so good... I created 12 partitions in my table, and I explicitly listed 12 partitions in my index. Now I'll drop the index, and add a new row to the table (which creates another partition )

SQL>
SQL>
SQL> drop index ix;

Index dropped.

SQL>
SQL> insert into t
  2  values (2000,2000);

1 row created.

SQL>
SQL>
SQL> create index IX on T ( y  )
  2  local
  3  (
  4      partition p1,
  5      partition p2,
  6      partition p3,
  7      partition p4,
  8      partition p5,
  9      partition p6,
 10      partition p7,
 11      partition p8,
 12      partition p9,
 13      partition p10,
 14      partition p11,
 15      partition p12
 16  )
 17  ;
create index IX on T ( y  )
                   *
ERROR at line 1:
ORA-14024: number of partitions of LOCAL index must equal that of the underlying table



Now my same DDL does not work, because there are 13 table partitions and I only listed 12 index partitions. The easy workaround is not to list the partitions at all.

SQL>
SQL> create index IX on T ( y  )
  2  local ;

Index created.

SQL>
SQL>




Is this answer out of date? If it is, please let us know via a Comment

More to Explore

VLDB

If you are new to partitioning, check out Connor McDonald's introduction series here.

VLDB

Documentation set on VLDB and Partitioning.