@@ -501,10 +501,10 @@ GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
501
501
RelFileNumber
502
502
GetNewRelFileNumber (Oid reltablespace , Relation pg_class , char relpersistence )
503
503
{
504
- RelFileLocatorBackend rlocator ;
505
- char * rpath ;
504
+ RelFileLocator locator ;
506
505
bool collides ;
507
506
BackendId backend ;
507
+ SMgrRelation srel ;
508
508
509
509
/*
510
510
* If we ever get here during pg_upgrade, there's something wrong; all
@@ -528,53 +528,29 @@ GetNewRelFileNumber(Oid reltablespace, Relation pg_class, char relpersistence)
528
528
}
529
529
530
530
/* This logic should match RelationInitPhysicalAddr */
531
- rlocator . locator .spcOid = reltablespace ? reltablespace : MyDatabaseTableSpace ;
532
- rlocator . locator .dbOid =
533
- (rlocator . locator .spcOid == GLOBALTABLESPACE_OID ) ?
531
+ locator .spcOid = reltablespace ? reltablespace : MyDatabaseTableSpace ;
532
+ locator .dbOid =
533
+ (locator .spcOid == GLOBALTABLESPACE_OID ) ?
534
534
InvalidOid : MyDatabaseId ;
535
535
536
- /*
537
- * The relpath will vary based on the backend ID, so we must initialize
538
- * that properly here to make sure that any collisions based on filename
539
- * are properly detected.
540
- */
541
- rlocator .backend = backend ;
542
-
543
536
do
544
537
{
545
538
CHECK_FOR_INTERRUPTS ();
546
539
547
540
/* Generate the OID */
548
541
if (pg_class )
549
- rlocator . locator .relNumber = GetNewOidWithIndex (pg_class , ClassOidIndexId ,
542
+ locator .relNumber = GetNewOidWithIndex (pg_class , ClassOidIndexId ,
550
543
Anum_pg_class_oid );
551
544
else
552
- rlocator . locator .relNumber = GetNewObjectId ();
545
+ locator .relNumber = GetNewObjectId ();
553
546
554
547
/* Check for existing file of same name */
555
- rpath = relpath (rlocator , MAIN_FORKNUM );
556
-
557
- if (access (rpath , F_OK ) == 0 )
558
- {
559
- /* definite collision */
560
- collides = true;
561
- }
562
- else
563
- {
564
- /*
565
- * Here we have a little bit of a dilemma: if errno is something
566
- * other than ENOENT, should we declare a collision and loop? In
567
- * practice it seems best to go ahead regardless of the errno. If
568
- * there is a colliding file we will get an smgr failure when we
569
- * attempt to create the new relation file.
570
- */
571
- collides = false;
572
- }
573
-
574
- pfree (rpath );
548
+ srel = smgropen (locator , backend , relpersistence );
549
+ collides = smgrexists (srel , MAIN_FORKNUM );
550
+ smgrclose (srel );
575
551
} while (collides );
576
552
577
- return rlocator . locator .relNumber ;
553
+ return locator .relNumber ;
578
554
}
579
555
580
556
/*
0 commit comments