]> granicus.if.org Git - postgresql/commit
Avoid creation of the free space map for small heap relations.
authorAmit Kapila <akapila@postgresql.org>
Mon, 28 Jan 2019 02:44:06 +0000 (08:14 +0530)
committerAmit Kapila <akapila@postgresql.org>
Mon, 28 Jan 2019 02:44:06 +0000 (08:14 +0530)
commitac88d2962a96a9c7e83d5acfc28fe49a72812086
treec66901928bff8ba6a1998f3304551f13cab68c61
parentd66e3664b8baf41908865ad363c6ba943e6f9c4e
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
16 files changed:
contrib/pageinspect/expected/page.out
contrib/pageinspect/sql/page.sql
doc/src/sgml/storage.sgml
src/backend/access/brin/brin.c
src/backend/access/brin/brin_pageops.c
src/backend/access/heap/hio.c
src/backend/access/heap/vacuumlazy.c
src/backend/access/transam/xact.c
src/backend/storage/freespace/README
src/backend/storage/freespace/freespace.c
src/backend/storage/freespace/indexfsm.c
src/include/storage/freespace.h
src/test/regress/expected/fsm.out [new file with mode: 0644]
src/test/regress/parallel_schedule
src/test/regress/serial_schedule
src/test/regress/sql/fsm.sql [new file with mode: 0644]