Bird
0
0

Given a table products(id SERIAL PRIMARY KEY, price NUMERIC) with a B-tree index on price, what will the query SELECT * FROM products WHERE price > 100 ORDER BY price; most likely use?

medium📝 query result Q13 of 15
PostgreSQL - Indexing Strategies
Given a table products(id SERIAL PRIMARY KEY, price NUMERIC) with a B-tree index on price, what will the query SELECT * FROM products WHERE price > 100 ORDER BY price; most likely use?
AA sequential scan ignoring the index
BA B-tree index scan to quickly find rows with price > 100
CA hash index scan on price
DA bitmap index scan on price
Step-by-Step Solution
Solution:
  1. Step 1: Understand query conditions and index type

    The query filters with price > 100 and orders by price; B-tree indexes support range queries and sorting.
  2. Step 2: Identify index usage

    PostgreSQL will use the B-tree index to efficiently find and order matching rows.
  3. Final Answer:

    A B-tree index scan to quickly find rows with price > 100 -> Option B
  4. Quick Check:

    Range query + order = B-tree index scan [OK]
Quick Trick: Range queries with ORDER BY use B-tree index scans [OK]
Common Mistakes:
  • Assuming sequential scan always used
  • Confusing hash or bitmap index usage
  • Ignoring index benefits for range queries

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes