Skip to content

Commit 70c064d

Browse files
committed
Use heap_getattr and copy slot before using
1 parent e898585 commit 70c064d

File tree

2 files changed

+39
-10
lines changed

2 files changed

+39
-10
lines changed

src/debug_print.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
#include "rangeset.h"
1212

1313
#include "postgres.h"
14+
#include "fmgr.h"
1415
#include "nodes/bitmapset.h"
1516
#include "nodes/pg_list.h"
1617
#include "lib/stringinfo.h"
18+
#include "utils/lsyscache.h"
1719

1820

1921
/*
@@ -99,3 +101,32 @@ irange_print(IndexRange irange)
99101

100102
return str.data;
101103
}
104+
105+
/*
106+
* Print Datum as cstring
107+
*/
108+
#ifdef __GNUC__
109+
__attribute__((unused))
110+
#endif
111+
static char *
112+
datum_print(Datum origval, Oid typid)
113+
{
114+
Oid typoutput;
115+
bool typisvarlena;
116+
Datum val;
117+
118+
/* Query output function */
119+
getTypeOutputInfo(typid, &typoutput, &typisvarlena);
120+
121+
if (typisvarlena && VARATT_IS_EXTERNAL_ONDISK(origval))
122+
return NULL; //unchanged-toast-datum
123+
else if (!typisvarlena)
124+
val = origval;
125+
else
126+
{
127+
/* Definitely detoasted Datum */
128+
val = PointerGetDatum(PG_DETOAST_DATUM(origval));
129+
}
130+
131+
return OidOutputFunctionCall(typoutput, val);
132+
}

src/partition_filter.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,7 @@ struct expr_walker_context
532532
{
533533
const PartRelationInfo *prel;
534534
TupleTableSlot *slot;
535+
HeapTuple tup;
535536
bool clear;
536537
};
537538

@@ -564,7 +565,8 @@ adapt_values (Node *node, struct expr_walker_context *context)
564565
/* check that type is still same */
565566
Assert(context->slot->tts_tupleDescriptor->
566567
attrs[attnum - 1]->atttypid == cst->consttype);
567-
cst->constvalue = slot_getattr(context->slot, attnum, &isNull);
568+
cst->constvalue = heap_getattr(context->tup, attnum,
569+
context->slot->tts_tupleDescriptor, &isNull);
568570
cst->constisnull = isNull;
569571
}
570572
return false;
@@ -633,22 +635,18 @@ partition_filter_exec(CustomScanState *node)
633635
/* Prepare walker context */
634636
expr_walker_context.prel = prel; /* maybe slot will be enough */
635637
expr_walker_context.slot = slot;
636-
expr_walker_context.clear = true;
637-
638-
/* Clear values from slot for expression */
639-
adapt_values((Node *)prel->expr, (void *) &expr_walker_context);
640-
641-
/* Prepare state before execution */
642-
expr_state = ExecPrepareExpr(prel->expr, estate);
638+
expr_walker_context.tup = ExecCopySlotTuple(slot);
639+
expr_walker_context.clear = false;
643640

644641
/* Switch to per-tuple context */
645642
old_cxt = MemoryContextSwitchTo(GetPerTupleMemoryContext(estate));
646643

647-
expr_walker_context.clear = false;
648-
649644
/* Fetch values from slot for expression */
650645
adapt_values((Node *)prel->expr, (void *) &expr_walker_context);
651646

647+
/* Prepare state before execution */
648+
expr_state = ExecPrepareExpr(prel->expr, estate);
649+
652650
/* Execute expression */
653651
value = ExecEvalExpr(expr_state, econtext, &isnull, &itemIsDone);
654652

0 commit comments

Comments
 (0)