Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 740239f

Browse files
committed
Fix declarative syntax for pg10
1 parent 61f5c80 commit 740239f

File tree

3 files changed

+29
-19
lines changed

3 files changed

+29
-19
lines changed

Makefile

+4-6
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@
22

33
MODULE_big = pg_pathman
44

5-
# versions of postgresql with declarative partitioning
6-
DECL_CHECK_VERSIONS = 10 11
7-
85
ifdef USE_PGXS
96
PG_CONFIG = pg_config
107
VNUM := $(shell $(PG_CONFIG) --version | awk '{print $$2}')
11-
ifeq ($(VNUM),$(filter $(VNUM), $(DECL_CHECK_VERSIONS)))
8+
ifeq ($(VNUM),$(filter 10% 11%,$(VNUM)))
129
EXTRA_REGRESS = pathman_declarative
1310
EXTRA_OBJS = src/declarative.o
1411
endif
@@ -21,7 +18,7 @@ OBJS = src/init.o src/relation_info.o src/utils.o src/partition_filter.o \
2118
src/hooks.o src/nodes_common.o src/xact_handling.o src/utility_stmt_hooking.o \
2219
src/planner_tree_modification.o src/debug_print.o src/partition_creation.o \
2320
src/compat/pg_compat.o src/compat/rowmarks_fix.o src/partition_router.o \
24-
src/partition_overseer.o $(WIN32RES)
21+
src/partition_overseer.o $(EXTRA_OBJS) $(WIN32RES)
2522

2623
ifdef USE_PGXS
2724
override PG_CPPFLAGS += -I$(CURDIR)/src/include
@@ -73,7 +70,8 @@ REGRESS = pathman_array_qual \
7370
pathman_update_triggers \
7471
pathman_upd_del \
7572
pathman_utility_stmt \
76-
pathman_views ${EXTRA_REGRESS}
73+
pathman_views $(EXTRA_REGRESS)
74+
7775

7876
EXTRA_REGRESS_OPTS=--temp-config=$(top_srcdir)/$(subdir)/conf.add
7977

expected/pathman_declarative.out

-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ Check constraints:
5858
Inherits: test.range_rel
5959

6060
ALTER TABLE test.range_rel DETACH PARTITION test.r2;
61-
NOTICE: trigger "range_rel_upd_trig" for relation "test.r2" does not exist, skipping
6261
SELECT * FROM pathman.pathman_partition_list;
6362
parent | partition | parttype | expr | range_min | range_max
6463
----------------+------------------+----------+------+------------+------------

src/declarative.c

+25-12
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
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

3437
if (IsA(query->utilityStmt, AlterTableStmt))
3538
{
39+
PartRelationInfo *prel;
3640
ListCell *lcmd;
3741
Oid relid;
3842

3943
AlterTableStmt *stmt = (AlterTableStmt *) query->utilityStmt;
4044
relid = 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+
4349
foreach(lcmd, stmt->cmds)
4450
{
4551
AlterTableCmd *cmd = (AlterTableCmd *) lfirst(lcmd);
@@ -61,16 +67,20 @@ modify_declative_partitioning_query(Query *query)
6167
bool
6268
is_pathman_related_partitioning_cmd(Node *parsetree, Oid *parent_relid)
6369
{
70+
PartRelationInfo *prel;
71+
6472
if (IsA(parsetree, AlterTableStmt))
6573
{
6674
ListCell *lc;
6775
AlterTableStmt *stmt = (AlterTableStmt *) parsetree;
6876
int 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)
7280
return 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
{
107117
RangeVar *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)
110120
return false;
111121

122+
close_pathman_relation_info(prel);
112123
if (stmt->tableElts != NIL)
113124
elog(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)
202213
A_Const *con;
203214
List *fn_args;
204215
ParseState *pstate = make_parsestate(NULL);
205-
const PartRelationInfo *prel;
216+
PartRelationInfo *prel;
206217

207218
PartitionCmd *pcmd = (PartitionCmd *) cmd->def;
208219

@@ -238,6 +249,7 @@ handle_attach_partition(Oid parent_relid, AlterTableCmd *cmd)
238249
rdatum = (PartitionRangeDatum *) linitial(bound->upperdatums);
239250
con = castNode(A_Const, rdatum->value);
240251
rval = 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 */
243255
fmgr_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

257269
proc_fcinfo.arg[2] = lval->constvalue;
258-
proc_fcinfo.argnull[2] = ldatum->infinite || lval->constisnull;
270+
proc_fcinfo.argnull[2] = lval->constisnull;
259271
proc_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 */
263275
FunctionCallInvoke(&proc_fcinfo);
@@ -303,7 +315,7 @@ handle_create_partition_of(Oid parent_relid, CreateStmt *stmt)
303315
{
304316
Bound start,
305317
end;
306-
const PartRelationInfo *prel;
318+
PartRelationInfo *prel;
307319
ParseState *pstate = make_parsestate(NULL);
308320
PartitionRangeDatum *ldatum,
309321
*rdatum;
@@ -339,6 +351,7 @@ handle_create_partition_of(Oid parent_relid, CreateStmt *stmt)
339351
rdatum = (PartitionRangeDatum *) linitial(bound->upperdatums);
340352
con = castNode(A_Const, rdatum->value);
341353
rval = transform_bound_value(pstate, con, prel->ev_type, prel->ev_typmod);
354+
close_pathman_relation_info(prel);
342355

343356
start = lval->constisnull?
344357
MakeBoundInf(MINUS_INFINITY) :

0 commit comments

Comments
 (0)