8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.39 2002/09/04 20:31:15 momjian Exp $
11
+ * $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.40 2002/09/06 00:01:53 tgl Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -3325,11 +3325,9 @@ AlterTableCreateToastTable(Oid relOid, bool silent)
3325
3325
{
3326
3326
Relation rel ;
3327
3327
HeapTuple reltup ;
3328
- HeapTupleData classtuple ;
3329
3328
TupleDesc tupdesc ;
3330
3329
bool shared_relation ;
3331
3330
Relation class_rel ;
3332
- Buffer buffer ;
3333
3331
Oid toast_relid ;
3334
3332
Oid toast_idxid ;
3335
3333
char toast_relname [NAMEDATALEN ];
@@ -3366,42 +3364,14 @@ AlterTableCreateToastTable(Oid relOid, bool silent)
3366
3364
if (shared_relation && IsUnderPostmaster )
3367
3365
elog (ERROR , "Shared relations cannot be toasted after initdb" );
3368
3366
3369
- /*
3370
- * lock the pg_class tuple for update (is that really needed?)
3371
- */
3372
- class_rel = heap_openr (RelationRelationName , RowExclusiveLock );
3373
-
3374
- reltup = SearchSysCache (RELOID ,
3375
- ObjectIdGetDatum (relOid ),
3376
- 0 , 0 , 0 );
3377
- if (!HeapTupleIsValid (reltup ))
3378
- elog (ERROR , "ALTER TABLE: relation \"%s\" not found" ,
3379
- RelationGetRelationName (rel ));
3380
- classtuple .t_self = reltup -> t_self ;
3381
- ReleaseSysCache (reltup );
3382
-
3383
- switch (heap_mark4update (class_rel , & classtuple , & buffer ,
3384
- GetCurrentCommandId ()))
3385
- {
3386
- case HeapTupleSelfUpdated :
3387
- case HeapTupleMayBeUpdated :
3388
- break ;
3389
- default :
3390
- elog (ERROR , "couldn't lock pg_class tuple" );
3391
- }
3392
- reltup = heap_copytuple (& classtuple );
3393
- ReleaseBuffer (buffer );
3394
-
3395
3367
/*
3396
3368
* Is it already toasted?
3397
3369
*/
3398
- if ((( Form_pg_class ) GETSTRUCT ( reltup )) -> reltoastrelid != InvalidOid )
3370
+ if (rel -> rd_rel -> reltoastrelid != InvalidOid )
3399
3371
{
3400
3372
if (silent )
3401
3373
{
3402
3374
heap_close (rel , NoLock );
3403
- heap_close (class_rel , NoLock );
3404
- heap_freetuple (reltup );
3405
3375
return ;
3406
3376
}
3407
3377
@@ -3417,8 +3387,6 @@ AlterTableCreateToastTable(Oid relOid, bool silent)
3417
3387
if (silent )
3418
3388
{
3419
3389
heap_close (rel , NoLock );
3420
- heap_close (class_rel , NoLock );
3421
- heap_freetuple (reltup );
3422
3390
return ;
3423
3391
}
3424
3392
@@ -3509,8 +3477,17 @@ AlterTableCreateToastTable(Oid relOid, bool silent)
3509
3477
setRelhasindex (toast_relid , true, true, toast_idxid );
3510
3478
3511
3479
/*
3512
- * Store the toast table's OID in the parent relation's tuple
3480
+ * Store the toast table's OID in the parent relation's pg_class row
3513
3481
*/
3482
+ class_rel = heap_openr (RelationRelationName , RowExclusiveLock );
3483
+
3484
+ reltup = SearchSysCacheCopy (RELOID ,
3485
+ ObjectIdGetDatum (relOid ),
3486
+ 0 , 0 , 0 );
3487
+ if (!HeapTupleIsValid (reltup ))
3488
+ elog (ERROR , "ALTER TABLE: relation \"%s\" not found" ,
3489
+ RelationGetRelationName (rel ));
3490
+
3514
3491
((Form_pg_class ) GETSTRUCT (reltup ))-> reltoastrelid = toast_relid ;
3515
3492
3516
3493
simple_heap_update (class_rel , & reltup -> t_self , reltup );
@@ -3520,6 +3497,8 @@ AlterTableCreateToastTable(Oid relOid, bool silent)
3520
3497
3521
3498
heap_freetuple (reltup );
3522
3499
3500
+ heap_close (class_rel , RowExclusiveLock );
3501
+
3523
3502
/*
3524
3503
* Register dependency from the toast table to the master, so that the
3525
3504
* toast table will be deleted if the master is.
@@ -3534,9 +3513,8 @@ AlterTableCreateToastTable(Oid relOid, bool silent)
3534
3513
recordDependencyOn (& toastobject , & baseobject , DEPENDENCY_INTERNAL );
3535
3514
3536
3515
/*
3537
- * Close relations and make changes visible
3516
+ * Clean up and make changes visible
3538
3517
*/
3539
- heap_close (class_rel , NoLock );
3540
3518
heap_close (rel , NoLock );
3541
3519
3542
3520
CommandCounterIncrement ();
0 commit comments