Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite81ad79

Browse files
committed
Don't call ExecOpenIndices if pg_class relhasindex shows there are no
indexes to open. Avoid unnecessary work in ExecCheckPerm, too.
1 parentd40dbb7 commite81ad79

File tree

2 files changed

+28
-38
lines changed

2 files changed

+28
-38
lines changed

‎src/backend/executor/execMain.c

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*
2727
*
2828
* IDENTIFICATION
29-
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.98 1999/10/30 23:13:30 tgl Exp $
29+
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.99 1999/11/01 05:09:17 tgl Exp $
3030
*
3131
*-------------------------------------------------------------------------
3232
*/
@@ -383,26 +383,26 @@ ExecCheckPerms(CmdType operation,
383383
List*rangeTable,
384384
Query*parseTree)
385385
{
386-
inti=1;
387-
Oidrelid;
388-
HeapTuplehtup;
386+
intrtindex=0;
389387
List*lp;
390388
List*qvars,
391389
*tvars;
392390
int32ok=1,
393391
aclcheck_result=-1;
394392
char*opstr;
395-
NameDatarname;
393+
char*relName=NULL;
396394
char*userName;
397395

398-
#defineCHECK(MODE)pg_aclcheck(rname.data, userName, MODE)
396+
#defineCHECK(MODE)pg_aclcheck(relName, userName, MODE)
399397

400398
userName=GetPgUserName();
401399

402400
foreach(lp,rangeTable)
403401
{
404402
RangeTblEntry*rte=lfirst(lp);
405403

404+
++rtindex;
405+
406406
if (rte->skipAcl)
407407
{
408408

@@ -415,16 +415,8 @@ ExecCheckPerms(CmdType operation,
415415
continue;
416416
}
417417

418-
relid=rte->relid;
419-
htup=SearchSysCacheTuple(RELOID,
420-
ObjectIdGetDatum(relid),
421-
0,0,0);
422-
if (!HeapTupleIsValid(htup))
423-
elog(ERROR,"ExecCheckPerms: bogus RT relid: %u",relid);
424-
StrNCpy(rname.data,
425-
((Form_pg_class)GETSTRUCT(htup))->relname.data,
426-
NAMEDATALEN);
427-
if (i==resultRelation)
418+
relName=rte->relname;
419+
if (rtindex==resultRelation)
428420
{/* this is the result relation */
429421
qvars=pull_varnos(parseTree->qual);
430422
tvars=pull_varnos((Node*)parseTree->targetList);
@@ -461,10 +453,9 @@ ExecCheckPerms(CmdType operation,
461453
}
462454
if (!ok)
463455
break;
464-
++i;
465456
}
466457
if (!ok)
467-
elog(ERROR,"%s: %s",rname.data,aclcheck_error_strings[aclcheck_result]);
458+
elog(ERROR,"%s: %s",relName,aclcheck_error_strings[aclcheck_result]);
468459

469460
if (parseTree!=NULL&&parseTree->rowMark!=NULL)
470461
{
@@ -475,19 +466,11 @@ ExecCheckPerms(CmdType operation,
475466
if (!(rm->info&ROW_ACL_FOR_UPDATE))
476467
continue;
477468

478-
relid= ((RangeTblEntry*)nth(rm->rti-1,rangeTable))->relid;
479-
htup=SearchSysCacheTuple(RELOID,
480-
ObjectIdGetDatum(relid),
481-
0,0,0);
482-
if (!HeapTupleIsValid(htup))
483-
elog(ERROR,"ExecCheckPerms: bogus RT relid: %u",relid);
484-
StrNCpy(rname.data,
485-
((Form_pg_class)GETSTRUCT(htup))->relname.data,
486-
NAMEDATALEN);
469+
relName=rt_fetch(rm->rti,rangeTable)->relname;
487470
ok= ((aclcheck_result=CHECK(ACL_WR))==ACLCHECK_OK);
488471
opstr="write";
489472
if (!ok)
490-
elog(ERROR,"%s: %s",rname.data,aclcheck_error_strings[aclcheck_result]);
473+
elog(ERROR,"%s: %s",relName,aclcheck_error_strings[aclcheck_result]);
491474
}
492475
}
493476
}
@@ -586,10 +569,13 @@ InitPlan(CmdType operation, Query *parseTree, Plan *plan, EState *estate)
586569
resultRelationInfo->ri_IndexRelationInfo=NULL;
587570

588571
/*
589-
* open indices on result relation and save descriptors in the
590-
* result relation information..
572+
* If there are indices on the result relation, open them and save
573+
* descriptors in the result relation info, so that we can add new
574+
* index entries for the tuples we add/update. We need not do this
575+
* for a DELETE, however, since deletion doesn't affect indexes.
591576
*/
592-
if (operation!=CMD_DELETE)
577+
if (resultRelationDesc->rd_rel->relhasindex&&
578+
operation!=CMD_DELETE)
593579
ExecOpenIndices(resultRelationOid,resultRelationInfo);
594580

595581
estate->es_result_relation_info=resultRelationInfo;
@@ -618,7 +604,7 @@ InitPlan(CmdType operation, Query *parseTree, Plan *plan, EState *estate)
618604
foreach(l,parseTree->rowMark)
619605
{
620606
rm=lfirst(l);
621-
relid=((RangeTblEntry*)nth(rm->rti-1,rangeTable))->relid;
607+
relid=rt_fetch(rm->rti,rangeTable)->relid;
622608
relation=heap_open(relid,RowShareLock);
623609
if (!(rm->info&ROW_MARK_FOR_UPDATE))
624610
continue;
@@ -740,6 +726,8 @@ InitPlan(CmdType operation, Query *parseTree, Plan *plan, EState *estate)
740726
* XXX rather than having to call setheapoverride(true)
741727
* and then back to false, we should change the arguments
742728
* to heap_open() instead..
729+
*
730+
* XXX no, we should use commandCounterIncrement...
743731
*/
744732
setheapoverride(true);
745733

‎src/backend/executor/nodeAppend.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/executor/nodeAppend.c,v 1.27 1999/10/30 23:13:30 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/executor/nodeAppend.c,v 1.28 1999/11/01 05:09:18 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -181,7 +181,6 @@ ExecInitAppend(Append *node, EState *estate, Plan *parent)
181181
{
182182
AppendState*appendstate;
183183
intnplans;
184-
List*resultList=NULL;
185184
List*rtable;
186185
List*appendplans;
187186
bool*initialized;
@@ -246,13 +245,14 @@ ExecInitAppend(Append *node, EState *estate, Plan *parent)
246245
if ((es_rri!= (RelationInfo*)NULL)&&
247246
(node->inheritrelid==es_rri->ri_RangeTableIndex))
248247
{
249-
RelationInfo*rri;
248+
List*resultList=NIL;
250249
List*rtentryP;
251250

252251
foreach(rtentryP,rtable)
253252
{
254-
Oidreloid;
255-
RangeTblEntry*rtentry=lfirst(rtentryP);
253+
RangeTblEntry*rtentry=lfirst(rtentryP);
254+
Oidreloid;
255+
RelationInfo*rri;
256256

257257
reloid=rtentry->relid;
258258
rri=makeNode(RelationInfo);
@@ -262,8 +262,10 @@ ExecInitAppend(Append *node, EState *estate, Plan *parent)
262262
rri->ri_IndexRelationDescs=NULL;/* index descs */
263263
rri->ri_IndexRelationInfo=NULL;/* index key info */
264264

265+
if (rri->ri_RelationDesc->rd_rel->relhasindex)
266+
ExecOpenIndices(reloid,rri);
267+
265268
resultList=lcons(rri,resultList);
266-
ExecOpenIndices(reloid,rri);
267269
}
268270
appendstate->as_result_relation_info_list=resultList;
269271
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp