8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.161 2000/06/28 03:31:28 tgl Exp $
11
+ * $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.162 2000/07/05 16:17:38 wieck Exp $
12
12
*
13
13
14
14
*-------------------------------------------------------------------------
@@ -58,7 +58,7 @@ static void vacuum_init(void);
58
58
static void vacuum_shutdown (void );
59
59
static void vac_vacuum (NameData * VacRelP , bool analyze , List * anal_cols2 );
60
60
static VRelList getrels (NameData * VacRelP );
61
- static void vacuum_rel (Oid relid , bool analyze );
61
+ static void vacuum_rel (Oid relid , bool analyze , bool is_toastrel );
62
62
static void scan_heap (VRelStats * vacrelstats , Relation onerel , VacPageList vacuum_pages , VacPageList fraged_pages );
63
63
static void repair_frag (VRelStats * vacrelstats , Relation onerel , VacPageList vacuum_pages , VacPageList fraged_pages , int nindices , Relation * Irel );
64
64
static void vacuum_heap (VRelStats * vacrelstats , Relation onerel , VacPageList vacpagelist );
@@ -235,7 +235,7 @@ vac_vacuum(NameData *VacRelP, bool analyze, List *anal_cols2)
235
235
/* vacuum each heap relation */
236
236
for (cur = vrl ; cur != (VRelList ) NULL ; cur = cur -> vrl_next )
237
237
{
238
- vacuum_rel (cur -> vrl_relid , analyze );
238
+ vacuum_rel (cur -> vrl_relid , analyze , false );
239
239
/* analyze separately so locking is minimized */
240
240
if (analyze )
241
241
analyze_rel (cur -> vrl_relid , anal_cols2 , MESSAGE_LEVEL );
@@ -347,7 +347,7 @@ getrels(NameData *VacRelP)
347
347
* us to lock the entire database during one pass of the vacuum cleaner.
348
348
*/
349
349
static void
350
- vacuum_rel (Oid relid , bool analyze )
350
+ vacuum_rel (Oid relid , bool analyze , bool is_toastrel )
351
351
{
352
352
HeapTuple tuple ;
353
353
Relation onerel ;
@@ -361,8 +361,10 @@ vacuum_rel(Oid relid, bool analyze)
361
361
i ;
362
362
VRelStats * vacrelstats ;
363
363
bool reindex = false;
364
+ Oid toast_relid ;
364
365
365
- StartTransactionCommand ();
366
+ if (!is_toastrel )
367
+ StartTransactionCommand ();
366
368
367
369
/*
368
370
* Check for user-requested abort. Note we want this to be inside a
@@ -380,7 +382,8 @@ vacuum_rel(Oid relid, bool analyze)
380
382
0 , 0 , 0 );
381
383
if (!HeapTupleIsValid (tuple ))
382
384
{
383
- CommitTransactionCommand ();
385
+ if (!is_toastrel )
386
+ CommitTransactionCommand ();
384
387
return ;
385
388
}
386
389
@@ -392,14 +395,21 @@ vacuum_rel(Oid relid, bool analyze)
392
395
*/
393
396
onerel = heap_open (relid , AccessExclusiveLock );
394
397
398
+ /*
399
+ * Remember the relations TOAST relation for later
400
+ *
401
+ */
402
+ toast_relid = onerel -> rd_rel -> reltoastrelid ;
403
+
395
404
#ifndef NO_SECURITY
396
405
if (!pg_ownercheck (GetPgUserName (), RelationGetRelationName (onerel ),
397
406
RELNAME ))
398
407
{
399
408
elog (NOTICE , "Skipping \"%s\" --- only table owner can VACUUM it" ,
400
409
RelationGetRelationName (onerel ));
401
410
heap_close (onerel , AccessExclusiveLock );
402
- CommitTransactionCommand ();
411
+ if (!is_toastrel )
412
+ CommitTransactionCommand ();
403
413
return ;
404
414
}
405
415
#endif
@@ -488,8 +498,18 @@ vacuum_rel(Oid relid, bool analyze)
488
498
update_relstats (vacrelstats -> relid , vacrelstats -> num_pages ,
489
499
vacrelstats -> num_tuples , vacrelstats -> hasindex , vacrelstats );
490
500
501
+ /* If the relation has a secondary toast one, vacuum that too
502
+ * while we still hold the lock on the master table. We don't
503
+ * need to propagate "analyze" to it, because the toaster
504
+ * allways uses hardcoded index access and statistics are
505
+ * totally unimportant for toast relations
506
+ */
507
+ if (toast_relid != InvalidOid )
508
+ vacuum_rel (toast_relid , false, true);
509
+
491
510
/* next command frees attribute stats */
492
- CommitTransactionCommand ();
511
+ if (!is_toastrel )
512
+ CommitTransactionCommand ();
493
513
}
494
514
495
515
/*
0 commit comments