Skip to content

Commit 5f6fed0

Browse files
committed
make handle_const() check for 'for_insert' flag
1 parent b303f6c commit 5f6fed0

File tree

5 files changed

+28
-11
lines changed

5 files changed

+28
-11
lines changed

src/hooks.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ pathman_join_pathlist_hook(PlannerInfo *root,
9191
WrapperNode *wrap;
9292

9393
/* We aim to persist cached context->ranges */
94-
InitWalkerContextCustomNode(&context, inner_prel,
95-
NULL, CurrentMemoryContext,
94+
InitWalkerContextCustomNode(&context, inner_prel, NULL,
95+
CurrentMemoryContext, false,
9696
&context_initialized);
9797

9898
wrap = walk_expr_tree((Expr *) lfirst(lc), &context);
@@ -225,7 +225,7 @@ pathman_rel_pathlist_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTb
225225
ranges = list_make1_irange(make_irange(0, prel->children_count - 1, false));
226226

227227
/* Make wrappers over restrictions and collect final rangeset */
228-
InitWalkerContext(&context, prel, NULL, CurrentMemoryContext);
228+
InitWalkerContext(&context, prel, NULL, CurrentMemoryContext, false);
229229
wrappers = NIL;
230230
foreach(lc, rel->baserestrictinfo)
231231
{

src/nodes_common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ rescan_append_common(CustomScanState *node)
503503
ranges = list_make1_irange(make_irange(0, prel->children_count - 1, false));
504504

505505
InitWalkerContextCustomNode(&scan_state->wcxt, scan_state->prel,
506-
econtext, CurrentMemoryContext,
506+
econtext, CurrentMemoryContext, false,
507507
&scan_state->wcxt_cached);
508508

509509
foreach (lc, scan_state->custom_exprs)

src/partition_filter.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ partition_filter_exec(CustomScanState *node)
162162
CopyToTempConst(constlen, attlen);
163163
CopyToTempConst(constbyval, attbyval);
164164

165-
InitWalkerContextCustomNode(&state->wcxt, state->prel,
166-
econtext, CurrentMemoryContext,
165+
InitWalkerContextCustomNode(&state->wcxt, state->prel, econtext,
166+
CurrentMemoryContext, true,
167167
&state->wcxt_cached);
168168

169169
/* Switch to per-tuple context */

src/pathman.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,12 +289,14 @@ typedef struct
289289
hasGreatest;
290290
Datum least,
291291
greatest;
292+
293+
bool for_insert; /* are we in PartitionFilter now? */
292294
} WalkerContext;
293295

294296
/*
295297
* Usual initialization procedure for WalkerContext
296298
*/
297-
#define InitWalkerContext(context, prel_info, ecxt, mcxt) \
299+
#define InitWalkerContext(context, prel_info, ecxt, mcxt, for_ins) \
298300
do { \
299301
(context)->prel = (prel_info); \
300302
(context)->econtext = (ecxt); \
@@ -303,14 +305,15 @@ typedef struct
303305
(context)->hasLeast = false; \
304306
(context)->hasGreatest = false; \
305307
(context)->persistent_mcxt = (mcxt); \
308+
(context)->for_insert = (for_ins); \
306309
} while (0)
307310

308311
/*
309312
* We'd like to persist RangeEntry (ranges) array
310313
* in case of range partitioning, so 'wcxt' is stored
311314
* inside of Custom Node
312315
*/
313-
#define InitWalkerContextCustomNode(context, prel_info, ecxt, mcxt, isCached) \
316+
#define InitWalkerContextCustomNode(context, prel_info, ecxt, mcxt, for_ins, isCached) \
314317
do { \
315318
if (!*isCached) \
316319
{ \
@@ -319,6 +322,7 @@ typedef struct
319322
(context)->ranges = NULL; \
320323
(context)->nranges = 0; \
321324
(context)->persistent_mcxt = (mcxt); \
325+
(context)->for_insert = (for_ins); \
322326
*isCached = true; \
323327
} \
324328
(context)->hasLeast = false; \

src/pg_pathman.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ handle_modification_query(Query *parse)
331331
return;
332332

333333
/* Parse syntax tree and extract partition ranges */
334-
InitWalkerContext(&context, prel, NULL, CurrentMemoryContext);
334+
InitWalkerContext(&context, prel, NULL, CurrentMemoryContext, false);
335335
wrap = walk_expr_tree(expr, &context);
336336
finish_least_greatest(wrap, &context);
337337
clear_walker_context(&context);
@@ -1125,6 +1125,20 @@ handle_const(const Const *c, WalkerContext *context)
11251125
const PartRelationInfo *prel = context->prel;
11261126
WrapperNode *result = (WrapperNode *) palloc(sizeof(WrapperNode));
11271127

1128+
/*
1129+
* Had to add this check for queries like:
1130+
* select * from test.hash_rel where txt = NULL;
1131+
*/
1132+
if (!context->for_insert)
1133+
{
1134+
result->rangeset = list_make1_irange(make_irange(0,
1135+
prel->children_count - 1,
1136+
true));
1137+
result->paramsel = 1.0;
1138+
1139+
return result;
1140+
}
1141+
11281142
switch (prel->parttype)
11291143
{
11301144
case PT_HASH:
@@ -1156,8 +1170,7 @@ handle_const(const Const *c, WalkerContext *context)
11561170
break;
11571171

11581172
default:
1159-
result->rangeset = list_make1_irange(make_irange(0, prel->children_count - 1, true));
1160-
result->paramsel = 1.0;
1173+
elog(ERROR, "Unknown partitioning type %u", prel->parttype);
11611174
break;
11621175
}
11631176

0 commit comments

Comments
 (0)