Get startedGet started for free

Analyze that temp table

Athletes qualify for the Olympics through hard work and dedication. However, some factors, like the climate of the athlete's home country, do have an impact. You want to dive deeper into these relationships by creating a list of all countries with Olympians and examining country demographics.

You have access to the table athletes, but it has thousands of entries, making it slow to query. One solution is to create a temporary table of all country codes. You can then analyze statistics related to country characteristics using the temporary table, which allow the query planner to optimize the query execution better.

This exercise is part of the course

Improving Query Performance in PostgreSQL

View Course

Exercise instructions

  • Create a TEMP TABLE called countries.
  • Allow the query planner to collect statistics on the table.
  • Count all entries in the newly created table.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

-- Create temp countries table
___ ___ ___ ___ ___
    SELECT DISTINCT o.region, a.country_code, o.country
    FROM athletes a
    INNER JOIN oregions o
      ON a.country_code = o.olympic_cc;
      
___ ___; -- Collect the statistics

-- Count the entries
SELECT ___(*) FROM ___;
Edit and Run Code