-- cleanup from failed prior invocation
DROP TABLE foo;
ROLLBACK PREPARED 'f';

CREATE UNLOGGED TABLE foo AS SELECT generate_series(1, 10000000) i;
DELETE FROM foo WHERE i < (10000000 * 0.05);
VACUUM foo;

-- prevent further cleanup
BEGIN;
SELECT txid_current();
PREPARE TRANSACTION 'f';

DELETE FROM foo WHERE i < (10000000 * 0.1);

-- show sane stats
SELECT n_live_tup, n_dead_tup FROM pg_stat_user_tables WHERE relid = 'foo'::regclass;

-- show less sane stats
VACUUM foo;
SELECT n_live_tup, n_dead_tup FROM pg_stat_user_tables WHERE relid = 'foo'::regclass;

VACUUM foo;
VACUUM foo;
VACUUM foo;
VACUUM foo;
VACUUM foo;
VACUUM foo;
VACUUM foo;
VACUUM foo;
VACUUM foo;

 -- show insane stats
SELECT n_live_tup, n_dead_tup FROM pg_stat_user_tables WHERE relid = 'foo'::regclass;

-- show stats computed by ANALYZE
ANALYZE foo;
SELECT n_live_tup, n_dead_tup FROM pg_stat_user_tables WHERE relid = 'foo'::regclass;

-- it's due to page skipping:
VACUUM (DISABLE_PAGE_SKIPPING) foo;
SELECT n_live_tup, n_dead_tup FROM pg_stat_user_tables WHERE relid = 'foo'::regclass;

-- cleanup
DROP TABLE foo;
ROLLBACK PREPARED 'f';
