Commit e81ad79d authored by Tom Lane's avatar Tom Lane

Don't call ExecOpenIndices if pg_class relhasindex shows there are no

indexes to open.  Avoid unnecessary work in ExecCheckPerm, too.
parent d40dbb73
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.98 1999/10/30 23:13:30 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.99 1999/11/01 05:09:17 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -383,19 +383,17 @@ ExecCheckPerms(CmdType operation, ...@@ -383,19 +383,17 @@ ExecCheckPerms(CmdType operation,
List *rangeTable, List *rangeTable,
Query *parseTree) Query *parseTree)
{ {
int i = 1; int rtindex = 0;
Oid relid;
HeapTuple htup;
List *lp; List *lp;
List *qvars, List *qvars,
*tvars; *tvars;
int32 ok = 1, int32 ok = 1,
aclcheck_result = -1; aclcheck_result = -1;
char *opstr; char *opstr;
NameData rname; char *relName = NULL;
char *userName; char *userName;
#define CHECK(MODE) pg_aclcheck(rname.data, userName, MODE) #define CHECK(MODE) pg_aclcheck(relName, userName, MODE)
userName = GetPgUserName(); userName = GetPgUserName();
...@@ -403,6 +401,8 @@ ExecCheckPerms(CmdType operation, ...@@ -403,6 +401,8 @@ ExecCheckPerms(CmdType operation,
{ {
RangeTblEntry *rte = lfirst(lp); RangeTblEntry *rte = lfirst(lp);
++rtindex;
if (rte->skipAcl) if (rte->skipAcl)
{ {
...@@ -415,16 +415,8 @@ ExecCheckPerms(CmdType operation, ...@@ -415,16 +415,8 @@ ExecCheckPerms(CmdType operation,
continue; continue;
} }
relid = rte->relid; relName = rte->relname;
htup = SearchSysCacheTuple(RELOID, if (rtindex == resultRelation)
ObjectIdGetDatum(relid),
0, 0, 0);
if (!HeapTupleIsValid(htup))
elog(ERROR, "ExecCheckPerms: bogus RT relid: %u", relid);
StrNCpy(rname.data,
((Form_pg_class) GETSTRUCT(htup))->relname.data,
NAMEDATALEN);
if (i == resultRelation)
{ /* this is the result relation */ { /* this is the result relation */
qvars = pull_varnos(parseTree->qual); qvars = pull_varnos(parseTree->qual);
tvars = pull_varnos((Node *) parseTree->targetList); tvars = pull_varnos((Node *) parseTree->targetList);
...@@ -461,10 +453,9 @@ ExecCheckPerms(CmdType operation, ...@@ -461,10 +453,9 @@ ExecCheckPerms(CmdType operation,
} }
if (!ok) if (!ok)
break; break;
++i;
} }
if (!ok) if (!ok)
elog(ERROR, "%s: %s", rname.data, aclcheck_error_strings[aclcheck_result]); elog(ERROR, "%s: %s", relName, aclcheck_error_strings[aclcheck_result]);
if (parseTree != NULL && parseTree->rowMark != NULL) if (parseTree != NULL && parseTree->rowMark != NULL)
{ {
...@@ -475,19 +466,11 @@ ExecCheckPerms(CmdType operation, ...@@ -475,19 +466,11 @@ ExecCheckPerms(CmdType operation,
if (!(rm->info & ROW_ACL_FOR_UPDATE)) if (!(rm->info & ROW_ACL_FOR_UPDATE))
continue; continue;
relid = ((RangeTblEntry *) nth(rm->rti - 1, rangeTable))->relid; relName = rt_fetch(rm->rti, rangeTable)->relname;
htup = SearchSysCacheTuple(RELOID,
ObjectIdGetDatum(relid),
0, 0, 0);
if (!HeapTupleIsValid(htup))
elog(ERROR, "ExecCheckPerms: bogus RT relid: %u", relid);
StrNCpy(rname.data,
((Form_pg_class) GETSTRUCT(htup))->relname.data,
NAMEDATALEN);
ok = ((aclcheck_result = CHECK(ACL_WR)) == ACLCHECK_OK); ok = ((aclcheck_result = CHECK(ACL_WR)) == ACLCHECK_OK);
opstr = "write"; opstr = "write";
if (!ok) if (!ok)
elog(ERROR, "%s: %s", rname.data, aclcheck_error_strings[aclcheck_result]); elog(ERROR, "%s: %s", relName, aclcheck_error_strings[aclcheck_result]);
} }
} }
} }
...@@ -586,10 +569,13 @@ InitPlan(CmdType operation, Query *parseTree, Plan *plan, EState *estate) ...@@ -586,10 +569,13 @@ InitPlan(CmdType operation, Query *parseTree, Plan *plan, EState *estate)
resultRelationInfo->ri_IndexRelationInfo = NULL; resultRelationInfo->ri_IndexRelationInfo = NULL;
/* /*
* open indices on result relation and save descriptors in the * If there are indices on the result relation, open them and save
* result relation information.. * descriptors in the result relation info, so that we can add new
* index entries for the tuples we add/update. We need not do this
* for a DELETE, however, since deletion doesn't affect indexes.
*/ */
if (operation != CMD_DELETE) if (resultRelationDesc->rd_rel->relhasindex &&
operation != CMD_DELETE)
ExecOpenIndices(resultRelationOid, resultRelationInfo); ExecOpenIndices(resultRelationOid, resultRelationInfo);
estate->es_result_relation_info = resultRelationInfo; estate->es_result_relation_info = resultRelationInfo;
...@@ -618,7 +604,7 @@ InitPlan(CmdType operation, Query *parseTree, Plan *plan, EState *estate) ...@@ -618,7 +604,7 @@ InitPlan(CmdType operation, Query *parseTree, Plan *plan, EState *estate)
foreach(l, parseTree->rowMark) foreach(l, parseTree->rowMark)
{ {
rm = lfirst(l); rm = lfirst(l);
relid = ((RangeTblEntry *) nth(rm->rti - 1, rangeTable))->relid; relid = rt_fetch(rm->rti, rangeTable)->relid;
relation = heap_open(relid, RowShareLock); relation = heap_open(relid, RowShareLock);
if (!(rm->info & ROW_MARK_FOR_UPDATE)) if (!(rm->info & ROW_MARK_FOR_UPDATE))
continue; continue;
...@@ -740,6 +726,8 @@ InitPlan(CmdType operation, Query *parseTree, Plan *plan, EState *estate) ...@@ -740,6 +726,8 @@ InitPlan(CmdType operation, Query *parseTree, Plan *plan, EState *estate)
* XXX rather than having to call setheapoverride(true) * XXX rather than having to call setheapoverride(true)
* and then back to false, we should change the arguments * and then back to false, we should change the arguments
* to heap_open() instead.. * to heap_open() instead..
*
* XXX no, we should use commandCounterIncrement...
*/ */
setheapoverride(true); setheapoverride(true);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/nodeAppend.c,v 1.27 1999/10/30 23:13:30 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/executor/nodeAppend.c,v 1.28 1999/11/01 05:09:18 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -181,7 +181,6 @@ ExecInitAppend(Append *node, EState *estate, Plan *parent) ...@@ -181,7 +181,6 @@ ExecInitAppend(Append *node, EState *estate, Plan *parent)
{ {
AppendState *appendstate; AppendState *appendstate;
int nplans; int nplans;
List *resultList = NULL;
List *rtable; List *rtable;
List *appendplans; List *appendplans;
bool *initialized; bool *initialized;
...@@ -246,13 +245,14 @@ ExecInitAppend(Append *node, EState *estate, Plan *parent) ...@@ -246,13 +245,14 @@ ExecInitAppend(Append *node, EState *estate, Plan *parent)
if ((es_rri != (RelationInfo *) NULL) && if ((es_rri != (RelationInfo *) NULL) &&
(node->inheritrelid == es_rri->ri_RangeTableIndex)) (node->inheritrelid == es_rri->ri_RangeTableIndex))
{ {
RelationInfo *rri; List *resultList = NIL;
List *rtentryP; List *rtentryP;
foreach(rtentryP, rtable) foreach(rtentryP, rtable)
{ {
Oid reloid;
RangeTblEntry *rtentry = lfirst(rtentryP); RangeTblEntry *rtentry = lfirst(rtentryP);
Oid reloid;
RelationInfo *rri;
reloid = rtentry->relid; reloid = rtentry->relid;
rri = makeNode(RelationInfo); rri = makeNode(RelationInfo);
...@@ -262,8 +262,10 @@ ExecInitAppend(Append *node, EState *estate, Plan *parent) ...@@ -262,8 +262,10 @@ ExecInitAppend(Append *node, EState *estate, Plan *parent)
rri->ri_IndexRelationDescs = NULL; /* index descs */ rri->ri_IndexRelationDescs = NULL; /* index descs */
rri->ri_IndexRelationInfo = NULL; /* index key info */ rri->ri_IndexRelationInfo = NULL; /* index key info */
resultList = lcons(rri, resultList); if (rri->ri_RelationDesc->rd_rel->relhasindex)
ExecOpenIndices(reloid, rri); ExecOpenIndices(reloid, rri);
resultList = lcons(rri, resultList);
} }
appendstate->as_result_relation_info_list = resultList; appendstate->as_result_relation_info_list = resultList;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment