Postgresql hard
How does the PostgreSQL query planner typically optimize a correlated subquery (e.g., `WHERE EXISTS (...)`) to prevent repetitive re-execution for every outer row?
- A It caches the result of the first N subquery executions in the L1 CPU cache to speed up subsequent hits.
- B It transforms the subquery into a more efficient 'Semi-Join' or 'Anti-Join' that uses set-level logic.
- C It offloads the subquery to a dedicated background worker thread that runs independently of the main plan.
- D It forces the query into a sequential scan to avoid the overhead of index-based nested loop lookups.
Answer: B. It transforms the subquery into a more efficient 'Semi-Join' or 'Anti-Join' that uses set-level logic.
Looping for every row is slow. By converting `EXISTS` into a Semi-Join, Postgres can use its world-class Join algorithms (Hash Join or Merge Join). This allows the database to process the subquery relationship at massive scale.
One system design question a day, with spaced repetition so the ones you miss come back.
Get the appRelated questions
- In a PostgreSQL environment, what functional characteristic distinguishes a `MATERIALIZED VIEW` from a standard `VIEW`?
- Which standard PostgreSQL utility is designed to extract a single database into a script or archive file for backup purposes?
- Why would PostgreSQL reject a `DELETE` operation on a record despite the user having full administrative privileges?
- The 'Heap Only Tuples' (HOT) optimization improves UPDATE performance. Which specific set of conditions must be met for a HOT update to occur?
- Which native command-line utility is used to execute SQL queries and manage PostgreSQL databases from a terminal session?
- What is the specific purpose of 'Freezing' a row (modifying its `xmin` status) during a major VACUUM operation?