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- int i = 1 ;
387- Oid relid ;
388- HeapTuple htup ;
386+ int rtindex = 0 ;
389387 List * lp ;
390388 List * qvars ,
391389 * tvars ;
392390 int32 ok = 1 ,
393391 aclcheck_result = -1 ;
394392 char * opstr ;
395- NameData rname ;
393+ char * relName = NULL ;
396394 char * userName ;
397395
398- #define CHECK (MODE ) pg_aclcheck(rname.data , userName, MODE)
396+ #define CHECK (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
0 commit comments