]> granicus.if.org Git - postgresql/blobdiff - src/backend/commands/vacuum.c
From: t-ishii@sra.co.jp
[postgresql] / src / backend / commands / vacuum.c
index 1ce7b0998dbd0d8410feb7372297b41cae564f97..79c0c9bbf61a093ee3b56cf1d30295ed99c159a5 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.49 1997/11/02 15:25:07 vadim Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.68 1998/07/26 04:30:25 scrappy Exp $
  *
  *-------------------------------------------------------------------------
  */
 #include <fcntl.h>
 #include <unistd.h>
 
-#include <postgres.h>
-
-#include <fmgr.h>
-#include <utils/portal.h>
-#include <access/genam.h>
-#include <access/heapam.h>
-#include <access/xact.h>
-#include <storage/bufmgr.h>
-#include <access/transam.h>
-#include <catalog/pg_index.h>
-#include <catalog/index.h>
-#include <catalog/catname.h>
-#include <catalog/catalog.h>
-#include <catalog/pg_class.h>
-#include <catalog/pg_proc.h>
-#include <catalog/pg_statistic.h>
-#include <catalog/pg_type.h>
-#include <catalog/pg_operator.h>
-#include <storage/smgr.h>
-#include <storage/lmgr.h>
-#include <utils/inval.h>
-#include <utils/mcxt.h>
-#include <utils/inval.h>
-#include <utils/syscache.h>
-#include <utils/builtins.h>
-#include <commands/vacuum.h>
-#include <parser/catalog_utils.h>
-#include <storage/bufpage.h>
+#include "postgres.h"
+
+#include "access/genam.h"
+#include "access/heapam.h"
+#include "access/transam.h"
+#include "access/xact.h"
+#include "catalog/catalog.h"
+#include "catalog/catname.h"
+#include "catalog/index.h"
+#ifdef MULTIBYTE
+#include "catalog/pg_class_mb.h"
+#else
+#include "catalog/pg_class.h"
+#endif
+#include "catalog/pg_index.h"
+#include "catalog/pg_operator.h"
+#include "catalog/pg_statistic.h"
+#include "catalog/pg_type.h"
+#include "commands/vacuum.h"
+#include "fmgr.h"
+#include "parser/parse_oper.h"
+#include "storage/bufmgr.h"
+#include "storage/bufpage.h"
 #include "storage/shmem.h"
+#include "storage/smgr.h"
+#include "storage/lmgr.h"
+#include "utils/builtins.h"
+#include "utils/inval.h"
+#include "utils/mcxt.h"
+#include "utils/portal.h"
+#include "utils/syscache.h"
+
 #ifndef HAVE_GETRUSAGE
 #include <rusagestub.h>
 #else
@@ -54,9 +57,9 @@
 #include <sys/resource.h>
 #endif
 
-#include <port-protos.h>
+ /* #include <port-protos.h> *//* Why? */
 
-extern int BlowawayRelationBuffers(Relation rdesc, BlockNumber block);
+extern int     BlowawayRelationBuffers(Relation rdesc, BlockNumber block);
 
 bool           VacuumRunning = false;
 
@@ -67,9 +70,9 @@ static int    MESSAGE_LEVEL;          /* message level */
 #define swapLong(a,b)  {long tmp; tmp=a; a=b; b=tmp;}
 #define swapInt(a,b)   {int tmp; tmp=a; a=b; b=tmp;}
 #define swapDatum(a,b) {Datum tmp; tmp=a; a=b; b=tmp;}
-#define VacAttrStatsEqValid(stats) ( stats->f_cmpeq != NULL )
-#define VacAttrStatsLtGtValid(stats) ( stats->f_cmplt != NULL && \
-                                                                  stats->f_cmpgt != NULL && \
+#define VacAttrStatsEqValid(stats) ( stats->f_cmpeq.fn_addr != NULL )
+#define VacAttrStatsLtGtValid(stats) ( stats->f_cmplt.fn_addr != NULL && \
+                                                                  stats->f_cmpgt.fn_addr != NULL && \
                                                                   RegProcedureIsValid(stats->outfunc) )
 
 
@@ -82,7 +85,7 @@ static void vc_vacone(Oid relid, bool analyze, List *va_cols);
 static void vc_scanheap(VRelStats *vacrelstats, Relation onerel, VPageList Vvpl, VPageList Fvpl);
 static void vc_rpfheap(VRelStats *vacrelstats, Relation onerel, VPageList Vvpl, VPageList Fvpl, int nindices, Relation *Irel);
 static void vc_vacheap(VRelStats *vacrelstats, Relation onerel, VPageList vpl);
-static void vc_vacpage(Page page, VPageDescr vpd, Relation archrel);
+static void vc_vacpage(Page page, VPageDescr vpd);
 static void vc_vaconeind(VPageList vpl, Relation indrel, int nhtups);
 static void vc_scanoneind(Relation indrel, int nhtups);
 static void vc_attrstats(Relation onerel, VRelStats *vacrelstats, HeapTuple htup);
