{"id":4224,"date":"2025-06-15T18:43:51","date_gmt":"2025-06-15T18:43:51","guid":{"rendered":"https:\/\/w3buddy.com\/?post_type=cposts&#038;p=4224"},"modified":"2026-09-26T13:08:06","modified_gmt":"2026-09-26T07:38:06","slug":"oracle-index-management","status":"publish","type":"post","link":"https:\/\/w3buddy.com\/blog\/oracle-index-management\/","title":{"rendered":"Oracle Index Management"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">What is an Index in Oracle?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">An <strong>index<\/strong> in Oracle is a performance tuning structure that improves the <strong>speed of data retrieval<\/strong> on a table. It works like a <strong>lookup<\/strong>\u2014instead of scanning every row, Oracle uses the index to find data faster.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Why Use Indexes?<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Speed up <code>SELECT<\/code>, <code>JOIN<\/code>, and <code>WHERE<\/code> clauses.<\/li>\n\n\n\n<li>Help enforce <strong>uniqueness<\/strong> with unique indexes.<\/li>\n\n\n\n<li>Reduce I\/O for large datasets.<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">Think of it like an index in a book\u2014jump directly to what you need.<\/p>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\">Real-Time Example<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code><code>-- Without index: full table scan\nSELECT * FROM employees WHERE email = 'HR@EXAMPLE.COM';\n\n-- Create index to speed it up\nCREATE INDEX emp_email_idx ON employees(email);<\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Types of Indexes (Just Names Here; Explained Later)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Oracle provides multiple index types to optimize different query patterns. The right index improves performance by reducing I\/O and speeding up data access.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Why So Many Types?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Each index type is designed for <strong>specific data characteristics<\/strong> or <strong>workload patterns<\/strong>.<br>Knowing the difference helps you create <strong>faster and leaner systems<\/strong>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Common Index Types and Use Cases<\/h3>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Index Type<\/th><th>Description<\/th><th>Best Use Case<\/th><th>Sample Command<\/th><\/tr><\/thead><tbody><tr><td><strong>B-tree<\/strong> (default)<\/td><td>Balanced tree structure for fast access to unique or near-unique values.<\/td><td>Primary\/foreign keys, searches, sorting<\/td><td><code>CREATE INDEX idx ON emp(email);<\/code><\/td><\/tr><tr><td><strong>Bitmap<\/strong><\/td><td>Uses bitmaps for storage, ideal for low-cardinality data.<\/td><td>Gender, status, Y\/N flags in warehouses<\/td><td><code>CREATE BITMAP INDEX idx ON emp(gender);<\/code><\/td><\/tr><tr><td><strong>Function-based<\/strong><\/td><td>Stores result of an expression or function.<\/td><td>Queries using functions in <code>WHERE<\/code> clause<\/td><td><code>CREATE INDEX idx ON emp(UPPER(name));<\/code><\/td><\/tr><tr><td><strong>Unique<\/strong><\/td><td>Ensures all values in the indexed column(s) are unique.<\/td><td>Enforcing uniqueness<\/td><td><code>CREATE UNIQUE INDEX idx ON emp(email);<\/code><\/td><\/tr><tr><td><strong>Composite<\/strong><\/td><td>Multi-column index for compound filter conditions.<\/td><td>Filtering on multiple columns<\/td><td><code>CREATE INDEX idx ON emp(dept_id, name);<\/code><\/td><\/tr><tr><td><strong>Invisible<\/strong><\/td><td>Index exists but is ignored by optimizer unless hinted.<\/td><td>Testing index effect without using it<\/td><td><code>CREATE INDEX idx ON emp(job_id) INVISIBLE;<\/code><\/td><\/tr><tr><td><strong>Unusable<\/strong><\/td><td>Index marked as unusable; skipped by optimizer.<\/td><td>During data load or rebuild<\/td><td><code>ALTER INDEX idx UNUSABLE;<\/code><\/td><\/tr><tr><td><strong>Compressed<\/strong><\/td><td>Compresses repeating values in leading columns.<\/td><td>Large indexes with repetitive data<\/td><td><code>CREATE INDEX idx ON emp(dept_id, job_id) COMPRESS;<\/code><\/td><\/tr><tr><td><strong>Automatic (19c+)<\/strong><\/td><td>Created and managed by Oracle automatically.<\/td><td>Let Oracle decide based on workload<\/td><td>Auto-managed by Oracle<\/td><\/tr><tr><td><strong>B-tree Clustered<\/strong><\/td><td>Created on cluster key; shared by all clustered tables.<\/td><td>Clustered tables<\/td><td><code>CREATE INDEX idx ON CLUSTER emp_cluster;<\/code><\/td><\/tr><tr><td><strong>Hash Cluster<\/strong><\/td><td>Used with hash clusters; not created like normal indexes.<\/td><td>Fast equality searches using hash keys<\/td><td>Done via cluster definition<\/td><\/tr><tr><td><strong>Global Partitioned<\/strong><\/td><td>One index spanning all partitions.<\/td><td>Queries accessing multiple partitions<\/td><td><code>CREATE INDEX idx ON sales(date) GLOBAL;<\/code><\/td><\/tr><tr><td><strong>Local Partitioned<\/strong><\/td><td>Index created per partition.<\/td><td>Partition-pruned queries<\/td><td><code>CREATE INDEX idx ON sales(date) LOCAL;<\/code><\/td><\/tr><tr><td><strong>Reverse Key<\/strong><\/td><td>Reverses bytes to prevent index block contention.<\/td><td>RAC\/high-insert environments<\/td><td><code>CREATE INDEX idx ON emp(emp_id) REVERSE;<\/code><\/td><\/tr><tr><td><strong>Domain<\/strong><\/td><td>User-defined, for special data like text or spatial.<\/td><td>Text, XML, spatial data types<\/td><td><code>CREATE INDEX idx ON docs(text) INDEXTYPE IS CTXSYS.CONTEXT;<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Quick Tips<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use <strong>B-tree<\/strong> for most OLTP cases.<\/li>\n\n\n\n<li>Choose <strong>Bitmap<\/strong> for reporting and static data.<\/li>\n\n\n\n<li>Go <strong>Function-based<\/strong> when filters use expressions.<\/li>\n\n\n\n<li>Make indexes <strong>Invisible<\/strong> to test without dropping.<\/li>\n\n\n\n<li>Compress large indexes to <strong>save space<\/strong>.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Guidelines for Managing Indexes in Oracle<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Efficient indexing improves query performance, reduces I\/O, and optimizes storage. These best practices will help you maintain effective, high-performance indexes.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. Index Creation Strategy<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Create Indexes <em>After<\/em> Inserting Table Data<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Creating indexes <strong>after bulk inserts<\/strong> improves performance and avoids unnecessary index maintenance during data load.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>-- Load data first\nINSERT INTO employees ...\n\n-- Then create index\nCREATE INDEX emp_name_idx ON employees(last_name);<\/code><\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Consider Parallel and NOLOGGING Options<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Speed up index creation for large tables.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>CREATE INDEX emp_idx ON employees(email) PARALLEL 4 NOLOGGING;<\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2. Choose the Right Columns to Index<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Index Only Frequently Queried Columns<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Focus on columns used in <code>WHERE<\/code>, <code>JOIN<\/code>, or <code>ORDER BY<\/code> clauses.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Don\u2019t index:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Columns with few distinct values (e.g., YES\/NO)<\/li>\n\n\n\n<li>Columns rarely used in queries<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">Order Columns Smartly in Composite Indexes<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Put the <strong>most selective column first<\/strong> in multi-column indexes.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>CREATE INDEX emp_comp_idx ON employees(department_id, job_id);<\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3. Manage Index Overhead<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Limit the Number of Indexes Per Table<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Too many indexes = slow DML (INSERT\/UPDATE\/DELETE).<br>Keep only what is necessary for performance.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Drop Unused Indexes<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Use index usage monitoring to decide what to drop.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>-- Start monitoring\nALTER INDEX emp_idx MONITORING USAGE;\n\n-- Check usage\nSELECT * FROM V$OBJECT_USAGE WHERE INDEX_NAME = 'EMP_IDX';\n\n-- Drop if unused\nDROP INDEX emp_idx;<\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">4. Storage and Tablespace Planning<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Specify Tablespace for Indexes<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Separate index I\/O and improve manageability.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>CREATE INDEX emp_idx ON employees(email) TABLESPACE idx_tbs;<\/code><\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Estimate Index Size<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Helps plan storage needs and avoid surprises.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>-- Use DBMS_SPACE to estimate\nSELECT * FROM TABLE(DBMS_SPACE.CREATE_INDEX_COST(...));<\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">5. Special Index Features<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Use Unusable Indexes for Large Loads<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Mark index unusable to skip maintenance during loads.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>ALTER INDEX emp_idx UNUSABLE;<\/code><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Rebuild after data load:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>ALTER INDEX emp_idx REBUILD;<\/code><\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Use Invisible Indexes for Safe Testing<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Invisible indexes don\u2019t affect execution plans unless hinted.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>CREATE INDEX emp_test_idx ON employees(email) INVISIBLE;<\/code><\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Avoid Duplicate Indexes<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Oracle 12.2+ allows multiple indexes on same columns (e.g., B-tree &amp; bitmap), but avoid unless for controlled testing.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">6. Index Maintenance and Optimization<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Coalesce or Rebuild Fragmented Indexes<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Coalesce:<\/strong> Lightweight; merges leaf blocks.<\/li>\n\n\n\n<li><strong>Rebuild:<\/strong> Recreates the index from scratch.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code><code>ALTER INDEX emp_idx COALESCE;\nALTER INDEX emp_idx REBUILD;<\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">7. Be Careful with Constraints<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">\u26a0\ufe0f Dropping Constraints Also Drops Indexes<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">If you drop a <strong>unique<\/strong> or <strong>primary key constraint<\/strong>, the index is also dropped unless it&#8217;s user-defined.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>ALTER TABLE employees DROP CONSTRAINT emp_email_uk;\n-- Unique index on 'email' may be gone<\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">8. Advanced Considerations<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Leverage Deferred Segment Creation<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Index segment is not created until data is inserted\u2014saves space for empty tables.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>SELECT SEGMENT_CREATED FROM USER_INDEXES WHERE INDEX_NAME = 'EMP_IDX';<\/code><\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Reduce Indexes with In-Memory Column Store<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Oracle Database In-Memory eliminates the need for many indexes for analytics.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>ALTER TABLE employees INMEMORY;<\/code><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Summary Table<\/h2>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Area<\/th><th>Guideline Example<\/th><\/tr><\/thead><tbody><tr><td>Index Timing<\/td><td>Create after data load<\/td><\/tr><tr><td>Column Selection<\/td><td>Index frequently queried columns only<\/td><\/tr><tr><td>Composite Indexes<\/td><td>Order columns by selectivity<\/td><\/tr><tr><td>Usage Monitoring<\/td><td>Use <code>MONITORING USAGE<\/code> and <code>V$OBJECT_USAGE<\/code><\/td><\/tr><tr><td>Maintenance<\/td><td>Use <code>COALESCE<\/code> or <code>REBUILD<\/code> as needed<\/td><\/tr><tr><td>Performance Optimization<\/td><td>Use <code>PARALLEL<\/code> and <code>NOLOGGING<\/code> options<\/td><\/tr><tr><td>Storage Management<\/td><td>Estimate size, assign to index tablespace<\/td><\/tr><tr><td>Advanced Options<\/td><td>Use Invisible, Unusable, or In-Memory as needed<\/td><\/tr><tr><td>Constraint Awareness<\/td><td>Be cautious when dropping constraints<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Creating Indexes in Oracle<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Indexes boost performance by allowing Oracle to find rows faster. Here&#8217;s how to create different types of indexes efficiently, with the right options and use cases.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u2705 Prerequisites for Creating Indexes<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">You must have:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>CREATE INDEX<\/code> privilege<\/li>\n\n\n\n<li>Enough tablespace (if specified)<\/li>\n\n\n\n<li>Valid column data types (not LOB directly)<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Create an Index Explicitly<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Creates a <strong>non-unique<\/strong> index.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>CREATE INDEX emp_dept_idx ON employees(department_id);<\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Create a Unique Index<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Ensures indexed column(s) contain unique values.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>CREATE UNIQUE INDEX emp_email_uk_idx ON employees(email);<\/code><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\ud83d\udd39 Oracle automatically creates these if a <strong>UNIQUE constraint<\/strong> is defined.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Index with a Constraint<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Oracle auto-creates index with <code>PRIMARY KEY<\/code> or <code>UNIQUE<\/code> constraints.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>ALTER TABLE employees ADD CONSTRAINT emp_pk PRIMARY KEY (employee_id);\n-- Implicitly creates a unique index<\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Create a Large Index<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Use <strong>PARALLEL<\/strong> and <strong>NOLOGGING<\/strong> to speed up creation and reduce redo.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>CREATE INDEX big_sales_idx ON sales(transaction_date) PARALLEL 4 NOLOGGING TABLESPACE idx_tbs;<\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Create Index Online<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Avoid table locking\u2014ideal for production.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>CREATE INDEX emp_job_idx ON employees(job_id) ONLINE;<\/code><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u2705 Allows concurrent DML during creation.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Function-Based Index<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Pre-computes values of expressions or functions.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>CREATE INDEX emp_upper_name_idx ON employees(UPPER(last_name));<\/code><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\ud83d\udd38 Enables efficient search on transformed values.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Compressed Index<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Compresses repeated column values to save space.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>CREATE INDEX emp_multi_col_idx ON employees(department_id, job_id) COMPRESS 1;<\/code><\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>COMPRESS 1<\/code> compresses all but the last column.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Create an Unusable Index<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Created but <strong>not available for use<\/strong> until rebuilt. Useful for deferred builds.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>CREATE INDEX emp_temp_idx ON employees(temp_col) UNUSABLE;\n-- Later: ALTER INDEX emp_temp_idx REBUILD;<\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Create an Invisible Index<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Invisible to optimizer unless hinted\u2014great for testing.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>CREATE INDEX emp_test_idx ON employees(email) INVISIBLE;<\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Multiple Indexes on Same Columns<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Since Oracle 12.2, allowed in special cases (e.g., different index types).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>-- One B-tree, one bitmap (if allowed on same columns)\nCREATE INDEX emp_btree_idx ON employees(email);\nCREATE BITMAP INDEX emp_bmap_idx ON employees(email);<\/code><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u2757 Use sparingly\u2014Oracle chooses only one during optimization.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Summary Table<\/h2>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Type<\/th><th>Syntax<\/th><th>Use Case<\/th><\/tr><\/thead><tbody><tr><td>Basic<\/td><td><code>CREATE INDEX<\/code><\/td><td>Simple search on columns<\/td><\/tr><tr><td>Unique<\/td><td><code>CREATE UNIQUE INDEX<\/code><\/td><td>Enforce uniqueness<\/td><\/tr><tr><td>With Constraint<\/td><td><code>ALTER TABLE ADD CONSTRAINT<\/code><\/td><td>Auto-index created<\/td><\/tr><tr><td>Function-Based<\/td><td><code>ON table(FUNC(col))<\/code><\/td><td>Searching on computed values<\/td><\/tr><tr><td>Compressed<\/td><td><code>COMPRESS N<\/code><\/td><td>Save space<\/td><\/tr><tr><td>Unusable<\/td><td><code>UNUSABLE<\/code><\/td><td>Create but don\u2019t use immediately<\/td><\/tr><tr><td>Invisible<\/td><td><code>INVISIBLE<\/code><\/td><td>Testing new indexes<\/td><\/tr><tr><td>Large<\/td><td><code>PARALLEL<\/code>, <code>NOLOGGING<\/code><\/td><td>Fast creation on big data<\/td><\/tr><tr><td>Online<\/td><td><code>ONLINE<\/code><\/td><td>Avoids locks<\/td><\/tr><tr><td>Multiple on Same Columns<\/td><td>Oracle 12.2+<\/td><td>Rare, advanced use<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Altering Indexes in Oracle<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Indexes aren\u2019t \u201cset and forget\u201d\u2014you may need to <strong>rebuild, rename, hide, monitor, or drop<\/strong> them as data and access patterns evolve.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">About Altering Indexes<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Index changes help optimize performance, reclaim space, or control usage. Oracle allows many runtime adjustments.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Altering Storage of an Index<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Change tablespace, storage, or parallel settings:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>ALTER INDEX emp_idx REBUILD TABLESPACE fast_idx PARALLEL 2;<\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Rebuilding an Index<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Fix fragmentation or make an unusable index usable.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>ALTER INDEX emp_idx REBUILD;\nALTER INDEX emp_idx REBUILD ONLINE;<\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Make an Index Unusable<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Disable without dropping. Good for bulk operations.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>ALTER INDEX emp_idx UNUSABLE;\n-- Rebuild later when needed<\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Make Index Invisible\/Visible<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Invisible indexes are ignored by the optimizer (unless hinted).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>ALTER INDEX emp_idx INVISIBLE;\nALTER INDEX emp_idx VISIBLE;<\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Rename an Index<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Change index name without recreating.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>ALTER INDEX emp_idx RENAME TO emp_name_idx;<\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Monitor Index Usage<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Track if an index is used in queries.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>ALTER INDEX emp_idx MONITORING USAGE;\nSELECT * FROM V$OBJECT_USAGE;<\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Monitor Space Use<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Check index size and bloat:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>SELECT SEGMENT_NAME, BYTES\/1024\/1024 AS MB\nFROM DBA_SEGMENTS\nWHERE SEGMENT_TYPE = 'INDEX' AND SEGMENT_NAME = 'EMP_IDX';<\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Drop an Index<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Remove when no longer needed.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>DROP INDEX emp_idx;<\/code><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u26a0 If it&#8217;s part of a <code>PRIMARY KEY<\/code> or <code>UNIQUE<\/code> constraint, drop the constraint first.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Automatic Indexing (Oracle 19c+)<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Oracle can <strong>auto-create, monitor, and drop indexes<\/strong> using internal intelligence. It\u2019s optional but powerful.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">About Automatic Indexing<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Runs in the background (Autonomous or manually enabled)<\/li>\n\n\n\n<li>Learns query patterns<\/li>\n\n\n\n<li>Only keeps beneficial indexes<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">How It Works<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Creates indexes in <strong>INVISIBLE<\/strong> mode<\/li>\n\n\n\n<li>Tests performance<\/li>\n\n\n\n<li>Promotes or drops based on benefit<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Configure Automatic Indexing<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Enable or disable:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>-- Enable\nEXEC DBMS_AUTO_INDEX.CONFIGURE('AUTO_INDEX_MODE','IMPLEMENT');\n\n-- Disable\nEXEC DBMS_AUTO_INDEX.CONFIGURE('AUTO_INDEX_MODE','OFF');<\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Generate Auto Index Reports<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Check what Oracle\u2019s doing:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>SELECT DBMS_AUTO_INDEX.REPORT_LAST_ACTIVITY FROM DUAL;\nSELECT DBMS_AUTO_INDEX.REPORT_ACTIVITY(SYSDATE-1, SYSDATE) FROM DUAL;<\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Views for Auto Index Info<\/h3>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>View<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>DBA_AUTO_INDEX_CONFIG<\/code><\/td><td>Current config<\/td><\/tr><tr><td><code>DBA_AUTO_INDEXES<\/code><\/td><td>All auto-created indexes<\/td><\/tr><tr><td><code>DBA_AUTO_INDEX_TASKS<\/code><\/td><td>Execution tasks<\/td><\/tr><tr><td><code>DBA_AUTO_INDEX_STATISTICS<\/code><\/td><td>Index benefits\/costs<\/td><\/tr><tr><td><code>DBA_AUTO_INDEX_SQL_ACTIONS<\/code><\/td><td>SQL statements affected<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Recap: What You Can Do<\/h2>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Action<\/th><th>Command<\/th><\/tr><\/thead><tbody><tr><td>Rebuild<\/td><td><code>ALTER INDEX ... REBUILD<\/code><\/td><\/tr><tr><td>Rename<\/td><td><code>ALTER INDEX ... RENAME TO<\/code><\/td><\/tr><tr><td>Make unusable<\/td><td><code>ALTER INDEX ... UNUSABLE<\/code><\/td><\/tr><tr><td>Invisible<\/td><td><code>ALTER INDEX ... INVISIBLE<\/code><\/td><\/tr><tr><td>Drop<\/td><td><code>DROP INDEX<\/code><\/td><\/tr><tr><td>Monitor usage<\/td><td><code>ALTER INDEX ... MONITORING USAGE<\/code><\/td><\/tr><tr><td>Use Auto Index<\/td><td><code>DBMS_AUTO_INDEX.CONFIGURE(...)<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Oracle Indexes Data Dictionary Views<\/h2>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th><strong>View Name<\/strong><\/th><th><strong>Scope<\/strong><\/th><th><strong>Purpose \/ What It Shows<\/strong><\/th><th><strong>Common Use Cases \/ Notes<\/strong><\/th><\/tr><\/thead><tbody><tr><td><code>DBA_INDEXES<\/code><\/td><td>All indexes<\/td><td>Shows metadata about all indexes in the database.<\/td><td>Type, status, uniqueness, tablespace, logging, compression, visibility, etc.<\/td><\/tr><tr><td><code>ALL_INDEXES<\/code><\/td><td>Accessible<\/td><td>Same as <code>DBA_INDEXES<\/code> but limited to tables accessible to the current user.<\/td><td>Use when you don\u2019t have DBA access.<\/td><\/tr><tr><td><code>USER_INDEXES<\/code><\/td><td>Owned<\/td><td>Metadata for indexes owned by the current user.<\/td><td>Fastest for personal schema-level queries.<\/td><\/tr><tr><td><code>DBA_IND_COLUMNS<\/code><\/td><td>All indexes<\/td><td>Details about columns that compose indexes (name, position, length, order).<\/td><td>Useful to identify which columns are indexed.<\/td><\/tr><tr><td><code>ALL_IND_COLUMNS<\/code><\/td><td>Accessible<\/td><td>Indexed column details for all accessible indexes.<\/td><td>Use when working with objects not owned but accessible.<\/td><\/tr><tr><td><code>USER_IND_COLUMNS<\/code><\/td><td>Owned<\/td><td>Indexed columns in the user\u2019s own schema.<\/td><td>Used frequently to find column-level index info.<\/td><\/tr><tr><td><code>DBA_IND_PARTITIONS<\/code><\/td><td>Partitioned only<\/td><td>Partition-level index info: partition name, storage, stats, tablespace.<\/td><td>Use for managing or analyzing partitioned index structures.<\/td><\/tr><tr><td><code>ALL_IND_PARTITIONS<\/code><\/td><td>Accessible<\/td><td>Same as above, for accessible indexes.<\/td><td><\/td><\/tr><tr><td><code>USER_IND_PARTITIONS<\/code><\/td><td>Owned<\/td><td>Partition details for user\u2019s own indexes.<\/td><td>Helps troubleshoot local\/global index partitions.<\/td><\/tr><tr><td><code>DBA_IND_EXPRESSIONS<\/code><\/td><td>Function-based<\/td><td>Expression definitions used in function-based indexes.<\/td><td>Shows stored expressions like <code>UPPER(column_name)<\/code>.<\/td><\/tr><tr><td><code>ALL_IND_EXPRESSIONS<\/code><\/td><td>Accessible<\/td><td>Same as above, for accessible indexes.<\/td><td><\/td><\/tr><tr><td><code>USER_IND_EXPRESSIONS<\/code><\/td><td>Owned<\/td><td>Expression info for user-created function-based indexes.<\/td><td>Good for review and tuning function-based indexing.<\/td><\/tr><tr><td><code>DBA_IND_STATISTICS<\/code><\/td><td>All indexes<\/td><td>Optimizer statistics for indexes (e.g. clustering factor, distinct keys).<\/td><td>Populated via <code>DBMS_STATS<\/code> or <code>ANALYZE<\/code>.<\/td><\/tr><tr><td><code>ALL_IND_STATISTICS<\/code><\/td><td>Accessible<\/td><td>Optimizer stats for indexes the user can access.<\/td><td><\/td><\/tr><tr><td><code>USER_IND_STATISTICS<\/code><\/td><td>Owned<\/td><td>Stats for user-owned indexes.<\/td><td>Useful before\/after stats collection.<\/td><\/tr><tr><td><code>INDEX_STATS<\/code><\/td><td>Manual Analysis<\/td><td>Temporary view populated by <code>ANALYZE INDEX ... VALIDATE STRUCTURE<\/code>.<\/td><td>Used for index structure validation (e.g., height, blocks).<\/td><\/tr><tr><td><code>INDEX_HISTOGRAM<\/code><\/td><td>Manual Analysis<\/td><td>Populated by same <code>ANALYZE<\/code> statement. Shows distribution of leaf rows by block.<\/td><td>Rarely used, but good for detailed analysis or corruption checks.<\/td><\/tr><tr><td><code>USER_OBJECT_USAGE<\/code><\/td><td>Monitoring<\/td><td>Shows if an index was used since <code>ALTER INDEX ... MONITORING USAGE<\/code>.<\/td><td>Essential for deciding whether to drop an index.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Sample Queries:<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>-- List indexes on a table\nSELECT index_name, index_type FROM USER_INDEXES WHERE table_name = 'EMPLOYEES';\n\n-- Show indexed columns\nSELECT index_name, column_name FROM USER_IND_COLUMNS WHERE table_name = 'EMPLOYEES';\n\n-- See if an index was used (after enabling monitoring)\nSELECT * FROM USER_OBJECT_USAGE WHERE index_name = 'EMP_EMAIL_IDX';<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>What is an Index in Oracle? An index in Oracle is a performance tuning structure that improves the speed of data retrieval on a table. It works like a lookup\u2014instead of scanning every row, Oracle uses the index to find data faster. Why Use Indexes? Think of it like an index in a book\u2014jump directly [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"googlesitekit_rrm_CAowu461DA:productID":"","footnotes":""},"categories":[1225,984],"tags":[],"class_list":["post-4224","post","type-post","status-publish","format-standard","hentry","category-database","category-oracle-dba-d2d-tasks"],"_links":{"self":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/posts\/4224","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/comments?post=4224"}],"version-history":[{"count":1,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/posts\/4224\/revisions"}],"predecessor-version":[{"id":4225,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/posts\/4224\/revisions\/4225"}],"wp:attachment":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/media?parent=4224"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/categories?post=4224"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/tags?post=4224"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}