7
7
*
8
8
*
9
9
* IDENTIFICATION
10
- * $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.105 1999/10/26 03:12:33 momjian Exp $
10
+ * $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.106 1999/11/04 08:00:56 inoue Exp $
11
11
*
12
12
*
13
13
* INTERFACE ROUTINES
@@ -176,7 +176,8 @@ Relation
176
176
heap_create (char * relname ,
177
177
TupleDesc tupDesc ,
178
178
bool isnoname ,
179
- bool istemp )
179
+ bool istemp ,
180
+ bool storage_create )
180
181
{
181
182
unsigned i ;
182
183
Oid relid ;
@@ -264,7 +265,8 @@ heap_create(char *relname,
264
265
265
266
rel = (Relation ) palloc (len );
266
267
MemSet ((char * ) rel , 0 , len );
267
-
268
+ rel -> rd_fd = -1 ; /* table is not open */
269
+ rel -> rd_unlinked = TRUE; /* table is not created yet */
268
270
/*
269
271
* create a new tuple descriptor from the one passed in
270
272
*/
@@ -316,9 +318,9 @@ heap_create(char *relname,
316
318
* ----------------
317
319
*/
318
320
319
- rel -> rd_nonameunlinked = TRUE; /* change once table is created */
320
- rel -> rd_fd = ( File ) smgrcreate ( DEFAULT_SMGR , rel );
321
- rel -> rd_nonameunlinked = FALSE ;
321
+ /* smgrcreate() is moved to heap_storage_create() */
322
+ if ( storage_create )
323
+ heap_storage_create ( rel ) ;
322
324
323
325
RelationRegisterRelation (rel );
324
326
@@ -334,6 +336,19 @@ heap_create(char *relname,
334
336
return rel ;
335
337
}
336
338
339
+ bool
340
+ heap_storage_create (Relation rel )
341
+ {
342
+ bool smgrcall = false;
343
+
344
+ if (rel -> rd_unlinked )
345
+ {
346
+ rel -> rd_fd = (File ) smgrcreate (DEFAULT_SMGR , rel );
347
+ rel -> rd_unlinked = FALSE;
348
+ smgrcall = true;
349
+ }
350
+ return smgrcall ;
351
+ }
337
352
338
353
/* ----------------------------------------------------------------
339
354
* heap_create_with_catalog - Create a cataloged relation
@@ -795,16 +810,26 @@ heap_create_with_catalog(char *relname,
795
810
}
796
811
797
812
/* ----------------
798
- * ok, relation does not already exist so now we
799
- * create an uncataloged relation and pull its relation oid
800
- * from the newly formed relation descriptor.
813
+ * get_temp_rel_by_name() couldn't check the simultaneous
814
+ * creation. Uniqueness will be really checked by unique
815
+ * indexes of system tables but we couldn't check it here.
816
+ * We have to pospone to create the disk file for this
817
+ * relation.
818
+ * Another boolean parameter "storage_create" was added
819
+ * to heap_create() function. If the parameter is false
820
+ * heap_create() only registers an uncataloged relation
821
+ * to relation cache and heap_storage_create() should be
822
+ * called later.
823
+ * We could pull its relation oid from the newly formed
824
+ * relation descriptor.
801
825
*
802
- * Note: The call to heap_create() does all the "real" work
803
- * of creating the disk file for the relation.
804
- * This changes relname for noname and temp tables.
826
+ * Note: The call to heap_create() changes relname for
827
+ * noname and temp tables.
828
+ * The call to heap_storage_create() does all the "real"
829
+ * work of creating the disk file for the relation.
805
830
* ----------------
806
831
*/
807
- new_rel_desc = heap_create (relname , tupdesc , false, istemp );
832
+ new_rel_desc = heap_create (relname , tupdesc , false, istemp , false );
808
833
809
834
new_rel_oid = new_rel_desc -> rd_att -> attrs [0 ]-> attrelid ;
810
835
@@ -843,6 +868,10 @@ heap_create_with_catalog(char *relname,
843
868
pfree (temp_relname );
844
869
}
845
870
871
+ /*
872
+ * We create the disk file for this relation here
873
+ */
874
+ heap_storage_create (new_rel_desc );
846
875
/* ----------------
847
876
* ok, the relation has been cataloged, so close our relations
848
877
* and return the oid of the newly created relation.
@@ -1519,10 +1548,10 @@ heap_destroy_with_catalog(char *relname)
1519
1548
* unlink the relation's physical file and finish up.
1520
1549
* ----------------
1521
1550
*/
1522
- if (!(rel -> rd_isnoname ) || !(rel -> rd_nonameunlinked ))
1551
+ if (!(rel -> rd_isnoname ) || !(rel -> rd_unlinked ))
1523
1552
smgrunlink (DEFAULT_SMGR , rel );
1524
1553
1525
- rel -> rd_nonameunlinked = TRUE;
1554
+ rel -> rd_unlinked = TRUE;
1526
1555
1527
1556
/*
1528
1557
* Close relcache entry, but *keep* AccessExclusiveLock on the
@@ -1548,9 +1577,9 @@ void
1548
1577
heap_destroy (Relation rel )
1549
1578
{
1550
1579
ReleaseRelationBuffers (rel );
1551
- if (!(rel -> rd_isnoname ) || !(rel -> rd_nonameunlinked ))
1580
+ if (!(rel -> rd_isnoname ) || !(rel -> rd_unlinked ))
1552
1581
smgrunlink (DEFAULT_SMGR , rel );
1553
- rel -> rd_nonameunlinked = TRUE;
1582
+ rel -> rd_unlinked = TRUE;
1554
1583
heap_close (rel , NoLock );
1555
1584
RemoveFromNoNameRelList (rel );
1556
1585
}
0 commit comments