1
+ #include "pathman.h"
1
2
#include "declarative.h"
2
3
#include "utils.h"
3
4
#include "partition_creation.h"
4
5
5
- #include "fmgr.h"
6
6
#include "access/htup_details.h"
7
7
#include "catalog/namespace.h"
8
- #include "catalog/pg_type.h"
9
8
#include "catalog/pg_proc.h"
9
+ #include "catalog/pg_type.h"
10
+ #include "fmgr.h"
11
+ #include "nodes/makefuncs.h"
10
12
#include "nodes/nodeFuncs.h"
11
- #include "parser/parse_func .h"
13
+ #include "optimizer/planner .h"
12
14
#include "parser/parse_coerce.h"
13
- #include "utils/int8.h"
14
- #include "utils/lsyscache.h"
15
+ #include "parser/parse_func.h"
15
16
#include "utils/builtins.h"
16
17
#include "utils/int8.h"
18
+ #include "utils/int8.h"
19
+ #include "utils/lsyscache.h"
17
20
#include "utils/lsyscache.h"
18
21
#include "utils/syscache.h"
19
22
#include "utils/varbit.h"
@@ -33,13 +36,16 @@ modify_declative_partitioning_query(Query *query)
33
36
34
37
if (IsA (query -> utilityStmt , AlterTableStmt ))
35
38
{
39
+ PartRelationInfo * prel ;
36
40
ListCell * lcmd ;
37
41
Oid relid ;
38
42
39
43
AlterTableStmt * stmt = (AlterTableStmt * ) query -> utilityStmt ;
40
44
relid = RangeVarGetRelid (stmt -> relation , NoLock , true);
41
- if (get_pathman_relation_info (relid ) != NULL )
45
+ if (( prel = get_pathman_relation_info (relid ) ) != NULL )
42
46
{
47
+ close_pathman_relation_info (prel );
48
+
43
49
foreach (lcmd , stmt -> cmds )
44
50
{
45
51
AlterTableCmd * cmd = (AlterTableCmd * ) lfirst (lcmd );
@@ -61,16 +67,20 @@ modify_declative_partitioning_query(Query *query)
61
67
bool
62
68
is_pathman_related_partitioning_cmd (Node * parsetree , Oid * parent_relid )
63
69
{
70
+ PartRelationInfo * prel ;
71
+
64
72
if (IsA (parsetree , AlterTableStmt ))
65
73
{
66
74
ListCell * lc ;
67
75
AlterTableStmt * stmt = (AlterTableStmt * ) parsetree ;
68
76
int cnt = 0 ;
69
77
70
78
* 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 )
72
80
return false;
73
81
82
+ close_pathman_relation_info (prel );
83
+
74
84
/*
75
85
* Since cmds can contain multiple commmands but we can handle only
76
86
* 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)
106
116
{
107
117
RangeVar * rv = castNode (RangeVar , linitial (stmt -> inhRelations ));
108
118
* 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 )
110
120
return false;
111
121
122
+ close_pathman_relation_info (prel );
112
123
if (stmt -> tableElts != NIL )
113
124
elog (ERROR , "pg_pathman doesn't support column definitions "
114
125
"in declarative syntax yet" );
@@ -202,7 +213,7 @@ handle_attach_partition(Oid parent_relid, AlterTableCmd *cmd)
202
213
A_Const * con ;
203
214
List * fn_args ;
204
215
ParseState * pstate = make_parsestate (NULL );
205
- const PartRelationInfo * prel ;
216
+ PartRelationInfo * prel ;
206
217
207
218
PartitionCmd * pcmd = (PartitionCmd * ) cmd -> def ;
208
219
@@ -238,6 +249,7 @@ handle_attach_partition(Oid parent_relid, AlterTableCmd *cmd)
238
249
rdatum = (PartitionRangeDatum * ) linitial (bound -> upperdatums );
239
250
con = castNode (A_Const , rdatum -> value );
240
251
rval = transform_bound_value (pstate , con , prel -> ev_type , prel -> ev_typmod );
252
+ close_pathman_relation_info (prel );
241
253
242
254
/* Lookup function's Oid and get FmgrInfo */
243
255
fmgr_info (LookupFuncName (proc_name , 4 , proc_args , false), & proc_flinfo );
@@ -255,9 +267,9 @@ handle_attach_partition(Oid parent_relid, AlterTableCmd *cmd)
255
267
(Node * ) make_fn_expr (proc_fcinfo .flinfo -> fn_oid , fn_args );
256
268
257
269
proc_fcinfo .arg [2 ] = lval -> constvalue ;
258
- proc_fcinfo .argnull [2 ] = ldatum -> infinite || lval -> constisnull ;
270
+ proc_fcinfo .argnull [2 ] = lval -> constisnull ;
259
271
proc_fcinfo .arg [3 ] = rval -> constvalue ;
260
- proc_fcinfo .argnull [3 ] = rdatum -> infinite || rval -> constisnull ;
272
+ proc_fcinfo .argnull [3 ] = rval -> constisnull ;
261
273
262
274
/* Invoke the callback */
263
275
FunctionCallInvoke (& proc_fcinfo );
@@ -303,7 +315,7 @@ handle_create_partition_of(Oid parent_relid, CreateStmt *stmt)
303
315
{
304
316
Bound start ,
305
317
end ;
306
- const PartRelationInfo * prel ;
318
+ PartRelationInfo * prel ;
307
319
ParseState * pstate = make_parsestate (NULL );
308
320
PartitionRangeDatum * ldatum ,
309
321
* rdatum ;
@@ -339,6 +351,7 @@ handle_create_partition_of(Oid parent_relid, CreateStmt *stmt)
339
351
rdatum = (PartitionRangeDatum * ) linitial (bound -> upperdatums );
340
352
con = castNode (A_Const , rdatum -> value );
341
353
rval = transform_bound_value (pstate , con , prel -> ev_type , prel -> ev_typmod );
354
+ close_pathman_relation_info (prel );
342
355
343
356
start = lval -> constisnull ?
344
357
MakeBoundInf (MINUS_INFINITY ) :
0 commit comments