postgresql/src/backend
Andres Freund b8d7f053c5 Faster expression evaluation and targetlist projection.
This replaces the old, recursive tree-walk based evaluation, with
non-recursive, opcode dispatch based, expression evaluation.
Projection is now implemented as part of expression evaluation.

This both leads to significant performance improvements, and makes
future just-in-time compilation of expressions easier.

The speed gains primarily come from:
- non-recursive implementation reduces stack usage / overhead
- simple sub-expressions are implemented with a single jump, without
  function calls
- sharing some state between different sub-expressions
- reduced amount of indirect/hard to predict memory accesses by laying
  out operation metadata sequentially; including the avoidance of
  nearly all of the previously used linked lists
- more code has been moved to expression initialization, avoiding
  constant re-checks at evaluation time

Future just-in-time compilation (JIT) has become easier, as
demonstrated by released patches intended to be merged in a later
release, for primarily two reasons: Firstly, due to a stricter split
between expression initialization and evaluation, less code has to be
handled by the JIT. Secondly, due to the non-recursive nature of the
generated "instructions", less performance-critical code-paths can
easily be shared between interpreted and compiled evaluation.

The new framework allows for significant future optimizations. E.g.:
- basic infrastructure for to later reduce the per executor-startup
  overhead of expression evaluation, by caching state in prepared
  statements.  That'd be helpful in OLTPish scenarios where
  initialization overhead is measurable.
- optimizing the generated "code". A number of proposals for potential
  work has already been made.
- optimizing the interpreter. Similarly a number of proposals have
  been made here too.

The move of logic into the expression initialization step leads to some
backward-incompatible changes:
- Function permission checks are now done during expression
  initialization, whereas previously they were done during
  execution. In edge cases this can lead to errors being raised that
  previously wouldn't have been, e.g. a NULL array being coerced to a
  different array type previously didn't perform checks.
- The set of domain constraints to be checked, is now evaluated once
  during expression initialization, previously it was re-built
  every time a domain check was evaluated. For normal queries this
  doesn't change much, but e.g. for plpgsql functions, which caches
  ExprStates, the old set could stick around longer.  The behavior
  around might still change.

Author: Andres Freund, with significant changes by Tom Lane,
	changes by Heikki Linnakangas
Reviewed-By: Tom Lane, Heikki Linnakangas
Discussion: https://postgr.es/m/20161206034955.bh33paeralxbtluv@alap3.anarazel.de
2017-03-25 14:52:06 -07:00
..
access Reverting 42b4b0b241 2017-03-24 17:56:17 +00:00
bootstrap Faster expression evaluation and targetlist projection. 2017-03-25 14:52:06 -07:00
catalog Faster expression evaluation and targetlist projection. 2017-03-25 14:52:06 -07:00
commands Faster expression evaluation and targetlist projection. 2017-03-25 14:52:06 -07:00
executor Faster expression evaluation and targetlist projection. 2017-03-25 14:52:06 -07:00
foreign Spelling fixes in code comments 2017-03-14 12:58:39 -04:00
lib Fix overflow check in StringInfo; add missing casts 2017-01-10 11:41:13 -03:00
libpq Allow SCRAM authentication, when pg_hba.conf says 'md5'. 2017-03-24 13:32:21 +02:00
main Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
nodes Implement multivariate n-distinct coefficients 2017-03-24 14:06:10 -03:00
optimizer Faster expression evaluation and targetlist projection. 2017-03-25 14:52:06 -07:00
parser Add COMMENT and SECURITY LABEL support for publications and subscriptions 2017-03-24 23:44:23 -04:00
po Translation updates 2016-08-08 11:08:00 -04:00
port Fix WaitEventSetWait() to handle write-ready waits properly on Windows. 2017-03-17 14:58:06 -04:00
postmaster Logical replication support for initial data copy 2017-03-23 08:55:37 -04:00
regex ICU support 2017-03-23 15:28:48 -04:00
replication Report catalog_xmin separately in hot_standby_feedback 2017-03-25 14:07:27 +00:00
rewrite Support XMLTABLE query expression 2017-03-08 12:40:26 -03:00
snowball Add ICU_FLAGS to one more place 2017-03-23 16:53:10 -04:00
statistics Implement multivariate n-distinct coefficients 2017-03-24 14:06:10 -03:00
storage Report catalog_xmin separately in hot_standby_feedback 2017-03-25 14:07:27 +00:00
tcop Add missing break 2017-03-25 00:50:05 -04:00
tsearch Spelling fixes in code comments 2017-03-14 12:58:39 -04:00
utils Faster expression evaluation and targetlist projection. 2017-03-25 14:52:06 -07:00
.gitignore Add .gitignore entries for AIX-specific intermediate build artifacts. 2015-07-08 20:44:22 -04:00
common.mk ICU support 2017-03-23 15:28:48 -04:00
Makefile Implement multivariate n-distinct coefficients 2017-03-24 14:06:10 -03:00
nls.mk Remove trailing slashes from directories in find command 2015-09-18 22:06:54 -04:00