Test your expertise with this challenging quiz on indexes, covering key principles, types, maintenance, and performance optimization. Perfect for those seeking a deep understanding of index structures and their practical implications in database systems.
Which of the following best describes a clustered index in a relational database table?
Explanation: A clustered index determines the physical order of data rows in a table, making retrieval efficient for range queries on the indexed columns. Nonclustered indexes store index entries separately from the table data, acting as pointers. Clustered indexes can be created on base tables as well as certain types of views, but not exclusively on views. While a clustered index often requires a unique key (either enforced or with an internal identifier), it does not require every column to be unique.
Why can frequent data modifications (INSERT, UPDATE, DELETE) negatively impact index performance?
Explanation: Whenever data is added, updated, or removed, index structures must be updated to reflect those changes, potentially leading to fragmentation or increased overhead. Indexes do not require full database rebuilds after every modification, only localized updates. Table locks are not necessarily held for extended durations due to indexes unless misconfigured. Additional indexes can still be created, unless explicitly restricted.
Which statement about index selectivity is correct in optimizing query performance?
Explanation: High selectivity means many distinct values, leading to more efficient lookups and filtering, thus improving index usefulness. Low selectivity indexes, on columns with many duplicate values, tend to provide less performance benefit. Selectivity is an important metric for index effectiveness, not irrelevant. Indexes on foreign keys may or may not be selective, depending on the data.
Given a composite index on (last_name, first_name), which query filter benefits most from this index?
Explanation: A composite index on (last_name, first_name) is most effective when the query includes both columns, or at least the leading one. Filtering only on the second column (first_name) won't efficiently use the index. Queries on unrelated columns, such as age or city, derive no benefit from the composite index. Using both columns matches the index's order, providing the greatest performance improvement.
What is the main purpose of a unique index on a column?
Explanation: A unique index enforces the rule that each value in the indexed column must be distinct, supporting data integrity. Reverse order storage is not the primary purpose, although indexing can specify sort direction. Indexes have no inherent impact on backup speed or table-level compression; those functions are handled separately.
Which type of index is most commonly used to improve performance on columns with many range queries?
Explanation: B-tree indexes enable fast traversal for range-based queries by maintaining a balanced tree structure, making them ideal for such cases. Hash indexes are optimized for exact-match lookups but not ranges. Bitmap indexes are more suitable for columns with low cardinality rather than range queries. Inverted indexes are used primarily for full-text searching rather than numeric or date ranges.
What is a key advantage of a covering index in query optimization?
Explanation: A covering index includes all the fields required by a query, so the database can satisfy the request using only the index, avoiding additional reads from the table. It does not inherently restrict access to data or enforce referential integrity. Covering indexes are a subset of nonclustered indexes and do not prevent their use or creation.
How does significant index fragmentation affect database read performance?
Explanation: Fragmented indexes have data stored non-sequentially, resulting in more disk or memory reads and harming read speed. Fragmentation does not block queries entirely; the index still functions, just less efficiently. Data loss is not a consequence of fragmentation alone. Fragmentation is not the same as compression; it actually reduces, not improves, storage efficiency.
Which hidden cost should be considered before adding multiple indexes to a large table?
Explanation: Additional indexes consume more disk space and introduce additional overhead during data modifications, potentially slowing down INSERT, UPDATE, or DELETE operations. Indexes do not automatically rewrite queries for better performance; query plans are chosen by the optimizer. Not all queries benefit from indexes, and some may even perform worse if the wrong index is used. Indexing updates are not instantaneous and add extra processing steps.
What is a partial index in the context of optimizing queries?
Explanation: Partial indexes are created by specifying a condition so only rows meeting that condition are indexed, improving space and performance for targeted queries. It does not refer to failed index creation or skipping rows arbitrarily. Index definitions do not depend on whether a column contains partial data types; the term refers to conditional row inclusion.