Discussions
Categories
- 197.1K All Categories
- 2.5K Data
- 546 Big Data Appliance
- 1.9K Data Science
- 450.7K Databases
- 221.9K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 31 Multilingual Engine
- 552 MySQL Community Space
- 479 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3.1K ORDS, SODA & JSON in the Database
- 555 SQLcl
- 4K SQL Developer Data Modeler
- 187.2K SQL & PL/SQL
- 21.3K SQL Developer
- 296.3K Development
- 17 Developer Projects
- 139 Programming Languages
- 293K Development Tools
- 110 DevOps
- 3.1K QA/Testing
- 646.1K Java
- 28 Java Learning Subscription
- 37K Database Connectivity
- 158 Java Community Process
- 105 Java 25
- 22.1K Java APIs
- 138.2K Java Development Tools
- 165.3K Java EE (Java Enterprise Edition)
- 19 Java Essentials
- 162 Java 8 Questions
- 86K Java Programming
- 81 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 205 Java User Groups
- 24 JavaScript - Nashorn
- Programs
- 468 LiveLabs
- 39 Workshops
- 10.2K Software
- 6.7K Berkeley DB Family
- 3.5K JHeadstart
- 5.7K Other Languages
- 2.3K Chinese
- 175 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 233 Portuguese
Indexes become unusable

Hi All ,
Could you help me with this scenario where we see indexes marked as unusable post our application migration to a higher version.
We have recently migrated our application to a higher version , which comprise of sql scripts ran against the DB .... which leave few indexes unusable and has to rebuilt manually.
Environment :
DB - 11.2.0.4
Tables - Non partitioned
[ select owner, table_name, partitioning_type, subpartitioning_type from all_part_tables ; .., SELECT * FROM dba_part_tables; ., SELECT * FROM dba_part_index; select partition_name from user_tab_partitions where table_name = 'xxxxxxxxxxxxxxx';]
To be precise , what the sql's consist and does is ...
- adds new columns to fewer tables
- adding indees if not exist
- add new constraint to table if it does not exist
- add new sequence if it does not exist
- create unique indexes
- creating foreign keys for all of the tables
Glance of Syntax's of the scripts used :
==============================
ALTER TABLE xxxxxxxxxxx
CREATE INDEX xxxxxxxxxxxx
ON xxxxxxxxxxxxxxx(
xxxxxxxxxxxxxx,
xxxxxxxxxxx,
xxxxxxxxxxxx
)TABLESPACE xxxxxxxxxxxxxxx;
ALTER TABLE xxxxxxxxxxxxx
ADD (CONSTRAINT xxxxxxxxxxxxxxxxxxxxx PRIMARY KEY (id)) ;
CREATE UNIQUE INDEX xxxxxxxxxxxxxxxxxxxx
ON xxxxxxxxx(
xxxxxxxxxxxxx,
xxxxxxxxxxxxxx
)TABLESPACE xxxxxxxxxxxxxx;
ALTER TABLE xxxxxxxxxxxxxxxx
ADD CONSTRAINT xxxxxxxxxxxxxxxxxxx FOREIGN KEY (xxxxxx)
REFERENCES xxxxx (id)
ON DELETE SET NULL;
ALTER TABLE xxxxxxxxxxxxxxx
ADD CONSTRAINT xxxxxxxxxxxxxxxxxx FOREIGN KEY (xxxxxxxxxxxxx)
REFERENCES xxxxxxxxxxxx(id)
ON DELETE CASCADE ;
Thanks
Answers
-
Indexes general are unusable because they were never built in the first place or because you’ve done some segment move without updating them.
When you build the indexes, were they unusable? How much time passed before they became unusable? What DDL was processed at that point? Alter table.. move?
-
If you know which indexes got invalid, you can then determine to which table this index belongs.
Search in your scripts for commands referencing this index or this table.
Perhaps you are doing a 'alter table move' somewhere or a direct path load?
-
Hans Steijntjes wrote:If you know which indexes got invalid, you can then determine to which table this index belongs.Search in your scripts for commands referencing this index or this table.Perhaps you are doing a 'alter table move' somewhere or a direct path load?
Direct path load maintains indexes, sql ldr direct path load makes indexes unusable before it kicks off.
-
To be precise, here is the script syntax for the table in question ...
The syntax of table in question whose indexes ( ind1_xxxxxxxxxxxx, ind2_xxxxxxxxxxx , ind3_xxxxxxxxxxx , ind5_xxxxxxxxxxx ) is as below along with indexes ,
CREATE TABLE tabname
(id number(20,0) NOT NULL,
version int DEFAULT 0 NOT NULL,
bid number(20,0) NOT NULL,
xxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxx
....
....
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
attributes CLOB NULL
)
LOB (attributes) STORE AS lobaccountattr (TABLESPACE xxxxxxxxxxxxxxx;
TABLESPACE xxxxxxxxxxxxxxx;
--
--
CREATE UNIQUE INDEX ind1_xxxxxxxxxxxx
ON tab (
id
)TABLESPACE xxxxxxxxxxxxxxx;
--
--
CREATE UNIQUE INDEX ind2_xxxxxxxxxxxx
ON pcwbankaccount (
cid
)TABLESPACE xxxxxxxxxxxx;
--
--
CREATE UNIQUE INDEX ind3_xxxxxxxxxxxx
ON pcwbankaccount (
cid,
acntnum,
rt
)TABLESPACE xxxxxxxxxxxx;
--
--
CREATE INDEX ind5_xxxxxxxxxxxx;
ON xxxxxxxxxxxx;(
wtypeid,
cart,
cid
)TABLESPACE xxxxxxxxxxxx;
ALTER TABLE xxxxxxxxxxxx
ADD (CONSTRAINT tabname_id_pk PRIMARY KEY (id)) ;
-
Hi Andrew,
Alter table only to add constraint ... please see my detailed syntax w.r.t the same.
Thank you.
-
Thanks Hans , Please find the details in my reply to the original question.
-
What the others are trying to tell you is that nothing in the redacted scripts you posted should have caused the indexes to become unusable, so the problem most likely lies elsewhere.
-
Index become unusable when something like alter table shrink space or alter table move compress happens. Has anything like that happened.
Or indexes may become unusable when they are explicitly altered to be set unusable, which may be done in order to have some updates go faster. After that, indexes may be rebuilt. Not necessarily one by one, but they may be rebuilt using a script.