mirror of
https://github.com/postgres/postgres.git
synced 2026-01-27 21:43:08 +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:
@@ -39,6 +39,8 @@ typedef struct PlannerInfo PlannerInfo; /* avoid including pathnodes.h here */
|
||||
typedef struct IndexOptInfo IndexOptInfo;
|
||||
typedef struct SpecialJoinInfo SpecialJoinInfo;
|
||||
typedef struct WindowClause WindowClause;
|
||||
typedef struct RangeTblFunction RangeTblFunction; /* ditto for parsenodes.h */
|
||||
typedef struct HeapTupleData *HeapTuple; /* and htup.h too */
|
||||
|
||||
/*
|
||||
* The Simplify request allows the support function to perform plan-time
|
||||
@@ -69,6 +71,34 @@ typedef struct SupportRequestSimplify
|
||||
FuncExpr *fcall; /* Function call to be simplified */
|
||||
} SupportRequestSimplify;
|
||||
|
||||
/*
|
||||
* The InlineInFrom request allows the support function to perform plan-time
|
||||
* simplification of a call to its target function that appears in FROM.
|
||||
* The rules for this are sufficiently different from ordinary expressions
|
||||
* that it's best to make this a separate request from Simplify.
|
||||
*
|
||||
* The planner's PlannerInfo "root" is typically not needed, but can be
|
||||
* consulted if it's necessary to obtain info about Vars present in
|
||||
* the given node tree. Beware that root could be NULL in some usages.
|
||||
*
|
||||
* "rtfunc" will be a RangeTblFunction node for the support function's target
|
||||
* function. The call appeared alone (and without ORDINALITY) in FROM.
|
||||
*
|
||||
* "proc" will be the HeapTuple for the pg_proc row of the target function.
|
||||
*
|
||||
* The result should be a semantically-equivalent SELECT Query tree,
|
||||
* or NULL if no simplification could be performed. The tree must have
|
||||
* been passed through parse analysis and rewrite.
|
||||
*/
|
||||
typedef struct SupportRequestInlineInFrom
|
||||
{
|
||||
NodeTag type;
|
||||
|
||||
PlannerInfo *root; /* Planner's infrastructure */
|
||||
RangeTblFunction *rtfunc; /* Function call to be simplified */
|
||||
HeapTuple proc; /* Function definition from pg_proc */
|
||||
} SupportRequestInlineInFrom;
|
||||
|
||||
/*
|
||||
* The Selectivity request allows the support function to provide a
|
||||
* selectivity estimate for a function appearing at top level of a WHERE
|
||||
|
||||
@@ -50,8 +50,8 @@ extern int NumRelids(PlannerInfo *root, Node *clause);
|
||||
|
||||
extern void CommuteOpExpr(OpExpr *clause);
|
||||
|
||||
extern Query *inline_set_returning_function(PlannerInfo *root,
|
||||
RangeTblEntry *rte);
|
||||
extern Query *inline_function_in_from(PlannerInfo *root,
|
||||
RangeTblEntry *rte);
|
||||
|
||||
extern Bitmapset *pull_paramids(Expr *expr);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user