Discover how Oracle indexes, including B-Tree, composite, and function-based types, optimize database queries. Learn key principles for efficient index strategies and common pitfalls developers face.
What is the primary reason to create an index on a database table column?
Explanation: The main purpose of an index is to help the database quickly locate rows, making queries much faster. Indexes do not make columns unique (unless a unique index is specifically created), do not perform backups, and usually increase rather than decrease storage space.
What happens during a full table scan?
Explanation: A full table scan requires the engine to read each row to locate desired data, which can be inefficient. Indexes, in contrast, allow targeted row retrieval. The other options either mischaracterize scanning or refer to unrelated query methods.
Which type of index is the default in Oracle databases?
Explanation: B-Tree indexes are the standard in Oracle, offering efficient sorted access. Bitmap and hash indexes are specialized types, and Oracle does not have clustered indexes as a default.
What do the leaf blocks of a B-Tree index contain?
Explanation: Leaf blocks store the indexed values and their corresponding ROWIDs, which point to the row location. They do not hold entire rows, query results, or SQL code.
Why would a composite index be preferred over two single-column indexes for filtering by multiple columns?
Explanation: A composite index speeds up queries using multiple columns by following their order. It doesn't change the number of columns, is not always faster in all query situations, and cannot reduce table size to zero.
When using a composite index on (cust_id, sale_date), which WHERE clause can make effective use of the index?
Explanation: An index on (cust_id, sale_date) needs the leading column, cust_id, in the filter to be effective. Filtering only by sale_date ignores the leading edge, and filters on unrelated columns won't use this index.
Why is the order of columns critical when creating a composite index?
Explanation: Ordering affects index efficiency as the B-Tree structure sorts data first by the initial column. Index size doesn't change based on column order alone, and all columns are part of the index unless ignored in filters.
What issue does a function-based index resolve in Oracle?
Explanation: A function-based index stores the result of expressions like UPPER(column), enabling fast searches. It doesn't directly stop all table scans, remove duplicates, or enforce uniqueness unless combined with constraints.
If a query searches for UPPER(cust_name) = 'ACME CORP', why does a standard index on cust_name not help?
Explanation: A basic index cannot help if the search transforms data (e.g., uppercasing), as it stores original values. Text columns can be indexed, indexes are not automatically dropped with function use, and standard indexes are not limited to NULLs.
What is a recommended method for choosing which columns go first in a composite index?
Explanation: Placing the most selective or lead filter column first improves index effectiveness. Alphabetic order, smallest data type, or random choice ignore query patterns and data characteristics.