MCPcopy Create free account
hub / github.com/documentdb/documentdb / CreateLocalShardInsertPlan

Function CreateLocalShardInsertPlan

pg_documentdb/src/commands/insert.c:1614–1669  ·  view source on GitHub ↗

* CreateLocalShardInsertPlan * * Creates a PlannedStmt for inserting into a local shard table directly. * This avoids planning phase. * * Returns: * PlannedStmt* - The planned statement ready for execution. */

Source from the content-addressed store, hash-verified

1612 * PlannedStmt* - The planned statement ready for execution.
1613 */
1614static PlannedStmt *
1615CreateLocalShardInsertPlan(MongoCollection *collection, Oid shardOid,
1616 List *valuesLists)
1617{
1618 const Cost startupCost = 0.0; /* No startup cost for VALUES scan */
1619 const Cost totalCost = 0.0125; /* Arbitrary small cost for the VALUES scan */
1620 const Cardinality planRows = list_length(valuesLists);
1621 int planWidth = get_relation_data_width(shardOid, NULL);
1622 const Index relationRelId = 1; /* RTE index for the base table */
1623 const Index valueListRelId = 2; /* RTE index for the VALUES list */
1624
1625 PlannedStmt *stmt = makeNode(PlannedStmt);
1626#if PG_VERSION_NUM >= 160000
1627 RangeTblEntry *relationRte = CreateBaseTableRteForInsert(collection, shardOid,
1628 &stmt->permInfos);
1629#else
1630 RangeTblEntry *relationRte = CreateBaseTableRteForInsert(collection, shardOid, NULL);
1631#endif
1632 RangeTblEntry *valuesRte = CreateValueRteForInsert(collection, valuesLists);
1633 List *targetList = CreateTargetListForInsert(collection);
1634
1635
1636 /* Create the ValuesScan node for the VALUES RTE */
1637 ValuesScan *vscan = makeNode(ValuesScan);
1638 vscan->scan.scanrelid = valueListRelId;
1639 vscan->values_lists = copyObject(valuesRte->values_lists);
1640 valuesRte->values_lists = NULL;
1641
1642 Plan *vplan = &vscan->scan.plan;
1643 vplan->startup_cost = startupCost;
1644 vplan->total_cost = totalCost;
1645 vplan->plan_rows = planRows;
1646 vplan->plan_width = planWidth;
1647 vplan->targetlist = targetList;
1648
1649 /* Create the ModifyTable node for the insert operation */
1650 ModifyTable *mt = makeNode(ModifyTable);
1651 mt->operation = CMD_INSERT;
1652 mt->canSetTag = true;
1653 mt->resultRelations = list_make1_int(relationRelId);
1654 mt->plan.lefttree = (Plan *) vscan;
1655 mt->plan.total_cost = totalCost;
1656 mt->plan.plan_rows = planRows;
1657 mt->plan.plan_width = planWidth;
1658 mt->nominalRelation = relationRelId;
1659
1660 /* Fill in the PlannedStmt */
1661 stmt->commandType = CMD_INSERT;
1662 stmt->canSetTag = true;
1663 stmt->planTree = (Plan *) mt;
1664 stmt->rtable = list_make2(relationRte, valuesRte);
1665 stmt->resultRelations = list_make1_int(relationRelId);
1666 stmt->relationOids = list_make1_oid(relationRte->relid);
1667
1668 return stmt;
1669}
1670
1671

Callers 2

ProcessInsertionFunction · 0.85

Calls 3

CreateValueRteForInsertFunction · 0.85

Tested by

no test coverage detected