@@ -96,9 +99,6 @@ static void vc_vpinsert(VPageList vpl, VPageDescr vpnew);
 static void vc_free(VRelList vrl);
 static void vc_getindices(Oid relid, int *nindices, Relation **Irel);
 static void vc_clsindices(int nindices, Relation *Irel);
-static Relation vc_getarchrel(Relation heaprel);
-static void vc_archive(Relation archrel, HeapTuple htup);
-static bool vc_isarchrel(char *rname);
 static void vc_mkindesc(Relation onerel, int nindices, Relation *Irel, IndDesc **Idesc);
 static char *vc_find_eq(char *bot, int nelem, int size, char *elm, int (*compar) (char *, char *));
 static int     vc_cmp_blk(char *left, char *right);
@@ -138,7 +138,9 @@ vacuum(char *vacrel, bool verbose, bool analyze, List *va_spec)
        pmem = PortalGetVariableMemory(vc_portal);
        old = MemoryContextSwitchTo((MemoryContext) pmem);
 
-       Assert(va_spec == NIL || analyze);
+       if (va_spec != NIL && !analyze)
+               elog(ERROR, "Can't vacuum columns, only tables.  You can 'vacuum analyze' columns.");
+
        foreach(le, va_spec)
        {
                char       *col = (char *) lfirst(le);
@@ -188,7 +190,7 @@ vc_init()
        int                     fd;
 
        if ((fd = open("pg_vlock", O_CREAT | O_EXCL, 0600)) < 0)
-               elog(WARN, "can't create lock file -- another vacuum cleaner running?");
+               elog(ERROR, "can't create lock file -- another vacuum cleaner running?");
 
        close(fd);
 
@@ -210,7 +212,7 @@ vc_shutdown()
 {
        /* on entry, not in a transaction */
        if (unlink("pg_vlock") < 0)
-               elog(WARN, "vacuum: can't destroy lock file!");
+               elog(ERROR, "vacuum: can't destroy lock file!");
 
        /* okay, we're done */
        VacuumRunning = false;
@@ -271,7 +273,6 @@ vc_getrels(NameData *VacRelP)
        Datum           d;
        char       *rname;
        char            rkind;
-       int16           smgrno;
        bool            n;
        ScanKeyData pgckey;
        bool            found = false;
@@ -281,13 +282,13 @@ vc_getrels(NameData *VacRelP)
        if (VacRelP->data)
        {
                ScanKeyEntryInitialize(&pgckey, 0x0, Anum_pg_class_relname,
-                                                          NameEqualRegProcedure,
+                                                          F_NAMEEQ,
                                                           PointerGetDatum(VacRelP->data));
        }
        else
        {
                ScanKeyEntryInitialize(&pgckey, 0x0, Anum_pg_class_relkind,
-                                                 CharacterEqualRegProcedure, CharGetDatum('r'));
+                                                 F_CHAREQ, CharGetDatum('r'));
        }
 
        portalmem = PortalGetVariableMemory(vc_portal);
@@ -296,30 +297,16 @@ vc_getrels(NameData *VacRelP)
        pgclass = heap_openr(RelationRelationName);
        pgcdesc = RelationGetTupleDescriptor(pgclass);
 
-       pgcscan = heap_beginscan(pgclass, false, NowTimeQual, 1, &pgckey);
+       pgcscan = heap_beginscan(pgclass, false, false, 1, &pgckey);
 
        while (HeapTupleIsValid(pgctup = heap_getnext(pgcscan, 0, &buf)))
        {
 
                found = true;
 
-               /*
-                * We have to be careful not to vacuum the archive (since it
-                * already contains vacuumed tuples), and not to vacuum relations
-                * on write-once storage managers like the Sony jukebox at
-                * Berkeley.
-                */
-
-               d = heap_getattr(pgctup, buf, Anum_pg_class_relname, pgcdesc, &n);
+               d = heap_getattr(pgctup, Anum_pg_class_relname, pgcdesc, &n);
                rname = (char *) d;
 
-               /* skip archive relations */
-               if (vc_isarchrel(rname))
-               {
-                       ReleaseBuffer(buf);
-                       continue;
-               }
-
                /*
                 * don't vacuum large objects for now - something breaks when we
                 * do
@@ -335,17 +322,7 @@ vc_getrels(NameData *VacRelP)
                        continue;
                }
 
-               d = heap_getattr(pgctup, buf, Anum_pg_class_relsmgr, pgcdesc, &n);
-               smgrno = DatumGetInt16(d);
-
-               /* skip write-once storage managers */
-               if (smgriswo(smgrno))
-               {
-                       ReleaseBuffer(buf);
-                       continue;
-               }
-
-               d = heap_getattr(pgctup, buf, Anum_pg_class_relkind, pgcdesc, &n);
+               d = heap_getattr(pgctup, Anum_pg_class_relkind, pgcdesc, &n);
 
                rkind = DatumGetChar(d);
 
@@ -360,9 +337,7 @@ vc_getrels(NameData *VacRelP)
                /* get a relation list entry for this guy */
                old = MemoryContextSwitchTo((MemoryContext) portalmem);
                if (vrl == (VRelList) NULL)
-               {
                        vrl = cur = (VRelList) palloc(sizeof(VRelListData));
-               }
                else
                {
                        cur->vrl_next = (VRelList) palloc(sizeof(VRelListData));
@@ -424,12 +399,12 @@ vc_vacone(Oid relid, bool analyze, List *va_cols)
        StartTransactionCommand();
 
        ScanKeyEntryInitialize(&pgckey, 0x0, ObjectIdAttributeNumber,
-                                                  ObjectIdEqualRegProcedure,
+                                                  F_OIDEQ,
                                                   ObjectIdGetDatum(relid));
 
        pgclass = heap_openr(RelationRelationName);
        pgcdesc = RelationGetTupleDescriptor(pgclass);
-       pgcscan = heap_beginscan(pgclass, false, NowTimeQual, 1, &pgckey);
+       pgcscan = heap_beginscan(pgclass, false, false, 1, &pgckey);
 
        /*
         * Race condition -- if the pg_class tuple has gone away since the
@@ -466,7 +441,7 @@ vc_vacone(Oid relid, bool analyze, List *va_cols)
                        List       *le;
 
                        if (length(va_cols) > attr_cnt)
-                               elog(WARN, "vacuum: too many attributes specified for relation %s",
+                               elog(ERROR, "vacuum: too many attributes specified for relation %s",
                                         (RelationGetRelationName(onerel))->data);
                        attnums = (int *) palloc(attr_cnt * sizeof(int));
                        foreach(le, va_cols)
@@ -482,7 +457,7 @@ vc_vacone(Oid relid, bool analyze, List *va_cols)
                                        attnums[tcnt++] = i;
                                else
                                {
-                                       elog(WARN, "vacuum: there is no attribute %s in %s",
+                                       elog(ERROR, "vacuum: there is no attribute %s in %s",
                                                 col, (RelationGetRelationName(onerel))->data);
                                }
                        }
@@ -512,35 +487,29 @@ vc_vacone(Oid relid, bool analyze, List *va_cols)
                        func_operator = oper("=", stats->attr->atttypid, stats->attr->atttypid, true);
                        if (func_operator != NULL)
                        {
-                               int                     nargs;
-
                                pgopform = (OperatorTupleForm) GETSTRUCT(func_operator);
-                               fmgr_info(pgopform->oprcode, &(stats->f_cmpeq), &nargs);
+                               fmgr_info(pgopform->oprcode, &(stats->f_cmpeq));
                        }
                        else
-                               stats->f_cmpeq = NULL;
+                               stats->f_cmpeq.fn_addr = NULL;
 
                        func_operator = oper("<", stats->attr->atttypid, stats->attr->atttypid, true);
                        if (func_operator != NULL)
                        {
-                               int                     nargs;
-
                                pgopform = (OperatorTupleForm) GETSTRUCT(func_operator);
-                               fmgr_info(pgopform->oprcode, &(stats->f_cmplt), &nargs);
+                               fmgr_info(pgopform->oprcode, &(stats->f_cmplt));
                        }
                        else
-                               stats->f_cmplt = NULL;
+                               stats->f_cmplt.fn_addr = NULL;
 
                        func_operator = oper(">", stats->attr->atttypid, stats->attr->atttypid, true);
                        if (func_operator != NULL)
                        {
-                               int                     nargs;
-
                                pgopform = (OperatorTupleForm) GETSTRUCT(func_operator);
-                               fmgr_info(pgopform->oprcode, &(stats->f_cmpgt), &nargs);
+                               fmgr_info(pgopform->oprcode, &(stats->f_cmpgt));
                        }
                        else
-                               stats->f_cmpgt = NULL;
+                               stats->f_cmpgt.fn_addr = NULL;
 
                        pgttup = SearchSysCacheTuple(TYPOID,
                                                                 ObjectIdGetDatum(stats->attr->atttypid),
@@ -687,6 +656,8 @@ vc_scanheap(VRelStats *vacrelstats, Relation onerel,
        vpc = (VPageDescr) palloc(sizeof(VPageDescrData) + MaxOffsetNumber * sizeof(OffsetNumber));
        vpc->vpd_nusd = 0;
 
+       elog(MESSAGE_LEVEL, "--Relation %s--", relname);
+       
        for (blkno = 0; blkno < nblocks; blkno++)
        {
                buf = ReadBuffer(onerel, blkno);
@@ -757,8 +728,9 @@ vc_scanheap(VRelStats *vacrelstats, Relation onerel,
                                        }
                                        else if (!TransactionIdIsInProgress(htup->t_xmin))
                                        {
+
                                                /*
-                                                * Not Aborted, Not Committed, Not in Progress - 
+                                                * Not Aborted, Not Committed, Not in Progress -
                                                 * so it's from crashed process. - vadim 11/26/96
                                                 */
                                                ncrash++;
@@ -773,11 +745,11 @@ vc_scanheap(VRelStats *vacrelstats, Relation onerel,
                                }
                        }
 
-                       /* 
-                        * here we are concerned about tuples with xmin committed 
-                        * and xmax unknown or committed
+                       /*
+                        * here we are concerned about tuples with xmin committed and
+                        * xmax unknown or committed
                         */
-                       if (htup->t_infomask & HEAP_XMIN_COMMITTED && 
+                       if (htup->t_infomask & HEAP_XMIN_COMMITTED &&
                                !(htup->t_infomask & HEAP_XMAX_INVALID))
                        {
                                if (htup->t_infomask & HEAP_XMAX_COMMITTED)
@@ -791,6 +763,7 @@ vc_scanheap(VRelStats *vacrelstats, Relation onerel,
                                        tupgone = true;
                                else if (!TransactionIdIsInProgress(htup->t_xmax))
                                {
+
                                        /*
                                         * Not Aborted, Not Committed, Not in Progress - so it
                                         * from crashed process. - vadim 06/02/97
@@ -939,16 +912,15 @@ vc_scanheap(VRelStats *vacrelstats, Relation onerel,
 
        getrusage(RUSAGE_SELF, &ru1);
 
-       elog(MESSAGE_LEVEL, "Rel %s: Pages %u: Changed %u, Reapped %u, Empty %u, New %u; \
+       elog(MESSAGE_LEVEL, "Pages %u: Changed %u, Reapped %u, Empty %u, New %u; \
 Tup %u: Vac %u, Crash %u, UnUsed %u, MinLen %u, MaxLen %u; Re-using: Free/Avail. Space %u/%u; EndEmpty/Avail. Pages %u/%u. Elapsed %u/%u sec.",
-                relname,
                 nblocks, nchpg, Vvpl->vpl_npages, nempg, nnepg,
                 ntups, nvac, ncrash, nunused, min_tlen, max_tlen,
                 frsize, frsusf, nemend, Fvpl->vpl_npages,
                 ru1.ru_stime.tv_sec - ru0.ru_stime.tv_sec,
                 ru1.ru_utime.tv_sec - ru0.ru_utime.tv_sec);
 
-}                                                              /* vc_scanheap */
+}      /* vc_scanheap */
 
 
 /*
@@ -1005,7 +977,6 @@ vc_rpfheap(VRelStats *vacrelstats, Relation onerel,
                                ntups;
        bool            isempty,
                                dowrite;
-       Relation        archrel;
        struct rusage ru0,
                                ru1;
 
@@ -1022,27 +993,6 @@ vc_rpfheap(VRelStats *vacrelstats, Relation onerel,
                inulls = (char *) palloc(INDEX_MAX_KEYS * sizeof(*inulls));
        }
 
-       /* if the relation has an archive, open it */
-       if (onerel->rd_rel->relarch != 'n')
-       {
-               archrel = vc_getarchrel(onerel);
-               /* Archive tuples from "empty" end-pages */
-               for (vpp = Vvpl->vpl_pgdesc + Vvpl->vpl_npages - 1,
-                        i = Vvpl->vpl_nemend; i > 0; i--, vpp--)
-               {
-                       if ((*vpp)->vpd_noff > 0)
-                       {
-                               buf = ReadBuffer(onerel, (*vpp)->vpd_blkno);
-                               page = BufferGetPage(buf);
-                               Assert(!PageIsEmpty(page));
-                               vc_vacpage(page, *vpp, archrel);
-                               WriteBuffer(buf);
-                       }
-               }
-       }
-       else
-               archrel = (Relation) NULL;
-
        Nvpl.vpl_npages = 0;
        Fnpages = Fvpl->vpl_npages;
        Fvplast = Fvpl->vpl_pgdesc[Fnpages - 1];
@@ -1078,13 +1028,11 @@ vc_rpfheap(VRelStats *vacrelstats, Relation onerel,
                        if (Vvplast->vpd_noff > 0)      /* there are dead tuples */
                        {                                       /* on this page - clean */
                                Assert(!isempty);
-                               vc_vacpage(page, Vvplast, archrel);
+                               vc_vacpage(page, Vvplast);
                                dowrite = true;
                        }
                        else
-                       {
                                Assert(isempty);
-                       }
                        --Vnpages;
                        Assert(Vnpages > 0);
                        /* get prev reapped page from Vvpl */
@@ -1107,9 +1055,7 @@ vc_rpfheap(VRelStats *vacrelstats, Relation onerel,
                        }
                }
                else
-               {
                        Assert(!isempty);
-               }
 
                vpc->vpd_blkno = blkno;
                maxoff = PageGetMaxOffsetNumber(page);
@@ -1137,23 +1083,19 @@ vc_rpfheap(VRelStats *vacrelstats, Relation onerel,
                                        /*
                                         * If no one tuple can't be added to this page -
                                         * remove page from Fvpl. - vadim 11/27/96
+                                        *
+                                        * But we can't remove last page - this is our
+                                        * "show-stopper" !!!   - vadim 02/25/98
                                         */
-                                       if (!vc_enough_space(ToVpd, vacrelstats->min_tlen))
+                                       if (ToVpd != Fvplast &&
+                                               !vc_enough_space(ToVpd, vacrelstats->min_tlen))
                                        {
-                                               if (ToVpd != Fvplast)
-                                               {
-                                                       Assert(Fnpages > ToVpI + 1);
-                                                       memmove(Fvpl->vpl_pgdesc + ToVpI,
-                                                                       Fvpl->vpl_pgdesc + ToVpI + 1,
-                                                       sizeof(VPageDescr *) * (Fnpages - ToVpI - 1));
-                                               }
-                                               Assert(Fnpages >= 1);
+                                               Assert(Fnpages > ToVpI + 1);
+                                               memmove(Fvpl->vpl_pgdesc + ToVpI,
+                                                               Fvpl->vpl_pgdesc + ToVpI + 1,
+                                                  sizeof(VPageDescr *) * (Fnpages - ToVpI - 1));
                                                Fnpages--;
-                                               if (Fnpages == 0)
-                                                       break;
-                                               /* get prev reapped page from Fvpl */
-                                               Fvplast = Fvpl->vpl_pgdesc[Fnpages - 1];
-                                               Fblklast = Fvplast->vpd_blkno;
+                                               Assert(Fvplast == Fvpl->vpl_pgdesc[Fnpages - 1]);
                                        }
                                }
                                for (i = 0; i < Fnpages; i++)
@@ -1169,7 +1111,7 @@ vc_rpfheap(VRelStats *vacrelstats, Relation onerel,
                                ToPage = BufferGetPage(ToBuf);
                                /* if this page was not used before - clean it */
                                if (!PageIsEmpty(ToPage) && ToVpd->vpd_nusd == 0)
-                                       vc_vacpage(ToPage, ToVpd, archrel);
+                                       vc_vacpage(ToPage, ToVpd);
                        }
 
                        /* copy tuple */
@@ -1189,7 +1131,7 @@ vc_rpfheap(VRelStats *vacrelstats, Relation onerel,
                                                                 InvalidOffsetNumber, LP_USED);
                        if (newoff == InvalidOffsetNumber)
                        {
-                               elog(WARN, "\
+                               elog(ERROR, "\
 failed to add item with len = %u to page %u (free space %u, nusd %u, noff %u)",
                                         tlen, ToVpd->vpd_blkno, ToVpd->vpd_free,
                                         ToVpd->vpd_nusd, ToVpd->vpd_noff);
@@ -1292,7 +1234,7 @@ failed to add item with len = %u to page %u (free space %u, nusd %u, noff %u)",
                         * re-used
                         */
                        Assert((*vpp)->vpd_noff > 0);
-                       vc_vacpage(page, *vpp, archrel);
+                       vc_vacpage(page, *vpp);
                }
                else
 /* this page was used */
@@ -1391,15 +1333,12 @@ Elapsed %u/%u sec.",
        {
                i = BlowawayRelationBuffers(onerel, blkno);
                if (i < 0)
-                       elog (FATAL, "VACUUM (vc_rpfheap): BlowawayRelationBuffers returned %d", i);
-               blkno = smgrtruncate(onerel->rd_rel->relsmgr, onerel, blkno);
+                       elog(FATAL, "VACUUM (vc_rpfheap): BlowawayRelationBuffers returned %d", i);
+               blkno = smgrtruncate(DEFAULT_SMGR, onerel, blkno);
                Assert(blkno >= 0);
                vacrelstats->npages = blkno;    /* set new number of blocks */
        }
 
-       if (archrel != (Relation) NULL)
-               heap_close(archrel);
-
        if (Irel != (Relation *) NULL)          /* pfree index' allocations */
        {
                pfree(Idesc);
@@ -1410,7 +1349,7 @@ Elapsed %u/%u sec.",
 
        pfree(vpc);
 
-}                                                              /* vc_rpfheap */
+}      /* vc_rpfheap */
 
 /*
  *     vc_vacheap() -- free dead tuples
@@ -1424,19 +1363,11 @@ vc_vacheap(VRelStats *vacrelstats, Relation onerel, VPageList Vvpl)
        Buffer          buf;
        Page            page;
        VPageDescr *vpp;
-       Relation        archrel;
        int                     nblocks;
        int                     i;
 
        nblocks = Vvpl->vpl_npages;
-       /* if the relation has an archive, open it */
-       if (onerel->rd_rel->relarch != 'n')
-               archrel = vc_getarchrel(onerel);
-       else
-       {
-               archrel = (Relation) NULL;
-               nblocks -= Vvpl->vpl_nemend;    /* nothing to do with them */
-       }
+       nblocks -= Vvpl->vpl_nemend;/* nothing to do with them */
 
        for (i = 0, vpp = Vvpl->vpl_pgdesc; i < nblocks; i++, vpp++)
        {
@@ -1444,7 +1375,7 @@ vc_vacheap(VRelStats *vacrelstats, Relation onerel, VPageList Vvpl)
                {
                        buf = ReadBuffer(onerel, (*vpp)->vpd_blkno);
                        page = BufferGetPage(buf);
-                       vc_vacpage(page, *vpp, archrel);
+                       vc_vacpage(page, *vpp);
                        WriteBuffer(buf);
                }
        }
@@ -1463,46 +1394,37 @@ vc_vacheap(VRelStats *vacrelstats, Relation onerel, VPageList Vvpl)
                 * it) before truncation
                 */
                FlushBufferPool(!TransactionFlushEnabled());
-               
+
                i = BlowawayRelationBuffers(onerel, nblocks);
                if (i < 0)
-                       elog (FATAL, "VACUUM (vc_vacheap): BlowawayRelationBuffers returned %d", i);
+                       elog(FATAL, "VACUUM (vc_vacheap): BlowawayRelationBuffers returned %d", i);
 
-               nblocks = smgrtruncate(onerel->rd_rel->relsmgr, onerel, nblocks);
+               nblocks = smgrtruncate(DEFAULT_SMGR, onerel, nblocks);
                Assert(nblocks >= 0);
                vacrelstats->npages = nblocks;  /* set new number of blocks */
        }
 
-       if (archrel != (Relation) NULL)
-               heap_close(archrel);
-
-}                                                              /* vc_vacheap */
+}      /* vc_vacheap */
 
 /*
- *     vc_vacpage() -- free (and archive if needed) dead tuples on a page
+ *     vc_vacpage() -- free dead tuples on a page
  *                                      and repaire its fragmentation.
  */
 static void
-vc_vacpage(Page page, VPageDescr vpd, Relation archrel)
+vc_vacpage(Page page, VPageDescr vpd)
 {
        ItemId          itemid;
-       HeapTuple       htup;
        int                     i;
 
        Assert(vpd->vpd_nusd == 0);
        for (i = 0; i < vpd->vpd_noff; i++)
        {
                itemid = &(((PageHeader) page)->pd_linp[vpd->vpd_voff[i] - 1]);
-               if (archrel != (Relation) NULL && ItemIdIsUsed(itemid))
-               {
-                       htup = (HeapTuple) PageGetItem(page, itemid);
-                       vc_archive(archrel, htup);
-               }
                itemid->lp_flags &= ~LP_USED;
        }
        PageRepairFragmentation(page);
 
-}                                                              /* vc_vacpage */
+}      /* vc_vacpage */
 
 /*
  *     _vc_scanoneind() -- scan one index relation to update statistic.
@@ -1548,7 +1470,7 @@ vc_scanoneind(Relation indrel, int nhtups)
                elog(NOTICE, "Ind %s: NUMBER OF INDEX' TUPLES (%u) IS NOT THE SAME AS HEAP' (%u)",
                         indrel->rd_rel->relname.data, nitups, nhtups);
 
-}                                                              /* vc_scanoneind */
+}      /* vc_scanoneind */
 
 /*
  *     vc_vaconeind() -- vacuum one index relation.
@@ -1606,9 +1528,7 @@ vc_vaconeind(VPageList vpl, Relation indrel, int nhtups)
                        index_delete(indrel, &res->index_iptr);
                }
                else
-               {
                        nitups++;
-               }
 
                /* be tidy */
                pfree(res);
