Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitd1255a5

Browse files
committed
WIP various changes due to EPQ
1 parent784170a commitd1255a5

File tree

4 files changed

+83
-74
lines changed

4 files changed

+83
-74
lines changed

‎src/include/partition_router.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ typedef struct PartitionRouterState
3232

3333
Oidpartitioned_table;
3434
JunkFilter*junkfilter;
35+
EPQStateepqstate;
36+
intepqparam;
3537
Plan*subplan;/* proxy variable to store subplan */
3638
}PartitionRouterState;
3739

@@ -64,6 +66,7 @@ void init_partition_router_static_data(void);
6466
Plan*make_partition_router(Plan*subplan,
6567
Oidparent_relid,
6668
Indexparent_rti,
69+
intepq_param,
6770
List*returning_list);
6871

6972

‎src/partition_filter.c

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static Node *fix_returning_list_mutator(Node *node, void *state);
8787
staticIndexappend_rte_to_estate(EState*estate,RangeTblEntry*rte);
8888
staticintappend_rri_to_estate(EState*estate,ResultRelInfo*rri);
8989

90-
staticList*pfilter_build_tlist(Relationparent_rel,Plan*subplan);
90+
staticList*pfilter_build_tlist(Plan*subplan);
9191

9292
staticvoidpf_memcxt_callback(void*arg);
9393
staticestate_mod_data*fetch_estate_mod_data(EState*estate);
@@ -637,7 +637,6 @@ make_partition_filter(Plan *subplan,
637637
CmdTypecommand_type)
638638
{
639639
CustomScan*cscan=makeNode(CustomScan);
640-
Relationparent_rel;
641640

642641
/* Currently we don't support ON CONFLICT clauses */
643642
if (conflict_action!=ONCONFLICT_NONE)
@@ -655,14 +654,12 @@ make_partition_filter(Plan *subplan,
655654
cscan->methods=&partition_filter_plan_methods;
656655
cscan->custom_plans=list_make1(subplan);
657656

658-
/* Build an appropriate target list using a cached Relation entry */
659-
parent_rel=RelationIdGetRelation(parent_relid);
660-
cscan->scan.plan.targetlist=pfilter_build_tlist(parent_rel,subplan);
661-
RelationClose(parent_rel);
662-
663657
/* No physical relation will be scanned */
664658
cscan->scan.scanrelid=0;
665659

660+
/* Build an appropriate target list */
661+
cscan->scan.plan.targetlist=pfilter_build_tlist(subplan);
662+
666663
/* Prepare 'custom_scan_tlist' for EXPLAIN (VERBOSE) */
667664
cscan->custom_scan_tlist=copyObject(cscan->scan.plan.targetlist);
668665
ChangeVarNodes((Node*)cscan->custom_scan_tlist,INDEX_VAR,parent_rti,0);
@@ -830,44 +827,37 @@ partition_filter_explain(CustomScanState *node, List *ancestors, ExplainState *e
830827
* Build partition filter's target list pointing to subplan tuple's elements.
831828
*/
832829
staticList*
833-
pfilter_build_tlist(Relationparent_rel,Plan*subplan)
830+
pfilter_build_tlist(Plan*subplan)
834831
{
835832
List*result_tlist=NIL;
836833
ListCell*lc;
837834

838835
foreach (lc,subplan->targetlist)
839836
{
840-
TargetEntry*tle= (TargetEntry*)lfirst(lc),
841-
*newtle=NULL;
837+
TargetEntry*tle= (TargetEntry*)lfirst(lc),
838+
*newtle=NULL;
842839

843840
if (IsA(tle->expr,Const))
844-
newtle=makeTargetEntry(copyObject(tle->expr),tle->resno,tle->resname,
845-
tle->resjunk);
846-
841+
{
842+
/* TODO: maybe we should use copyObject(tle->expr)? */
843+
newtle=makeTargetEntry(tle->expr,
844+
tle->resno,
845+
tle->resname,
846+
tle->resjunk);
847+
}
847848
else
848849
{
849-
if (tle->expr!=NULL&&IsA(tle->expr,Var))
850-
{
851-
Var*var= (Var*)palloc(sizeof(Var));
852-
*var=*((Var*)(tle->expr));
853-
var->varno=INDEX_VAR;
854-
var->varattno=tle->resno;
855-
856-
newtle=makeTargetEntry((Expr*)var,tle->resno,tle->resname,
857-
tle->resjunk);
858-
}
859-
else
860-
{
861-
Var*var=makeVar(INDEX_VAR,/* point to subplan's elements */
862-
tle->resno,
863-
exprType((Node*)tle->expr),
864-
exprTypmod((Node*)tle->expr),
865-
exprCollation((Node*)tle->expr),
866-
0);
867-
868-
newtle=makeTargetEntry((Expr*)var,tle->resno,tle->resname,
869-
tle->resjunk);
870-
}
850+
Var*var=makeVar(INDEX_VAR,/* point to subplan's elements */
851+
tle->resno,
852+
exprType((Node*)tle->expr),
853+
exprTypmod((Node*)tle->expr),
854+
exprCollation((Node*)tle->expr),
855+
0);
856+
857+
newtle=makeTargetEntry((Expr*)var,
858+
tle->resno,
859+
tle->resname,
860+
tle->resjunk);
871861
}
872862

873863
result_tlist=lappend(result_tlist,newtle);

‎src/partition_router.c

Lines changed: 49 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ boolpg_pathman_enable_partition_router = true;
2828
CustomScanMethodspartition_router_plan_methods;
2929
CustomExecMethodspartition_router_exec_methods;
3030

31-
staticTupleTableSlot*ExecDeleteInternal(ItemPointertupleid,
32-
EPQState*epqstate,
33-
EState*estate);
31+
staticboolExecDeleteInternal(ItemPointertupleid,
32+
EPQState*epqstate,
33+
EState*estate);
3434

3535
void
3636
init_partition_router_static_data(void)
@@ -65,6 +65,7 @@ Plan *
6565
make_partition_router(Plan*subplan,
6666
Oidparent_relid,
6767
Indexparent_rti,
68+
intepq_param,
6869
List*returning_list)
6970

7071
{
@@ -85,16 +86,17 @@ make_partition_router(Plan *subplan,
8586
cscan->scan.plan.plan_rows=subplan->plan_rows;
8687
cscan->scan.plan.plan_width=subplan->plan_width;
8788

88-
/* Setup methods andchild plan */
89+
/* Setup methods,child plan and param number for EPQ */
8990
cscan->methods=&partition_router_plan_methods;
9091
cscan->custom_plans=list_make1(pfilter);
91-
92-
/* Build an appropriate target list */
93-
cscan->scan.plan.targetlist=pfilter->targetlist;
92+
cscan->custom_private=list_make1(makeInteger(epq_param));
9493

9594
/* No physical relation will be scanned */
9695
cscan->scan.scanrelid=0;
9796

97+
/* Build an appropriate target list */
98+
cscan->scan.plan.targetlist=pfilter->targetlist;
99+
98100
/* FIXME: should we use the same tlist? */
99101
cscan->custom_scan_tlist=subplan->targetlist;
100102

@@ -113,7 +115,9 @@ partition_router_create_scan_state(CustomScan *node)
113115
state->css.methods=&partition_router_exec_methods;
114116

115117
/* Extract necessary variables */
118+
state->epqparam=intVal(linitial(node->custom_private));
116119
state->subplan= (Plan*)linitial(node->custom_plans);
120+
117121
return (Node*)state;
118122
}
119123

@@ -122,6 +126,10 @@ partition_router_begin(CustomScanState *node, EState *estate, int eflags)
122126
{
123127
PartitionRouterState*state= (PartitionRouterState*)node;
124128

129+
EvalPlanQualInit(&state->epqstate,estate,
130+
state->subplan,NIL,
131+
state->epqparam);
132+
125133
/* It's convenient to store PlanState in 'custom_ps' */
126134
node->custom_ps=list_make1(ExecInitNode(state->subplan,estate,eflags));
127135
}
@@ -134,14 +142,14 @@ partition_router_exec(CustomScanState *node)
134142
TupleTableSlot*slot;
135143
PartitionRouterState*state= (PartitionRouterState*)node;
136144

145+
take_next_tuple:
137146
/* execute PartitionFilter child node */
138147
slot=ExecProcNode(child_ps);
139148

140149
if (!TupIsNull(slot))
141150
{
142151
ResultRelInfo*new_rri,/* new tuple owner */
143152
*old_rri;/* previous tuple owner */
144-
EPQStateepqstate;
145153
PartitionFilterState*child_state;
146154
charrelkind;
147155
ItemPointerDatactid;
@@ -203,8 +211,12 @@ partition_router_exec(CustomScanState *node)
203211

204212
/* Delete tuple from old partition */
205213
Assert(ItemPointerIsValid(&ctid));
206-
EvalPlanQualSetSlot(&epqstate,child_state->subplan_slot);
207-
ExecDeleteInternal(&ctid,&epqstate,estate);
214+
EvalPlanQualSetSlot(&state->epqstate,child_state->subplan_slot);
215+
if (!ExecDeleteInternal(&ctid,&state->epqstate,estate))
216+
{
217+
elog(INFO,"oops, deleted, taking next tuple!");
218+
gototake_next_tuple;
219+
}
208220

209221
/* Magic: replace parent's ResultRelInfo with child's one (INSERT) */
210222
estate->es_result_relation_info=new_rri;
@@ -244,40 +256,42 @@ partition_router_explain(CustomScanState *node, List *ancestors, ExplainState *e
244256
* ----------------------------------------------------------------
245257
*/
246258

247-
staticTupleTableSlot*
259+
staticbool
248260
ExecDeleteInternal(ItemPointertupleid,
249261
EPQState*epqstate,
250262
EState*estate)
251263
{
252-
ResultRelInfo*resultRelInfo;
253-
RelationresultRelationDesc;
264+
ResultRelInfo*rri;
265+
Relationrel;
254266
HTSU_Resultresult;
255267
HeapUpdateFailureDatahufd;
256268

257269
/*
258270
* get information on the (current) result relation
259271
*/
260-
resultRelInfo=estate->es_result_relation_info;
261-
resultRelationDesc=resultRelInfo->ri_RelationDesc;
272+
rri=estate->es_result_relation_info;
273+
rel=rri->ri_RelationDesc;
262274

263-
/* BEFORE ROWDELETE Triggers */
264-
if (resultRelInfo->ri_TrigDesc&&
265-
resultRelInfo->ri_TrigDesc->trig_delete_before_row)
275+
/* BEFORE ROWUPDATE triggers */
276+
if (rri->ri_TrigDesc&&
277+
rri->ri_TrigDesc->trig_update_before_row)
266278
{
267-
booldodelete;
268-
269-
dodelete=ExecBRDeleteTriggers(estate,epqstate,resultRelInfo,
270-
tupleid,NULL);
279+
elog(INFO,"kek!");
280+
}
271281

272-
if (!dodelete)
273-
elog(ERROR,"the old row always should be deleted from child table");
282+
/* BEFORE ROW DELETE triggers */
283+
if (rri->ri_TrigDesc&&
284+
rri->ri_TrigDesc->trig_delete_before_row)
285+
{
286+
if (!ExecBRDeleteTriggers(estate,epqstate,rri,tupleid,NULL))
287+
return false;
274288
}
275289

276290
if (tupleid!=NULL)
277291
{
278292
/* delete the tuple */
279293
ldelete:
280-
result=heap_delete_compat(resultRelationDesc,tupleid,
294+
result=heap_delete_compat(rel,tupleid,
281295
estate->es_output_cid,
282296
estate->es_crosscheck_snapshot,
283297
true/* wait for commit */ ,
@@ -292,7 +306,7 @@ ExecDeleteInternal(ItemPointer tupleid,
292306
errhint("Consider using an AFTER trigger instead of a BEFORE trigger to propagate changes to other rows.")));
293307

294308
/* Else, already deleted by self; nothing to do */
295-
returnNULL;
309+
returnfalse;
296310

297311
caseHeapTupleMayBeUpdated:
298312
break;
@@ -302,37 +316,39 @@ ExecDeleteInternal(ItemPointer tupleid,
302316
ereport(ERROR,
303317
(errcode(ERRCODE_T_R_SERIALIZATION_FAILURE),
304318
errmsg("could not serialize access due to concurrent update")));
319+
305320
if (!ItemPointerEquals(tupleid,&hufd.ctid))
306321
{
307322
TupleTableSlot*epqslot;
308323

309324
epqslot=EvalPlanQual(estate,
310325
epqstate,
311-
resultRelationDesc,
312-
resultRelInfo->ri_RangeTableIndex,
326+
rel,
327+
rri->ri_RangeTableIndex,
313328
LockTupleExclusive,
314329
&hufd.ctid,
315330
hufd.xmax);
331+
316332
if (!TupIsNull(epqslot))
317333
{
318334
Assert(tupleid!=NULL);
319335
*tupleid=hufd.ctid;
320336
gotoldelete;
321337
}
322338
}
339+
323340
/* tuple already deleted; nothing to do */
324-
returnNULL;
341+
returnfalse;
325342

326343
default:
327344
elog(ERROR,"unrecognized heap_delete status: %u",result);
328-
returnNULL;
329345
}
330346
}
331347
else
332348
elog(ERROR,"tupleid should be specified for deletion");
333349

334-
/* AFTER ROW DELETETriggers */
335-
ExecARDeleteTriggersCompat(estate,resultRelInfo,tupleid,NULL,NULL);
350+
/* AFTER ROW DELETEtriggers */
351+
ExecARDeleteTriggersCompat(estate,rri,tupleid,NULL,NULL);
336352

337-
returnNULL;
353+
returntrue;
338354
}

‎src/planner_tree_modification.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -666,15 +666,14 @@ partition_router_visitor(Plan *plan, void *context)
666666

667667
if (modifytable_contains_fdw(rtable,modify_table))
668668
{
669-
ereport(NOTICE,
670-
(errcode(ERRCODE_STATEMENT_TOO_COMPLEX),
671-
errmsg("discovered mix of local and foreign tables, "
672-
UPDATE_NODE_NAME" will be disabled")));
673-
return;
669+
ereport(ERROR,
670+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
671+
errmsg(UPDATE_NODE_NAME" does not support foreign data wrappers")));
674672
}
675673

676674
lc3=list_head(modify_table->returningLists);
677-
forboth (lc1,modify_table->plans,lc2,modify_table->resultRelations)
675+
forboth (lc1,modify_table->plans,
676+
lc2,modify_table->resultRelations)
678677
{
679678
Indexrindex=lfirst_int(lc2);
680679
Oidrelid=getrelid(rindex,rtable),
@@ -698,6 +697,7 @@ partition_router_visitor(Plan *plan, void *context)
698697

699698
lfirst(lc1)=make_partition_router((Plan*)lfirst(lc1),relid,
700699
modify_table->nominalRelation,
700+
modify_table->epqParam,
701701
returning_list);
702702
}
703703
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp