postgresql/src/pl
Tom Lane 73b06cf893 Avoid taking a new snapshot for an immutable simple expression in plpgsql.
We already used this optimization if the plpgsql function is read-only.
But it seems okay to do it even in a read-write function, if the
expression contains only immutable functions/operators.  There would
only be a change of behavior if an "immutable" called function depends
on seeing database updates made during the current plpgsql function.
That's enough of a violation of the promise of immutability that anyone
who complains won't have much of a case.

The benefits are significant --- for simple cases like

  while i < 10000000
  loop
    i := i + 1;
  end loop;

I see net performance improvements around 45%.  Of course, real-world
cases won't get that much faster, but it ought to be noticeable.
At the very least, this removes much of the performance penalty that
used to exist for forgetting to mark a plpgsql function non-volatile.

Konstantin Knizhnik, reviewed by Pavel Stehule, cosmetic changes by me

Discussion: https://postgr.es/m/ed9da20e-01aa-d04b-d085-e6c16b14b9d7@postgrespro.ru
2019-11-22 15:02:18 -05:00
..
plperl Fix ecpglib.h to declare bool consistently with c.h. 2019-11-12 13:00:04 -05:00
plpgsql Avoid taking a new snapshot for an immutable simple expression in plpgsql. 2019-11-22 15:02:18 -05:00
plpython Fix some compiler warnings on older compilers 2019-11-04 11:07:32 +01:00
tcl Have LookupFuncName accept NULL argtypes for 0 args 2019-11-12 17:06:58 -03:00
Makefile Make distprep and *clean build targets recurse into all subdirectories. 2011-07-03 13:55:12 -04:00