summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2020-05-04 09:45:35 -0600
committermo khan <mo.khan@gmail.com>2020-05-04 09:45:35 -0600
commitc59ed9d1683279edec283cc6659429e85091dd1b (patch)
tree5426e625fb40062de7ea624a5ff413eda8d559ac
parent2f847480a67d398dd08e39ef42cf0eff7201257d (diff)
Talk about costs
-rw-r--r--README.md36
-rw-r--r--costs.pngbin0 -> 275409 bytes
2 files changed, 36 insertions, 0 deletions
diff --git a/README.md b/README.md
index be700bc..1d9215e 100644
--- a/README.md
+++ b/README.md
@@ -2801,3 +2801,39 @@ execution plans.
* can be used to speed up sorting
![scan types](scan-types.png)
+
+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';
+```
+
+![costs](costs.png)
+
+```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
new file mode 100644
index 0000000..3d869ee
--- /dev/null
+++ b/costs.png
Binary files differ