1
0
mirror of https://github.com/postgres/postgres.git synced 2025-10-25 13:17:41 +03:00

More infrastructure for btree compaction project. Tree-traversal code

now knows what to do upon hitting a dead page (in theory anyway, it's
untested...).  Add a post-VACUUM-cleanup entry point for index AMs, to
provide a place for dead-page scavenging to happen.
Also, fix oversight that broke btpo_prev links in temporary indexes.
initdb forced due to additions in pg_am.
This commit is contained in:
Tom Lane
2003-02-22 00:45:05 +00:00
parent 4fff132d1b
commit 799bc58dc7
18 changed files with 709 additions and 345 deletions

View File

@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: genam.h,v 1.37 2002/09/04 20:31:36 momjian Exp $
* $Id: genam.h,v 1.38 2003/02/22 00:45:05 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -20,17 +20,32 @@
#include "nodes/primnodes.h"
/* Struct for statistics returned by bulk-delete operation */
/*
* Struct for statistics returned by bulk-delete operation
*
* This is now also passed to the index AM's vacuum-cleanup operation,
* if it has one, which can modify the results as needed. Note that
* an index AM could choose to have bulk-delete return a larger struct
* of which this is just the first field; this provides a way for bulk-delete
* to communicate additional private data to vacuum-cleanup.
*/
typedef struct IndexBulkDeleteResult
{
BlockNumber num_pages; /* pages remaining in index */
double num_index_tuples; /* tuples remaining */
double tuples_removed; /* # removed by bulk-delete operation */
double num_index_tuples; /* # remaining */
BlockNumber pages_free; /* # unused pages in index */
} IndexBulkDeleteResult;
/* Typedef for callback function to determine if a tuple is bulk-deletable */
typedef bool (*IndexBulkDeleteCallback) (ItemPointer itemptr, void *state);
/* Struct for additional arguments passed to vacuum-cleanup operation */
typedef struct IndexVacuumCleanupInfo
{
bool vacuum_full; /* VACUUM FULL (we have exclusive lock) */
int message_level; /* elog level for progress messages */
} IndexVacuumCleanupInfo;
/* Struct for heap-or-index scans of system tables */
typedef struct SysScanDescData
@@ -72,6 +87,9 @@ extern bool index_getnext_indexitem(IndexScanDesc scan,
extern IndexBulkDeleteResult *index_bulk_delete(Relation indexRelation,
IndexBulkDeleteCallback callback,
void *callback_state);
extern IndexBulkDeleteResult *index_vacuum_cleanup(Relation indexRelation,
IndexVacuumCleanupInfo *info,
IndexBulkDeleteResult *stats);
extern RegProcedure index_cost_estimator(Relation indexRelation);
extern RegProcedure index_getprocid(Relation irel, AttrNumber attnum,
uint16 procnum);

View File

@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: nbtree.h,v 1.64 2003/02/21 00:06:22 tgl Exp $
* $Id: nbtree.h,v 1.65 2003/02/22 00:45:05 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -54,6 +54,7 @@ typedef BTPageOpaqueData *BTPageOpaque;
#define BTP_ROOT (1 << 1) /* root page (has no parent) */
#define BTP_DELETED (1 << 2) /* page has been deleted from tree */
#define BTP_META (1 << 3) /* meta-page */
#define BTP_HALF_DEAD (1 << 4) /* empty, but still in tree */
/*
@@ -124,12 +125,13 @@ typedef BTItemData *BTItem;
#define SizeOfBTItem sizeof(BTItemData)
/* Test whether items are the "same" per the above notes */
#define BTItemSame(i1, i2) ( (i1)->bti_itup.t_tid.ip_blkid.bi_hi == \
(i2)->bti_itup.t_tid.ip_blkid.bi_hi && \
(i1)->bti_itup.t_tid.ip_blkid.bi_lo == \
(i2)->bti_itup.t_tid.ip_blkid.bi_lo && \
(i1)->bti_itup.t_tid.ip_posid == \
(i2)->bti_itup.t_tid.ip_posid )
#define BTTidSame(i1, i2) \
( (i1).ip_blkid.bi_hi == (i2).ip_blkid.bi_hi && \
(i1).ip_blkid.bi_lo == (i2).ip_blkid.bi_lo && \
(i1).ip_posid == (i2).ip_posid )
#define BTItemSame(i1, i2) \
BTTidSame((i1)->bti_itup.t_tid, (i2)->bti_itup.t_tid)
/*
* In general, the btree code tries to localize its knowledge about
@@ -150,6 +152,7 @@ typedef BTItemData *BTItem;
#define P_ISLEAF(opaque) ((opaque)->btpo_flags & BTP_LEAF)
#define P_ISROOT(opaque) ((opaque)->btpo_flags & BTP_ROOT)
#define P_ISDELETED(opaque) ((opaque)->btpo_flags & BTP_DELETED)
#define P_IGNORE(opaque) ((opaque)->btpo_flags & (BTP_DELETED|BTP_HALF_DEAD))
/*
* Lehman and Yao's algorithm requires a ``high key'' on every non-rightmost
@@ -412,8 +415,6 @@ typedef BTScanOpaqueData *BTScanOpaque;
/*
* prototypes for functions in nbtree.c (external entry points for btree)
*/
extern bool BuildingBtree; /* in nbtree.c */
extern void AtEOXact_nbtree(void);
extern Datum btbuild(PG_FUNCTION_ARGS);
@@ -426,6 +427,7 @@ extern Datum btendscan(PG_FUNCTION_ARGS);
extern Datum btmarkpos(PG_FUNCTION_ARGS);
extern Datum btrestrpos(PG_FUNCTION_ARGS);
extern Datum btbulkdelete(PG_FUNCTION_ARGS);
extern Datum btvacuumcleanup(PG_FUNCTION_ARGS);
/*
* prototypes for functions in nbtinsert.c

View File

@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: xlog.h,v 1.41 2003/02/21 00:06:22 tgl Exp $
* $Id: xlog.h,v 1.42 2003/02/22 00:45:05 tgl Exp $
*/
#ifndef XLOG_H
#define XLOG_H
@@ -56,17 +56,18 @@ typedef struct XLogRecord
#define XLR_INFO_MASK 0x0F
/*
* We support backup of up to 2 disk blocks per XLOG record (could support
* more if we cared to dedicate more xl_info bits for this purpose; currently
* do not need more than 2 anyway). If we backed up any disk blocks then we
* use flag bits in xl_info to signal it.
* If we backed up any disk blocks with the XLOG record, we use flag bits in
* xl_info to signal it. We support backup of up to 3 disk blocks per XLOG
* record. (Could support 4 if we cared to dedicate all the xl_info bits for
* this purpose; currently bit 0 of xl_info is unused and available.)
*/
#define XLR_BKP_BLOCK_MASK 0x0C /* all info bits used for bkp
#define XLR_BKP_BLOCK_MASK 0x0E /* all info bits used for bkp
* blocks */
#define XLR_MAX_BKP_BLOCKS 2
#define XLR_MAX_BKP_BLOCKS 3
#define XLR_SET_BKP_BLOCK(iblk) (0x08 >> (iblk))
#define XLR_BKP_BLOCK_1 XLR_SET_BKP_BLOCK(0) /* 0x08 */
#define XLR_BKP_BLOCK_2 XLR_SET_BKP_BLOCK(1) /* 0x04 */
#define XLR_BKP_BLOCK_3 XLR_SET_BKP_BLOCK(2) /* 0x02 */
/*
* Sometimes we log records which are out of transaction control.