mirror of https://github.com/citusdata/citus.git
Create function_utils for pg function call related utilities
parent
d3e284dcd6
commit
cc401a2616
1
Makefile
1
Makefile
|
@ -95,6 +95,7 @@ OBJS = src/backend/distributed/shared_library_init.o \
|
|||
src/backend/distributed/utils/distribution_column.o \
|
||||
src/backend/distributed/utils/errormessage.o \
|
||||
src/backend/distributed/utils/foreign_key_relationship.o \
|
||||
src/backend/distributed/utils/function_utils.o \
|
||||
src/backend/distributed/utils/hash_helpers.o \
|
||||
src/backend/distributed/utils/listutils.o \
|
||||
src/backend/distributed/utils/maintenanced.o \
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include "access/htup_details.h"
|
||||
#include "access/nbtree.h"
|
||||
#include "catalog/indexing.h"
|
||||
#include "catalog/namespace.h"
|
||||
#include "catalog/pg_aggregate.h"
|
||||
#include "catalog/pg_am.h"
|
||||
#include "catalog/pg_proc.h"
|
||||
|
@ -29,6 +28,7 @@
|
|||
#include "distributed/citus_ruleutils.h"
|
||||
#include "distributed/colocation_utils.h"
|
||||
#include "distributed/extended_op_node_utils.h"
|
||||
#include "distributed/function_utils.h"
|
||||
#include "distributed/metadata_cache.h"
|
||||
#include "distributed/multi_logical_optimizer.h"
|
||||
#include "distributed/multi_logical_planner.h"
|
||||
|
@ -45,12 +45,8 @@
|
|||
#include "parser/parse_coerce.h"
|
||||
#include "parser/parse_oper.h"
|
||||
#include "parser/parsetree.h"
|
||||
#include "utils/builtins.h"
|
||||
#include "utils/fmgroids.h"
|
||||
#include "utils/lsyscache.h"
|
||||
#if (PG_VERSION_NUM >= 100000)
|
||||
#include "utils/regproc.h"
|
||||
#endif
|
||||
#include "utils/rel.h"
|
||||
#include "utils/syscache.h"
|
||||
#include "utils/tqual.h"
|
||||
|
@ -2991,44 +2987,6 @@ AggregateFunctionOid(const char *functionName, Oid inputType)
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
* FunctionOid looks for a function that has the given name and the given number
|
||||
* of arguments, and returns the corresponding function's oid.
|
||||
*/
|
||||
Oid
|
||||
FunctionOid(const char *schemaName, const char *functionName, int argumentCount)
|
||||
{
|
||||
FuncCandidateList functionList = NULL;
|
||||
Oid functionOid = InvalidOid;
|
||||
|
||||
char *qualifiedFunctionName = quote_qualified_identifier(schemaName, functionName);
|
||||
List *qualifiedFunctionNameList = stringToQualifiedNameList(qualifiedFunctionName);
|
||||
List *argumentList = NIL;
|
||||
const bool findVariadics = false;
|
||||
const bool findDefaults = false;
|
||||
const bool missingOK = true;
|
||||
|
||||
functionList = FuncnameGetCandidates(qualifiedFunctionNameList, argumentCount,
|
||||
argumentList, findVariadics,
|
||||
findDefaults, missingOK);
|
||||
|
||||
if (functionList == NULL)
|
||||
{
|
||||
ereport(ERROR, (errcode(ERRCODE_UNDEFINED_FUNCTION),
|
||||
errmsg("function \"%s\" does not exist", functionName)));
|
||||
}
|
||||
else if (functionList->next != NULL)
|
||||
{
|
||||
ereport(ERROR, (errcode(ERRCODE_AMBIGUOUS_FUNCTION),
|
||||
errmsg("more than one function named \"%s\"", functionName)));
|
||||
}
|
||||
|
||||
/* get function oid from function list's head */
|
||||
functionOid = functionList->oid;
|
||||
return functionOid;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* TypeOid looks for a type that has the given name and schema, and returns the
|
||||
* corresponding type's oid.
|
||||
|
|
|
@ -11,9 +11,8 @@
|
|||
#include "miscadmin.h"
|
||||
#include "pgstat.h"
|
||||
|
||||
#include "distributed/multi_logical_optimizer.h"
|
||||
#include "distributed/function_utils.h"
|
||||
#include "distributed/multi_progress.h"
|
||||
#include "nodes/execnodes.h"
|
||||
#include "storage/dsm.h"
|
||||
#include "utils/builtins.h"
|
||||
|
||||
|
@ -23,8 +22,6 @@ static uint64 currentProgressDSMHandle = DSM_HANDLE_INVALID;
|
|||
|
||||
static ProgressMonitorData * MonitorDataFromDSMHandle(dsm_handle dsmHandle,
|
||||
dsm_segment **attachedSegment);
|
||||
static ReturnSetInfo * FunctionCallGetTupleStore1(PGFunction function, Oid functionId,
|
||||
Datum argument);
|
||||
|
||||
|
||||
/*
|
||||
|
@ -247,29 +244,3 @@ DetachFromDSMSegments(List *dsmSegmentList)
|
|||
dsm_detach(dsmSegment);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* FunctionCallGetTupleStore1 calls the given set-returning PGFunction with the given
|
||||
* argument and returns the ResultSetInfo filled by the called function.
|
||||
*/
|
||||
static ReturnSetInfo *
|
||||
FunctionCallGetTupleStore1(PGFunction function, Oid functionId, Datum argument)
|
||||
{
|
||||
FunctionCallInfoData fcinfo;
|
||||
FmgrInfo flinfo;
|
||||
ReturnSetInfo *rsinfo = makeNode(ReturnSetInfo);
|
||||
EState *estate = CreateExecutorState();
|
||||
rsinfo->econtext = GetPerTupleExprContext(estate);
|
||||
rsinfo->allowedModes = SFRM_Materialize;
|
||||
|
||||
fmgr_info(functionId, &flinfo);
|
||||
InitFunctionCallInfoData(fcinfo, &flinfo, 1, InvalidOid, NULL, (Node *) rsinfo);
|
||||
|
||||
fcinfo.arg[0] = argument;
|
||||
fcinfo.argnull[0] = false;
|
||||
|
||||
(*function)(&fcinfo);
|
||||
|
||||
return rsinfo;
|
||||
}
|
||||
|
|
|
@ -17,9 +17,9 @@
|
|||
|
||||
#include "access/xact.h"
|
||||
#include "distributed/connection_management.h"
|
||||
#include "distributed/function_utils.h"
|
||||
#include "distributed/lock_graph.h"
|
||||
#include "distributed/master_protocol.h"
|
||||
#include "distributed/multi_logical_optimizer.h"
|
||||
#include "distributed/metadata_cache.h"
|
||||
#include "distributed/remote_commands.h"
|
||||
#include "distributed/run_from_same_connection.h"
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* function_utils.c
|
||||
* Utilities regarding calls to PG functions
|
||||
*
|
||||
* Copyright (c) 2012-2018, Citus Data, Inc.
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "postgres.h"
|
||||
|
||||
#include "catalog/namespace.h"
|
||||
#include "distributed/function_utils.h"
|
||||
#include "executor/executor.h"
|
||||
#include "utils/builtins.h"
|
||||
#if (PG_VERSION_NUM >= 100000)
|
||||
#include "utils/regproc.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* FunctionOid looks for a function that has the given name and the given number
|
||||
* of arguments, and returns the corresponding function's oid.
|
||||
*/
|
||||
Oid
|
||||
FunctionOid(const char *schemaName, const char *functionName, int argumentCount)
|
||||
{
|
||||
FuncCandidateList functionList = NULL;
|
||||
Oid functionOid = InvalidOid;
|
||||
|
||||
char *qualifiedFunctionName = quote_qualified_identifier(schemaName, functionName);
|
||||
List *qualifiedFunctionNameList = stringToQualifiedNameList(qualifiedFunctionName);
|
||||
List *argumentList = NIL;
|
||||
const bool findVariadics = false;
|
||||
const bool findDefaults = false;
|
||||
const bool missingOK = true;
|
||||
|
||||
functionList = FuncnameGetCandidates(qualifiedFunctionNameList, argumentCount,
|
||||
argumentList, findVariadics,
|
||||
findDefaults, missingOK);
|
||||
|
||||
if (functionList == NULL)
|
||||
{
|
||||
ereport(ERROR, (errcode(ERRCODE_UNDEFINED_FUNCTION),
|
||||
errmsg("function \"%s\" does not exist", functionName)));
|
||||
}
|
||||
else if (functionList->next != NULL)
|
||||
{
|
||||
ereport(ERROR, (errcode(ERRCODE_AMBIGUOUS_FUNCTION),
|
||||
errmsg("more than one function named \"%s\"", functionName)));
|
||||
}
|
||||
|
||||
/* get function oid from function list's head */
|
||||
functionOid = functionList->oid;
|
||||
return functionOid;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* FunctionCallGetTupleStore1 calls the given set-returning PGFunction with the given
|
||||
* argument and returns the ResultSetInfo filled by the called function.
|
||||
*/
|
||||
ReturnSetInfo *
|
||||
FunctionCallGetTupleStore1(PGFunction function, Oid functionId, Datum argument)
|
||||
{
|
||||
FunctionCallInfoData fcinfo;
|
||||
FmgrInfo flinfo;
|
||||
ReturnSetInfo *rsinfo = makeNode(ReturnSetInfo);
|
||||
EState *estate = CreateExecutorState();
|
||||
rsinfo->econtext = GetPerTupleExprContext(estate);
|
||||
rsinfo->allowedModes = SFRM_Materialize;
|
||||
|
||||
fmgr_info(functionId, &flinfo);
|
||||
InitFunctionCallInfoData(fcinfo, &flinfo, 1, InvalidOid, NULL, (Node *) rsinfo);
|
||||
|
||||
fcinfo.arg[0] = argument;
|
||||
fcinfo.argnull[0] = false;
|
||||
|
||||
(*function)(&fcinfo);
|
||||
|
||||
return rsinfo;
|
||||
}
|
|
@ -29,11 +29,11 @@
|
|||
#include "distributed/colocation_utils.h"
|
||||
#include "distributed/connection_management.h"
|
||||
#include "distributed/citus_ruleutils.h"
|
||||
#include "distributed/function_utils.h"
|
||||
#include "distributed/foreign_key_relationship.h"
|
||||
#include "distributed/master_metadata_utility.h"
|
||||
#include "distributed/metadata_cache.h"
|
||||
#include "distributed/multi_executor.h"
|
||||
#include "distributed/multi_logical_optimizer.h"
|
||||
#include "distributed/pg_dist_local_group.h"
|
||||
#include "distributed/pg_dist_node_metadata.h"
|
||||
#include "distributed/pg_dist_node.h"
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* function_utils.h
|
||||
* Utilities regarding calls to PG functions
|
||||
*
|
||||
* Copyright (c) 2012-2018, Citus Data, Inc.
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#include "nodes/execnodes.h"
|
||||
|
||||
|
||||
/* Function declaration for getting oid for the given function name */
|
||||
extern Oid FunctionOid(const char *schemaName, const char *functionName,
|
||||
int argumentCount);
|
||||
extern ReturnSetInfo * FunctionCallGetTupleStore1(PGFunction function, Oid functionId,
|
||||
Datum argument);
|
|
@ -136,10 +136,6 @@ extern void MultiLogicalPlanOptimize(MultiTreeRoot *multiTree);
|
|||
/* Function declaration for getting partition method for the given relation */
|
||||
extern char PartitionMethod(Oid relationId);
|
||||
|
||||
/* Function declaration for getting oid for the given function name */
|
||||
extern Oid FunctionOid(const char *schemaName, const char *functionName,
|
||||
int argumentCount);
|
||||
|
||||
/* Function declaration for helper functions in subquery pushdown */
|
||||
extern bool GroupedByColumn(List *groupClauseList, List *targetList, Var *column);
|
||||
extern List * SubqueryMultiTableList(MultiNode *multiNode);
|
||||
|
|
Loading…
Reference in New Issue