8000 make PrelExpressionForRelid() more memory-safe · postgrespro/pg_pathman@0963406 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0963406

Browse files
committed
make PrelExpressionForRelid() more memory-safe
1 parent 09d9331 commit 0963406

File tree

4 files changed

+13
-15
lines changed

4 files changed

+13
-15
lines changed

src/include/relation_info.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,15 +261,11 @@ PrelExpressionColumnNames(const PartRelationInfo *prel)
261261
static inline Node *
262262
PrelExpressionForRelid(const PartRelationInfo *prel, Index rel_index)
263263
{
264-
Node *expr;
265-
266264
/* TODO: implement some kind of cache */
265+
Node *expr = copyObject(prel->expr);
266+
267267
if (rel_index != PART_EXPR_VARNO)
268-
{
269-
expr = copyObject(prel->expr);
270268
ChangeVarNodes(expr, PART_EXPR_VARNO, rel_index, 0);
271-
}
272-
else expr = prel->expr;
273269

274270
return expr;
275271
}

src/include/runtimeappend.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ typedef struct
4141
/* Refined clauses for partition pruning */
4242
List *canon_custom_exprs;
4343

44+
/* Copy of partitioning expression (protect from invalidations) */
45+
Node *prel_expr;
46+
4447
/* All available plans \ plan states */
4548
HTAB *children_table;
4649
HASHCTL children_table_config;

src/nodes_common.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -635,10 +635,16 @@ create_append_scan_state_common(CustomScan *node,
635635
void
636636
begin_append_common(CustomScanState *node, EState *estate, int eflags)
637637
{
638-
RuntimeAppendState *scan_state = (RuntimeAppendState *) node;
638+
RuntimeAppendState *scan_state = (RuntimeAppendState *) node;
639+
const PartRelationInfo *prel;
639640

640641
node->ss.ps.ps_TupFromTlist = false;
641642

643+
prel = get_pathman_relation_info(scan_state->relid);
644+
645+
/* Prepare expression according to set_set_customscan_references() */
646+
scan_state->prel_expr = PrelExpressionForRelid(prel, INDEX_VAR);
647+
642648
/* Prepare custom expression according to set_set_customscan_references() */
643649
scan_state->canon_custom_exprs =
644650
canonicalize_custom_exprs(scan_state->custom_exprs);
@@ -709,18 +715,14 @@ rescan_append_common(CustomScanState *node)
709715
WalkerContext wcxt;
710716
Oid *parts;
711717
int nparts;
712-
Node *prel_expr;
713718

714719
prel = get_pathman_relation_info(scan_state->relid);
715720
Assert(prel);
716721

717-
/* Prepare expression according to set_set_customscan_references() */
718-
prel_expr = PrelExpressionForRelid(prel, INDEX_VAR);
719-
720722
/* First we select all available partitions... */
721723
ranges = list_make1_irange_full(prel, IR_COMPLETE);
722724

723-
InitWalkerContext(&wcxt, prel_expr, prel, econtext);
725+
InitWalkerContext(&wcxt, scan_state->prel_expr, prel, econtext);
724726
foreach (lc, scan_state->canon_custom_exprs)
725727
{
726728
WrapperNode *wrap;

src/partition_filter.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -560,9 +560,6 @@ partition_filter_begin(CustomScanState *node, EState *estate, int eflags)
560560
}
561561
expr = PrelExpressionForRelid(prel, parent_varno);
562562

563-
/* HACK: protect expression from 'prel' invalidation */
564-
expr = copyObject(expr);
565-
566563
/* Prepare state for expression execution */
567564
old_mcxt = MemoryContextSwitchTo(estate->es_query_cxt);
568565
state->expr_state = ExecInitExpr((Expr *) expr, NULL);

0 commit comments

Comments
 (0)
0