Sample questions
Question 1Easy
Which column is typically a poor candidate for a standalone B-tree index?
- A gender column with two or three values
- A primary key
- A foreign key column used in frequent joins with a large parent table
- A unique email column
Answer: A. A gender column with two or three values
Explanation
Low-selectivity columns match a large fraction of rows, so a full scan is often as fast.
Step-by-step solution
- A gender column has only two or three values.
- A standalone index on it matches a large share of rows.
- A full scan is often as fast as using the index.
- So a low-selectivity column such as gender is a poor standalone index (option A).
Why the other options are wrong
- B. A primary key is unique and is the best index candidate.
- C. A foreign key used in frequent joins benefits from an index.
- D. A unique email column is highly selective and suits an index.
Tip: Index columns with many distinct values; low-cardinality columns rarely help alone.
Question 2Easy
What does a database index mainly speed up?
- Backups
- Lookups and filters on the indexed columns
- Every write to the table
- Network transfer between the database and every connected client
Answer: B. Lookups and filters on the indexed columns
Explanation
An index avoids a full table scan for matching rows; writes become slightly slower because the index must be updated.
Step-by-step solution
- An index is a sorted structure over chosen columns.
- A lookup or filter on an indexed column finds rows without scanning the whole table.
- Writes get slightly slower because the index must be updated.
- So an index mainly speeds up lookups and filters on the indexed columns (option B).
Why the other options are wrong
- A. Backups do not depend on indexes.
- C. Indexes make writes slightly slower, not faster.
- D. Network transfer to clients is not what an index reduces.
Tip: Index the columns you filter or look up by, and remember each index costs some write speed.
Question 3Easy
An inverted index (used in search engines) maps:
- Each user to their most recently searched queries, sorted by time
- Each row to its primary key
- Each document to its byte offset on disk
- Each term to the documents containing it
Answer: D. Each term to the documents containing it
Explanation
Looking up a word returns its posting list of matching documents, which makes full-text search fast.
Step-by-step solution
- An inverted index is built for full-text search.
- It stores, for each word, the list of documents that contain it.
- A search for a word reads that list directly.
- So an inverted index maps each term to the documents containing it (option D).
Why the other options are wrong
- A. A per-user list of recent searches is a log or history table, not an inverted index.
- B. Mapping rows to primary keys is an ordinary index idea, not an inverted index.
- C. Mapping documents to byte offsets is a different structure from the term-to-document map.
Tip: Inverted index: word to list of documents; the basis of search engine lookup.
Question 4Easy
Most relational databases use which structure for default indexes?
- Hash table only
- B-tree (B+ tree)
- Bloom filter that stores every value of the indexed column
- Linked list
Answer: B. B-tree (B+ tree)
Explanation
B+ trees keep keys sorted, support range queries, and stay shallow even for huge tables.
Step-by-step solution
- Most relational databases use B-tree or B+ tree indexes by default.
- B+ trees keep keys sorted.
- Sorted keys support both point lookups and range queries, and stay shallow for large tables.
- So the default structure is the B-tree (B+ tree) (option B).
Why the other options are wrong
- A. A hash table alone does not support range queries, so it is not the usual default.
- C. A Bloom filter does not store every value and cannot list matches.
- D. A linked list would be a slow scan, not an index.
Tip: B+ trees are the default index because they support both exact and range lookups.
Question 5Medium
A composite index on (country, city). Which query can use it efficiently?
- WHERE city = 'Pune' only
- ORDER BY city alone, without any filter or condition on the country column
- WHERE pincode = '411001'
- WHERE country = 'IN' AND city = 'Pune'
Answer: D. WHERE country = 'IN' AND city = 'Pune'
Explanation
B-tree composite indexes follow the leftmost-prefix rule: the leading column must be constrained.
Step-by-step solution
- A composite index is sorted by country, then by city within country.
- It helps queries that use the leftmost column(s).
- country = 'IN' AND city = 'Pune' uses both columns.
Why the other options are wrong
- A. city alone skips the leftmost column, so the index cannot be used efficiently.
- B. Ordering by city alone does not use the leading column, so the sort order does not match.
- C. pincode is not in the index.
Tip: Think phone book: sorted by country, then city.
Question 6Medium
Keyset (cursor) pagination works by:
- Returning all rows and letting the client page through them locally
- Caching every page
- Using a larger OFFSET
- Filtering on the last seen sort key, e.g. WHERE id > last_id
Answer: D. Filtering on the last seen sort key, e.g. WHERE id > last_id
Explanation
It seeks directly via the index to where the previous page ended, giving stable performance at any depth.
Step-by-step solution
- Keyset pagination remembers the sort key of the last row on the page.
- The next page asks for rows after that key, such as WHERE id > last_id.
- The index seeks straight to that point, so skipped rows are not read.
- So keyset pagination works by filtering on the last seen sort key (option D).
Why the other options are wrong
- A. Returning all rows to the client is slow and not keyset pagination.
- B. Caching pages is a different technique.
- C. A larger OFFSET is the slow method keyset pagination avoids.
Tip: Use WHERE on the last seen key, with the same sort, for stable fast paging.
Question 7Medium
A write-heavy table has a dozen secondary indexes and inserts are slow. Why?
- Slower writes and extra storage, since each index must be updated
- Indexes block all reads
- Indexes force the table to be sharded across nodes
- Faster writes but slower reads
Answer: A. Slower writes and extra storage, since each index must be updated
Explanation
Every INSERT/UPDATE/DELETE maintains each index, adding write amplification.
Step-by-step solution
- Every insert must also update each secondary index.
- A dozen indexes means a dozen extra writes per insert.
- Indexes also use more storage.
Why the other options are wrong
- B. Indexes do not block all reads; reads usually get faster.
- C. Indexes have nothing to do with sharding.
- D. Indexes make reads faster but writes slower, not the other way round.
Tip: More indexes: faster reads, slower writes.
Question 8Medium
A covering index for a query means:
- The index is used by every query
- The index has all columns the query needs, so the table is skipped
- An index whose leaf pages are stored on a separate covering disk
- The index covers every table in the database
Answer: B. The index has all columns the query needs, so the table is skipped
Explanation
If all selected and filtered columns are in the index, the database answers from the index alone.
Step-by-step solution
- A query reads some columns and filters on some columns.
- If an index holds all of them, the database can answer from the index alone.
- The table rows are not needed, so the table is skipped.
- So a covering index has all the needed columns and the table is skipped (option B).
Why the other options are wrong
- A. An index is used only by queries whose columns it covers or filters.
- C. Leaf pages do not sit on a separate covering disk; the term is about columns.
- D. An index covers the columns of one query, not every table.
Tip: A covering index saves table lookups when every needed column is in the index.
Question 9Hard
A global (term-partitioned) secondary index makes reads faster but has which cost?
- Writes may touch several shards, often updating the index asynchronously
- It cannot be partitioned
- Reads must hit all shards
- It only works for numeric columns that are evenly distributed
Answer: A. Writes may touch several shards, often updating the index asynchronously
Explanation
One row write may require updating index entries on other shards, so global indexes are often eventually consistent.
Step-by-step solution
- A global index is partitioned by the indexed term.
- A single row write may need to update an index on another shard.
- Often done asynchronously, so writes cost more.
Why the other options are wrong
- B. Global indexes can be partitioned (by term).
- C. Reading one term hits few shards, which is the benefit.
- D. It is not limited to numeric columns.
Question 10Hard
In a sharded database, a secondary index partitioned locally (per shard) means a query on that index must:
- Avoid the index entirely
- Hit exactly one shard
- Scatter to all shards and gather results
- Read the global index first and then contact exactly one shard to fetch the row
Answer: C. Scatter to all shards and gather results
Explanation
Local indexes only cover each shard's rows, so lookups by non-shard-key columns fan out to every shard.
Step-by-step solution
- A local index covers only the rows in its own shard.
- The query's value may exist on any shard.
- So the query must be sent to every shard and the results merged (scatter-gather).
Why the other options are wrong
- A. Skipping the index would mean a full scan, not what local indexing implies.
- B. Only a query that includes the shard key can go to one shard.
- D. That describes a global index, not a local one.
Tip: Local index: cheap writes, scatter-gather reads.
Practise all 12 questions free
The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.
Open this topic in the app →