1. Learn
  2. /
  3. Courses
  4. /
  5. Improving Query Performance in PostgreSQL

Connected

Exercise

Subqueries vs. CTEs

You have learned different ways of writing queries and how these choices impact performance. This exercise will again look at country demographics for the African countries with athletes competing in the Olympics. You will focus on the Summer Olympics.

Using pre-written queries, you will restructure the queries and assess the impact of the changes. You will start by seeing the difference in query plans when using subqueries compared to common table expressions (CTEs).

Run the execution plan for each step.

Instructions 1/2

undefined XP
  • 1

    Run the execution plan. Notice the order of the filtering steps and the number of rows removed in the query plan.

  • 2

    Restructure the demographics subquery into a CTE and run the execution plan.