diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2007-02-22 22:00:26 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2007-02-22 22:00:26 +0000 |
commit | eab6b8b27eba54b8fd0ad3f64989d12200979c96 (patch) | |
tree | ca4fad45c65c60b7900df6e373bd5999993ea2b1 /src/backend/executor | |
parent | 849000c7823d604270094aea76fc530b6cfe9466 (diff) | |
download | postgresql-eab6b8b27eba54b8fd0ad3f64989d12200979c96.tar.gz postgresql-eab6b8b27eba54b8fd0ad3f64989d12200979c96.zip |
Turn the rangetable used by the executor into a flat list, and avoid storing
useless substructure for its RangeTblEntry nodes. (I chose to keep using the
same struct node type and just zero out the link fields for unneeded info,
rather than making a separate ExecRangeTblEntry type --- it seemed too
fragile to have two different rangetable representations.)
Along the way, put subplans into a list in the toplevel PlannedStmt node,
and have SubPlan nodes refer to them by list index instead of direct pointers.
Vadim wanted to do that years ago, but I never understood what he was on about
until now. It makes things a *whole* lot more robust, because we can stop
worrying about duplicate processing of subplans during expression tree
traversals. That's been a constant source of bugs, and it's finally gone.
There are some consequent simplifications yet to be made, like not using
a separate EState for subplans in the executor, but I'll tackle that later.
Diffstat (limited to 'src/backend/executor')
-rw-r--r-- | src/backend/executor/execMain.c | 50 | ||||
-rw-r--r-- | src/backend/executor/execUtils.c | 6 | ||||
-rw-r--r-- | src/backend/executor/nodeFunctionscan.c | 3 | ||||
-rw-r--r-- | src/backend/executor/nodeSubplan.c | 17 | ||||
-rw-r--r-- | src/backend/executor/nodeSubqueryscan.c | 24 | ||||
-rw-r--r-- | src/backend/executor/nodeValuesscan.c | 3 |
6 files changed, 32 insertions, 71 deletions
diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c index 405b58f9fd6..d0df0ea6f47 100644 --- a/src/backend/executor/execMain.c +++ b/src/backend/executor/execMain.c @@ -26,7 +26,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.287 2007/02/20 17:32:14 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.288 2007/02/22 22:00:22 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -92,9 +92,9 @@ static void ExecProcessReturning(ProjectionInfo *projectReturning, DestReceiver *dest); static TupleTableSlot *EvalPlanQualNext(EState *estate); static void EndEvalPlanQual(EState *estate); +static void ExecCheckRTPerms(List *rangeTable); static void ExecCheckRTEPerms(RangeTblEntry *rte); static void ExecCheckXactReadOnly(PlannedStmt *plannedstmt); -static void ExecCheckRangeTblReadOnly(List *rtable); static void EvalPlanQualStart(evalPlanQual *epq, EState *estate, evalPlanQual *priorepq); static void EvalPlanQualStop(evalPlanQual *epq); @@ -348,16 +348,14 @@ ExecutorRewind(QueryDesc *queryDesc) * ExecCheckRTPerms * Check access permissions for all relations listed in a range table. */ -void +static void ExecCheckRTPerms(List *rangeTable) { ListCell *l; foreach(l, rangeTable) { - RangeTblEntry *rte = lfirst(l); - - ExecCheckRTEPerms(rte); + ExecCheckRTEPerms((RangeTblEntry *) lfirst(l)); } } @@ -373,12 +371,9 @@ ExecCheckRTEPerms(RangeTblEntry *rte) Oid userid; /* - * Only plain-relation RTEs need to be checked here. Subquery RTEs are - * checked by ExecInitSubqueryScan if the subquery is still a separate - * subquery --- if it's been pulled up into our query level then the RTEs - * are in our rangetable and will be checked here. Function RTEs are + * Only plain-relation RTEs need to be checked here. Function RTEs are * checked by init_fcache when the function is prepared for execution. - * Join and special RTEs need no checks. + * Join, subquery, and special RTEs need no checks. */ if (rte->rtekind != RTE_RELATION) return; @@ -417,6 +412,8 @@ ExecCheckRTEPerms(RangeTblEntry *rte) static void ExecCheckXactReadOnly(PlannedStmt *plannedstmt) { + ListCell *l; + /* * CREATE TABLE AS or SELECT INTO? * @@ -426,32 +423,9 @@ ExecCheckXactReadOnly(PlannedStmt *plannedstmt) goto fail; /* Fail if write permissions are requested on any non-temp table */ - ExecCheckRangeTblReadOnly(plannedstmt->rtable); - - return; - -fail: - ereport(ERROR, - (errcode(ERRCODE_READ_ONLY_SQL_TRANSACTION), - errmsg("transaction is read-only"))); -} - -static void -ExecCheckRangeTblReadOnly(List *rtable) -{ - ListCell *l; - - /* Fail if write permissions are requested on any non-temp table */ - foreach(l, rtable) + foreach(l, plannedstmt->rtable) { - RangeTblEntry *rte = lfirst(l); - - if (rte->rtekind == RTE_SUBQUERY) - { - Assert(!rte->subquery->into); - ExecCheckRangeTblReadOnly(rte->subquery->rtable); - continue; - } + RangeTblEntry *rte = (RangeTblEntry *) lfirst(l); if (rte->rtekind != RTE_RELATION) continue; @@ -494,9 +468,7 @@ InitPlan(QueryDesc *queryDesc, int eflags) ListCell *l; /* - * Do permissions checks. It's sufficient to examine the query's top - * rangetable here --- subplan RTEs will be checked during - * ExecInitSubPlan(). + * Do permissions checks */ ExecCheckRTPerms(rangeTable); diff --git a/src/backend/executor/execUtils.c b/src/backend/executor/execUtils.c index d9957573883..d188a38489d 100644 --- a/src/backend/executor/execUtils.c +++ b/src/backend/executor/execUtils.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/executor/execUtils.c,v 1.145 2007/02/20 17:32:14 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/executor/execUtils.c,v 1.146 2007/02/22 22:00:22 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -847,7 +847,6 @@ ExecRelationIsTargetRelation(EState *estate, Index scanrelid) Relation ExecOpenScanRelation(EState *estate, Index scanrelid) { - RangeTblEntry *rtentry; Oid reloid; LOCKMODE lockmode; ResultRelInfo *resultRelInfos; @@ -885,8 +884,7 @@ ExecOpenScanRelation(EState *estate, Index scanrelid) } /* OK, open the relation and acquire lock as needed */ - rtentry = rt_fetch(scanrelid, estate->es_range_table); - reloid = rtentry->relid; + reloid = getrelid(scanrelid, estate->es_range_table); return heap_open(reloid, lockmode); } diff --git a/src/backend/executor/nodeFunctionscan.c b/src/backend/executor/nodeFunctionscan.c index d3d9886e3c3..87ac754a1e3 100644 --- a/src/backend/executor/nodeFunctionscan.c +++ b/src/backend/executor/nodeFunctionscan.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/executor/nodeFunctionscan.c,v 1.43 2007/02/19 02:23:11 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/executor/nodeFunctionscan.c,v 1.44 2007/02/22 22:00:23 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -24,7 +24,6 @@ #include "executor/nodeFunctionscan.h" #include "funcapi.h" -#include "parser/parsetree.h" #include "utils/builtins.h" diff --git a/src/backend/executor/nodeSubplan.c b/src/backend/executor/nodeSubplan.c index 32167a94efb..9bc96921f41 100644 --- a/src/backend/executor/nodeSubplan.c +++ b/src/backend/executor/nodeSubplan.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/executor/nodeSubplan.c,v 1.85 2007/02/06 02:59:11 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/executor/nodeSubplan.c,v 1.86 2007/02/22 22:00:23 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -637,14 +637,10 @@ void ExecInitSubPlan(SubPlanState *node, EState *estate, int eflags) { SubPlan *subplan = (SubPlan *) node->xprstate.expr; + Plan *plan = exec_subplan_get_plan(estate->es_plannedstmt, subplan); EState *sp_estate; /* - * Do access checking on the rangetable entries in the subquery. - */ - ExecCheckRTPerms(subplan->rtable); - - /* * initialize my state */ node->needShutdown = false; @@ -668,18 +664,21 @@ ExecInitSubPlan(SubPlanState *node, EState *estate, int eflags) * shares our Param ID space and es_query_cxt, however. XXX if rangetable * access were done differently, the subquery could share our EState, * which would eliminate some thrashing about in this module... + * + * XXX make that happen! */ sp_estate = CreateSubExecutorState(estate); node->sub_estate = sp_estate; - sp_estate->es_range_table = subplan->rtable; + sp_estate->es_range_table = estate->es_range_table; sp_estate->es_param_list_info = estate->es_param_list_info; sp_estate->es_param_exec_vals = estate->es_param_exec_vals; sp_estate->es_tupleTable = - ExecCreateTupleTable(ExecCountSlotsNode(subplan->plan) + 10); + ExecCreateTupleTable(ExecCountSlotsNode(plan) + 10); sp_estate->es_snapshot = estate->es_snapshot; sp_estate->es_crosscheck_snapshot = estate->es_crosscheck_snapshot; sp_estate->es_instrument = estate->es_instrument; + sp_estate->es_plannedstmt = estate->es_plannedstmt; /* * Start up the subplan (this is a very cut-down form of InitPlan()) @@ -692,7 +691,7 @@ ExecInitSubPlan(SubPlanState *node, EState *estate, int eflags) if (subplan->parParam == NIL && subplan->setParam == NIL) eflags |= EXEC_FLAG_REWIND; - node->planstate = ExecInitNode(subplan->plan, sp_estate, eflags); + node->planstate = ExecInitNode(plan, sp_estate, eflags); node->needShutdown = true; /* now we need to shutdown the subplan */ diff --git a/src/backend/executor/nodeSubqueryscan.c b/src/backend/executor/nodeSubqueryscan.c index 24d470d8edd..6d58a8cad4e 100644 --- a/src/backend/executor/nodeSubqueryscan.c +++ b/src/backend/executor/nodeSubqueryscan.c @@ -12,7 +12,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/executor/nodeSubqueryscan.c,v 1.35 2007/01/05 22:19:28 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/executor/nodeSubqueryscan.c,v 1.36 2007/02/22 22:00:23 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -29,7 +29,6 @@ #include "executor/execdebug.h" #include "executor/nodeSubqueryscan.h" -#include "parser/parsetree.h" static TupleTableSlot *SubqueryNext(SubqueryScanState *node); @@ -104,17 +103,18 @@ SubqueryScanState * ExecInitSubqueryScan(SubqueryScan *node, EState *estate, int eflags) { SubqueryScanState *subquerystate; - RangeTblEntry *rte; EState *sp_estate; /* check for unsupported flags */ Assert(!(eflags & EXEC_FLAG_MARK)); /* - * SubqueryScan should not have any "normal" children. + * SubqueryScan should not have any "normal" children. Also, if planner + * left anything in subrtable, it's fishy. */ Assert(outerPlan(node) == NULL); Assert(innerPlan(node) == NULL); + Assert(node->subrtable == NIL); /* * create state structure @@ -152,25 +152,18 @@ ExecInitSubqueryScan(SubqueryScan *node, EState *estate, int eflags) * initialize subquery * * This should agree with ExecInitSubPlan - */ - rte = rt_fetch(node->scan.scanrelid, estate->es_range_table); - Assert(rte->rtekind == RTE_SUBQUERY); - - /* - * Do access checking on the rangetable entries in the subquery. - */ - ExecCheckRTPerms(rte->subquery->rtable); - - /* + * * The subquery needs its own EState because it has its own rangetable. It * shares our Param ID space and es_query_cxt, however. XXX if rangetable * access were done differently, the subquery could share our EState, * which would eliminate some thrashing about in this module... + * + * XXX make that happen! */ sp_estate = CreateSubExecutorState(estate); subquerystate->sss_SubEState = sp_estate; - sp_estate->es_range_table = rte->subquery->rtable; + sp_estate->es_range_table = estate->es_range_table; sp_estate->es_param_list_info = estate->es_param_list_info; sp_estate->es_param_exec_vals = estate->es_param_exec_vals; sp_estate->es_tupleTable = @@ -178,6 +171,7 @@ ExecInitSubqueryScan(SubqueryScan *node, EState *estate, int eflags) sp_estate->es_snapshot = estate->es_snapshot; sp_estate->es_crosscheck_snapshot = estate->es_crosscheck_snapshot; sp_estate->es_instrument = estate->es_instrument; + sp_estate->es_plannedstmt = estate->es_plannedstmt; /* * Start up the subplan (this is a very cut-down form of InitPlan()) diff --git a/src/backend/executor/nodeValuesscan.c b/src/backend/executor/nodeValuesscan.c index 96e4b98a4e2..bfd837e0985 100644 --- a/src/backend/executor/nodeValuesscan.c +++ b/src/backend/executor/nodeValuesscan.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/executor/nodeValuesscan.c,v 1.6 2007/02/19 02:23:11 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/executor/nodeValuesscan.c,v 1.7 2007/02/22 22:00:23 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -25,7 +25,6 @@ #include "executor/executor.h" #include "executor/nodeValuesscan.h" -#include "parser/parsetree.h" #include "utils/memutils.h" |