1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-28 11:44:57 +03:00

Add SupportRequestInlineInFrom planner support request.

This request allows a support function to replace a function call
appearing in FROM (typically a set-returning function) with an
equivalent SELECT subquery.  The subquery will then be subject
to the planner's usual optimizations, potentially allowing a much
better plan to be generated.  While the planner has long done this
automatically for simple SQL-language functions, it's now possible
for extensions to do it for functions outside that group.
Notably, this could be useful for functions that are presently
implemented in PL/pgSQL and work by generating and then EXECUTE'ing
a SQL query.

Author: Paul A Jungwirth <pj@illuminatedcomputing.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/09de6afa-c33d-4d94-a5cb-afc6cea0d2bb@illuminatedcomputing.com
This commit is contained in:
Tom Lane
2025-11-22 19:33:34 -05:00
parent c0bc9af151
commit b140c8d7a3
9 changed files with 511 additions and 171 deletions

View File

@@ -4159,6 +4159,31 @@ supportfn(internal) returns internal
expression and an actual execution of the target function.
</para>
<para>
<literal>SupportRequestSimplify</literal> is not used
for <link linkend="queries-tablefunctions">set-returning
functions</link>. Instead, support functions can implement
the <literal>SupportRequestInlineInFrom</literal> request to expand
function calls appearing in the <literal>FROM</literal> clause of a
query. (It's also allowed to support this request for
non-set-returning functions, although
typically <literal>SupportRequestSimplify</literal> would serve as
well.) For this request type, a successful result must be
a <literal>SELECT</literal> Query tree, which will replace
the <literal>FROM</literal> item as though a sub-select had been
written instead. The Query tree must appear as it would after parse
analysis and rewrite processing. One way to ensure that that's true
is to build a SQL string then feed it
through <function>pg_parse_query</function>
and <function>pg_analyze_and_rewrite</function>, or related
functions. <literal>PARAM_EXTERN</literal> <structname>Param</structname>
nodes can appear within the Query to represent the function's
arguments; they will be replaced by the actual argument expressions.
As with <literal>SupportRequestSimplify</literal>, it is the support
function's responsibility that the replacement Query be equivalent to
normal execution of the target function.
</para>
<para>
For target functions that return <type>boolean</type>, it is often useful to estimate
the fraction of rows that will be selected by a <literal>WHERE</literal> clause using that