Test your understanding of database indexing fundamentals with this quiz covering composite keys, covering indexes, and interpreting EXPLAIN output. Ideal for learners seeking to solidify basic concepts of database optimization and query performance.
Composite Key Identification
Which of the following best describes a composite key in a relational database table?
- A single column that acts as a primary key
- A set of two or more columns used together as a primary key
- An automatically incremented column
- A key that contains only numeric data
Basic Index Purpose
What is the main purpose of creating an index on a database column?
- To allow more users to access the database simultaneously
- To increase the size of the database
- To encrypt the data in a column
- To speed up query performance for data retrieval
EXPLAIN Statement Usage
What does the EXPLAIN keyword do when placed before a SELECT statement in SQL?
- It runs the query and shows the result
- It deletes any existing indexes used in the query
- It explains the syntax of the query
- It provides a breakdown of how the database will execute the query
Composite Index Order Impact
Given a composite index on columns (first_name, last_name), which query benefits most from this index?
- SELECT * FROM users WHERE first_name = 'John' AND last_name = 'Smith'
- SELECT * FROM users WHERE last_name = 'Smith'
- SELECT * FROM users WHERE city = 'Boston'
- SELECT * FROM users WHERE age = 30
Covering Index Recognition
Which of the following describes a 'covering index'?
- An index that automatically updates deleted rows
- An index that is hidden from the query optimizer
- An index that covers only the primary key column
- An index containing all the columns needed by a query
Index Lookup Type
If the output of EXPLAIN shows 'index' in the type column, what does this typically indicate?
- The query is performing a full table scan
- The query is updating indexes
- No indexes are available
- An index is being used to read all the data needed for the query
Index Benefit Example
Which scenario would benefit MOST from adding an index on a 'created_at' timestamp column?
- Inserting new rows into the table
- Deleting old data using random IDs
- Frequently searching for rows based on the creation date
- Calculating the sum of all numeric columns
Composite Key Use Case
Why might a table use a composite key made up of (student_id, course_id)?
- To uniquely identify the enrollment of each student in each course
- To allow duplicate rows for the same student in the same course
- To store grades in a separate column
- To limit the number of courses a student can take
EXPLAIN Output Columns
When viewing the output of EXPLAIN, which column typically shows which index (if any) the database plans to use?
- owner
- rows
- select_type
- key
Covering Index Performance
How does a covering index help improve query performance?
- It slows down all SELECT statements
- It encrypts all indexed columns for security
- It allows the query to avoid accessing the main table since all required columns are in the index
- It increases the number of columns that can be queried