May 2017
Beginner
416 pages
10h 37m
English
However, there are many more optimizations in PostgreSQL, which happen behind the scenes and which contribute to overall good performance. One of those 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. As aid is indexed, PostgreSQL will go for an index scan. Note that our table has just one column so PostgreSQL even figured that all the data it needs can be found in the index.
Read now
Unlock full access