diff options
| author | Amit Kapila | 2019-01-28 02:44:06 +0000 |
|---|---|---|
| committer | Amit Kapila | 2019-01-28 02:44:06 +0000 |
| commit | ac88d2962a96a9c7e83d5acfc28fe49a72812086 (patch) | |
| tree | c66901928bff8ba6a1998f3304551f13cab68c61 /src/include | |
| parent | d66e3664b8baf41908865ad363c6ba943e6f9c4e (diff) | |
Avoid creation of the free space map for small heap relations.
Previously, all heaps had FSMs. For very small tables, this means that the
FSM took up more space than the heap did. This is wasteful, so now we
refrain from creating the FSM for heaps with 4 pages or fewer. If the last
known target block has insufficient space, we still try to insert into some
other page before giving up and extending the relation, since doing
otherwise leads to table bloat. Testing showed that trying every page
penalized performance slightly, so we compromise and try every other page.
This way, we visit at most two pages. Any pages with wasted free space
become visible at next relation extension, so we still control table bloat.
As a bonus, directly attempting one or two pages can even be faster than
consulting the FSM would have been.
Once the FSM is created for a heap we don't remove it even if somebody
deletes all the rows from the corresponding relation. We don't think it is
a useful optimization as it is quite likely that relation will again grow
to the same size.
Author: John Naylor with design inputs and some code contribution by Amit Kapila
Reviewed-by: Amit Kapila
Tested-by: Mithun C Y
Discussion: https://www.postgresql.org/message-id/CAJVSVGWvB13PzpbLEecFuGFc5V2fsO736BsdTakPiPAcdMM5tQ@mail.gmail.com
Diffstat (limited to 'src/include')
| -rw-r--r-- | src/include/storage/freespace.h | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/include/storage/freespace.h b/src/include/storage/freespace.h index 8b000334382..dbaae651c58 100644 --- a/src/include/storage/freespace.h +++ b/src/include/storage/freespace.h @@ -18,15 +18,20 @@ #include "storage/relfilenode.h" #include "utils/relcache.h" +/* Only create the FSM if the heap has greater than this many blocks */ +#define HEAP_FSM_CREATION_THRESHOLD 4 + /* prototypes for public functions in freespace.c */ extern Size GetRecordedFreeSpace(Relation rel, BlockNumber heapBlk); -extern BlockNumber GetPageWithFreeSpace(Relation rel, Size spaceNeeded); +extern BlockNumber GetPageWithFreeSpace(Relation rel, Size spaceNeeded, + bool check_fsm_only); extern BlockNumber RecordAndGetPageWithFreeSpace(Relation rel, BlockNumber oldPage, Size oldSpaceAvail, Size spaceNeeded); extern void RecordPageWithFreeSpace(Relation rel, BlockNumber heapBlk, - Size spaceAvail); + Size spaceAvail, BlockNumber nblocks); +extern void FSMClearLocalMap(void); extern void XLogRecordPageWithFreeSpace(RelFileNode rnode, BlockNumber heapBlk, Size spaceAvail); |
