X-Original-To: pgsql-patches-postgresql.org@postgresql.org Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id 654299FC58E for ; Sun, 27 Aug 2006 11:10:24 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 78111-06 for ; Sun, 27 Aug 2006 14:10:17 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey- Received: from localhost.localdomain (host86-130-26-100.range86-130.btcentralplus.com [86.130.26.100]) by postgresql.org (Postfix) with ESMTP id 11A869FC57B for ; Sun, 27 Aug 2006 11:10:16 -0300 (ADT) Received: from localhost ([127.0.0.1] helo=localhost.localdomain) by localhost.localdomain with esmtp (Exim 4.62) (envelope-from ) id 1GHLL4-00009V-UE for pgsql-patches@postgresql.org; Sun, 27 Aug 2006 15:10:14 +0100 To: pgsql-patches@postgresql.org Subject: Trivial patch to double vacuum speed on tables with no indexes From: stark X-Draft-From: ("nnimap+webmail.enterprisedb.com:Inbox" 777) Date: Sun, 27 Aug 2006 15:10:14 +0100 Message-ID: <877j0umfqx.fsf@enterprisedb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=2.081 tagged_above=0 required=5 tests=FORGED_RCVD_HELO, RCVD_IN_NJABL_DUL X-Spam-Level: ** X-Archive-Number: 200608/384 X-Sequence-Number: 20900 There isn't really any need for the second pass in lazy vacuum if the table has no indexes. The patch seems almost too easy but of course nothing having to do with vacuum is as easy as it appears. Perhaps there are some gotchas I haven't thought of? Index: src/backend/commands/vacuumlazy.c =================================================================== RCS file: /projects/cvsroot/pgsql/src/backend/commands/vacuumlazy.c,v retrieving revision 1.76 diff -c -r1.76 vacuumlazy.c *** src/backend/commands/vacuumlazy.c 31 Jul 2006 20:09:00 -0000 1.76 --- src/backend/commands/vacuumlazy.c 27 Aug 2006 14:06:10 -0000 *************** *** 450,455 **** --- 450,464 ---- { lazy_record_free_space(vacrelstats, blkno, PageGetFreeSpace(page)); + } else if (!nindexes) { + /* If there are no indexes we can vacuum the page right now instead + * of doing a second scan */ + + LockBuffer(buf, BUFFER_LOCK_UNLOCK); + LockBufferForCleanup(buf); + lazy_vacuum_page(onerel, blkno, buf, 0, vacrelstats); + lazy_record_free_space(vacrelstats, blkno, PageGetFreeSpace(BufferGetPage(buf))); + vacrelstats->num_dead_tuples = 0; } /* Remember the location of the last page with nonremovable tuples */ -- Gregory Stark EnterpriseDB http://www.enterprisedb.com