Understanding function inlining

As already outlined in this section, there are many optimizations which help to 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 which have to be made, in order to speed things up.

Here is an example of a function:

test=# CREATE OR REPLACE FUNCTION ld(int)RETURNS numeric AS$$   SELECT log(2, $1);$$LANGUAGE 'sql' IMMUTABLE;CREATE FUNCTION

The function will calculate the logarithmus dualis of the input value:

test=# SELECT ld(1024);        ld--------------------- 10.0000000000000000(1 row)

To demonstrate how things work, I will recreate the table with less content to speed up the index creation:

test=# ...

Get Mastering PostgreSQL 10 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.