November 2019
Beginner to intermediate
470 pages
11h 59m
English
As we already outlined in this section, there are many optimizations that help speed up queries. One of them is called function inlining. PostgreSQL is able to inline immutable SQL functions. The main idea is to reduce the number of function calls that have to be made in order to speed things up.
Here is an example of a function that can be inlined by the optimizer:
test=# CREATE OR REPLACE FUNCTION ld(int)RETURNS numeric AS$$ SELECT log(2, $1);$$LANGUAGE 'sql' IMMUTABLE;CREATE FUNCTION
This function will calculate the logarithmus dualis of the input value:
test=# SELECT ld(1024); ld--------------------- 10.0000000000000000(1 row)
To demonstrate how things work, we will recreate the table with less content ...
Read now
Unlock full access