Header And Logo

PostgreSQL
| The world's most advanced open source database.

indexfsm.c

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * indexfsm.c
00004  *    POSTGRES free space map for quickly finding free pages in relations
00005  *
00006  *
00007  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
00008  * Portions Copyright (c) 1994, Regents of the University of California
00009  *
00010  * IDENTIFICATION
00011  *    src/backend/storage/freespace/indexfsm.c
00012  *
00013  *
00014  * NOTES:
00015  *
00016  *  This is similar to the FSM used for heap, in freespace.c, but instead
00017  *  of tracking the amount of free space on pages, we only track whether
00018  *  pages are completely free or in-use. We use the same FSM implementation
00019  *  as for heaps, using BLCKSZ - 1 to denote used pages, and 0 for unused.
00020  *
00021  *-------------------------------------------------------------------------
00022  */
00023 #include "postgres.h"
00024 
00025 #include "storage/freespace.h"
00026 #include "storage/indexfsm.h"
00027 
00028 /*
00029  * Exported routines
00030  */
00031 
00032 /*
00033  * GetFreeIndexPage - return a free page from the FSM
00034  *
00035  * As a side effect, the page is marked as used in the FSM.
00036  */
00037 BlockNumber
00038 GetFreeIndexPage(Relation rel)
00039 {
00040     BlockNumber blkno = GetPageWithFreeSpace(rel, BLCKSZ / 2);
00041 
00042     if (blkno != InvalidBlockNumber)
00043         RecordUsedIndexPage(rel, blkno);
00044 
00045     return blkno;
00046 }
00047 
00048 /*
00049  * RecordFreeIndexPage - mark a page as free in the FSM
00050  */
00051 void
00052 RecordFreeIndexPage(Relation rel, BlockNumber freeBlock)
00053 {
00054     RecordPageWithFreeSpace(rel, freeBlock, BLCKSZ - 1);
00055 }
00056 
00057 
00058 /*
00059  * RecordUsedIndexPage - mark a page as used in the FSM
00060  */
00061 void
00062 RecordUsedIndexPage(Relation rel, BlockNumber usedBlock)
00063 {
00064     RecordPageWithFreeSpace(rel, usedBlock, 0);
00065 }
00066 
00067 /*
00068  * IndexFreeSpaceMapVacuum - scan and fix any inconsistencies in the FSM
00069  */
00070 void
00071 IndexFreeSpaceMapVacuum(Relation rel)
00072 {
00073     FreeSpaceMapVacuum(rel);
00074 }