PostgreSQL Source Code git master
indexfsm.c
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * indexfsm.c
4 * POSTGRES free space map for quickly finding free pages in relations
5 *
6 *
7 * Portions Copyright (c) 1996-2025, 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
28/*
29 * Exported routines
30 */
31
32/*
33 * GetFreeIndexPage - return a free page from the FSM
34 *
35 * As a side effect, the page is marked as used in the FSM.
36 */
39{
40 BlockNumber blkno = GetPageWithFreeSpace(rel, BLCKSZ / 2);
41
42 if (blkno != InvalidBlockNumber)
43 RecordUsedIndexPage(rel, blkno);
44
45 return blkno;
46}
47
48/*
49 * RecordFreeIndexPage - mark a page as free in the FSM
50 */
51void
53{
54 RecordPageWithFreeSpace(rel, freeBlock, BLCKSZ - 1);
55}
56
57
58/*
59 * RecordUsedIndexPage - mark a page as used in the FSM
60 */
61void
63{
64 RecordPageWithFreeSpace(rel, usedBlock, 0);
65}
66
67/*
68 * IndexFreeSpaceMapVacuum - scan and fix any inconsistencies in the FSM
69 */
70void
72{
74}
uint32 BlockNumber
Definition: block.h:31
#define InvalidBlockNumber
Definition: block.h:33
void FreeSpaceMapVacuum(Relation rel)
Definition: freespace.c:358
void RecordPageWithFreeSpace(Relation rel, BlockNumber heapBlk, Size spaceAvail)
Definition: freespace.c:194
BlockNumber GetPageWithFreeSpace(Relation rel, Size spaceNeeded)
Definition: freespace.c:137
void RecordUsedIndexPage(Relation rel, BlockNumber usedBlock)
Definition: indexfsm.c:62
BlockNumber GetFreeIndexPage(Relation rel)
Definition: indexfsm.c:38
void IndexFreeSpaceMapVacuum(Relation rel)
Definition: indexfsm.c:71
void RecordFreeIndexPage(Relation rel, BlockNumber freeBlock)
Definition: indexfsm.c:52