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.
Diese Übung ist Teil des Kurses
Improving Query Performance in PostgreSQL
Anleitung zur Übung
- Create a
TEMP TABLE
calledcountries
. - Allow the query planner to collect statistics on the table.
- Count all entries in the newly created table.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
-- 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 ___;