~ubuntu-branches/ubuntu/natty/postgresql-8.4/natty-security

« back to all changes in this revision

Viewing changes to src/backend/commands/vacuumlazy.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-07-01 17:41:41 UTC
  • mfrom: (1.1.4 upstream)
  • mto: This revision was merged to the branch mainline in revision 6.
  • Revision ID: james.westby@ubuntu.com-20090701174141-jfmn9tt8e69m950x
Tags: 8.4.0-1
* Final 8.4.0 release. Major enhancements:
  - Windowing Functions
  - Common Table Expressions and Recursive Queries
  - Default and variadic parameters for functions
  - Parallel Restore
  - Column Permissions
  - Per-database locale settings
  - Improved hash indexes
  - Improved join performance for EXISTS and NOT EXISTS queries
  - Easier-to-use Warm Standby
  - Automatic sizing of the Free Space Map
  - Visibility Map (greatly reduces vacuum overhead for slowly-changing
    tables)
  - Version-aware psql (backslash commands work against older servers)
  - Support SSL certificates for user authentication
  - Per-function runtime statistics
  - Easy editing of functions in psql
  - New contrib modules: pg_stat_statements, auto_explain, citext,
    btree_gin 
  Upload to unstable, 8.4 is the new default. 
* debian/control: Build the versionless metapackages and have them point to
  8.4.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
 *
30
30
 *
31
31
 * IDENTIFICATION
32
 
 *        $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.119 2009/03/24 20:17:14 tgl Exp $
 
32
 *        $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.121 2009/06/11 14:48:56 momjian Exp $
33
33
 *
34
34
 *-------------------------------------------------------------------------
35
35
 */
84
84
{
85
85
        /* hasindex = true means two-pass strategy; false means one-pass */
86
86
        bool            hasindex;
 
87
        bool            scanned_all;    /* have we scanned all pages (this far)? */
87
88
        /* Overall statistics about rel */
88
89
        BlockNumber rel_pages;
89
 
        double          rel_tuples;
 
90
        double          old_rel_tuples; /* previous value of pg_class.reltuples */
 
91
        double          rel_tuples;             /* counts only tuples on scanned pages */
90
92
        BlockNumber pages_removed;
91
93
        double          tuples_deleted;
92
94
        BlockNumber nonempty_pages; /* actually, last nonempty page + 1 */
96
98
        int                     max_dead_tuples;        /* # slots allocated in array */
97
99
        ItemPointer dead_tuples;        /* array of ItemPointerData */
98
100
        int                     num_index_scans;
99
 
        bool            scanned_all;    /* have we scanned all pages (this far)? */
100
101
} LVRelStats;
101
102
 
102
103
 
174
175
 
175
176
        vacrelstats = (LVRelStats *) palloc0(sizeof(LVRelStats));
176
177
 
 
178
        vacrelstats->scanned_all = true;        /* will be cleared if we skip a page */
 
179
        vacrelstats->old_rel_tuples = onerel->rd_rel->reltuples;
177
180
        vacrelstats->num_index_scans = 0;
178
 
        vacrelstats->scanned_all = true; /* will be cleared if we skip a page */
179
181
 
180
182
        /* Open all indexes of the relation */
181
183
        vac_open_indexes(onerel, RowExclusiveLock, &nindexes, &Irel);
182
184
        vacrelstats->hasindex = (nindexes > 0);
183
 
 
 
185
 
184
186
        /* Do the vacuuming */
185
187
        lazy_scan_heap(onerel, vacrelstats, Irel, nindexes, scan_all);
186
188
 
206
208
         * Update statistics in pg_class.  But only if we didn't skip any pages;
207
209
         * the tuple count only includes tuples from the pages we've visited, and
208
210
         * we haven't frozen tuples in unvisited pages either.  The page count is
209
 
         * accurate in any case, but because we use the reltuples / relpages
210
 
         * ratio in the planner, it's better to not update relpages either if we
211
 
         * can't update reltuples.
 
211
         * accurate in any case, but because we use the reltuples / relpages ratio
 
212
         * in the planner, it's better to not update relpages either if we can't
 
213
         * update reltuples.
212
214
         */
213
215
        if (vacrelstats->scanned_all)
214
216
                vac_update_relstats(onerel,
277
279
        int                     i;
278
280
        PGRUsage        ru0;
279
281
        Buffer          vmbuffer = InvalidBuffer;
280
 
        BlockNumber     all_visible_streak;
 
282
        BlockNumber all_visible_streak;
281
283
 
282
284
        pg_rusage_init(&ru0);
283
285
 
316
318
                bool            all_visible;
317
319
 
318
320
                /*
319
 
                 * Skip pages that don't require vacuuming according to the
320
 
                 * visibility map. But only if we've seen a streak of at least
 
321
                 * Skip pages that don't require vacuuming according to the visibility
 
322
                 * map. But only if we've seen a streak of at least
321
323
                 * SKIP_PAGES_THRESHOLD pages marked as clean. Since we're reading
322
324
                 * sequentially, the OS should be doing readahead for us and there's
323
325
                 * no gain in skipping a page now and then. You need a longer run of
556
558
                                                        all_visible = false;
557
559
                                                        break;
558
560
                                                }
 
561
 
559
562
                                                /*
560
 
                                                 * The inserter definitely committed. But is it
561
 
                                                 * old enough that everyone sees it as committed?
 
563
                                                 * The inserter definitely committed. But is it old
 
564
                                                 * enough that everyone sees it as committed?
562
565
                                                 */
563
566
                                                xmin = HeapTupleHeaderGetXmin(tuple.t_data);
564
567
                                                if (!TransactionIdPrecedes(xmin, OldestXmin))
876
879
        ivinfo.index = indrel;
877
880
        ivinfo.vacuum_full = false;
878
881
        ivinfo.analyze_only = false;
 
882
        ivinfo.estimated_count = true;
879
883
        ivinfo.message_level = elevel;
880
 
        /* We don't yet know rel_tuples, so pass -1 */
881
 
        ivinfo.num_heap_tuples = -1;
 
884
        ivinfo.num_heap_tuples = vacrelstats->old_rel_tuples;
882
885
        ivinfo.strategy = vac_strategy;
883
886
 
884
887
        /* Do bulk deletion */
908
911
        ivinfo.index = indrel;
909
912
        ivinfo.vacuum_full = false;
910
913
        ivinfo.analyze_only = false;
 
914
        ivinfo.estimated_count = !vacrelstats->scanned_all;
911
915
        ivinfo.message_level = elevel;
912
 
        ivinfo.num_heap_tuples = vacrelstats->rel_tuples;
 
916
        /* use rel_tuples only if we scanned all pages, else fall back */
 
917
        ivinfo.num_heap_tuples = vacrelstats->scanned_all ? vacrelstats->rel_tuples : vacrelstats->old_rel_tuples;
913
918
        ivinfo.strategy = vac_strategy;
914
919
 
915
920
        stats = index_vacuum_cleanup(&ivinfo, stats);
917
922
        if (!stats)
918
923
                return;
919
924
 
920
 
        /* now update statistics in pg_class */
921
 
        vac_update_relstats(indrel,
922
 
                                                stats->num_pages, stats->num_index_tuples,
923
 
                                                false, InvalidTransactionId);
 
925
        /*
 
926
         * Now update statistics in pg_class, but only if the index says the count
 
927
         * is accurate.
 
928
         */
 
929
        if (!stats->estimated_count)
 
930
                vac_update_relstats(indrel,
 
931
                                                        stats->num_pages, stats->num_index_tuples,
 
932
                                                        false, InvalidTransactionId);
924
933
 
925
934
        ereport(elevel,
926
935
                        (errmsg("index \"%s\" now contains %.0f row versions in %u pages",