diff options
| author | mo khan <mo.khan@gmail.com> | 2020-05-04 09:45:35 -0600 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2020-05-04 09:45:35 -0600 |
| commit | c59ed9d1683279edec283cc6659429e85091dd1b (patch) | |
| tree | 5426e625fb40062de7ea624a5ff413eda8d559ac | |
| parent | 2f847480a67d398dd08e39ef42cf0eff7201257d (diff) | |
Talk about costs
| -rw-r--r-- | README.md | 36 | ||||
| -rw-r--r-- | costs.png | bin | 0 -> 275409 bytes |
2 files changed, 36 insertions, 0 deletions
@@ -2801,3 +2801,39 @@ execution plans. * can be used to speed up sorting  + +cost comes from cost of each object. + +```sql +select * from pg_settings where name like '%_cost'; +select reltuples, relpages from pg_class where relname = 'test'; +``` + + + +```sql +create table large(id integer, x integer); +INSERT INTO large SELECT i, 1/1000 + 1 FROM generate_series(1, 1000000) as i; +TABLE large + +create table small(x integer); +insert into small values(1) + +ANALYZE small; -- to calculate statistics which can improve query planner like in this case. +``` + +* auto analyze happens by the auto vacuum. +* Look at `autovacuum_analyze_scale_factor` and `autovacuum_analyze_threshold`. +* with OLTP you want planning time as short as possible. +* with OLAP you might not mind planning time of 1 minute so that processing time is down from 1 hour to 30 minutes. + +```sql +# \h CREATE STATISTICS +Command: CREATE STATISTICS +Description: define extended statistics +Syntax: +CREATE STATISTICS [ IF NOT EXISTS ] statistics_name + [ ( statistics_kind [, ... ] ) ] + ON column_name, column_name [, ...] + FROM table_name +``` diff --git a/costs.png b/costs.png Binary files differnew file mode 100644 index 0000000..3d869ee --- /dev/null +++ b/costs.png |
