Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9d7980a

Browse files
committed
Fix partition router running
1 parent f18aa52 commit 9d7980a

File tree

2 files changed

+26
-40
lines changed

2 files changed

+26
-40
lines changed

src/partition_overseer.c

+20-21
Original file line numberDiff line numberDiff line change
@@ -68,25 +68,24 @@ partition_overseer_create_scan_state(CustomScan *node)
6868
static void
6969
set_mt_state_for_router(PlanState *state, void *context)
7070
{
71-
if (IsA(state, ModifyTableState))
72-
{
73-
ModifyTableState *mt_state = (ModifyTableState *) state;
74-
int i;
75-
76-
for (i = 0; i < mt_state->mt_nplans; i++)
77-
{
78-
CustomScanState *pf_state = (CustomScanState *) mt_state->mt_plans[i];
79-
PartitionRouterState *pr_state;
80-
81-
/* Check if this is a PartitionFilter + PartitionRouter combo */
82-
if (IsPartitionFilterState(pf_state) &&
83-
IsPartitionRouterState(pr_state = linitial(pf_state->custom_ps)))
84-
{
85-
/* HACK: point to ModifyTable in PartitionRouter */
86-
pr_state->mt_state = mt_state;
87-
}
88-
}
89-
}
71+
ModifyTableState *mt_state = (ModifyTableState *) state;
72+
73+
if (!IsA(state, ModifyTableState))
74+
return;
75+
76+
for (int i = 0; i < mt_state->mt_nplans; i++)
77+
{
78+
CustomScanState *pf_state = (CustomScanState *) mt_state->mt_plans[i];
79+
PartitionRouterState *pr_state;
80+
81+
/* Check if this is a PartitionFilter + PartitionRouter combo */
82+
if (IsPartitionFilterState(pf_state) &&
83+
IsPartitionRouterState(pr_state = linitial(pf_state->custom_ps)))
84+
{
85+
/* HACK: point to ModifyTable in PartitionRouter */
86+
pr_state->mt_state = mt_state;
87+
}
88+
}
9089
}
9190

9291
void
@@ -119,7 +118,7 @@ partition_overseer_exec(CustomScanState *node)
119118
mt_plans_old = mt_state->mt_nplans;
120119

121120
restart:
122-
/* Fetch next tuple */
121+
/* Run ModifyTable */
123122
slot = ExecProcNode((PlanState *) mt_state);
124123

125124
/* Get current signal */
@@ -136,7 +135,7 @@ partition_overseer_exec(CustomScanState *node)
136135
MTHackField(mt_state, mt_nplans) = mt_plans_old;
137136
MTHackField(mt_state, mt_whichplan) = state_idx;
138137

139-
/* Restart ModifyTable */
138+
/* Rerun ModifyTable */
140139
goto restart;
141140
}
142141

src/partition_router.c

+6-19
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ static TupleTableSlot *router_set_slot(PartitionRouterState *state,
6363
static TupleTableSlot *router_get_slot(PartitionRouterState *state,
6464
bool *should_process);
6565

66-
static void router_lazy_init_junkfilter(PartitionRouterState *state);
6766
static void router_lazy_init_constraint(PartitionRouterState *state);
6867

6968
static ItemPointerData router_extract_ctid(PartitionRouterState *state,
@@ -185,8 +184,9 @@ partition_router_exec(CustomScanState *node)
185184

186185
ItemPointerSetInvalid(&ctid);
187186

188-
/* Build new junkfilter lazily */
189-
router_lazy_init_junkfilter(state);
187+
/* Build new junkfilter if needed */
188+
if (state->junkfilter == NULL)
189+
state->junkfilter = state->current_rri->ri_junkFilter;
190190

191191
/* Build recheck constraint state lazily */
192192
router_lazy_init_constraint(state);
@@ -257,15 +257,14 @@ router_set_slot(PartitionRouterState *state,
257257
MTHackField(mt_state, mt_nplans) = -mt_state->mt_whichplan;
258258
MTHackField(mt_state, operation) = operation;
259259

260+
/* HACK: disable AFTER STATEMENT triggers */
261+
MTDisableStmtTriggers(mt_state, state);
262+
260263
if (!TupIsNull(slot))
261264
{
262265
/* We should've cached junk filter already */
263266
Assert(state->junkfilter);
264267

265-
/* HACK: disable AFTER STATEMENT triggers */
266-
MTDisableStmtTriggers(mt_state, state);
267-
268-
269268
/* HACK: conditionally disable junk filter in result relation */
270269
state->current_rri->ri_junkFilter = (operation == CMD_UPDATE) ?
271270
state->junkfilter :
@@ -276,11 +275,6 @@ router_set_slot(PartitionRouterState *state,
276275
slot->tts_tupleDescriptor);
277276
ExecCopySlot(state->yielded_slot, slot);
278277
}
279-
else
280-
{
281-
/* HACK: enable AFTER STATEMENT triggers */
282-
MTEnableStmtTriggers(mt_state, state);
283-
}
284278

285279
/* Yield */
286280
state->yielded = true;
@@ -324,13 +318,6 @@ router_get_slot(PartitionRouterState *state,
324318
return slot;
325319
}
326320

327-
static void
328-
router_lazy_init_junkfilter(PartitionRouterState *state)
329-
{
330-
if (state->junkfilter == NULL)
331-
state->junkfilter = state->current_rri->ri_junkFilter;
332-
}
333-
334321
static void
335322
router_lazy_init_constraint(PartitionRouterState *state)
336323
{

0 commit comments

Comments
 (0)