改進 PostgreSQL 的查詢效能
Amy McCarty
Instructor
欄向儲存
| 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 |
儲存方式

欄向儲存特性
分析導向
儲存方式

保留列關係
交易導向
儲存方式

| Postgres | Citus Data、Greenplum、Amazon Redshift |
| MySQL | MariaDB |
| Oracle | Oracle In-Memory Cloud Store |
| Clickhouse、Apache Druid、CrateDB |
減少欄位
SELECT *SELECT 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 |
減少欄位
SELECT *SELECT 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
改進 PostgreSQL 的查詢效能