Bird
0
0

Consider two large tables orders(order_id, product_id) and inventory(product_id, stock), both sorted on product_id. Which join algorithm will PostgreSQL most likely use to join them on product_id?

medium📝 query result Q5 of 15
PostgreSQL - Performance Tuning
Consider two large tables orders(order_id, product_id) and inventory(product_id, stock), both sorted on product_id. Which join algorithm will PostgreSQL most likely use to join them on product_id?
ANested Loop Join
BMerge Join
CHash Join
DCross Join
Step-by-Step Solution
Solution:
  1. Step 1: Analyze table properties

    Both tables are large and sorted on the join key product_id.
  2. Step 2: Consider join algorithms

    Merge Join is efficient when inputs are sorted on join keys.
  3. Step 3: Exclude other options

    Nested Loop is inefficient for large tables; Hash Join does not require sorted inputs; Cross Join is unrelated.
  4. Final Answer:

    Merge Join -> Option B
  5. Quick Check:

    Sorted large tables favor Merge Join [OK]
Quick Trick: Sorted large tables joined on key use Merge Join [OK]
Common Mistakes:
  • Choosing Hash Join despite sorted inputs
  • Selecting Nested Loop for large tables
  • Confusing Cross Join with other join types

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes