mirror of
https://github.com/postgres/postgres.git
synced 2025-07-27 12:41:57 +03:00
Avoid creation of the free space map for small heap relations, take 2.
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, Amit Kapila Reviewed-by: Amit Kapila Tested-by: Mithun C Y Discussion: https://www.postgresql.org/message-id/CAJVSVGWvB13PzpbLEecFuGFc5V2fsO736BsdTakPiPAcdMM5tQ@mail.gmail.com
This commit is contained in:
@ -1,26 +1,35 @@
|
||||
CREATE EXTENSION pageinspect;
|
||||
|
||||
CREATE TABLE test1 (a int, b int);
|
||||
INSERT INTO test1 VALUES (16777217, 131584);
|
||||
CREATE TABLE test_rel_forks (a int);
|
||||
-- Make sure there are enough blocks in the heap for the FSM to be created.
|
||||
INSERT INTO test_rel_forks SELECT i from generate_series(1,2000) i;
|
||||
|
||||
VACUUM test1; -- set up FSM
|
||||
-- set up FSM and VM
|
||||
VACUUM test_rel_forks;
|
||||
|
||||
-- The page contents can vary, so just test that it can be read
|
||||
-- successfully, but don't keep the output.
|
||||
|
||||
SELECT octet_length(get_raw_page('test1', 'main', 0)) AS main_0;
|
||||
SELECT octet_length(get_raw_page('test1', 'main', 1)) AS main_1;
|
||||
SELECT octet_length(get_raw_page('test_rel_forks', 'main', 0)) AS main_0;
|
||||
SELECT octet_length(get_raw_page('test_rel_forks', 'main', 100)) AS main_100;
|
||||
|
||||
SELECT octet_length(get_raw_page('test1', 'fsm', 0)) AS fsm_0;
|
||||
SELECT octet_length(get_raw_page('test1', 'fsm', 1)) AS fsm_1;
|
||||
SELECT octet_length(get_raw_page('test_rel_forks', 'fsm', 0)) AS fsm_0;
|
||||
SELECT octet_length(get_raw_page('test_rel_forks', 'fsm', 20)) AS fsm_20;
|
||||
|
||||
SELECT octet_length(get_raw_page('test1', 'vm', 0)) AS vm_0;
|
||||
SELECT octet_length(get_raw_page('test1', 'vm', 1)) AS vm_1;
|
||||
SELECT octet_length(get_raw_page('test_rel_forks', 'vm', 0)) AS vm_0;
|
||||
SELECT octet_length(get_raw_page('test_rel_forks', 'vm', 1)) AS vm_1;
|
||||
|
||||
SELECT octet_length(get_raw_page('xxx', 'main', 0));
|
||||
SELECT octet_length(get_raw_page('test1', 'xxx', 0));
|
||||
SELECT octet_length(get_raw_page('test_rel_forks', 'xxx', 0));
|
||||
|
||||
SELECT get_raw_page('test1', 0) = get_raw_page('test1', 'main', 0);
|
||||
SELECT * FROM fsm_page_contents(get_raw_page('test_rel_forks', 'fsm', 0));
|
||||
|
||||
SELECT get_raw_page('test_rel_forks', 0) = get_raw_page('test_rel_forks', 'main', 0);
|
||||
|
||||
DROP TABLE test_rel_forks;
|
||||
|
||||
CREATE TABLE test1 (a int, b int);
|
||||
INSERT INTO test1 VALUES (16777217, 131584);
|
||||
|
||||
SELECT pagesize, version FROM page_header(get_raw_page('test1', 0));
|
||||
|
||||
@ -29,8 +38,6 @@ SELECT page_checksum(get_raw_page('test1', 0), 0) IS NOT NULL AS silly_checksum_
|
||||
SELECT tuple_data_split('test1'::regclass, t_data, t_infomask, t_infomask2, t_bits)
|
||||
FROM heap_page_items(get_raw_page('test1', 0));
|
||||
|
||||
SELECT * FROM fsm_page_contents(get_raw_page('test1', 'fsm', 0));
|
||||
|
||||
DROP TABLE test1;
|
||||
|
||||
-- check that using any of these functions with a partitioned table or index
|
||||
|
Reference in New Issue
Block a user