CommencerCommencer gratuitement

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.

Cet exercice fait partie du cours

Improving Query Performance in PostgreSQL

Afficher le cours

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.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de 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 ___;
Modifier et exécuter le code