Bird
0
0

You wrote this query in PostgreSQL 11:

medium📝 Debug Q6 of 15
PostgreSQL - Common Table Expressions
You wrote this query in PostgreSQL 11:

WITH cte AS (SELECT id, name FROM users WHERE active = true) SELECT * FROM cte WHERE name LIKE 'A%';

The query runs slower than expected. What is a likely cause?
AThe CTE syntax is incorrect and causes a syntax error.
BThe LIKE operator is not supported inside CTEs.
CCTE materialization prevents planner optimizations on the WHERE clause.
DPostgreSQL does not support filtering after CTEs.
Step-by-Step Solution
Solution:
  1. Step 1: Identify CTE behavior in PG11

    CTEs are materialized, so filtering after the CTE cannot be pushed down into the CTE query.
  2. Step 2: Understand impact on performance

    This prevents the planner from optimizing the WHERE clause inside the CTE, causing slower execution.
  3. Final Answer:

    CTE materialization prevents planner optimizations on the WHERE clause. -> Option C
  4. Quick Check:

    CTE materialization blocks filter pushdown [OK]
Quick Trick: Filters after CTEs can't optimize inside CTE before PG12 [OK]
Common Mistakes:
  • Thinking LIKE is unsupported in CTEs
  • Assuming syntax error causes slowness
  • Believing filtering after CTE is disallowed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes