8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.131 2002/03/03 17:47:53 tgl Exp $
11
+ * $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.132 2002/03/26 19:15:11 tgl Exp $
12
12
*
13
13
*
14
14
* INTERFACE ROUTINES
15
15
* relation_open - open any relation by relation OID
16
- * relation_openr - open any relation by name
16
+ * relation_openrv - open any relation specified by a RangeVar
17
+ * relation_openr - open a system relation by name
17
18
* relation_close - close any relation
18
19
* heap_open - open a heap relation by relation OID
19
- * heap_openr - open a heap relation by name
20
+ * heap_openrv - open a heap relation specified by a RangeVar
21
+ * heap_openr - open a system heap relation by name
20
22
* heap_close - (now just a macro for relation_close)
21
23
* heap_beginscan - begin relation scan
22
24
* heap_rescan - restart a relation scan
44
46
#include "access/valid.h"
45
47
#include "access/xlogutils.h"
46
48
#include "catalog/catalog.h"
49
+ #include "catalog/namespace.h"
47
50
#include "miscadmin.h"
48
51
#include "utils/inval.h"
49
52
#include "utils/relcache.h"
@@ -481,29 +484,30 @@ relation_open(Oid relationId, LOCKMODE lockmode)
481
484
}
482
485
483
486
/* ----------------
484
- * relation_openr - open any relation by name
487
+ * relation_openrv - open any relation specified by a RangeVar
485
488
*
486
- * As above, but lookup by name instead of OID .
489
+ * As above, but the relation is specified by a RangeVar .
487
490
* ----------------
488
491
*/
489
492
Relation
490
- relation_openr (const char * relationName , LOCKMODE lockmode )
493
+ relation_openrv (const RangeVar * relation , LOCKMODE lockmode )
491
494
{
492
- Relation r ;
493
-
494
- Assert (lockmode >= NoLock && lockmode < MAX_LOCKMODES );
495
+ Oid relOid ;
495
496
496
497
/*
497
- * increment access statistics
498
+ * In bootstrap mode, don't do any namespace processing.
498
499
*/
499
- IncrHeapAccessStat (local_openr );
500
- IncrHeapAccessStat (global_openr );
500
+ if (IsBootstrapProcessingMode ())
501
+ {
502
+ Assert (relation -> schemaname == NULL );
503
+ return relation_openr (relation -> relname , lockmode );
504
+ }
501
505
502
506
/*
503
507
* Check for shared-cache-inval messages before trying to open the
504
508
* relation. This is needed to cover the case where the name
505
509
* identifies a rel that has been dropped and recreated since the
506
- * start of our transaction: if we don't flush the old relcache entry
510
+ * start of our transaction: if we don't flush the old syscache entry
507
511
* then we'll latch onto that entry and suffer an error when we do
508
512
* LockRelation. Note that relation_open does not need to do this,
509
513
* since a relation's OID never changes.
@@ -514,11 +518,43 @@ relation_openr(const char *relationName, LOCKMODE lockmode)
514
518
if (lockmode != NoLock )
515
519
AcceptInvalidationMessages ();
516
520
521
+ /* Look up the appropriate relation using namespace search */
522
+ relOid = RangeVarGetRelid (relation , false);
523
+
524
+ /* Let relation_open do the rest */
525
+ return relation_open (relOid , lockmode );
526
+ }
527
+
528
+ /* ----------------
529
+ * relation_openr - open a system relation specified by name.
530
+ *
531
+ * As above, but the relation is specified by an unqualified name;
532
+ * it is assumed to live in the system catalog namespace.
533
+ * ----------------
534
+ */
535
+ Relation
536
+ relation_openr (const char * sysRelationName , LOCKMODE lockmode )
537
+ {
538
+ Relation r ;
539
+
540
+ Assert (lockmode >= NoLock && lockmode < MAX_LOCKMODES );
541
+
542
+ /*
543
+ * increment access statistics
544
+ */
545
+ IncrHeapAccessStat (local_openr );
546
+ IncrHeapAccessStat (global_openr );
547
+
548
+ /*
549
+ * We assume we should not need to worry about the rel's OID changing,
550
+ * hence no need for AcceptInvalidationMessages here.
551
+ */
552
+
517
553
/* The relcache does all the real work... */
518
- r = RelationNameGetRelation ( relationName );
554
+ r = RelationSysNameGetRelation ( sysRelationName );
519
555
520
556
if (!RelationIsValid (r ))
521
- elog (ERROR , "Relation \"%s\" does not exist" , relationName );
557
+ elog (ERROR , "Relation \"%s\" does not exist" , sysRelationName );
522
558
523
559
if (lockmode != NoLock )
524
560
LockRelation (r , lockmode );
@@ -582,17 +618,44 @@ heap_open(Oid relationId, LOCKMODE lockmode)
582
618
}
583
619
584
620
/* ----------------
585
- * heap_openr - open a heap relation by name
621
+ * heap_openrv - open a heap relation specified
622
+ * by a RangeVar node
623
+ *
624
+ * As above, but relation is specified by a RangeVar.
625
+ * ----------------
626
+ */
627
+ Relation
628
+ heap_openrv (const RangeVar * relation , LOCKMODE lockmode )
629
+ {
630
+ Relation r ;
631
+
632
+ r = relation_openrv (relation , lockmode );
633
+
634
+ if (r -> rd_rel -> relkind == RELKIND_INDEX )
635
+ elog (ERROR , "%s is an index relation" ,
636
+ RelationGetRelationName (r ));
637
+ else if (r -> rd_rel -> relkind == RELKIND_SPECIAL )
638
+ elog (ERROR , "%s is a special relation" ,
639
+ RelationGetRelationName (r ));
640
+
641
+ pgstat_initstats (& r -> pgstat_info , r );
642
+
643
+ return r ;
644
+ }
645
+
646
+ /* ----------------
647
+ * heap_openr - open a system heap relation specified by name.
586
648
*
587
- * As above, but lookup by name instead of OID.
649
+ * As above, but the relation is specified by an unqualified name;
650
+ * it is assumed to live in the system catalog namespace.
588
651
* ----------------
589
652
*/
590
653
Relation
591
- heap_openr (const char * relationName , LOCKMODE lockmode )
654
+ heap_openr (const char * sysRelationName , LOCKMODE lockmode )
592
655
{
593
656
Relation r ;
594
657
595
- r = relation_openr (relationName , lockmode );
658
+ r = relation_openr (sysRelationName , lockmode );
596
659
597
660
if (r -> rd_rel -> relkind == RELKIND_INDEX )
598
661
elog (ERROR , "%s is an index relation" ,
0 commit comments