postgresql/src/backend
Tom Lane 7266d0997d Allow functions-in-FROM to be pulled up if they reduce to constants.
This allows simplification of the plan tree in some common usage
patterns: we can get rid of a join to the function RTE.

In principle we could pull up any immutable expression, but restricting
it to Consts avoids the risk that multiple evaluations of the expression
might cost more than we can save.  (Possibly this could be improved in
future --- but we've more or less promised people that putting a function
in FROM guarantees single evaluation, so we'd have to tread carefully.)

To do this, we need to rearrange when eval_const_expressions()
happens for expressions in function RTEs.  I moved it to
inline_set_returning_functions(), which already has to iterate over
every function RTE, and in consequence renamed that function to
preprocess_function_rtes().  A useful consequence is that
inline_set_returning_function() no longer has to do this for itself,
simplifying that code.

In passing, break out pull_up_simple_subquery's code that knows where
everything that needs pullup_replace_vars() processing is, so that
the new pull_up_constant_function() routine can share it.  We'd
gotten away with one-and-a-half copies of that code so far, since
pull_up_simple_values() could assume that a lot of cases didn't apply
to it --- but I don't think pull_up_constant_function() can make any
simplifying assumptions.  Might as well make pull_up_simple_values()
use it too.

(Possibly this refactoring should go further: maybe we could share
some of the code to fill in the pullup_replace_vars_context struct?
For now, I left it that the callers fill that completely.)

Note: the one existing test case that this patch changes has to be
changed because inlining its function RTEs would destroy the point
of the test, namely to check join order.

Alexander Kuzmenkov and Aleksandr Parfenov, reviewed by
Antonin Houska and Anastasia Lubennikova, and whacked around
some more by me

Discussion: https://postgr.es/m/402356c32eeb93d4fed01f66d6c7fe2d@postgrespro.ru
2019-08-01 18:50:22 -04:00
..
access Add error codes to some corruption log messages 2019-08-01 11:15:26 +02:00
bootstrap Fix inconsistencies and typos in the tree 2019-07-16 13:23:53 +09:00
catalog Fix inconsistencies and typos in the tree 2019-07-29 12:28:30 +09:00
commands Remove superfluous newlines in function prototypes. 2019-07-31 00:05:21 -07:00
executor Remove superfluous newlines in function prototypes. 2019-07-31 00:05:21 -07:00
foreign Update copyright for 2019 2019-01-02 12:44:25 -05:00
jit Avoid macro clash with LLVM 9. 2019-07-29 10:23:55 +12:00
lib Fix inconsistencies in the code 2019-07-08 13:15:09 +09:00
libpq Remove superfluous newlines in function prototypes. 2019-07-31 00:05:21 -07:00
main Replace @postgresql.org with @lists.postgresql.org for mailinglists 2019-01-19 19:06:35 +01:00
nodes Fix handling of expressions and predicates in REINDEX CONCURRENTLY 2019-07-29 09:58:49 +09:00
optimizer Allow functions-in-FROM to be pulled up if they reduce to constants. 2019-08-01 18:50:22 -04:00
parser Make identity sequence management more robust 2019-07-22 12:07:10 +02:00
partitioning Fix inconsistencies and typos in the tree 2019-07-22 10:01:50 +09:00
po Translation updates 2019-06-17 15:30:20 +02:00
port Fix inconsistencies and typos in the tree 2019-07-22 10:01:50 +09:00
postmaster Fix inconsistencies and typos in the tree 2019-07-29 12:28:30 +09:00
regex Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
replication Fix inconsistencies and typos in the tree 2019-07-29 12:28:30 +09:00
rewrite Make identity sequence management more robust 2019-07-22 12:07:10 +02:00
snowball Sync our Snowball stemmer dictionaries with current upstream 2019-07-04 13:26:48 +02:00
statistics Use column collation for extended statistics 2019-07-20 16:37:37 +02:00
storage Remove superfluous newlines in function prototypes. 2019-07-31 00:05:21 -07:00
tcop Fix inconsistencies and typos in the tree 2019-07-29 12:28:30 +09:00
tsearch Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
utils Add sort support routine for the inet data type. 2019-08-01 09:34:14 -07:00
.gitignore Add .gitignore entries for AIX-specific intermediate build artifacts. 2015-07-08 20:44:22 -04:00
Makefile Get rid of jsonpath_gram.h and jsonpath_scanner.h 2019-03-20 11:13:34 +03:00
common.mk Remove PARTIAL_LINKING build mode. 2018-03-30 17:33:04 -07:00
nls.mk Translation updates 2019-05-20 16:00:53 +02:00