Indexes & Performance · SQL SQL

Consider a table users with columns (id SERIAL PRIMARY KEY, email VARCHAR(255), status VARCHAR(50)). If a query frequently filters by email and statu…

Practice question from Indexes & Performance (SQL SQL), with the correct answer and a step-by-step solution.

medium · MCQ · Q-6B4B24

Consider a table users with columns (id SERIAL PRIMARY KEY, email VARCHAR(255), status VARCHAR(50)). If a query frequently filters by email and status using WHERE email = '[email protected]' AND status = 'active', which index design is most efficient?

  1. A.Two separate single-column indexes: CREATE INDEX idx_email ON users(email); CREATE INDEX idx_status ON users(status);
  2. B.A multi-column composite index: CREATE INDEX idx_email_status ON users(email, status);Correct answer
  3. C.A full-text search index on both columns
  4. D.No index is needed because equality filters use sequential scans faster

Solution

A composite index on (email, status) allows the database to navigate the B-tree using the leading column (email) and effectively filter the second column (status) within the same index structure. Separate single-column indexes force the database to use index intersection techniques, which are often much slower.

More from Indexes & Performance

All of Indexes & Performance

Practise more SQL

Sign up free for adaptive practice on this chapter, with instant feedback and hints on every question.

Start practising free

Free to start · No credit card needed