Bird
0
0

Why is the UNION ALL keyword used in recursive CTEs for graph traversal instead of UNION?

hard📝 Conceptual Q10 of 15
PostgreSQL - Common Table Expressions
Why is the UNION ALL keyword used in recursive CTEs for graph traversal instead of UNION?
ABecause UNION ALL is faster and duplicates are handled by recursion logic
BBecause UNION ALL removes duplicates automatically
CBecause UNION ALL sorts the results
DBecause UNION ALL limits recursion depth
Step-by-Step Solution
Solution:
  1. Step 1: Understand difference between UNION and UNION ALL

    UNION removes duplicates but is slower; UNION ALL keeps duplicates and is faster.
  2. Step 2: Recognize recursion handles duplicates

    Recursive CTEs often handle duplicates via logic, so UNION ALL is preferred for performance.
  3. Final Answer:

    Because UNION ALL is faster and duplicates are handled by recursion logic -> Option A
  4. Quick Check:

    UNION ALL preferred for speed; recursion manages duplicates [OK]
Quick Trick: Use UNION ALL for speed; recursion logic manages duplicates [OK]
Common Mistakes:
  • Thinking UNION ALL removes duplicates
  • Assuming UNION ALL sorts results
  • Believing UNION ALL limits recursion

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes