From b140c8d7a3f3a5de4e4cc4a0b52909aa13060d4c Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sat, 22 Nov 2025 19:33:34 -0500 Subject: 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 Reviewed-by: Tom Lane Discussion: https://postgr.es/m/09de6afa-c33d-4d94-a5cb-afc6cea0d2bb@illuminatedcomputing.com --- doc/src/sgml/xfunc.sgml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'doc/src') diff --git a/doc/src/sgml/xfunc.sgml b/doc/src/sgml/xfunc.sgml index 55a99c0ff34..537ee6fa254 100644 --- a/doc/src/sgml/xfunc.sgml +++ b/doc/src/sgml/xfunc.sgml @@ -4159,6 +4159,31 @@ supportfn(internal) returns internal expression and an actual execution of the target function. + + SupportRequestSimplify is not used + for set-returning + functions. Instead, support functions can implement + the SupportRequestInlineInFrom request to expand + function calls appearing in the FROM clause of a + query. (It's also allowed to support this request for + non-set-returning functions, although + typically SupportRequestSimplify would serve as + well.) For this request type, a successful result must be + a SELECT Query tree, which will replace + the FROM 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 pg_parse_query + and pg_analyze_and_rewrite, or related + functions. PARAM_EXTERN Param + nodes can appear within the Query to represent the function's + arguments; they will be replaced by the actual argument expressions. + As with SupportRequestSimplify, it is the support + function's responsibility that the replacement Query be equivalent to + normal execution of the target function. + + For target functions that return boolean, it is often useful to estimate the fraction of rows that will be selected by a WHERE clause using that -- cgit v1.2.3