Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Improving Query Performance in PostgreSQL

Cursus bekijken

Oefeninstructies

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

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

-- 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 ___;
Code bewerken en uitvoeren