@@ -1631,7 +1551,7 @@ vc_vaconeind(VPageList vpl, Relation indrel, int nhtups)
                elog(NOTICE, "Ind %s: NUMBER OF INDEX' TUPLES (%u) IS NOT THE SAME AS HEAP' (%u)",
                         indrel->rd_rel->relname.data, nitups, nhtups);
 
-}                                                              /* vc_vaconeind */
+}      /* vc_vaconeind */
 
 /*
  *     vc_tidreapped() -- is a particular tid reapped?
@@ -1675,7 +1595,7 @@ vc_tidreapped(ItemPointer itemptr, VPageList vpl)
 
        return (vp);
 
-}                                                              /* vc_tidreapped */
+}      /* vc_tidreapped */
 
 /*
  *     vc_attrstats() -- compute column statistics used by the optimzer
@@ -1713,7 +1633,7 @@ vc_attrstats(Relation onerel, VRelStats *vacrelstats, HeapTuple htup)
                VacAttrStats *stats = &vacattrstats[i];
                bool            value_hit = true;
 
-               value = heap_getattr(htup, InvalidBuffer,
+               value = heap_getattr(htup,
                                                         stats->attr->attnum, tupDesc, &isnull);
 
                if (!VacAttrStatsEqValid(stats))
@@ -1741,29 +1661,29 @@ vc_attrstats(Relation onerel, VRelStats *vacrelstats, HeapTuple htup)
                        }
                        if (VacAttrStatsLtGtValid(stats))
                        {
-                               if ((*(stats->f_cmplt)) (value, stats->min))
+                               if ((*fmgr_faddr(&stats->f_cmplt)) (value, stats->min))
                                {
                                        vc_bucketcpy(stats->attr, value, &stats->min, &stats->min_len);
                                        stats->min_cnt = 0;
                                }
-                               if ((*(stats->f_cmpgt)) (value, stats->max))
+                               if ((*fmgr_faddr(&stats->f_cmpgt)) (value, stats->max))
                                {
                                        vc_bucketcpy(stats->attr, value, &stats->max, &stats->max_len);
                                        stats->max_cnt = 0;
                                }
-                               if ((*(stats->f_cmpeq)) (value, stats->min))
+                               if ((*fmgr_faddr(&stats->f_cmpeq)) (value, stats->min))
                                        stats->min_cnt++;
-                               else if ((*(stats->f_cmpeq)) (value, stats->max))
+                               else if ((*fmgr_faddr(&stats->f_cmpeq)) (value, stats->max))
                                        stats->max_cnt++;
                        }
-                       if ((*(stats->f_cmpeq)) (value, stats->best))
+                       if ((*fmgr_faddr(&stats->f_cmpeq)) (value, stats->best))
                                stats->best_cnt++;
-                       else if ((*(stats->f_cmpeq)) (value, stats->guess1))
+                       else if ((*fmgr_faddr(&stats->f_cmpeq)) (value, stats->guess1))
                        {
                                stats->guess1_cnt++;
                                stats->guess1_hits++;
                        }
-                       else if ((*(stats->f_cmpeq)) (value, stats->guess2))
+                       else if ((*fmgr_faddr(&stats->f_cmpeq)) (value, stats->guess2))
                                stats->guess2_hits++;
                        else
                                value_hit = false;
@@ -1852,14 +1772,14 @@ vc_updstats(Oid relid, int npages, int ntups, bool hasindex, VRelStats *vacrelst
         * update number of tuples and number of pages in pg_class
         */
        ScanKeyEntryInitialize(&rskey, 0x0, ObjectIdAttributeNumber,
-                                                  ObjectIdEqualRegProcedure,
+                                                  F_OIDEQ,
                                                   ObjectIdGetDatum(relid));
 
        rd = heap_openr(RelationRelationName);
-       rsdesc = heap_beginscan(rd, false, NowTimeQual, 1, &rskey);
+       rsdesc = heap_beginscan(rd, false, false, 1, &rskey);
 
        if (!HeapTupleIsValid(rtup = heap_getnext(rsdesc, 0, &rbuf)))
-               elog(WARN, "pg_class entry for relid %d vanished during vacuuming",
+               elog(ERROR, "pg_class entry for relid %d vanished during vacuuming",
                         relid);
 
        /* overwrite the existing statistics in the tuple */
@@ -1879,7 +1799,7 @@ vc_updstats(Oid relid, int npages, int ntups, bool hasindex, VRelStats *vacrelst
                ScanKeyEntryInitialize(&askey, 0, Anum_pg_attribute_attrelid,
                                                           F_INT4EQ, relid);
 
-               asdesc = heap_beginscan(ad, false, NowTimeQual, 1, &askey);
+               asdesc = heap_beginscan(ad, false, false, 1, &askey);
 
                while (HeapTupleIsValid(atup = heap_getnext(asdesc, 0, &abuf)))
                {
@@ -1950,9 +1870,8 @@ vc_updstats(Oid relid, int npages, int ntups, bool hasindex, VRelStats *vacrelst
                                                                                                                                                 *
                                         pgcform->relname.data) */ )
                                {
-                                       func_ptr        out_function;
+                                       FmgrInfo        out_function;
                                        char       *out_string;
-                                       int                     dummy;
 
                                        for (i = 0; i < Natts_pg_statistic; ++i)
                                                nulls[i] = ' ';
@@ -1965,12 +1884,12 @@ vc_updstats(Oid relid, int npages, int ntups, bool hasindex, VRelStats *vacrelst
                                        values[i++] = (Datum) relid;            /* 1 */
                                        values[i++] = (Datum) attp->attnum; /* 2 */
                                        values[i++] = (Datum) InvalidOid;       /* 3 */
-                                       fmgr_info(stats->outfunc, &out_function, &dummy);
-                                       out_string = (*out_function) (stats->min, stats->attr->atttypid);
-                                       values[i++] = (Datum) fmgr(TextInRegProcedure, out_string);
+                                       fmgr_info(stats->outfunc, &out_function);
+                                       out_string = (*fmgr_faddr(&out_function)) (stats->min, stats->attr->atttypid);
+                                       values[i++] = (Datum) fmgr(F_TEXTIN, out_string);
                                        pfree(out_string);
-                                       out_string = (char *) (*out_function) (stats->max, stats->attr->atttypid);
-                                       values[i++] = (Datum) fmgr(TextInRegProcedure, out_string);
+                                       out_string = (char *) (*fmgr_faddr(&out_function)) (stats->max, stats->attr->atttypid);
+                                       values[i++] = (Datum) fmgr(F_TEXTIN, out_string);
                                        pfree(out_string);
 
                                        sdesc = sd->rd_att;
@@ -2025,12 +1944,12 @@ vc_delhilowstats(Oid relid, int attcnt, int *attnums)
        if (relid != InvalidOid)
        {
                ScanKeyEntryInitialize(&pgskey, 0x0, Anum_pg_statistic_starelid,
-                                                          ObjectIdEqualRegProcedure,
+                                                          F_OIDEQ,
                                                           ObjectIdGetDatum(relid));
-               pgsscan = heap_beginscan(pgstatistic, false, NowTimeQual, 1, &pgskey);
+               pgsscan = heap_beginscan(pgstatistic, false, false, 1, &pgskey);
        }
        else
-               pgsscan = heap_beginscan(pgstatistic, false, NowTimeQual, 0, NULL);
+               pgsscan = heap_beginscan(pgstatistic, false, false, 0, NULL);
 
        while (HeapTupleIsValid(pgstup = heap_getnext(pgsscan, 0, NULL)))
        {
@@ -2090,7 +2009,7 @@ vc_reappage(VPageList vpl, VPageDescr vpc)
        /* insert this page into vpl list */
        vc_vpinsert(vpl, newvpd);
 
-}                                                              /* vc_reappage */
+}      /* vc_reappage */
 
 static void
 vc_vpinsert(VPageList vpl, VPageDescr vpnew)
@@ -2128,51 +2047,6 @@ vc_free(VRelList vrl)
        MemoryContextSwitchTo(old);
 }
 
-/*
- *     vc_getarchrel() -- open the archive relation for a heap relation
- *
- *             The archive relation is named 'a,XXXXX' for the heap relation
- *             whose relid is XXXXX.
- */
-
-#define ARCHIVE_PREFIX "a,"
-
-static Relation
-vc_getarchrel(Relation heaprel)
-{
-       Relation        archrel;
-       char       *archrelname;
-
-       archrelname = palloc(sizeof(ARCHIVE_PREFIX) + NAMEDATALEN); /* bogus */
-       sprintf(archrelname, "%s%d", ARCHIVE_PREFIX, heaprel->rd_id);
-
-       archrel = heap_openr(archrelname);
-
-       pfree(archrelname);
-       return (archrel);
-}
-
-/*
- *     vc_archive() -- write a tuple to an archive relation
- *
- *             In the future, this will invoke the archived accessd method.  For
- *             now, archive relations are on mag disk.
- */
-static void
-vc_archive(Relation archrel, HeapTuple htup)
-{
-       doinsert(archrel, htup);
-}
-
-static bool
-vc_isarchrel(char *rname)
-{
-       if (strncmp(ARCHIVE_PREFIX, rname, strlen(ARCHIVE_PREFIX)) == 0)
-               return (true);
-
-       return (false);
-}
-
 static char *
 vc_find_eq(char *bot, int nelem, int size, char *elm, int (*compar) (char *, char *))
 {
@@ -2225,7 +2099,7 @@ vc_find_eq(char *bot, int nelem, int size, char *elm, int (*compar) (char *, cha
                first_move = true;
        }
 
-}                                                              /* vc_find_eq */
+}      /* vc_find_eq */
 
 static int
 vc_cmp_blk(char *left, char *right)
@@ -2242,7 +2116,7 @@ vc_cmp_blk(char *left, char *right)
                return (0);
        return (1);
 
-}                                                              /* vc_cmp_blk */
+}      /* vc_cmp_blk */
 
 static int
 vc_cmp_offno(char *left, char *right)
