Re: [HACKERS] WIP Patch: Precalculate stable functions, infrastructure v1

From: Marina Polyakova <m(dot)polyakova(at)postgrespro(dot)ru>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Cc: Aleksander Alekseev <a(dot)alekseev(at)postgrespro(dot)ru>, Andres Freund <andres(at)anarazel(dot)de>, Alexander Korotkov <a(dot)korotkov(at)postgrespro(dot)ru>, Robert Haas <robertmhaas(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: [HACKERS] WIP Patch: Precalculate stable functions, infrastructure v1
Date: 2017-12-31 05:55:02
Message-ID: 1c43da24e1179518288fe06563affc09@postgrespro.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello, hackers!

First of all, happy New Year!

Secondly, here there's a sixth version of the patch for the
precalculation of stable or immutable functions, stable or immutable
operators and other nonvolatile expressions.

The basic idea: the expression is precalculated (= calculated once for
all output rows, but as many times as the expression is mentioned in the
query) if:
1) it doesn't return a set,
2) it's not volatile itself,
3) its arguments are also constants or precalculated expressions.

Differences from the previous version:
* rebased, including changes for ArrayCoerce expressions;
* support for prepared statements (including tests, but only for
immutable functions);
* fix the caching of SQLValueFunctions (all of them are stable even
date/time functions);
* added the expected output for the tests in case the xml functions are
not supported;
* the tests are also performed in make check, not just in make
check-world;
* code cleanup.

Like for the previous patches it seems that there is no obvious
performance degradation too on regular queries (according to pgbench).

> pgbench probably isn't a very good test for this sort of thing - it
> only issues very short-running queries where the cost of evaluating
> expressions is a relatively small part of the total cost. Even if
> things get worse, I'm not sure if you'd see it. I'm not sure exactly
> how you could construct a test case that could be harmed by this patch
> - I guess you'd want to initialize lots of CacheExprs but never make
> use of the caching usefully?
>
> It could also be useful to test things like TPC-H to see if you get an
> improvement.
I'm sorry, the TPC-H comparative tests will be later..

Patch is attached. Any suggestions are welcome!

--
Marina Polyakova
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

Attachment Content-Type Size
v6-0001-Precalculate-stable-and-immutable-functions.patch text/plain 431.1 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Masahiko Sawada 2017-12-31 06:15:27 Re: [HACKERS] Commits don't block for synchronous replication
Previous Message Tom Lane 2017-12-31 00:00:19 Re: pgsql: Add parallel-aware hash joins.