\timing on

drop table if exists vis;

create table vis (a int) with (fillfactor=10);

insert into vis (a) select generate_series(1, 2000000);

-- cache it
select count(1) from (select * from vis) as vis;

-- bench freshly inserted data
select count(1) as fresh_insert from (select * from vis) as foo;
select count(1) as fresh_insert from (select * from vis) as foo;
select count(1) as fresh_insert from (select * from vis) as foo;

-- create some hot activity
update vis set a = 1;
update vis set a = 1;
update vis set a = 1;
select count(1) as post_update from (select * from vis) as foo;
select count(1) as post_update_select from (select * from vis) as foo;
vacuum verbose vis;

update vis set a = 1;
update vis set a = 1;
update vis set a = 1;
select count(1) as post_update from (select * from vis) as foo;
select count(1) as post_update_select from (select * from vis) as foo;
vacuum verbose vis;

update vis set a = 1;
update vis set a = 1;
update vis set a = 1;
select count(1) as post_update from (select * from vis) as foo;
select count(1) as post_update_select from (select * from vis) as foo;
vacuum verbose vis;

-- now we will do the same but vacuum first
update vis set a = 1;
update vis set a = 1;
update vis set a = 1;
vacuum verbose vis;
select count(1) as post_update_vac from (select * from vis) as foo;
select count(1) as post_update_vac_select from (select * from vis) as foo;

update vis set a = 1;
update vis set a = 1;
update vis set a = 1;
vacuum verbose vis;
select count(1) as post_update_vac from (select * from vis) as foo;
select count(1) as post_update_vac_select from (select * from vis) as foo;

update vis set a = 1;
update vis set a = 1;
update vis set a = 1;
vacuum verbose vis;
select count(1) as post_update_vac from (select * from vis) as foo;
select count(1) as post_update_vac_select from (select * from vis) as foo;
