Bird
0
0

Consider this EXPLAIN output for a query joining two tables:

hard📝 Application Q9 of 15
PostgreSQL - Performance Tuning
Consider this EXPLAIN output for a query joining two tables:
Hash Join  (cost=10.00..30.00 rows=500 width=150)
  Hash Cond: (a.id = b.a_id)
  -> Seq Scan on a
  -> Hash  
       -> Seq Scan on b

What does this plan imply about the join strategy?
APostgreSQL builds a hash table from table b and scans table a sequentially
BPostgreSQL uses nested loops to join tables a and b
CPostgreSQL sorts both tables before joining
DPostgreSQL uses an index scan on both tables
Step-by-Step Solution
Solution:
  1. Step 1: Analyze Hash Join components

    Hash Join builds a hash table from one input (here table b) for fast lookups.
  2. Step 2: Understand scan types

    Both tables are scanned sequentially; no index or sort is used.
  3. Final Answer:

    PostgreSQL builds a hash table from table b and scans table a sequentially -> Option A
  4. Quick Check:

    Hash Join = hash build + sequential scan [OK]
Quick Trick: Hash Join builds hash on one table, scans the other [OK]
Common Mistakes:
  • Confusing Hash Join with Nested Loop
  • Assuming sorting happens in Hash Join
  • Thinking indexes are used here

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes