MCPcopy Create free account
hub / github.com/apache/cloudberry / postgresPlanDirectModify

Function postgresPlanDirectModify

contrib/postgres_fdw/postgres_fdw.c:2436–2628  ·  view source on GitHub ↗

* postgresPlanDirectModify * Consider a direct foreign table modification * * Decide whether it is safe to modify a foreign table directly, and if so, * rewrite subplan accordingly. */

Source from the content-addressed store, hash-verified

2434 * rewrite subplan accordingly.
2435 */
2436static bool
2437postgresPlanDirectModify(PlannerInfo *root,
2438 ModifyTable *plan,
2439 Index resultRelation,
2440 int subplan_index)
2441{
2442 CmdType operation = plan->operation;
2443 RelOptInfo *foreignrel;
2444 RangeTblEntry *rte;
2445 PgFdwRelationInfo *fpinfo;
2446 Relation rel;
2447 StringInfoData sql;
2448 ForeignScan *fscan;
2449 List *processed_tlist = NIL;
2450 List *targetAttrs = NIL;
2451 List *remote_exprs;
2452 List *params_list = NIL;
2453 List *returningList = NIL;
2454 List *retrieved_attrs = NIL;
2455
2456 /*
2457 * Decide whether it is safe to modify a foreign table directly.
2458 */
2459
2460 /*
2461 * The table modification must be an UPDATE or DELETE.
2462 */
2463 if (operation != CMD_UPDATE && operation != CMD_DELETE)
2464 return false;
2465
2466 /*
2467 * Try to locate the ForeignScan subplan that's scanning resultRelation.
2468 */
2469 fscan = find_modifytable_subplan(root, plan, resultRelation, subplan_index);
2470 if (!fscan)
2471 return false;
2472
2473 /*
2474 * It's unsafe to modify a foreign table directly if there are any quals
2475 * that should be evaluated locally.
2476 */
2477 if (fscan->scan.plan.qual != NIL)
2478 return false;
2479
2480 /* Safe to fetch data about the target foreign rel */
2481 if (fscan->scan.scanrelid == 0)
2482 {
2483 foreignrel = find_join_rel(root, fscan->fs_relids);
2484 /* We should have a rel for this foreign join. */
2485 Assert(foreignrel);
2486 }
2487 else
2488 foreignrel = root->simple_rel_array[resultRelation];
2489 rte = root->simple_rte_array[resultRelation];
2490 fpinfo = (PgFdwRelationInfo *) foreignrel->fdw_private;
2491
2492 /*
2493 * It's unsafe to update a foreign table directly, if any expressions to

Callers

nothing calls this directly

Calls 15

find_modifytable_subplanFunction · 0.85
find_join_relFunction · 0.85
forbothFunction · 0.85
is_foreign_exprFunction · 0.85
initStringInfoFunction · 0.85
table_openFunction · 0.85
list_nthFunction · 0.85
build_remote_returningFunction · 0.85
deparseDirectUpdateSqlFunction · 0.85
deparseDirectDeleteSqlFunction · 0.85
makeStringFunction · 0.85

Tested by

no test coverage detected