Solved

ORA-01502: index is in unusable state

Posted on 2004-10-08
11
29,836 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 9

Expert Comment

by:konektor
ID: 12257424
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
ID: 12257668
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
ID: 12257676
Sorry, i submitted accidentally before I even finished:

as a step 3:
3. recreate the index.
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 23

Accepted Solution

by:
seazodiac earned 168 total points
ID: 12257681
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
 
LVL 48

Assisted Solution

by:schwertner
schwertner earned 166 total points
ID: 12258460
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
ID: 12276266
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
ID: 12284081
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
ID: 13284204
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

730 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