8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.331 2010/01/22 16:40:18 rhaas Exp $
11
+ * $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.332 2010/02/03 01:14:16 tgl Exp $
12
12
*
13
13
*
14
14
* INTERFACE ROUTINES
69
69
#include "utils/tqual.h"
70
70
71
71
72
+ /* Kluge for upgrade-in-place support */
73
+ Oid binary_upgrade_next_index_relfilenode = InvalidOid ;
74
+
72
75
/* state info for validate_index bulkdelete callback */
73
76
typedef struct
74
77
{
@@ -79,9 +82,6 @@ typedef struct
79
82
tups_inserted ;
80
83
} v_i_state ;
81
84
82
- /* For simple relation creation, this is the toast index relfilenode */
83
- Oid binary_upgrade_next_index_relfilenode = InvalidOid ;
84
-
85
85
/* non-export function prototypes */
86
86
static TupleDesc ConstructTupleDescriptor (Relation heapRelation ,
87
87
IndexInfo * indexInfo ,
@@ -642,21 +642,23 @@ index_create(Oid heapRelationId,
642
642
accessMethodObjectId ,
643
643
classObjectId );
644
644
645
- if (OidIsValid (binary_upgrade_next_index_relfilenode ))
646
- {
647
- indexRelationId = binary_upgrade_next_index_relfilenode ;
648
- binary_upgrade_next_index_relfilenode = InvalidOid ;
649
- }
650
- else if (!OidIsValid (indexRelationId ))
645
+ /*
646
+ * Allocate an OID for the index, unless we were told what to use.
647
+ *
648
+ * The OID will be the relfilenode as well, so make sure it doesn't
649
+ * collide with either pg_class OIDs or existing physical files.
650
+ */
651
+ if (!OidIsValid (indexRelationId ))
651
652
{
652
- /*
653
- * Allocate an OID for the index, unless we were told what to use.
654
- *
655
- * The OID will be the relfilenode as well, so make sure it doesn't
656
- * collide with either pg_class OIDs or existing physical files.
657
- */
658
- indexRelationId = GetNewRelFileNode (tableSpaceId , shared_relation ,
659
- pg_class );
653
+ /* Use binary-upgrade override if applicable */
654
+ if (OidIsValid (binary_upgrade_next_index_relfilenode ))
655
+ {
656
+ indexRelationId = binary_upgrade_next_index_relfilenode ;
657
+ binary_upgrade_next_index_relfilenode = InvalidOid ;
658
+ }
659
+ else
660
+ indexRelationId = GetNewRelFileNode (tableSpaceId , shared_relation ,
661
+ pg_class );
660
662
}
661
663
662
664
/*
@@ -1391,87 +1393,6 @@ index_update_stats(Relation rel,
1391
1393
heap_close (pg_class , RowExclusiveLock );
1392
1394
}
1393
1395
1394
- /*
1395
- * setNewRelfilenode - assign a new relfilenode value to the relation
1396
- *
1397
- * Caller must already hold exclusive lock on the relation.
1398
- *
1399
- * The relation is marked with relfrozenxid=freezeXid (InvalidTransactionId
1400
- * must be passed for indexes)
1401
- */
1402
- void
1403
- setNewRelfilenode (Relation relation , TransactionId freezeXid )
1404
- {
1405
- Oid newrelfilenode ;
1406
- RelFileNode newrnode ;
1407
- Relation pg_class ;
1408
- HeapTuple tuple ;
1409
- Form_pg_class rd_rel ;
1410
-
1411
- /* Can't change relfilenode for nailed tables (indexes ok though) */
1412
- Assert (!relation -> rd_isnailed ||
1413
- relation -> rd_rel -> relkind == RELKIND_INDEX );
1414
- /* Can't change for shared tables or indexes */
1415
- Assert (!relation -> rd_rel -> relisshared );
1416
- /* Indexes must have Invalid frozenxid; other relations must not */
1417
- Assert ((relation -> rd_rel -> relkind == RELKIND_INDEX &&
1418
- freezeXid == InvalidTransactionId ) ||
1419
- TransactionIdIsNormal (freezeXid ));
1420
-
1421
- /* Allocate a new relfilenode */
1422
- newrelfilenode = GetNewRelFileNode (relation -> rd_rel -> reltablespace ,
1423
- relation -> rd_rel -> relisshared ,
1424
- NULL );
1425
-
1426
- /*
1427
- * Find the pg_class tuple for the given relation. This is not used
1428
- * during bootstrap, so okay to use heap_update always.
1429
- */
1430
- pg_class = heap_open (RelationRelationId , RowExclusiveLock );
1431
-
1432
- tuple = SearchSysCacheCopy (RELOID ,
1433
- ObjectIdGetDatum (RelationGetRelid (relation )),
1434
- 0 , 0 , 0 );
1435
- if (!HeapTupleIsValid (tuple ))
1436
- elog (ERROR , "could not find tuple for relation %u" ,
1437
- RelationGetRelid (relation ));
1438
- rd_rel = (Form_pg_class ) GETSTRUCT (tuple );
1439
-
1440
- /*
1441
- * ... and create storage for corresponding forks in the new relfilenode.
1442
- *
1443
- * NOTE: any conflict in relfilenode value will be caught here
1444
- */
1445
- newrnode = relation -> rd_node ;
1446
- newrnode .relNode = newrelfilenode ;
1447
-
1448
- /*
1449
- * Create the main fork, like heap_create() does, and drop the old
1450
- * storage.
1451
- */
1452
- RelationCreateStorage (newrnode , relation -> rd_istemp );
1453
- smgrclosenode (newrnode );
1454
- RelationDropStorage (relation );
1455
-
1456
- /* update the pg_class row */
1457
- rd_rel -> relfilenode = newrelfilenode ;
1458
- rd_rel -> relpages = 0 ; /* it's empty until further notice */
1459
- rd_rel -> reltuples = 0 ;
1460
- rd_rel -> relfrozenxid = freezeXid ;
1461
- simple_heap_update (pg_class , & tuple -> t_self , tuple );
1462
- CatalogUpdateIndexes (pg_class , tuple );
1463
-
1464
- heap_freetuple (tuple );
1465
-
1466
- heap_close (pg_class , RowExclusiveLock );
1467
-
1468
- /* Make sure the relfilenode change is visible */
1469
- CommandCounterIncrement ();
1470
-
1471
- /* Mark the rel as having a new relfilenode in current transaction */
1472
- RelationCacheMarkNewRelfilenode (relation );
1473
- }
1474
-
1475
1396
1476
1397
/*
1477
1398
* index_build - invoke access-method-specific index build procedure
@@ -2562,7 +2483,7 @@ reindex_index(Oid indexId)
2562
2483
/*
2563
2484
* We'll build a new physical relation for the index.
2564
2485
*/
2565
- setNewRelfilenode (iRel , InvalidTransactionId );
2486
+ RelationSetNewRelfilenode (iRel , InvalidTransactionId );
2566
2487
}
2567
2488
2568
2489
/* Initialize the index and rebuild */
@@ -2660,8 +2581,8 @@ reindex_relation(Oid relid, bool toast_too)
2660
2581
* yet because all of this is transaction-safe. If we fail partway
2661
2582
* through, the updated rows are dead and it doesn't matter whether they
2662
2583
* have index entries. Also, a new pg_class index will be created with an
2663
- * entry for its own pg_class row because we do setNewRelfilenode() before
2664
- * we do index_build().
2584
+ * entry for its own pg_class row because we do RelationSetNewRelfilenode()
2585
+ * before we do index_build().
2665
2586
*
2666
2587
* Note that we also clear pg_class's rd_oidindex until the loop is done,
2667
2588
* so that that index can't be accessed either. This means we cannot
0 commit comments