@@ -2254,7 +2128,7 @@ vc_cmp_offno(char *left, char *right)
                return (0);
        return (1);
 
-}                                                              /* vc_cmp_offno */
+}      /* vc_cmp_offno */
 
 
 static void
@@ -2281,14 +2155,14 @@ vc_getindices(Oid relid, int *nindices, Relation **Irel)
        pgidesc = RelationGetTupleDescriptor(pgindex);
 
        ScanKeyEntryInitialize(&pgikey, 0x0, Anum_pg_index_indrelid,
-                                                  ObjectIdEqualRegProcedure,
+                                                  F_OIDEQ,
                                                   ObjectIdGetDatum(relid));
 
-       pgiscan = heap_beginscan(pgindex, false, NowTimeQual, 1, &pgikey);
+       pgiscan = heap_beginscan(pgindex, false, false, 1, &pgikey);
 
        while (HeapTupleIsValid(pgitup = heap_getnext(pgiscan, 0, NULL)))
        {
-               d = heap_getattr(pgitup, InvalidBuffer, Anum_pg_index_indexrelid,
+               d = heap_getattr(pgitup, Anum_pg_index_indexrelid,
                                                 pgidesc, &n);
                i++;
                if (i % 10 == 0)
@@ -2331,7 +2205,7 @@ vc_getindices(Oid relid, int *nindices, Relation **Irel)
                *Irel = (Relation *) NULL;
        }
 
-}                                                              /* vc_getindices */
+}      /* vc_getindices */
 
 
 static void
@@ -2342,12 +2216,10 @@ vc_clsindices(int nindices, Relation *Irel)
                return;
 
        while (nindices--)
-       {
                index_close(Irel[nindices]);
-       }
        pfree(Irel);
 
-}                                                              /* vc_clsindices */
+}      /* vc_clsindices */
 
 
 static void
@@ -2386,7 +2258,7 @@ vc_mkindesc(Relation onerel, int nindices, Relation *Irel, IndDesc **Idesc)
                idcur->natts = natts;
        }
 
-}                                                              /* vc_mkindesc */
+}      /* vc_mkindesc */
 
 
 static bool
@@ -2407,4 +2279,4 @@ vc_enough_space(VPageDescr vpd, Size len)
 
        return (false);
 
-}                                                              /* vc_enough_space */
+}      /* vc_enough_space */