Skip to content

Commit 691c6e1

Browse files
committed
Merge latest changes from master
2 parents a5987fb + 67aa0a6 commit 691c6e1

File tree

5 files changed

+56
-5
lines changed

5 files changed

+56
-5
lines changed

expected/pg_pathman.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ SELECT COUNT(*) FROM ONLY test.num_range_rel;
114114
0
115115
(1 row)
116116

117+
SELECT * FROM ONLY test.range_rel UNION SELECT * FROM test.range_rel;
118+
ERROR: It is prohibited to query partitioned tables both with and without ONLY modifier
117119
SET pg_pathman.enable_runtimeappend = OFF;
118120
SET pg_pathman.enable_runtimemergeappend = OFF;
119121
VACUUM;

sql/pg_pathman.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ INSERT INTO test.num_range_rel
4646
SELECT COUNT(*) FROM test.num_range_rel;
4747
SELECT COUNT(*) FROM ONLY test.num_range_rel;
4848

49+
SELECT * FROM ONLY test.range_rel UNION SELECT * FROM test.range_rel;
50+
4951
SET pg_pathman.enable_runtimeappend = OFF;
5052
SET pg_pathman.enable_runtimemergeappend = OFF;
5153

src/hooks.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ pathman_rel_pathlist_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTb
165165
return;
166166

167167
/* This works only for SELECT queries (at least for now) */
168-
if (root->parse->commandType != CMD_SELECT || !inheritance_disabled)
168+
if (root->parse->commandType != CMD_SELECT ||
169+
!list_member_oid(inheritance_enabled_relids, rte->relid))
169170
return;
170171

171172
/* Lookup partitioning information for parent relation */
@@ -372,7 +373,6 @@ pathman_planner_hook(Query *parse, int cursorOptions, ParamListInfo boundParams)
372373

373374
if (pg_pathman_enable)
374375
{
375-
inheritance_disabled = false;
376376
switch(parse->commandType)
377377
{
378378
case CMD_SELECT:
@@ -421,6 +421,9 @@ pathman_planner_hook(Query *parse, int cursorOptions, ParamListInfo boundParams)
421421
postprocess_lock_rows(result->rtable, (Plan *) lfirst(lc));
422422
}
423423

424+
list_free(inheritance_disabled_relids);
425+
inheritance_disabled_relids = NIL;
426+
424427
return result;
425428
}
426429

@@ -436,6 +439,9 @@ pathman_post_parse_analysis_hook(ParseState *pstate, Query *query)
436439

437440
if (post_parse_analyze_hook_next)
438441
post_parse_analyze_hook_next(pstate, query);
442+
443+
inheritance_disabled_relids = NIL;
444+
inheritance_enabled_relids = NIL;
439445
}
440446

441447
void

src/pathman.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,25 @@ typedef struct PathmanState
133133
DsmArray databases;
134134
} PathmanState;
135135

136+
136137
typedef enum
137138
{
138139
SEARCH_RANGEREL_OUT_OF_RANGE = 0,
139140
SEARCH_RANGEREL_GAP,
140141
SEARCH_RANGEREL_FOUND
141142
} search_rangerel_result;
142143

143-
extern bool inheritance_disabled;
144+
145+
/*
146+
* The list of partitioned relation relids that must be handled by pg_pathman
147+
*/
148+
extern List *inheritance_enabled_relids;
149+
/*
150+
* This list is used to ensure that partitioned relation isn't used both
151+
* with and without ONLY modifiers
152+
*/
153+
extern List *inheritance_disabled_relids;
154+
144155
extern bool pg_pathman_enable;
145156
extern PathmanState *pmstate;
146157

src/pg_pathman.c

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
PG_MODULE_MAGIC;
4848

4949

50-
bool inheritance_disabled;
50+
List *inheritance_disabled_relids = NIL;
51+
List *inheritance_enabled_relids = NIL;
5152
bool pg_pathman_enable;
5253
PathmanState *pmstate;
5354

@@ -199,6 +200,7 @@ disable_inheritance(Query *parse)
199200
foreach(lc, parse->rtable)
200201
{
201202
rte = (RangeTblEntry *) lfirst(lc);
203+
202204
switch(rte->rtekind)
203205
{
204206
case RTE_RELATION:
@@ -215,9 +217,28 @@ disable_inheritance(Query *parse)
215217
* when user uses ONLY statement from case when we
216218
* make rte->inh false intentionally.
217219
*/
218-
inheritance_disabled = true;
220+
inheritance_enabled_relids = \
221+
lappend_oid(inheritance_enabled_relids, rte->relid);
222+
223+
/*
224+
* Check if relation was already found with ONLY modifier. In
225+
* this case throw an error because we cannot handle
226+
* situations when partitioned table used both with and
227+
* without ONLY modifier in SELECT queries
228+
*/
229+
if (list_member_oid(inheritance_disabled_relids, rte->relid))
230+
goto disable_error;
231+
232+
goto disable_next;
219233
}
220234
}
235+
236+
inheritance_disabled_relids = \
237+
lappend_oid(inheritance_disabled_relids, rte->relid);
238+
239+
/* Check if relation was already found withoud ONLY modifier */
240+
if (list_member_oid(inheritance_enabled_relids, rte->relid))
241+
goto disable_error;
221242
break;
222243
case RTE_SUBQUERY:
223244
/* Recursively disable inheritance for subqueries */
@@ -226,7 +247,16 @@ disable_inheritance(Query *parse)
226247
default:
227248
break;
228249
}
250+
251+
disable_next:
252+
;
229253
}
254+
255+
return;
256+
257+
disable_error:
258+
elog(ERROR, "It is prohibited to query partitioned tables both "
259+
"with and without ONLY modifier");
230260
}
231261

232262
void

0 commit comments

Comments
 (0)