Skip to content

Commit 04d5ed2

Browse files
committed
initialize ResultRelInfos for partitions using savedRelInfo
1 parent c63c9a1 commit 04d5ed2

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/partition_filter.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ partition_filter_begin(CustomScanState *node, EState *estate, int eflags)
102102

103103
node->custom_ps = list_make1(ExecInitNode(state->subplan, estate, eflags));
104104
state->prel = get_pathman_relation_info(state->partitioned_table, NULL);
105+
state->savedRelInfo = NULL;
105106

106107
memset(result_rels_table_config, 0, sizeof(HASHCTL));
107108
result_rels_table_config->keysize = sizeof(Oid);
@@ -129,6 +130,10 @@ partition_filter_exec(CustomScanState *node)
129130

130131
slot = ExecProcNode(child_ps);
131132

133+
/* Save original ResultRelInfo */
134+
if (!state->savedRelInfo)
135+
state->savedRelInfo = estate->es_result_relation_info;
136+
132137
if (!TupIsNull(slot))
133138
{
134139
WalkerContext wcxt;
@@ -140,9 +145,11 @@ partition_filter_exec(CustomScanState *node)
140145
AttrNumber attnum = state->prel->attnum;
141146
Datum value = slot_getattr(slot, attnum, &isnull);
142147

148+
/* Fill const with value ... */
143149
state->temp_const.constvalue = value;
144150
state->temp_const.constisnull = isnull;
145151

152+
/* ... and some other important data */
146153
CopyToTempConst(consttype, atttypid);
147154
CopyToTempConst(consttypmod, atttypmod);
148155
CopyToTempConst(constcollid, attcollation);
@@ -162,6 +169,7 @@ partition_filter_exec(CustomScanState *node)
162169
else if (nparts == 0)
163170
elog(ERROR, "PartitionFilter could not select suitable partition");
164171

172+
/* Replace main table with suitable partition */
165173
estate->es_result_relation_info = getResultRelInfo(parts[0], state);
166174

167175
return slot;
@@ -209,6 +217,9 @@ partition_filter_explain(CustomScanState *node, List *ancestors, ExplainState *e
209217
static ResultRelInfo *
210218
getResultRelInfo(Oid partid, PartitionFilterState *state)
211219
{
220+
#define CopyToResultRelInfo(field_name) \
221+
( resultRelInfo->field_name = state->savedRelInfo->field_name )
222+
212223
ResultRelInfoHandle *resultRelInfoHandle;
213224
bool found;
214225

@@ -226,6 +237,17 @@ getResultRelInfo(Oid partid, PartitionFilterState *state)
226237

227238
ExecOpenIndices(resultRelInfo, state->onConflictAction != ONCONFLICT_NONE);
228239

240+
/* Copy necessary fields from saved ResultRelInfo */
241+
CopyToResultRelInfo(ri_WithCheckOptions);
242+
CopyToResultRelInfo(ri_WithCheckOptionExprs);
243+
CopyToResultRelInfo(ri_junkFilter);
244+
CopyToResultRelInfo(ri_projectReturning);
245+
CopyToResultRelInfo(ri_onConflictSetProj);
246+
CopyToResultRelInfo(ri_onConflictSetWhere);
247+
248+
/* ri_ConstraintExprs will be initialized by ExecRelCheck() */
249+
resultRelInfo->ri_ConstraintExprs = NULL;
250+
229251
resultRelInfoHandle->partid = partid;
230252
resultRelInfoHandle->resultRelInfo = resultRelInfo;
231253
}

src/partition_filter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ typedef struct
2222
Oid partitioned_table;
2323
PartRelationInfo *prel;
2424
OnConflictAction onConflictAction;
25+
ResultRelInfo *savedRelInfo;
2526

2627
Plan *subplan;
2728
Const temp_const; /* temporary const for expr walker */

0 commit comments

Comments
 (0)