1+ #include "pathman.h"
12#include "declarative.h"
23#include "utils.h"
34#include "partition_creation.h"
45
5- #include "fmgr.h"
66#include "access/htup_details.h"
77#include "catalog/namespace.h"
8- #include "catalog/pg_type.h"
98#include "catalog/pg_proc.h"
9+ #include "catalog/pg_type.h"
10+ #include "fmgr.h"
11+ #include "nodes/makefuncs.h"
1012#include "nodes/nodeFuncs.h"
11- #include "parser/parse_func .h"
13+ #include "optimizer/planner .h"
1214#include "parser/parse_coerce.h"
13- #include "utils/int8.h"
14- #include "utils/lsyscache.h"
15+ #include "parser/parse_func.h"
1516#include "utils/builtins.h"
1617#include "utils/int8.h"
18+ #include "utils/int8.h"
19+ #include "utils/lsyscache.h"
1720#include "utils/lsyscache.h"
1821#include "utils/syscache.h"
1922#include "utils/varbit.h"
@@ -33,13 +36,16 @@ modify_declative_partitioning_query(Query *query)
3336
3437if (IsA (query -> utilityStmt ,AlterTableStmt ))
3538{
39+ PartRelationInfo * prel ;
3640ListCell * lcmd ;
3741Oid relid ;
3842
3943AlterTableStmt * stmt = (AlterTableStmt * )query -> utilityStmt ;
4044relid = RangeVarGetRelid (stmt -> relation ,NoLock , true);
41- if (get_pathman_relation_info (relid )!= NULL )
45+ if (( prel = get_pathman_relation_info (relid ) )!= NULL )
4246{
47+ close_pathman_relation_info (prel );
48+
4349foreach (lcmd ,stmt -> cmds )
4450{
4551AlterTableCmd * cmd = (AlterTableCmd * )lfirst (lcmd );
@@ -61,16 +67,20 @@ modify_declative_partitioning_query(Query *query)
6167bool
6268is_pathman_related_partitioning_cmd (Node * parsetree ,Oid * parent_relid )
6369{
70+ PartRelationInfo * prel ;
71+
6472if (IsA (parsetree ,AlterTableStmt ))
6573{
6674ListCell * lc ;
6775AlterTableStmt * stmt = (AlterTableStmt * )parsetree ;
6876int cnt = 0 ;
6977
7078* parent_relid = RangeVarGetRelid (stmt -> relation ,NoLock , false);
71- if (get_pathman_relation_info (* parent_relid )== NULL )
79+ if (( prel = get_pathman_relation_info (* parent_relid ) )== NULL )
7280return false;
7381
82+ close_pathman_relation_info (prel );
83+
7484/*
7585 * Since cmds can contain multiple commmands but we can handle only
7686 * two of them here, so we need to check that there are only commands
@@ -106,9 +116,10 @@ is_pathman_related_partitioning_cmd(Node *parsetree, Oid *parent_relid)
106116{
107117RangeVar * rv = castNode (RangeVar ,linitial (stmt -> inhRelations ));
108118* parent_relid = RangeVarGetRelid (rv ,NoLock , false);
109- if (get_pathman_relation_info (* parent_relid )== NULL )
119+ if (( prel = get_pathman_relation_info (* parent_relid ) )== NULL )
110120return false;
111121
122+ close_pathman_relation_info (prel );
112123if (stmt -> tableElts != NIL )
113124elog (ERROR ,"pg_pathman doesn't support column definitions "
114125"in declarative syntax yet" );
@@ -202,7 +213,7 @@ handle_attach_partition(Oid parent_relid, AlterTableCmd *cmd)
202213A_Const * con ;
203214List * fn_args ;
204215ParseState * pstate = make_parsestate (NULL );
205- const PartRelationInfo * prel ;
216+ PartRelationInfo * prel ;
206217
207218PartitionCmd * pcmd = (PartitionCmd * )cmd -> def ;
208219
@@ -238,6 +249,7 @@ handle_attach_partition(Oid parent_relid, AlterTableCmd *cmd)
238249rdatum = (PartitionRangeDatum * )linitial (bound -> upperdatums );
239250con = castNode (A_Const ,rdatum -> value );
240251rval = transform_bound_value (pstate ,con ,prel -> ev_type ,prel -> ev_typmod );
252+ close_pathman_relation_info (prel );
241253
242254/* Lookup function's Oid and get FmgrInfo */
243255fmgr_info (LookupFuncName (proc_name ,4 ,proc_args , false),& proc_flinfo );
@@ -255,9 +267,9 @@ handle_attach_partition(Oid parent_relid, AlterTableCmd *cmd)
255267(Node * )make_fn_expr (proc_fcinfo .flinfo -> fn_oid ,fn_args );
256268
257269proc_fcinfo .arg [2 ]= lval -> constvalue ;
258- proc_fcinfo .argnull [2 ]= ldatum -> infinite || lval -> constisnull ;
270+ proc_fcinfo .argnull [2 ]= lval -> constisnull ;
259271proc_fcinfo .arg [3 ]= rval -> constvalue ;
260- proc_fcinfo .argnull [3 ]= rdatum -> infinite || rval -> constisnull ;
272+ proc_fcinfo .argnull [3 ]= rval -> constisnull ;
261273
262274/* Invoke the callback */
263275FunctionCallInvoke (& proc_fcinfo );
@@ -303,7 +315,7 @@ handle_create_partition_of(Oid parent_relid, CreateStmt *stmt)
303315{
304316Bound start ,
305317end ;
306- const PartRelationInfo * prel ;
318+ PartRelationInfo * prel ;
307319ParseState * pstate = make_parsestate (NULL );
308320PartitionRangeDatum * ldatum ,
309321* rdatum ;
@@ -339,6 +351,7 @@ handle_create_partition_of(Oid parent_relid, CreateStmt *stmt)
339351rdatum = (PartitionRangeDatum * )linitial (bound -> upperdatums );
340352con = castNode (A_Const ,rdatum -> value );
341353rval = transform_bound_value (pstate ,con ,prel -> ev_type ,prel -> ev_typmod );
354+ close_pathman_relation_info (prel );
342355
343356start = lval -> constisnull ?
344357MakeBoundInf (MINUS_INFINITY ) :