5 exercises — practise the English vocabulary for indexing strategy discussions: B-tree limitations, partial indexes, the leftmost prefix rule, covering indexes, and arguing about the trade-offs of excessive indexing.
0 / 26 completed
1 / 26
A DBA says: "B-tree indexes support equality and range queries on sortable types." A new column description TEXT is proposed for full-text search. Which query type would NOT benefit from a standard B-tree index on description?
-- Query A: WHERE description = 'exact match'
-- Query B: WHERE description LIKE 'prefix%'
-- Query C: WHERE description LIKE '%substring%'
-- Query D: WHERE description > 'alpha' AND description < 'beta'
B-tree index limitations vocabulary:
Option D is correct. A B-tree index stores values in sorted order, which enables equality lookups, prefix scans (LIKE 'prefix%'), and range queries. However, a leading wildcard pattern (LIKE '%substring%') cannot use the B-tree because there is no sorted starting point — the matching substring could appear anywhere in the value.
Query pattern
B-tree usable?
Why
= 'value'
Yes
Equality — direct lookup in sorted tree
LIKE 'prefix%'
Yes (with text_pattern_ops)
Prefix — B-tree can seek to the start of the prefix
LIKE '%substring%'
No
Leading wildcard — no sorted traversal entry point
> 'a' AND < 'z'
Yes
Range scan — B-tree traversal between two sorted bounds
Alternatives for substring/full-text search:
GIN index with to_tsvector — PostgreSQL full-text search; enables @@ match operator
pg_trgm extension + GIN/GiST index — enables fast LIKE '%substring%' and fuzzy matching
Dedicated search engine — Elasticsearch, OpenSearch for complex search requirements
2 / 26
A DBA proposes the following index during a performance review: "We should index only the active rows to avoid indexing 90% of the archived records." What is this index type called, and what is its primary maintenance advantage?
CREATE INDEX idx_orders_active ON orders (created_at)
WHERE status = 'active';
Partial index vocabulary:
Option B is the correct definition. A partial index is defined by a WHERE clause that limits which rows are included in the index. Only rows satisfying the predicate are indexed.
Why partial indexes matter in production:
Aspect
Full-table index
Partial index (WHERE status='active')
Index size
Indexes all N rows
Indexes only active rows (e.g., 10% of N)
Write overhead
Updated on every INSERT/UPDATE/DELETE
Updated only when predicate rows change
Query selectivity
Planner chooses based on statistics
Very selective for active-row queries
Planner usage
Used for any query on the column
Only used when WHERE matches the predicate
Practical comment for schema reviews:"Since 90% of orders are archived and we only query active orders, a partial index on WHERE status = 'active' will be roughly 10x smaller than a full index, update faster, and fit more easily in the buffer pool."
3 / 26
A senior engineer explains an index in a code review: "The composite index (last_name, first_name) will be used by queries filtering by last_name alone, but not by queries filtering only by first_name." What is this property called, and why does it apply to B-tree composite indexes?
Leftmost prefix rule vocabulary:
Option C is correct. A composite B-tree index sorts entries first by the first column, then by the second column within ties, etc. — like a phone book sorted by last name, then first name. A query filtering only by first_name has no sorted entry point in this structure.
Query predicate
Uses index (last_name, first_name)?
Why
WHERE last_name = 'Smith'
Yes
Leftmost column — can seek to sorted position
WHERE last_name = 'Smith' AND first_name = 'Alice'
Yes
Both columns — full composite lookup
WHERE first_name = 'Alice'
No
Skips leftmost column — no sorted starting point
Practical implications for index design discussions:
Column order in a composite index should match the most common query patterns.
If queries filter by first_name alone frequently, add a separate single-column index on first_name.
A three-column index (A, B, C) supports queries on A; A+B; and A+B+C — but not B alone, C alone, or B+C.
PostgreSQL can sometimes use a composite index with a range skip scan, but this is not guaranteed — always verify with EXPLAIN.
4 / 26
An engineer says during a schema review: "We added salary to the users index so the planner doesn't need to visit the heap for our reporting query." What is a covering index and what read path does it eliminate?
CREATE INDEX idx_users_dept_salary ON users (department_id)
INCLUDE (salary, full_name);
Covering index vocabulary:
Option A is the precise definition. A covering index stores all columns the query needs — both filter columns and SELECT column projections — within the index structure itself, so the query engine never needs to read from the heap (the main table storage).
INCLUDE clause vocabulary (PostgreSQL 11+):
Part of the index definition
Role
Key columns (before INCLUDE)
Stored in all B-tree levels; used for sorting and lookup
INCLUDE columns (after INCLUDE)
Stored only in leaf pages; not used for sorting; satisfy projections
Example:
-- Without covering index: Index Scan + heap fetch for salary
SELECT department_id, salary, full_name FROM users WHERE department_id = 5;
-- With INCLUDE (salary, full_name): Index Only Scan — no heap fetch
-- CREATE INDEX idx_users_dept_salary ON users (department_id) INCLUDE (salary, full_name);
Trade-off to mention in reviews: Covering indexes are larger because payload columns are duplicated from the table into the index. They increase write overhead for updates to the included columns. Use them selectively for hot, frequently-executed queries where the heap fetch is the dominant cost.
5 / 26
A junior engineer argues: "We should add a B-tree index on every foreign key column — it'll speed up all the JOIN operations." Which response best explains the trade-off of excessive indexing?
Indexing trade-off vocabulary:
Option C gives the accurate and complete trade-off explanation. Every index on a table is a secondary data structure that must be kept in sync with the table's data on every write operation.
Operation
Effect of each additional index
INSERT
New entry added to every index — N index writes per 1 table write
UPDATE (indexed column)
Old entry removed, new entry inserted in affected indexes
DELETE
Entry removed from every index
Autovacuum / VACUUM
Must clean dead entries in every index — vacuum time grows with index count
Storage
Each index occupies additional disk space
How to push back professionally in a review: "Indexing every foreign key is a reasonable starting heuristic, but it isn't free. Let's add indexes only where we have a measured query that does a JOIN or lookup on that FK column. On our orders table (high insert/update volume), unnecessary indexes will slow down every write. I'd suggest starting with the FKs hit by our top-10 slow queries and measuring before indexing the rest."
6 / 26
Sarah, a backend developer, posted this message in the team Slack channel after reviewing the performance of a query that frequently retrieves customer order details:
"The query is slow. It's scanning the entire `orders` table to find orders placed by John Doe. I suspect an index could help."
The correct answer focuses on indexing the primary key (`customer_id`), which is the most efficient way to locate records in a database. A full-text index (option 1) wouldn't be ideal for this specific retrieval scenario and would add unnecessary overhead. While composite indexes (option 2) can be useful, they aren't always optimal and could potentially slow down writes. Option 4, while potentially beneficial for read performance, is overkill without a clear understanding of the query patterns and might increase index maintenance costs unnecessarily; indexing the primary key directly addresses the immediate performance concern.
7 / 26
During a sprint planning meeting, the team is discussing optimizing queries against the `products` table. The product manager asks, 'What's the key difference between a standard B-tree index and a covering index when it comes to read performance?' David, the senior developer, explains: 'A standard B-tree index allows us to quickly locate rows based on the indexed column(s). A covering index, however, includes *all* the columns needed for a specific query within the same index definition. This eliminates the need to access the base table entirely.' Which of the following best describes the practical impact of this distinction?
The core difference lies in data locality. A standard B-tree index directs the database to the *starting point* of matching rows. However, if the query needs additional columns not part of the index, it still has to fetch those from the base table – a 'lookup' operation. A covering index includes all necessary columns within the index itself, effectively eliminating this lookup step and dramatically improving performance for queries that target only these columns. Option A is incorrect as they don't offer identical benefits; B is too strong a statement about always being superior, C accurately reflects the key distinction, and D highlights the query-specific nature of covering indexes.
8 / 26
During a standup update, Maria, the data modeler, says: 'We're seeing significant performance degradation on our customer segmentation query. It's retrieving all customer records and then filtering based on their purchase history – it's incredibly slow! We need to consider how indexes can help.' The query currently uses `WHERE last_purchase_date > '2023-01-01'` and `WHERE category = 'Electronics'`. Which of the following index strategies would MOST effectively address Maria's concern, and *why*?
The correct answer is option 1: A clustered index on last_purchase_date. Because Maria's query filters *primarily* by date and then category, a clustered index physically orders the table based on this column – dramatically improving performance for range queries like `last_purchase_date > '2023-01-01'`. Options B and C would still require scanning portions of the table even with the index. Option D (full-text indexing) is generally less efficient than a well-designed, targeted index for this specific query pattern; it's overkill.
9 / 26
During a code review, Alex, the lead developer, is discussing index design with Ben, a junior engineer. Alex says: 'We've noticed slow performance on queries that filter by `product_category`. Adding an index on this column will significantly improve query speed.' Ben counters: 'But what if we have products with multiple categories? Wouldn't that make the index less effective and potentially slower to maintain?' Which of the following best explains Alex's reasoning and addresses Ben's concern?
SELECT * FROM products WHERE product_category = 'Electronics';
Alex's reasoning correctly highlights the general benefit of indexing a frequently filtered column. The database optimizer *does* consider cardinality (the number of distinct values) when deciding whether to use an index. Ben's concern is valid – multi-valued columns can indeed complicate things. However, a standard single-column index on `product_category` will often still be effective, especially if the distribution of categories is relatively even. The optimizer *will* take into account this cardinality when choosing whether to utilize the index.
10 / 26
Sarah, a backend developer, posted this message in the team Slack channel after reviewing the performance of a query that frequently retrieves customer order details:
"The query is slow. It's scanning the entire `orders` table to find orders placed by John Doe. I suspect an index could help."
The correct answer focuses on indexing the primary key (`customer_id`), which is the most efficient way to locate records in a database. A full-text index (option 1) wouldn't be ideal for this specific retrieval scenario and would add unnecessary overhead. While composite indexes (option 2) can be useful, they aren't always optimal and could potentially slow down writes. Option 4, while potentially beneficial for read performance, is overkill without a clear understanding of the query patterns and might increase index maintenance costs unnecessarily; indexing the primary key directly addresses the immediate performance concern.
11 / 26
During a sprint planning meeting, the team is discussing optimizing queries against the `products` table. The product manager asks, 'What's the key difference between a standard B-tree index and a covering index when it comes to read performance?' David, the senior developer, explains: 'A standard B-tree index allows us to quickly locate rows based on the indexed column(s). A covering index, however, includes *all* the columns needed for a specific query within the same index definition. This eliminates the need to access the base table entirely.' Which of the following best describes the practical impact of this distinction?
The core difference lies in data locality. A standard B-tree index directs the database to the *starting point* of matching rows. However, if the query needs additional columns not part of the index, it still has to fetch those from the base table – a 'lookup' operation. A covering index includes all necessary columns within the index itself, effectively eliminating this lookup step and dramatically improving performance for queries that target only these columns. Option A is incorrect as they don't offer identical benefits; B is too strong a statement about always being superior, C accurately reflects the key distinction, and D highlights the query-specific nature of covering indexes.
12 / 26
During a standup update, Maria, the data modeler, says: 'We're seeing significant performance degradation on our customer segmentation query. It's retrieving all customer records and then filtering based on their purchase history – it's incredibly slow! We need to consider how indexes can help.' The query currently uses `WHERE last_purchase_date > '2023-01-01'` and `WHERE category = 'Electronics'`. Which of the following index strategies would MOST effectively address Maria's concern, and *why*?
The correct answer is option 1: A clustered index on last_purchase_date. Because Maria's query filters *primarily* by date and then category, a clustered index physically orders the table based on this column – dramatically improving performance for range queries like `last_purchase_date > '2023-01-01'`. Options B and C would still require scanning portions of the table even with the index. Option D (full-text indexing) is generally less efficient than a well-designed, targeted index for this specific query pattern; it's overkill.
13 / 26
During a code review, Alex, the lead developer, is discussing index design with Ben, a junior engineer. Alex says: 'We've noticed slow performance on queries that filter by `product_category`. Adding an index on this column will significantly improve query speed.' Ben counters: 'But what if we have products with multiple categories? Wouldn't that make the index less effective and potentially slower to maintain?' Which of the following best explains Alex's reasoning and addresses Ben's concern?
SELECT * FROM products WHERE product_category = 'Electronics';
Alex's reasoning correctly highlights the general benefit of indexing a frequently filtered column. The database optimizer *does* consider cardinality (the number of distinct values) when deciding whether to use an index. Ben's concern is valid – multi-valued columns can indeed complicate things. However, a standard single-column index on `product_category` will often still be effective, especially if the distribution of categories is relatively even. The optimizer *will* take into account this cardinality when choosing whether to utilize the index.
14 / 26
Sarah, a backend developer, posted this message in the team Slack channel after reviewing the performance of a query that frequently retrieves customer order details:
"The query is slow. It's scanning the entire `orders` table to find orders placed by John Doe. I suspect an index could help."
The correct answer focuses on indexing the primary key (`customer_id`), which is the most efficient way to locate records in a database. A full-text index (option 1) wouldn't be ideal for this specific retrieval scenario and would add unnecessary overhead. While composite indexes (option 2) can be useful, they aren't always optimal and could potentially slow down writes. Option 4, while potentially beneficial for read performance, is overkill without a clear understanding of the query patterns and might increase index maintenance costs unnecessarily; indexing the primary key directly addresses the immediate performance concern.
15 / 26
During a sprint planning meeting, the team is discussing optimizing queries against the `products` table. The product manager asks, 'What's the key difference between a standard B-tree index and a covering index when it comes to read performance?' David, the senior developer, explains: 'A standard B-tree index allows us to quickly locate rows based on the indexed column(s). A covering index, however, includes *all* the columns needed for a specific query within the same index definition. This eliminates the need to access the base table entirely.' Which of the following best describes the practical impact of this distinction?
The core difference lies in data locality. A standard B-tree index directs the database to the *starting point* of matching rows. However, if the query needs additional columns not part of the index, it still has to fetch those from the base table – a 'lookup' operation. A covering index includes all necessary columns within the index itself, effectively eliminating this lookup step and dramatically improving performance for queries that target only these columns. Option A is incorrect as they don't offer identical benefits; B is too strong a statement about always being superior, C accurately reflects the key distinction, and D highlights the query-specific nature of covering indexes.
16 / 26
During a standup update, Maria, the data modeler, says: 'We're seeing significant performance degradation on our customer segmentation query. It's retrieving all customer records and then filtering based on their purchase history – it's incredibly slow! We need to consider how indexes can help.' The query currently uses `WHERE last_purchase_date > '2023-01-01'` and `WHERE category = 'Electronics'`. Which of the following index strategies would MOST effectively address Maria's concern, and *why*?
The correct answer is option 1: A clustered index on last_purchase_date. Because Maria's query filters *primarily* by date and then category, a clustered index physically orders the table based on this column – dramatically improving performance for range queries like `last_purchase_date > '2023-01-01'`. Options B and C would still require scanning portions of the table even with the index. Option D (full-text indexing) is generally less efficient than a well-designed, targeted index for this specific query pattern; it's overkill.
17 / 26
During a code review, Alex, the lead developer, is discussing index design with Ben, a junior engineer. Alex says: 'We've noticed slow performance on queries that filter by `product_category`. Adding an index on this column will significantly improve query speed.' Ben counters: 'But what if we have products with multiple categories? Wouldn't that make the index less effective and potentially slower to maintain?' Which of the following best explains Alex's reasoning and addresses Ben's concern?
SELECT * FROM products WHERE product_category = 'Electronics';
Alex's reasoning correctly highlights the general benefit of indexing a frequently filtered column. The database optimizer *does* consider cardinality (the number of distinct values) when deciding whether to use an index. Ben's concern is valid – multi-valued columns can indeed complicate things. However, a standard single-column index on `product_category` will often still be effective, especially if the distribution of categories is relatively even. The optimizer *will* take into account this cardinality when choosing whether to utilize the index.
18 / 26
Sarah, a backend developer, posted this message in the team Slack channel after reviewing the performance of a query that frequently retrieves customer order details:
"The query is slow. It's scanning the entire `orders` table to find orders placed by John Doe. I suspect an index could help."
The correct answer focuses on indexing the primary key (`customer_id`), which is the most efficient way to locate records in a database. A full-text index (option 1) wouldn't be ideal for this specific retrieval scenario and would add unnecessary overhead. While composite indexes (option 2) can be useful, they aren't always optimal and could potentially slow down writes. Option 4, while potentially beneficial for read performance, is overkill without a clear understanding of the query patterns and might increase index maintenance costs unnecessarily; indexing the primary key directly addresses the immediate performance concern.
19 / 26
During a sprint planning meeting, the team is discussing optimizing queries against the `products` table. The product manager asks, 'What's the key difference between a standard B-tree index and a covering index when it comes to read performance?' David, the senior developer, explains: 'A standard B-tree index allows us to quickly locate rows based on the indexed column(s). A covering index, however, includes *all* the columns needed for a specific query within the same index definition. This eliminates the need to access the base table entirely.' Which of the following best describes the practical impact of this distinction?
The core difference lies in data locality. A standard B-tree index directs the database to the *starting point* of matching rows. However, if the query needs additional columns not part of the index, it still has to fetch those from the base table – a 'lookup' operation. A covering index includes all necessary columns within the index itself, effectively eliminating this lookup step and dramatically improving performance for queries that target only these columns. Option A is incorrect as they don't offer identical benefits; B is too strong a statement about always being superior, C accurately reflects the key distinction, and D highlights the query-specific nature of covering indexes.
20 / 26
During a standup update, Maria, the data modeler, says: 'We're seeing significant performance degradation on our customer segmentation query. It's retrieving all customer records and then filtering based on their purchase history – it's incredibly slow! We need to consider how indexes can help.' The query currently uses `WHERE last_purchase_date > '2023-01-01'` and `WHERE category = 'Electronics'`. Which of the following index strategies would MOST effectively address Maria's concern, and *why*?
The correct answer is option 1: A clustered index on last_purchase_date. Because Maria's query filters *primarily* by date and then category, a clustered index physically orders the table based on this column – dramatically improving performance for range queries like `last_purchase_date > '2023-01-01'`. Options B and C would still require scanning portions of the table even with the index. Option D (full-text indexing) is generally less efficient than a well-designed, targeted index for this specific query pattern; it's overkill.
21 / 26
During a code review, Alex, the lead developer, is discussing index design with Ben, a junior engineer. Alex says: 'We've noticed slow performance on queries that filter by `product_category`. Adding an index on this column will significantly improve query speed.' Ben counters: 'But what if we have products with multiple categories? Wouldn't that make the index less effective and potentially slower to maintain?' Which of the following best explains Alex's reasoning and addresses Ben's concern?
SELECT * FROM products WHERE product_category = 'Electronics';
Alex's reasoning correctly highlights the general benefit of indexing a frequently filtered column. The database optimizer *does* consider cardinality (the number of distinct values) when deciding whether to use an index. Ben's concern is valid – multi-valued columns can indeed complicate things. However, a standard single-column index on `product_category` will often still be effective, especially if the distribution of categories is relatively even. The optimizer *will* take into account this cardinality when choosing whether to utilize the index.
22 / 26
During a code review, David, the senior developer, comments on a PR draft:
"I'm concerned about this query. It's fetching all user data and then filtering based on `last_login`. We should consider adding an index to last_login to improve performance. What is the primary benefit of using a covering index in this situation?"
A covering index means all columns required by the query are present in the index. This allows the database to satisfy the entire request solely from the index without accessing the base table, significantly boosting performance. Option A is incorrect because a covering index doesn't *force* use; it simply makes it possible. Options C and D misrepresent the role of a covering index.
23 / 26
In a Slack message to the team, Elena, a data engineer, writes: 'We're experiencing slow response times when querying the `orders` table for orders placed in the last week. Indexing only the `order_date` column seems insufficient; it's still scanning a large portion of the table.' What is the most likely reason for this?"
A key principle of indexing is that a covering index should include all columns used in the query's WHERE clause. If only order_date is indexed and the query also uses other columns like `customer_id` or `product_id`, the database will still need to perform a full table scan because the index doesn't contain all necessary information.
24 / 26
During a standup meeting, Kenji, a developer, says: 'We've been seeing performance problems with our inventory query. It retrieves all product details and then filters by `product_name`. I'm thinking about creating an index on product_name, but I want to understand how it relates to covering indexes.' What is the primary purpose of a *covering* index in this context?
A covering index is designed to contain *all* columns required for a specific query. In this case, if the query only uses `product_name`, a covering index including `product_name` and other product details (like `id`, `price`) will allow the database to retrieve all necessary information from the index itself, avoiding a full table scan. Options A, C, and D describe secondary benefits or broader optimization strategies.
25 / 26
Sarah, a backend developer, is reviewing query performance data and notices that queries to the `users` table frequently filter by `registration_date`. She's considering adding an index. Which of the following statements best describes the relationship between B-tree indexes and covering indexes in this scenario?
B-tree indexes are a general type of index used by most databases. A *covering index* is specifically a type of B-tree index that includes all columns required to satisfy a particular query, eliminating the need for the database to access the base table. Option D mischaracterizes their roles; both are optimization techniques.
26 / 26
During a sprint planning meeting, the team is discussing query performance. The product owner asks: 'We're seeing slow response times when retrieving customer order details based on their ID. We have an index on `customer_id`, but it's still not fast enough. What could be causing this issue?'
A common performance issue with indexes arises when queries attempt to retrieve more data than what's included in the index. This is referred to as a 'non-covering' query. The database then has to perform a full table scan to retrieve the additional columns, negating the benefit of having an index on customer_id. Options A, B, and D present other possible causes but aren't the primary root of this specific problem.
What does the "Indexing Strategy Language" exercise practise?
Practice English for database indexing strategy discussions: B-tree limitations, partial indexes, leftmost prefix rule, covering indexes, and trade-offs of excessive indexing. 5 advanced exercises.
How many questions are in this exercise?
This exercise has 26 questions, each multiple-choice with a full explanation shown after you answer.
What English level is this exercise for?
This exercise is tagged Advanced. If the vocabulary feels difficult, browse the Database & SQL category page for an easier module to start with.
Is this exercise free to use?
Yes. Every exercise on CoderSlingo, including this one, is free with no account, sign-up, or paywall.
Do I get feedback if I answer incorrectly?
Yes — whichever option you choose, right or wrong, you'll immediately see an explanation clarifying the correct term and why the other options don't fit.
Can I retry this exercise?
Yes — once you finish all the questions, a "Try again" button on the results screen resets the exercise so you can practise as many times as you like.
Do I need an account to track my progress?
No account is required. Your progress bar and score for this session are tracked in the browser as you go, but nothing is saved once you leave the page.
Is "Indexing Strategy Language" part of a larger series?
Yes — it's one exercise in the Database & SQL category on CoderSlingo. See the category page for the full list of related exercises on similar terminology.
Can I link directly to this exercise?
Yes — this exercise has its own permanent URL, so you can bookmark it or share the link directly with a colleague or study partner.
Where can I find more exercises like this one?
See the Database & SQL category page for related exercises, or browse the main Exercises hub for other IT English topics.