LearnFrenzy
Sign in Take a free test

DBMS & SQL · Topic 9 of 11

Indexing and Query Optimisation: questions with answers

B+ tree indexes, clustered and secondary indexes, composite and covering indexes, when indexes are ignored, EXPLAIN, and GATE index arithmetic.

Questions
45
Timed sets
3
Queries executed
3
Your accuracy
–

What this topic covers

23 subtopics
  • Composite indexes5
  • When indexes are ignored5
  • B+ trees3
  • Clustered index3
  • Trade-offs3
  • EXPLAIN2
  • Index structures2
  • Index types2
  • Indexes created by constraints2
  • Optimisation workflow2
  • Optimiser2
  • Selectivity2
Show all 23 subtopics
  • Sorting2
  • Access paths1
  • Basics1
  • Block access1
  • Covering indexes1
  • Joins1
  • Pagination1
  • Partitioning1
  • Secondary indexes1
  • Unique index1
  • When indexes help1
  • Beginner 15
  • Intermediate 15
  • Advanced 15

About this topic

An index is a separate, sorted structure (in MySQL and MariaDB, a B+ tree) that lets the database find rows without scanning the whole table. Good indexes turn seconds into milliseconds; bad ones slow every write and are ignored by the optimiser. Senior interviews ask why a query does not use an index, how to order composite indexes and how to read EXPLAIN; GATE asks for B+ tree orders and block-access counts.

Free preview

Sample questions

Try each one first, then open the answer for the explanation and why the other options are wrong.

Question 1 Basics Beginner Practice

What is a database index?

The physical order in which rows are inserted
A copy of the whole table kept for backups
A constraint that prevents NULL values
A separate sorted structure that maps column values to row locations, so matching rows can be found without scanning the whole table
Show answer and explanation
Correct answer D

Explanation

Like the index at the back of a book, it lets the database jump to the right pages. Lookups become logarithmic instead of linear.

Why the other options are wrong

  • AInsertion order is not an index.
  • BIndexes hold keys and pointers, not a backup.
  • CThat is NOT NULL.
Question 2 When indexes are ignored Beginner Practice

orders has an index on order_date. Why can WHERE YEAR(order_date) = 2026 not use it efficiently, and what is the fix?

Dates cannot be indexed
YEAR() is not allowed in WHERE
The function hides the column from the index; write WHERE order_date >= '2026-01-01' AND order_date < '2027-01-01'
Add DISTINCT
Show answer and explanation
Correct answer C

Explanation

The index is sorted by order_date, not by YEAR(order_date), so the database would have to compute the function for every row. A range on the bare column is "sargable" and uses the index.

Why the other options are wrong

  • ADates index well.
  • BIt is allowed, just slow.
  • DDISTINCT is unrelated.
43 more questions in the timed setsSame format as the samples, with a timer, a question palette and a full review at the end.
Start practising

DBMS & SQL

All 11 topics

Topics, levels and full mocks
  1. 01 DBMS and SQL Fundamentals45 questions · 3 levels
  2. 02 Joins and Subqueries45 questions · 3 levels
  3. 03 Aggregates and GROUP BY45 questions · 3 levels
  4. 04 Window Functions45 questions · 3 levels
  5. 05 Keys and Constraints45 questions · 3 levels
  6. 06 ER Model and Relational Mapping45 questions · 3 levels
  7. 07 Normalization45 questions · 3 levels
  8. 08 Transactions and Concurrency45 questions · 3 levels
  9. 09 Indexing and Query Optimisation45 questions · 3 levels
  10. 10 Advanced SQL Queries45 questions · 3 levels
  11. 11 GATE-Style DBMS Questions (MSQ & NAT)45 questions · 3 levels

Search LearnFrenzy

Esc

Quick links