mirror of
https://github.com/postgres/postgres.git
synced 2025-12-10 14:22:35 +03:00
Revert "Avoid the creation of the free space map for small heap relations".
This feature was using a process local map to track the first few blocks in the relation. The map was reset each time we get the block with enough freespace. It was discussed that it would be better to track this map on a per-relation basis in relcache and then invalidate the same whenever vacuum frees up some space in the page or when FSM is created. The new design would be better both in terms of API design and performance. List of commits reverted, in reverse chronological order:06c8a5090eImprove code comments inb0eaa4c51b.13e8643bfcDuring pg_upgrade, conditionally skip transfer of FSMs.6f918159a9Add more tests for FSM.9c32e4c350Clear the local map when not used.29d108cdecUpdate the documentation for FSM behavior..08ecdfe7e5Make FSM test portable.b0eaa4c51bAvoid creation of the free space map for small heap relations. Discussion: https://postgr.es/m/20190416180452.3pm6uegx54iitbt5@alap3.anarazel.de
This commit is contained in:
@@ -1,73 +0,0 @@
|
||||
--
|
||||
-- Free Space Map test
|
||||
--
|
||||
SELECT current_setting('block_size')::integer AS blocksize,
|
||||
current_setting('block_size')::integer / 8 AS strsize
|
||||
\gset
|
||||
CREATE TABLE fsm_check_size (num int, str text);
|
||||
-- Fill 3 blocks with one record each
|
||||
ALTER TABLE fsm_check_size SET (fillfactor=15);
|
||||
INSERT INTO fsm_check_size SELECT i, rpad('', :strsize, 'a')
|
||||
FROM generate_series(1,3) i;
|
||||
-- There should be no FSM
|
||||
VACUUM fsm_check_size;
|
||||
SELECT pg_relation_size('fsm_check_size', 'main') / :blocksize AS heap_nblocks,
|
||||
pg_relation_size('fsm_check_size', 'fsm') / :blocksize AS fsm_nblocks;
|
||||
heap_nblocks | fsm_nblocks
|
||||
--------------+-------------
|
||||
3 | 0
|
||||
(1 row)
|
||||
|
||||
-- The following operations are for testing the functionality of the local
|
||||
-- in-memory map. In particular, we want to be able to insert into some
|
||||
-- other block than the one at the end of the heap, without using a FSM.
|
||||
-- Fill most of the last block
|
||||
ALTER TABLE fsm_check_size SET (fillfactor=100);
|
||||
INSERT INTO fsm_check_size SELECT i, rpad('', :strsize, 'a')
|
||||
FROM generate_series(101,105) i;
|
||||
-- Make sure records can go into any block but the last one
|
||||
ALTER TABLE fsm_check_size SET (fillfactor=30);
|
||||
-- Insert large record and make sure it does not cause the relation to extend
|
||||
INSERT INTO fsm_check_size VALUES (111, rpad('', :strsize, 'a'));
|
||||
VACUUM fsm_check_size;
|
||||
SELECT pg_relation_size('fsm_check_size', 'main') / :blocksize AS heap_nblocks,
|
||||
pg_relation_size('fsm_check_size', 'fsm') / :blocksize AS fsm_nblocks;
|
||||
heap_nblocks | fsm_nblocks
|
||||
--------------+-------------
|
||||
3 | 0
|
||||
(1 row)
|
||||
|
||||
-- Extend table with enough blocks to exceed the FSM threshold
|
||||
DO $$
|
||||
DECLARE curtid tid;
|
||||
num int;
|
||||
BEGIN
|
||||
num = 11;
|
||||
LOOP
|
||||
INSERT INTO fsm_check_size VALUES (num, 'b') RETURNING ctid INTO curtid;
|
||||
EXIT WHEN curtid >= tid '(4, 0)';
|
||||
num = num + 1;
|
||||
END LOOP;
|
||||
END;
|
||||
$$;
|
||||
VACUUM fsm_check_size;
|
||||
SELECT pg_relation_size('fsm_check_size', 'fsm') / :blocksize AS fsm_nblocks;
|
||||
fsm_nblocks
|
||||
-------------
|
||||
3
|
||||
(1 row)
|
||||
|
||||
-- Add long random string to extend TOAST table to 1 block
|
||||
INSERT INTO fsm_check_size
|
||||
VALUES(0, (SELECT string_agg(md5(chr(i)), '')
|
||||
FROM generate_series(1, :blocksize / 100) i));
|
||||
VACUUM fsm_check_size;
|
||||
SELECT pg_relation_size(reltoastrelid, 'main') / :blocksize AS toast_nblocks,
|
||||
pg_relation_size(reltoastrelid, 'fsm') / :blocksize AS toast_fsm_nblocks
|
||||
FROM pg_class WHERE relname = 'fsm_check_size';
|
||||
toast_nblocks | toast_fsm_nblocks
|
||||
---------------+-------------------
|
||||
1 | 0
|
||||
(1 row)
|
||||
|
||||
DROP TABLE fsm_check_size;
|
||||
@@ -20,7 +20,7 @@ test: boolean char name varchar text int2 int4 int8 oid float4 float8 bit numeri
|
||||
# strings depends on char, varchar and text
|
||||
# numerology depends on int2, int4, int8, float4, float8
|
||||
# ----------
|
||||
test: strings numerology point lseg line box path polygon circle date time timetz timestamp timestamptz interval inet macaddr macaddr8 tstypes fsm
|
||||
test: strings numerology point lseg line box path polygon circle date time timetz timestamp timestamptz interval inet macaddr macaddr8 tstypes
|
||||
|
||||
# ----------
|
||||
# Another group of parallel tests
|
||||
|
||||
@@ -40,7 +40,6 @@ test: inet
|
||||
test: macaddr
|
||||
test: macaddr8
|
||||
test: tstypes
|
||||
test: fsm
|
||||
test: geometry
|
||||
test: horology
|
||||
test: regex
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
--
|
||||
-- Free Space Map test
|
||||
--
|
||||
SELECT current_setting('block_size')::integer AS blocksize,
|
||||
current_setting('block_size')::integer / 8 AS strsize
|
||||
\gset
|
||||
|
||||
CREATE TABLE fsm_check_size (num int, str text);
|
||||
|
||||
-- Fill 3 blocks with one record each
|
||||
ALTER TABLE fsm_check_size SET (fillfactor=15);
|
||||
INSERT INTO fsm_check_size SELECT i, rpad('', :strsize, 'a')
|
||||
FROM generate_series(1,3) i;
|
||||
|
||||
-- There should be no FSM
|
||||
VACUUM fsm_check_size;
|
||||
SELECT pg_relation_size('fsm_check_size', 'main') / :blocksize AS heap_nblocks,
|
||||
pg_relation_size('fsm_check_size', 'fsm') / :blocksize AS fsm_nblocks;
|
||||
|
||||
-- The following operations are for testing the functionality of the local
|
||||
-- in-memory map. In particular, we want to be able to insert into some
|
||||
-- other block than the one at the end of the heap, without using a FSM.
|
||||
|
||||
-- Fill most of the last block
|
||||
ALTER TABLE fsm_check_size SET (fillfactor=100);
|
||||
INSERT INTO fsm_check_size SELECT i, rpad('', :strsize, 'a')
|
||||
FROM generate_series(101,105) i;
|
||||
|
||||
-- Make sure records can go into any block but the last one
|
||||
ALTER TABLE fsm_check_size SET (fillfactor=30);
|
||||
|
||||
-- Insert large record and make sure it does not cause the relation to extend
|
||||
INSERT INTO fsm_check_size VALUES (111, rpad('', :strsize, 'a'));
|
||||
|
||||
VACUUM fsm_check_size;
|
||||
SELECT pg_relation_size('fsm_check_size', 'main') / :blocksize AS heap_nblocks,
|
||||
pg_relation_size('fsm_check_size', 'fsm') / :blocksize AS fsm_nblocks;
|
||||
|
||||
-- Extend table with enough blocks to exceed the FSM threshold
|
||||
DO $$
|
||||
DECLARE curtid tid;
|
||||
num int;
|
||||
BEGIN
|
||||
num = 11;
|
||||
LOOP
|
||||
INSERT INTO fsm_check_size VALUES (num, 'b') RETURNING ctid INTO curtid;
|
||||
EXIT WHEN curtid >= tid '(4, 0)';
|
||||
num = num + 1;
|
||||
END LOOP;
|
||||
END;
|
||||
$$;
|
||||
|
||||
VACUUM fsm_check_size;
|
||||
SELECT pg_relation_size('fsm_check_size', 'fsm') / :blocksize AS fsm_nblocks;
|
||||
|
||||
-- Add long random string to extend TOAST table to 1 block
|
||||
INSERT INTO fsm_check_size
|
||||
VALUES(0, (SELECT string_agg(md5(chr(i)), '')
|
||||
FROM generate_series(1, :blocksize / 100) i));
|
||||
|
||||
VACUUM fsm_check_size;
|
||||
SELECT pg_relation_size(reltoastrelid, 'main') / :blocksize AS toast_nblocks,
|
||||
pg_relation_size(reltoastrelid, 'fsm') / :blocksize AS toast_fsm_nblocks
|
||||
FROM pg_class WHERE relname = 'fsm_check_size';
|
||||
|
||||
DROP TABLE fsm_check_size;
|
||||
Reference in New Issue
Block a user