diff options
| author | Tom Lane | 2009-10-10 01:43:50 +0000 |
|---|---|---|
| committer | Tom Lane | 2009-10-10 01:43:50 +0000 |
| commit | 8a5849b7ff24c637a1140c26fc171e45c9142005 (patch) | |
| tree | 8f660c08709c999c3a4299436312390c53231b01 /src/include | |
| parent | b865d2758255b767e30dc5f23c7c7d209e716f3b (diff) | |
Split the processing of INSERT/UPDATE/DELETE operations out of execMain.c.
They are now handled by a new plan node type called ModifyTable, which is
placed at the top of the plan tree. In itself this change doesn't do much,
except perhaps make the handling of RETURNING lists and inherited UPDATEs a
tad less klugy. But it is necessary preparation for the intended extension of
allowing RETURNING queries inside WITH.
Marko Tiikkaja
Diffstat (limited to 'src/include')
| -rw-r--r-- | src/include/commands/trigger.h | 4 | ||||
| -rw-r--r-- | src/include/executor/executor.h | 3 | ||||
| -rw-r--r-- | src/include/executor/nodeModifyTable.h | 23 | ||||
| -rw-r--r-- | src/include/nodes/execnodes.h | 24 | ||||
| -rw-r--r-- | src/include/nodes/nodes.h | 4 | ||||
| -rw-r--r-- | src/include/nodes/plannodes.h | 38 | ||||
| -rw-r--r-- | src/include/nodes/relation.h | 4 | ||||
| -rw-r--r-- | src/include/optimizer/planmain.h | 6 |
8 files changed, 71 insertions, 35 deletions
diff --git a/src/include/commands/trigger.h b/src/include/commands/trigger.h index c92337a5a1..94cb061959 100644 --- a/src/include/commands/trigger.h +++ b/src/include/commands/trigger.h @@ -6,7 +6,7 @@ * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/commands/trigger.h,v 1.75 2009/07/29 20:56:20 tgl Exp $ + * $PostgreSQL: pgsql/src/include/commands/trigger.h,v 1.76 2009/10/10 01:43:50 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -139,6 +139,7 @@ extern void ExecBSDeleteTriggers(EState *estate, extern void ExecASDeleteTriggers(EState *estate, ResultRelInfo *relinfo); extern bool ExecBRDeleteTriggers(EState *estate, + PlanState *subplanstate, ResultRelInfo *relinfo, ItemPointer tupleid); extern void ExecARDeleteTriggers(EState *estate, @@ -149,6 +150,7 @@ extern void ExecBSUpdateTriggers(EState *estate, extern void ExecASUpdateTriggers(EState *estate, ResultRelInfo *relinfo); extern HeapTuple ExecBRUpdateTriggers(EState *estate, + PlanState *subplanstate, ResultRelInfo *relinfo, ItemPointer tupleid, HeapTuple newtuple); diff --git a/src/include/executor/executor.h b/src/include/executor/executor.h index 69fbb932fe..cb79e26976 100644 --- a/src/include/executor/executor.h +++ b/src/include/executor/executor.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/executor/executor.h,v 1.160 2009/09/27 21:10:53 tgl Exp $ + * $PostgreSQL: pgsql/src/include/executor/executor.h,v 1.161 2009/10/10 01:43:50 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -167,6 +167,7 @@ extern bool ExecContextForcesOids(PlanState *planstate, bool *hasoids); extern void ExecConstraints(ResultRelInfo *resultRelInfo, TupleTableSlot *slot, EState *estate); extern TupleTableSlot *EvalPlanQual(EState *estate, Index rti, + PlanState *subplanstate, ItemPointer tid, TransactionId priorXmax); extern PlanState *ExecGetActivePlanTree(QueryDesc *queryDesc); extern DestReceiver *CreateIntoRelDestReceiver(void); diff --git a/src/include/executor/nodeModifyTable.h b/src/include/executor/nodeModifyTable.h new file mode 100644 index 0000000000..e9662d4cf8 --- /dev/null +++ b/src/include/executor/nodeModifyTable.h @@ -0,0 +1,23 @@ +/*------------------------------------------------------------------------- + * + * nodeModifyTable.h + * + * + * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * $PostgreSQL: pgsql/src/include/executor/nodeModifyTable.h,v 1.1 2009/10/10 01:43:50 tgl Exp $ + * + *------------------------------------------------------------------------- + */ +#ifndef NODEMODIFYTABLE_H +#define NODEMODIFYTABLE_H + +#include "nodes/execnodes.h" + +extern ModifyTableState *ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags); +extern TupleTableSlot *ExecModifyTable(ModifyTableState *node); +extern void ExecEndModifyTable(ModifyTableState *node); +extern void ExecReScanModifyTable(ModifyTableState *node, ExprContext *exprCtxt); + +#endif /* NODEMODIFYTABLE_H */ diff --git a/src/include/nodes/execnodes.h b/src/include/nodes/execnodes.h index ea66e109c1..264ef741da 100644 --- a/src/include/nodes/execnodes.h +++ b/src/include/nodes/execnodes.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/nodes/execnodes.h,v 1.208 2009/09/27 20:09:58 tgl Exp $ + * $PostgreSQL: pgsql/src/include/nodes/execnodes.h,v 1.209 2009/10/10 01:43:50 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -339,7 +339,7 @@ typedef struct EState ResultRelInfo *es_result_relations; /* array of ResultRelInfos */ int es_num_result_relations; /* length of array */ ResultRelInfo *es_result_relation_info; /* currently active array elt */ - JunkFilter *es_junkFilter; /* currently active junk filter */ + JunkFilter *es_junkFilter; /* top-level junk filter, if any */ /* Stuff used for firing triggers: */ List *es_trig_target_relations; /* trigger-only ResultRelInfos */ @@ -976,12 +976,24 @@ typedef struct ResultState } ResultState; /* ---------------- + * ModifyTableState information + * ---------------- + */ +typedef struct ModifyTableState +{ + PlanState ps; /* its first field is NodeTag */ + CmdType operation; + PlanState **mt_plans; /* subplans (one per target rel) */ + int mt_nplans; /* number of plans in the array */ + int mt_whichplan; /* which one is being executed (0..n-1) */ + bool fireBSTriggers; /* do we need to fire stmt triggers? */ +} ModifyTableState; + +/* ---------------- * AppendState information * - * nplans how many plans are in the list + * nplans how many plans are in the array * whichplan which plan is being executed (0 .. n-1) - * firstplan first plan to execute (usually 0) - * lastplan last plan to execute (usually n-1) * ---------------- */ typedef struct AppendState @@ -990,8 +1002,6 @@ typedef struct AppendState PlanState **appendplans; /* array of PlanStates for my inputs */ int as_nplans; int as_whichplan; - int as_firstplan; - int as_lastplan; } AppendState; /* ---------------- diff --git a/src/include/nodes/nodes.h b/src/include/nodes/nodes.h index 2a4468799f..53c406cc51 100644 --- a/src/include/nodes/nodes.h +++ b/src/include/nodes/nodes.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/nodes/nodes.h,v 1.228 2009/10/08 02:39:24 tgl Exp $ + * $PostgreSQL: pgsql/src/include/nodes/nodes.h,v 1.229 2009/10/10 01:43:50 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -43,6 +43,7 @@ typedef enum NodeTag */ T_Plan = 100, T_Result, + T_ModifyTable, T_Append, T_RecursiveUnion, T_BitmapAnd, @@ -81,6 +82,7 @@ typedef enum NodeTag */ T_PlanState = 200, T_ResultState, + T_ModifyTableState, T_AppendState, T_RecursiveUnionState, T_BitmapAndState, diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h index 44f14140f4..26b0fc3335 100644 --- a/src/include/nodes/plannodes.h +++ b/src/include/nodes/plannodes.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/nodes/plannodes.h,v 1.110 2009/06/11 14:49:11 momjian Exp $ + * $PostgreSQL: pgsql/src/include/nodes/plannodes.h,v 1.111 2009/10/10 01:43:50 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -38,6 +38,8 @@ typedef struct PlannedStmt CmdType commandType; /* select|insert|update|delete */ + bool hasReturning; /* is it insert|update|delete RETURNING? */ + bool canSetTag; /* do I set the command result tag? */ bool transientPlan; /* redo plan when TransactionXmin changes? */ @@ -57,18 +59,6 @@ typedef struct PlannedStmt Bitmapset *rewindPlanIDs; /* indices of subplans that require REWIND */ - /* - * If the query has a returningList then the planner will store a list of - * processed targetlists (one per result relation) here. We must have a - * separate RETURNING targetlist for each result rel because column - * numbers may vary within an inheritance tree. In the targetlists, Vars - * referencing the result relation will have their original varno and - * varattno, while Vars referencing other rels will be converted to have - * varno OUTER and varattno referencing a resjunk entry in the top plan - * node's targetlist. - */ - List *returningLists; /* list of lists of TargetEntry, or NIL */ - List *rowMarks; /* a list of RowMarkClause's */ List *relationOids; /* OIDs of relations the plan depends on */ @@ -165,21 +155,29 @@ typedef struct Result } Result; /* ---------------- + * ModifyTable node - + * Apply rows produced by subplan(s) to result table(s), + * by inserting, updating, or deleting. + * ---------------- + */ +typedef struct ModifyTable +{ + Plan plan; + CmdType operation; /* INSERT, UPDATE, or DELETE */ + List *resultRelations; /* integer list of RT indexes */ + List *plans; /* plan(s) producing source data */ + List *returningLists; /* per-target-table RETURNING tlists */ +} ModifyTable; + +/* ---------------- * Append node - * Generate the concatenation of the results of sub-plans. - * - * Append nodes are sometimes used to switch between several result relations - * (when the target of an UPDATE or DELETE is an inheritance set). Such a - * node will have isTarget true. The Append executor is then responsible - * for updating the executor state to point at the correct target relation - * whenever it switches subplans. * ---------------- */ typedef struct Append { Plan plan; List *appendplans; - bool isTarget; } Append; /* ---------------- diff --git a/src/include/nodes/relation.h b/src/include/nodes/relation.h index 9b59d63b2b..5e504b0ab4 100644 --- a/src/include/nodes/relation.h +++ b/src/include/nodes/relation.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/nodes/relation.h,v 1.175 2009/09/17 20:49:29 tgl Exp $ + * $PostgreSQL: pgsql/src/include/nodes/relation.h,v 1.176 2009/10/10 01:43:50 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -140,8 +140,6 @@ typedef struct PlannerInfo List *resultRelations; /* integer list of RT indexes, or NIL */ - List *returningLists; /* list of lists of TargetEntry, or NIL */ - List *init_plans; /* init SubPlans for query */ List *cte_plan_ids; /* per-CTE-item list of subplan IDs */ diff --git a/src/include/optimizer/planmain.h b/src/include/optimizer/planmain.h index 3ffd80003a..1e27bd847c 100644 --- a/src/include/optimizer/planmain.h +++ b/src/include/optimizer/planmain.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/optimizer/planmain.h,v 1.118 2009/06/11 14:49:11 momjian Exp $ + * $PostgreSQL: pgsql/src/include/optimizer/planmain.h,v 1.119 2009/10/10 01:43:50 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -41,7 +41,7 @@ extern Plan *optimize_minmax_aggregates(PlannerInfo *root, List *tlist, extern Plan *create_plan(PlannerInfo *root, Path *best_path); extern SubqueryScan *make_subqueryscan(List *qptlist, List *qpqual, Index scanrelid, Plan *subplan, List *subrtable); -extern Append *make_append(List *appendplans, bool isTarget, List *tlist); +extern Append *make_append(List *appendplans, List *tlist); extern RecursiveUnion *make_recursive_union(List *tlist, Plan *lefttree, Plan *righttree, int wtParam, List *distinctList, long numGroups); @@ -74,6 +74,8 @@ extern SetOp *make_setop(SetOpCmd cmd, SetOpStrategy strategy, Plan *lefttree, long numGroups, double outputRows); extern Result *make_result(PlannerInfo *root, List *tlist, Node *resconstantqual, Plan *subplan); +extern ModifyTable *make_modifytable(CmdType operation, List *resultRelations, + List *subplans, List *returningLists); extern bool is_projection_capable_plan(Plan *plan); /* |
