Test your knowledge of database indexing basics with this quiz covering composite keys, covering indexes, and using EXPLAIN for query diagnosis. Ideal for beginners seeking to understand key indexing strategies and performance analysis in databases.
Identifying Composite Keys
Which statement best describes a composite key in a database table?
- A set of two or more columns used together as a unique identifier
- A field used only for sorting rows
- A single column that uniquely identifies each row
- A key that automatically increases in value
Understanding Covering Indexes
What makes an index a covering index for a specific query?
- It includes all columns referenced by the query
- It covers all the tables in the database
- It has the largest number of indexed columns
- It only covers the primary key column
Composite Index Use Case
If a table has a composite index on (last_name, first_name), which query will most efficiently use this index?
- SELECT * FROM employees WHERE age u003E 30
- SELECT * FROM employees
- SELECT * FROM employees WHERE first_name = 'Anna'
- SELECT * FROM employees WHERE last_name = 'Lee' AND first_name = 'Anna'
Diagnosing Queries with EXPLAIN
What is the primary purpose of using the EXPLAIN command in database queries?
- To find syntax errors in the query
- To display the database schema
- To display how the database will execute the query
- To show the actual query results
Index Benefits
How do indexes most commonly improve query performance in databases?
- By storing entire tables in memory
- By enforcing numeric data types
- By encrypting rows automatically
- By reducing the amount of data scanned for query matches
Partial Index Condition
Suppose a composite index is created on (city, postal_code); which query will not fully benefit from this index?
- SELECT * FROM addresses WHERE postal_code = '75001'
- SELECT * FROM addresses WHERE city LIKE 'Pa%'
- SELECT * FROM addresses WHERE city = 'Paris'
- SELECT * FROM addresses WHERE city = 'Paris' AND postal_code = '75001'
EXPLAIN Output Understanding
If the EXPLAIN output for a query shows 'Using index' in the Extra column, what does it indicate?
- The index is about to be created
- The result is retrieved using only the index, without accessing table rows
- The query plan is unknown
- The query uses no index and does a full table scan
Index Choice for Range Queries
Which index would be most suitable for the query: SELECT * FROM sales WHERE date u003E= '2023-01-01' AND date u003C= '2023-06-30'?
- A composite index on (product_id, amount)
- No index at all
- A composite index on (date, customer_id)
- A single-column index on amount
Order of Columns in Composite Indexes
Why does the order of columns in a composite index affect query performance?
- Because the indexing engine searches leftmost columns first
- Because queries must filter on all columns at once
- It has no impact at all
- Because columns are always searched in reverse order
Avoiding Duplicate Indexes
Which of the following is a reason to avoid creating duplicate indexes on the same columns?
- It is required for all composite keys
- It speeds up query execution further
- It improves insert performance
- It increases storage requirements unnecessarily