Improving Query Performance in PostgreSQL
Amy McCarty
Instructor
Query
Query (execution) plan
What are joins?
What are joins?
Why use joins?
How?
Sales ID | Order Dt | Amt | Cust No |
---|---|---|---|
01 | 2019-02-02 | 145.30 | 911 |
ID | Name | Customer Since |
---|---|---|
911 | Jim Smith | 2019-01-01 |
Sales ID | Order Dt | Amt | Name |
---|---|---|---|
01 | 2019-02-02 | 145.30 | Jim Smith |
SELECT *
FROM athletes a
INNER JOIN countries c
ON a.country = c.country
Athlete | Country | Country1 | Name | Pop (mil) |
---|---|---|---|---|
Jack | AUT | AUT | Austria | 9 |
Aditya | IND | IND | India | 1,339 |
Mikhail | RUS | RUS | Russia | 145 |
SELECT *
FROM athletes a
INNER JOIN countries c
ON a.country = c.country
Athlete | Country | Country1 | Name | Pop (mil) |
---|---|---|---|---|
Jack | AUT | AUT | Austria | 9 |
Aditya | IND | IND | India | 1,339 |
Mikhail | RUS | RUS | Russia | 145 |
SELECT *
FROM athletes
INNER JOIN countries
USING (country)
Athlete | Country | Name | Pop (mil) |
---|---|---|---|
Jack | AUT | Austria | 9 |
Aditya | IND | India | 1,339 |
Mikhail | RUS | Russia | 145 |
SELECT *
FROM athletes
INNER JOIN countries
USING (country)
Athlete | Country | Name | Pop (mil) |
---|---|---|---|
Jack | AUT | Austria | 9 |
Aditya | IND | India | 1,339 |
Mikhail | RUS | Russia | 145 |
SELECT *
FROM athletes a
LEFT JOIN countries c
ON a.country = c.country
Athlete | Country | Country1 | Name | Pop (mil) | |
---|---|---|---|---|---|
Jack | AUT | AUT | Austria | 9 | |
Aditya | IND | IND | India | 1,339 | |
Mikhail | RUS | RUS | Russia | 145 | |
Javier | MEX |
SELECT *
FROM athletes a
LEFT JOIN countries c
ON a.country = c.country
Athlete | Country | Country1 | Name | Pop (mil) |
---|---|---|---|---|
Jack | AUT | AUT | Austria | 9 |
Aditya | IND | IND | India | 1,339 |
Mikhail | RUS | RUS | Russia | 145 |
Javier | MEX |
SELECT *
FROM athletes a
RIGHT JOIN countries c
ON a.country = c.country
Athlete | Country | Country1 | Name | Pop (mil) |
---|---|---|---|---|
Jack | AUT | AUT | Austria | 9 |
Aditya | IND | IND | India | 1,339 |
Mikhail | RUS | RUS | Russia | 145 |
BRA | Brazil | 209 |
SELECT *
FROM athletes a
RIGHT JOIN countries c
ON a.country = c.country
Athlete | Country | Country1 | Name | Pop (mil) |
---|---|---|---|---|
Jack | AUT | AUT | Austria | 9 |
Aditya | IND | IND | India | 1,339 |
Mikhail | RUS | RUS | Russia | 145 |
BRA | Brazil | 209 |
SELECT *
FROM athletes a
FULL OUTER JOIN countries c
ON a.country = c.country
Athlete Nme | Country | Country1 | Name | Pop (mil) |
---|---|---|---|---|
Jack | AUT | AUT | Austria | 9 |
Aditya | IND | IND | India | 1,339 |
Mikhail | RUS | RUS | Russia | 145 |
Javier | MEX | |||
BRA | Brazil | 209 |
Improving Query Performance in PostgreSQL