Bird
0
0

Given a table users(id SERIAL PRIMARY KEY, name TEXT) with 1 million rows, which scan is PostgreSQL likely to use for this query?

medium📝 query result Q13 of 15
PostgreSQL - Performance Tuning
Given a table users(id SERIAL PRIMARY KEY, name TEXT) with 1 million rows, which scan is PostgreSQL likely to use for this query?
SELECT * FROM users WHERE id = 500000;
AIndex scan using the primary key index
BSequential scan scanning all 1 million rows
CBitmap heap scan reading random rows
DNo scan, query will fail
Step-by-Step Solution
Solution:
  1. Step 1: Analyze query condition and table size

    The query filters by primary key id, which has an index, and the table is large (1 million rows).
  2. Step 2: Determine efficient scan type

    PostgreSQL uses an index scan to quickly find the single matching row instead of scanning all rows.
  3. Final Answer:

    Index scan using the primary key index -> Option A
  4. Quick Check:

    Selective query on indexed column = index scan [OK]
Quick Trick: Selective query on indexed column uses index scan [OK]
Common Mistakes:
  • Assuming sequential scan for large tables with indexed filter
  • Confusing bitmap heap scan with index scan
  • Thinking query fails without reason

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes