Bird
0
0

Why does UNION remove duplicates internally, and how does this affect performance compared to UNION ALL?

hard📝 Conceptual Q10 of 15
PostgreSQL - Set Operations and Advanced Queries
Why does UNION remove duplicates internally, and how does this affect performance compared to UNION ALL?
AUNION and UNION ALL have identical performance because they do the same work
BUNION removes duplicates by joining tables, making it faster than UNION ALL
CUNION removes duplicates by sorting or hashing, which adds overhead; UNION ALL is faster as it skips this step
DUNION removes duplicates by filtering rows before combining, which is faster than UNION ALL
Step-by-Step Solution
Solution:
  1. Step 1: Understand how UNION removes duplicates

    UNION removes duplicates by sorting or hashing the combined result, which requires extra processing.
  2. Step 2: Compare performance with UNION ALL

    UNION ALL skips duplicate removal, so it runs faster because it just concatenates results.
  3. Final Answer:

    UNION removes duplicates by sorting or hashing, which adds overhead; UNION ALL is faster as it skips this step -> Option C
  4. Quick Check:

    UNION slower due to duplicate removal; UNION ALL faster [OK]
Quick Trick: UNION removes duplicates with sorting/hashing; UNION ALL is faster [OK]
Common Mistakes:
  • Thinking UNION is faster than UNION ALL
  • Assuming both do same work
  • Misunderstanding duplicate removal process

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes