Recall & Review
beginner
What is a covering index in PostgreSQL?
A covering index is an index that contains all the columns needed to satisfy a query, so the database can get the data directly from the index without looking up the main table.
Click to reveal answer
beginner
What does the INCLUDE clause do in a PostgreSQL index?
The INCLUDE clause adds extra columns to the index as non-key columns. These columns are stored in the index but not used for sorting or searching, allowing queries to be covered by the index.
Click to reveal answer
intermediate
Why use INCLUDE columns instead of adding them as key columns in an index?
INCLUDE columns do not affect the index's sort order or size as much as key columns do. They help cover queries without slowing down index scans or increasing index maintenance cost significantly.
Click to reveal answer
beginner
Write a PostgreSQL command to create an index on column 'user_id' and include 'email' and 'created_at' columns.
CREATE INDEX idx_user_id_include ON users (user_id) INCLUDE (email, created_at);
Click to reveal answer
beginner
How does a covering index improve query performance?
It allows the database to answer queries using only the index without accessing the main table, reducing disk reads and speeding up query execution.
Click to reveal answer
What is the main benefit of using INCLUDE columns in a PostgreSQL index?
✗ Incorrect
INCLUDE columns add extra data to the index to cover queries without affecting the index's sort order or complexity.
Which of these is true about columns added with INCLUDE in PostgreSQL indexes?
✗ Incorrect
INCLUDE columns are stored in the index to cover queries but do not affect sorting or searching.
Which SQL command creates a covering index on 'order_id' including 'order_date' and 'customer_id'?
✗ Incorrect
The key column is 'order_id' and 'order_date' and 'customer_id' are included as non-key columns.
What happens if a query can be answered entirely from a covering index?
✗ Incorrect
Covering indexes allow queries to be answered using only the index, which is faster.
Which PostgreSQL version introduced the INCLUDE clause for indexes?
✗ Incorrect
The INCLUDE clause for indexes was introduced in PostgreSQL 11.
Explain what a covering index is and how the INCLUDE clause helps create one in PostgreSQL.
Think about how indexes can store extra columns to answer queries fully.
You got /3 concepts.
Describe the difference between key columns and INCLUDE columns in a PostgreSQL index.
Consider how sorting and searching work in indexes.
You got /3 concepts.