November 2019
Beginner to intermediate
470 pages
11h 59m
English
However, there are many more optimizations in PostgreSQL that take place behind the scenes and that contribute to overall good performance. One of these features is called constant folding. The idea is to turn expressions into constants, as shown in the following example:
test=# explain SELECT * FROM a WHERE aid = 3 + 1; QUERY PLAN ---------------------------------------------------------------- Index Only Scan using idx_a on a (cost=0.57..4.58 rows=1 width=4) Index Cond: (aid = 4) (2 rows)
As you can see, PostgreSQL will try to look for 4. Since aid is indexed, PostgreSQL will go for an index scan. Note that our table has just one column, so PostgreSQL even figured out that all the data it needs can be found in the index. ...
Read now
Unlock full access