mirror of
https://github.com/postgres/postgres.git
synced 2025-07-07 00:36:50 +03:00
Create the infrastructure for planner support functions.
Rename/repurpose pg_proc.protransform as "prosupport". The idea is still that it names an internal function that provides knowledge to the planner about the behavior of the function it's attached to; but redesign the API specification so that it's not limited to doing just one thing, but can support an extensible set of requests. The original purpose of simplifying a function call is handled by the first request type to be invented, SupportRequestSimplify. Adjust all the existing transform functions to handle this API, and rename them fron "xxx_transform" to "xxx_support" to reflect the potential generalization of what they do. (Since we never previously provided any way for extensions to add transform functions, this change doesn't create an API break for them.) Also add DDL and pg_dump support for attaching a support function to a user-defined function. Unfortunately, DDL access has to be restricted to superusers, at least for now; but seeing that support functions will pretty much have to be written in C, that limitation is just theoretical. (This support is untested in this patch, but a follow-on patch will add cases that exercise it.) Discussion: https://postgr.es/m/15193.1548028093@sss.pgh.pa.us
This commit is contained in:
@ -32,6 +32,7 @@
|
||||
#include "miscadmin.h"
|
||||
#include "nodes/makefuncs.h"
|
||||
#include "nodes/nodeFuncs.h"
|
||||
#include "nodes/supportnodes.h"
|
||||
#include "optimizer/clauses.h"
|
||||
#include "optimizer/cost.h"
|
||||
#include "optimizer/optimizer.h"
|
||||
@ -3985,13 +3986,16 @@ simplify_function(Oid funcid, Oid result_type, int32 result_typmod,
|
||||
args, funcvariadic,
|
||||
func_tuple, context);
|
||||
|
||||
if (!newexpr && allow_non_const && OidIsValid(func_form->protransform))
|
||||
if (!newexpr && allow_non_const && OidIsValid(func_form->prosupport))
|
||||
{
|
||||
/*
|
||||
* Build a dummy FuncExpr node containing the simplified arg list. We
|
||||
* use this approach to present a uniform interface to the transform
|
||||
* function regardless of how the function is actually being invoked.
|
||||
* Build a SupportRequestSimplify node to pass to the support
|
||||
* function, pointing to a dummy FuncExpr node containing the
|
||||
* simplified arg list. We use this approach to present a uniform
|
||||
* interface to the support function regardless of how the target
|
||||
* function is actually being invoked.
|
||||
*/
|
||||
SupportRequestSimplify req;
|
||||
FuncExpr fexpr;
|
||||
|
||||
fexpr.xpr.type = T_FuncExpr;
|
||||
@ -4005,9 +4009,16 @@ simplify_function(Oid funcid, Oid result_type, int32 result_typmod,
|
||||
fexpr.args = args;
|
||||
fexpr.location = -1;
|
||||
|
||||
req.type = T_SupportRequestSimplify;
|
||||
req.root = context->root;
|
||||
req.fcall = &fexpr;
|
||||
|
||||
newexpr = (Expr *)
|
||||
DatumGetPointer(OidFunctionCall1(func_form->protransform,
|
||||
PointerGetDatum(&fexpr)));
|
||||
DatumGetPointer(OidFunctionCall1(func_form->prosupport,
|
||||
PointerGetDatum(&req)));
|
||||
|
||||
/* catch a possible API misunderstanding */
|
||||
Assert(newexpr != (Expr *) &fexpr);
|
||||
}
|
||||
|
||||
if (!newexpr && allow_non_const)
|
||||
|
Reference in New Issue
Block a user