Bird
0
0

Consider the following SQL commands:

medium📝 Debug Q14 of 15
PostgreSQL - Indexing Strategies

Consider the following SQL commands:
CREATE TABLE employees(id INT, name TEXT);
CREATE INDEX emp_id_hash ON employees USING hash (id);
SELECT * FROM employees WHERE id > 5;

What is the problem with using the hash index in this query?

AThe table must have a primary key before creating a hash index.
BThe index name is invalid for hash indexes.
CHash indexes do not support range queries like <code>id > 5</code>.
DThe query syntax is incorrect for using indexes.
Step-by-Step Solution
Solution:
  1. Step 1: Understand hash index limitations

    Hash indexes only support equality searches, not range conditions like id > 5.
  2. Step 2: Analyze the query condition

    The query uses a range condition, so the hash index cannot be used efficiently here.
  3. Final Answer:

    Hash indexes do not support range queries like id > 5. -> Option C
  4. Quick Check:

    Range query + hash index = no use [OK]
Quick Trick: Hash indexes only work with '=' conditions. [OK]
Common Mistakes:
  • Thinking hash indexes support range queries
  • Believing index names must follow special rules
  • Assuming primary key is required for hash index

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes