]> granicus.if.org Git - postgresql/blob - src/backend/storage/freespace/indexfsm.c
Stamp copyrights for year 2011.
[postgresql] / src / backend / storage / freespace / indexfsm.c
1 /*-------------------------------------------------------------------------
2  *
3  * indexfsm.c
4  *        POSTGRES free space map for quickly finding free pages in relations
5  *
6  *
7  * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * IDENTIFICATION
11  *        src/backend/storage/freespace/indexfsm.c
12  *
13  *
14  * NOTES:
15  *
16  *      This is similar to the FSM used for heap, in freespace.c, but instead
17  *      of tracking the amount of free space on pages, we only track whether
18  *      pages are completely free or in-use. We use the same FSM implementation
19  *      as for heaps, using BLCKSZ - 1 to denote used pages, and 0 for unused.
20  *
21  *-------------------------------------------------------------------------
22  */
23 #include "postgres.h"
24
25 #include "storage/freespace.h"
26 #include "storage/indexfsm.h"
27 #include "storage/smgr.h"
28
29 /*
30  * Exported routines
31  */
32
33 /*
34  * GetFreeIndexPage - return a free page from the FSM
35  *
36  * As a side effect, the page is marked as used in the FSM.
37  */
38 BlockNumber
39 GetFreeIndexPage(Relation rel)
40 {
41         BlockNumber blkno = GetPageWithFreeSpace(rel, BLCKSZ / 2);
42
43         if (blkno != InvalidBlockNumber)
44                 RecordUsedIndexPage(rel, blkno);
45
46         return blkno;
47 }
48
49 /*
50  * RecordFreeIndexPage - mark a page as free in the FSM
51  */
52 void
53 RecordFreeIndexPage(Relation rel, BlockNumber freeBlock)
54 {
55         RecordPageWithFreeSpace(rel, freeBlock, BLCKSZ - 1);
56 }
57
58
59 /*
60  * RecordUsedIndexPage - mark a page as used in the FSM
61  */
62 void
63 RecordUsedIndexPage(Relation rel, BlockNumber usedBlock)
64 {
65         RecordPageWithFreeSpace(rel, usedBlock, 0);
66 }
67
68 /*
69  * IndexFreeSpaceMapVacuum - scan and fix any inconsistencies in the FSM
70  */
71 void
72 IndexFreeSpaceMapVacuum(Relation rel)
73 {
74         FreeSpaceMapVacuum(rel);
75 }