
-- New table
create table foo (num int);
select pg_relation_size('foo', 'main') as heap, pg_relation_size('foo', 'fsm') as fsm;

-- 1 heap block
-- On master FSM is created with 3 blocks, with patch not
insert into foo values (0);
vacuum foo;
select pg_relation_size('foo', 'main') as heap, pg_relation_size('foo', 'fsm') as fsm;

-- More than 10 heap blocks
-- Now FSM created with patch
insert into foo select g from generate_series(1,3000) g;
vacuum foo;
select pg_relation_size('foo', 'main') as heap, pg_relation_size('foo', 'fsm') as fsm;

-- Truncate heap to 1 block
-- No change in FSM
delete from foo where num > 0;
vacuum foo;
select pg_relation_size('foo', 'main') as heap, pg_relation_size('foo', 'fsm') as fsm;

-- Truncate heap to 0 blocks
-- FSM now truncated to 2 blocks
delete from foo;
vacuum foo;
select pg_relation_size('foo', 'main') as heap, pg_relation_size('foo', 'fsm') as fsm;

-- 1 heap block
-- On master FSM is extended to 3 blocks, with patch not
insert into foo values (0);
vacuum foo;
select pg_relation_size('foo', 'main') as heap, pg_relation_size('foo', 'fsm') as fsm;

