Improving Query Performance in PostgreSQL
Amy McCarty
Instructor
Column-oriented storage
| id | name | species | age | habitat | received |
|---|---|---|---|---|---|
| 01 | Bob | panda | 2 | Asia | 2018 |
| 02 | Sunny | zebra | 3 | Africa | 2018 |
| 03 | Beco | zebra | 10 | Africa | 2017 |
| 04 | Coco | koala | 5 | Australia | 2016 |
Stored as

Column-oriented storage properties
Analytics focus
Stored as

Row relationships retained
Transactional focus
Stored as

| Postgres | Citus Data, Greenplum, Amazon Redshift |
| MySQL | MariaDB |
| Oracle | Oracle In-Memory Cloud Store |
| Clickhouse, Apache Druid, CrateDB |
Reducing the columns
SELECT * sparinglySELECT column_name, data_type
FROM information_schema.columns
WHERE table_catalog = 'schema_name'
AND table_name = 'zoo_animals'
| column_name | data_type |
|---|---|
| id | integer |
| name | text |
| species | text |
Reducing the columns
SELECT * sparinglySELECT column_name, data_type
FROM information_schema.columns
WHERE table_catalog = 'schema_name'
AND table_name = 'zoo_animals'
| column_name | data_type |
|---|---|
| id | integer |
| name | text |
| species | text |
| id | name | species | age | habitat | received |
|---|---|---|---|---|---|
| 01 | Bob | panda | 2 | Asia | 2018 |
| 02 | Sunny | zebra | 3 | Africa | 2018 |
| 03 | Beco | zebra | 10 | Africa | 2017 |
| 04 | Coco | koala | 5 | Australia | 2016 |
-- Structure for column oriented
SELECT MIN(age), MAX(age)
FROM zoo_animals
WHERE species = 'zebra'
-- Structure for row-oriented
SELECT *
FROM zoo_animals
WHERE species = 'zebra'
ORDER BY age
Improving Query Performance in PostgreSQL