postgresql/src/include
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 Fix backup canceling 2017-03-24 13:53:40 +03:00
bootstrap Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
catalog Make header self-contained 2017-03-24 23:36:10 -04:00
commands Implement multivariate n-distinct coefficients 2017-03-24 14:06:10 -03:00
common Sync pg_dump and pg_dumpall output 2017-03-22 10:20:13 -04:00
datatype Consistently declare timestamp variables as TimestampTz. 2017-02-23 15:57:08 -05:00
executor Faster expression evaluation and targetlist projection. 2017-03-25 14:52:06 -07:00
fe_utils Add a "void *" passthrough pointer for psqlscan.l's callback functions. 2017-03-13 17:14:46 -04:00
foreign Allow custom and foreign scans to have shutdown callbacks. 2017-02-26 13:41:12 +05:30
lib Make simplehash.h grow hashtable in additional cases. 2017-03-06 14:13:06 -08:00
libpq Allow SCRAM authentication, when pg_hba.conf says 'md5'. 2017-03-24 13:32:21 +02:00
mb ICU support 2017-03-23 15:28:48 -04:00
nodes Faster expression evaluation and targetlist projection. 2017-03-25 14:52:06 -07:00
optimizer Don't scan partitioned tables. 2017-03-21 09:48:04 -04:00
parser Logical replication support for initial data copy 2017-03-23 08:55:37 -04:00
port Enable 64 bit atomics on ARM64. 2017-03-10 11:19:54 -08:00
portability Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
postmaster Add pg_current_logfile() function. 2017-03-03 11:43:11 +05:30
regex Document intentional violations of header inclusion policy. 2017-03-08 17:01:13 -05:00
replication Remove trailing comma from enum definition 2017-03-23 11:58:11 -04:00
rewrite Remove deprecated COMMENT ON RULE syntax 2017-02-23 08:19:52 -05:00
snowball Document intentional violations of header inclusion policy. 2017-03-08 17:01:13 -05: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 Allow for parallel execution whenever ExecutorRun() is done only once. 2017-03-23 13:14:36 -04:00
tsearch Fix typos in comments. 2017-02-06 11:33:58 +02:00
utils Faster expression evaluation and targetlist projection. 2017-03-25 14:52:06 -07:00
.gitignore Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
c.h Recommend wrappers of PG_DETOAST_DATUM_PACKED(). 2017-03-12 19:35:33 -04:00
fmgr.h Faster expression evaluation and targetlist projection. 2017-03-25 14:52:06 -07:00
funcapi.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
getaddrinfo.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
getopt_long.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
Makefile Generate fmgr prototypes automatically 2017-01-17 14:06:07 -05:00
miscadmin.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
pg_config_ext.h.in Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
pg_config_ext.h.win32 Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
pg_config_manual.h Fix default minimum value for descending sequences 2017-01-23 14:00:58 -05:00
pg_config.h.in ICU support 2017-03-23 15:28:48 -04:00
pg_config.h.win32 Add configure test to see if the C compiler has gcc-style computed gotos. 2017-03-20 13:35:26 -04:00
pg_getopt.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
pg_trace.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
pgstat.h Fix enum definition. 2017-03-23 16:10:43 -04:00
pgtar.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
pgtime.h Fix incorrect comment: pgtime's tm_mon is 1-based, not 0-based. 2017-01-24 09:36:17 -05:00
port.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
postgres_ext.h Move atooid() definition to a central place 2017-03-01 11:55:28 -05:00
postgres_fe.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
postgres.h Recommend wrappers of PG_DETOAST_DATUM_PACKED(). 2017-03-12 19:35:33 -04:00
rusagestub.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
windowapi.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00