Solved

ORA-01502: index is in unusable state

Posted on 2004-10-08
11
29,422 Views
Last Modified: 2012-06-27
I am using sqlloader with direct=TRUE , i am trying to insert 2 million records in to table through flat files. This flat files some times may have duplicated records also.
(using Direct Path Load)

The loading tables has a primary key constraint on some columns.

Sqlloader is loading successfully but the index which is created for primary key by default by oracle
is getting in unusable state.

1>Due to this the select query in the procedure is giving the error that index is in unsable state.

ORA-01502: index 'DOS_OWNER.PK_MARKETING_COPY1234' or partition of such
index is in unusable state


2>I am not able to even delete the duplicate records also because for the same error.

SQL> alter session set skip_unusable_indexes=true;

Session altered.

SQL> ed
Wrote file afiedt.buf

  1  delete from marketing_copy
  2   where rowid in ( select rowid
  3     from ( select
  4   row_number() over ( partition by full_isbn,
  5  region,
  6  marketing_copy_type,load_date
  7   order by full_isbn ) rn
  8                          from marketing_copy )
  9*                        where rn <> 1)
SQL> /
delete from marketing_copy
*
ERROR at line 1:
ORA-01502: index 'GLOBAL_HEPM_OWNER.PK_MARKETING_COPY1234' or partition of such
index is in unusable state


3> I am not able to re build also
SQL> alter index PK_MARKETING_COPY1234 rebuild;
alter index PK_MARKETING_COPY1234 rebuild
*
ERROR at line 1:
ORA-01452: cannot CREATE UNIQUE INDEX; duplicate keys found
================================================================
I am using
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production


1) How to proceed now any logic/method to handle this situation.
2) how can i rebuild my index / How delete duplicate records

Please Help me ouT....!

0
Comment
Question by:UMESHNC
11 Comments
 
LVL 9

Expert Comment

by:konektor
Comment Utility
1) indexes gets into unusable state eg. when u delete partitions in partitioned tables. oracle released some fixes of this feature like "UPDATE INDEXES" in "alter table ... drop partition ..." clausule ...
2) alter index <index name> rebuild
0
 
LVL 23

Expert Comment

by:seazodiac
Comment Utility
UMESHNC:

1. drop the index first:

SQL>drop index GLOBAL_HEPM_OWNER.PK_MARKETING_COPY1234;


2. delete the duplicate rows:

delete from
GLOBAL_HEPM_OWNER.marketing_copy
where row_id > (select min(row_id) from
GLOBAL_HEPM_OWNER.marketing_copy
group by <PK_marketing_copy columns>);
0
 
LVL 23

Expert Comment

by:seazodiac
Comment Utility
Sorry, i submitted accidentally before I even finished:

as a step 3:
3. recreate the index.
0
 
LVL 23

Accepted Solution

by:
seazodiac earned 168 total points
Comment Utility
In fact, Reading from this post first:

preceding my solution above, because you have this Unique index PK_MARKETING_COPY1234 also as A Primary key on this table.,


you might have to disable the PK constraint first:

SQL>alter table GLOBAL_HEPM_OWNER.marketing_copy disable constraint GLOBAL_HEPM_OWNER.PK_MARKETING_COPY1234;



then proceed with step 1, 2, 3
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 47

Assisted Solution

by:schwertner
schwertner earned 166 total points
Comment Utility
Under certain conditions, INDEXES can become marked unusable after altering a table.
This has been recorded in several bugs.
Using the parameter SKIP_UNUSABLE_INDEXES = TRUE often will prevent these errors.
If this do not helps then use the following:
A workaround is to use a hint in the SQL statement which causes the  
optimizer not to select a plan which uses an unavailable index,
or  to drop and recreate the index.
 
To delete the duplicate rows:

SQL>delete from DUPTABLE A
        where A.ROWID <> ( select MIN(ROWID)
                    from DUPTABLE B
                     where A.ID = B.ID
                     and A.NAME = B.NAME
                     and A.NOTE = B.NOTE
                  )
SQL> /
SQL> commit;
0
 
LVL 11

Expert Comment

by:sujit_kumar
Comment Utility
1. drop the index first:

SQL>drop index GLOBAL_HEPM_OWNER.PK_MARKETING_COPY1234;


2. delete the duplicate rows:

delete from
GLOBAL_HEPM_OWNER.marketing_copy
where row_id  not in (select min(row_id) from
GLOBAL_HEPM_OWNER.marketing_copy
group by <PK_marketing_copy columns>);

3. import.

4. built the index again.

0
 

Author Comment

by:UMESHNC
Comment Utility
hi  seazodiac,

The Delete statement takes more time than the one i have Given Earlier...

Your delete statement takes more than a 10 min ....i killed the query. I had 1 million
record with 80% duplicate records. Where my query took 1.5 minutes.


delete from
GLOBAL_HEPM_OWNER.marketing_copy
where row_id > (select min(row_id) from
GLOBAL_HEPM_OWNER.marketing_copy
group by <PK_marketing_copy columns>);


Thanks
0
 
LVL 11

Assisted Solution

by:sujit_kumar
sujit_kumar earned 166 total points
Comment Utility
try,

delete from
GLOBAL_HEPM_OWNER.marketing_copy a
where not exists ( select 1 from
GLOBAL_HEPM_OWNER.marketing_copy b
where b.row_id = a.row_id
group by <PK_marketing_copy columns>);
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now