Skip to content

Commit

Permalink
Combine vacuum and vacuum_multi tests
Browse files Browse the repository at this point in the history
The reason vacuum and vacuum_multi was separate is because vacuuming
multiple relations is only supported in PG11+. Since we no longer
support versions < PG11 we can combine those 2 tests.
  • Loading branch information
svenklemm committed Apr 5, 2021
1 parent dbbbce6 commit cebe497
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 191 deletions.
133 changes: 133 additions & 0 deletions test/expected/vacuum.out
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ ORDER BY tablename, attname, array_to_string(histogram_bounds, ',');
analyze_test | time | {"Fri Jan 20 16:00:01 2017","Sat Jan 21 16:00:01 2017","Thu Apr 20 16:00:01 2017","Fri Apr 21 16:00:01 2017","Tue Jun 20 16:00:01 2017","Wed Jun 21 16:00:01 2017"} | -1
(2 rows)

DROP TABLE analyze_test;
-- Run vacuum on a normal (non-hypertable) table
CREATE TABLE vacuum_norm(time timestamp, temp float);
INSERT INTO vacuum_norm VALUES ('2017-01-20T09:00:01', 17.5),
Expand All @@ -157,3 +158,135 @@ INFO: vacuuming "public.vacuum_norm"
INFO: "vacuum_norm": found 0 removable, 6 nonremovable row versions in 1 out of 1 pages
INFO: analyzing "public.vacuum_norm"
INFO: "vacuum_norm": scanned 1 of 1 pages, containing 6 live rows and 0 dead rows; 6 rows in sample, 6 estimated total rows
DROP TABLE vacuum_norm;
--Similar to normal vacuum tests, but PG11 introduced ability to vacuum multiple tables at once, we make sure that works for hypertables as well.
CREATE TABLE vacuum_test(time timestamp, temp float);
-- create hypertable with three chunks
SELECT create_hypertable('vacuum_test', 'time', chunk_time_interval => 2628000000000, create_default_indexes => false);
NOTICE: adding not-null constraint to column "time"
create_hypertable
--------------------------
(3,public,vacuum_test,t)
(1 row)

INSERT INTO vacuum_test VALUES ('2017-01-20T16:00:01', 17.5),
('2017-01-21T16:00:01', 19.1),
('2017-04-20T16:00:01', 89.5),
('2017-04-21T16:00:01', 17.1),
('2017-06-20T16:00:01', 18.5),
('2017-06-21T16:00:01', 11.0);
CREATE TABLE analyze_test(time timestamp, temp float);
SELECT create_hypertable('analyze_test', 'time', chunk_time_interval => 2628000000000, create_default_indexes => false);
NOTICE: adding not-null constraint to column "time"
create_hypertable
---------------------------
(4,public,analyze_test,t)
(1 row)

INSERT INTO analyze_test VALUES ('2017-01-20T16:00:01', 17.5),
('2017-01-21T16:00:01', 19.1),
('2017-04-20T16:00:01', 89.5),
('2017-04-21T16:00:01', 17.1),
('2017-06-20T16:00:01', 18.5),
('2017-06-21T16:00:01', 11.0);
CREATE TABLE vacuum_norm(time timestamp, temp float);
INSERT INTO vacuum_norm VALUES ('2017-01-20T09:00:01', 17.5),
('2017-01-21T09:00:01', 19.1),
('2017-04-20T09:00:01', 89.5),
('2017-04-21T09:00:01', 17.1),
('2017-06-20T09:00:01', 18.5),
('2017-06-21T09:00:01', 11.0);
-- no stats
SELECT tablename, attname, histogram_bounds, n_distinct FROM pg_stats
WHERE schemaname = '_timescaledb_internal' AND tablename LIKE '_hyper_%_chunk'
ORDER BY tablename, attname, array_to_string(histogram_bounds, ',');
tablename | attname | histogram_bounds | n_distinct
-----------+---------+------------------+------------
(0 rows)

SELECT tablename, attname, histogram_bounds, n_distinct FROM pg_stats
WHERE schemaname = 'public'
ORDER BY tablename, attname, array_to_string(histogram_bounds, ',');
tablename | attname | histogram_bounds | n_distinct
-----------+---------+------------------+------------
(0 rows)

VACUUM (VERBOSE, ANALYZE) vacuum_norm, vacuum_test, analyze_test;
INFO: vacuuming "_timescaledb_internal._hyper_3_7_chunk"
INFO: "_hyper_3_7_chunk": found 0 removable, 2 nonremovable row versions in 1 out of 1 pages
INFO: analyzing "_timescaledb_internal._hyper_3_7_chunk"
INFO: "_hyper_3_7_chunk": scanned 1 of 1 pages, containing 2 live rows and 0 dead rows; 2 rows in sample, 2 estimated total rows
INFO: vacuuming "_timescaledb_internal._hyper_3_8_chunk"
INFO: "_hyper_3_8_chunk": found 0 removable, 2 nonremovable row versions in 1 out of 1 pages
INFO: analyzing "_timescaledb_internal._hyper_3_8_chunk"
INFO: "_hyper_3_8_chunk": scanned 1 of 1 pages, containing 2 live rows and 0 dead rows; 2 rows in sample, 2 estimated total rows
INFO: vacuuming "_timescaledb_internal._hyper_3_9_chunk"
INFO: "_hyper_3_9_chunk": found 0 removable, 2 nonremovable row versions in 1 out of 1 pages
INFO: analyzing "_timescaledb_internal._hyper_3_9_chunk"
INFO: "_hyper_3_9_chunk": scanned 1 of 1 pages, containing 2 live rows and 0 dead rows; 2 rows in sample, 2 estimated total rows
INFO: vacuuming "_timescaledb_internal._hyper_4_10_chunk"
INFO: "_hyper_4_10_chunk": found 0 removable, 2 nonremovable row versions in 1 out of 1 pages
INFO: analyzing "_timescaledb_internal._hyper_4_10_chunk"
INFO: "_hyper_4_10_chunk": scanned 1 of 1 pages, containing 2 live rows and 0 dead rows; 2 rows in sample, 2 estimated total rows
INFO: vacuuming "_timescaledb_internal._hyper_4_11_chunk"
INFO: "_hyper_4_11_chunk": found 0 removable, 2 nonremovable row versions in 1 out of 1 pages
INFO: analyzing "_timescaledb_internal._hyper_4_11_chunk"
INFO: "_hyper_4_11_chunk": scanned 1 of 1 pages, containing 2 live rows and 0 dead rows; 2 rows in sample, 2 estimated total rows
INFO: vacuuming "_timescaledb_internal._hyper_4_12_chunk"
INFO: "_hyper_4_12_chunk": found 0 removable, 2 nonremovable row versions in 1 out of 1 pages
INFO: analyzing "_timescaledb_internal._hyper_4_12_chunk"
INFO: "_hyper_4_12_chunk": scanned 1 of 1 pages, containing 2 live rows and 0 dead rows; 2 rows in sample, 2 estimated total rows
INFO: vacuuming "public.vacuum_norm"
INFO: "vacuum_norm": found 0 removable, 6 nonremovable row versions in 1 out of 1 pages
INFO: analyzing "public.vacuum_norm"
INFO: "vacuum_norm": scanned 1 of 1 pages, containing 6 live rows and 0 dead rows; 6 rows in sample, 6 estimated total rows
INFO: vacuuming "public.vacuum_test"
INFO: "vacuum_test": found 0 removable, 0 nonremovable row versions in 0 out of 0 pages
INFO: analyzing "public.vacuum_test"
INFO: "vacuum_test": scanned 0 of 0 pages, containing 0 live rows and 0 dead rows; 0 rows in sample, 0 estimated total rows
INFO: analyzing "public.vacuum_test" inheritance tree
INFO: "_hyper_3_7_chunk": scanned 1 of 1 pages, containing 2 live rows and 0 dead rows; 2 rows in sample, 2 estimated total rows
INFO: "_hyper_3_8_chunk": scanned 1 of 1 pages, containing 2 live rows and 0 dead rows; 2 rows in sample, 2 estimated total rows
INFO: "_hyper_3_9_chunk": scanned 1 of 1 pages, containing 2 live rows and 0 dead rows; 2 rows in sample, 2 estimated total rows
INFO: vacuuming "public.analyze_test"
INFO: "analyze_test": found 0 removable, 0 nonremovable row versions in 0 out of 0 pages
INFO: analyzing "public.analyze_test"
INFO: "analyze_test": scanned 0 of 0 pages, containing 0 live rows and 0 dead rows; 0 rows in sample, 0 estimated total rows
INFO: analyzing "public.analyze_test" inheritance tree
INFO: "_hyper_4_10_chunk": scanned 1 of 1 pages, containing 2 live rows and 0 dead rows; 2 rows in sample, 2 estimated total rows
INFO: "_hyper_4_11_chunk": scanned 1 of 1 pages, containing 2 live rows and 0 dead rows; 2 rows in sample, 2 estimated total rows
INFO: "_hyper_4_12_chunk": scanned 1 of 1 pages, containing 2 live rows and 0 dead rows; 2 rows in sample, 2 estimated total rows
-- stats should exist for all 6 chunks
SELECT tablename, attname, histogram_bounds, n_distinct FROM pg_stats
WHERE schemaname = '_timescaledb_internal' AND tablename LIKE '_hyper_%_chunk'
ORDER BY tablename, attname, array_to_string(histogram_bounds, ',');
tablename | attname | histogram_bounds | n_distinct
-------------------+---------+---------------------------------------------------------+------------
_hyper_3_7_chunk | temp | {17.5,19.1} | -1
_hyper_3_7_chunk | time | {"Fri Jan 20 16:00:01 2017","Sat Jan 21 16:00:01 2017"} | -1
_hyper_3_8_chunk | temp | {17.1,89.5} | -1
_hyper_3_8_chunk | time | {"Thu Apr 20 16:00:01 2017","Fri Apr 21 16:00:01 2017"} | -1
_hyper_3_9_chunk | temp | {11,18.5} | -1
_hyper_3_9_chunk | time | {"Tue Jun 20 16:00:01 2017","Wed Jun 21 16:00:01 2017"} | -1
_hyper_4_10_chunk | temp | {17.5,19.1} | -1
_hyper_4_10_chunk | time | {"Fri Jan 20 16:00:01 2017","Sat Jan 21 16:00:01 2017"} | -1
_hyper_4_11_chunk | temp | {17.1,89.5} | -1
_hyper_4_11_chunk | time | {"Thu Apr 20 16:00:01 2017","Fri Apr 21 16:00:01 2017"} | -1
_hyper_4_12_chunk | temp | {11,18.5} | -1
_hyper_4_12_chunk | time | {"Tue Jun 20 16:00:01 2017","Wed Jun 21 16:00:01 2017"} | -1
(12 rows)

-- stats should exist on parent hypertable and normal table
SELECT tablename, attname, histogram_bounds, n_distinct FROM pg_stats
WHERE schemaname = 'public'
ORDER BY tablename, attname, array_to_string(histogram_bounds, ',');
tablename | attname | histogram_bounds | n_distinct
--------------+---------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------
analyze_test | temp | {11,17.1,17.5,18.5,19.1,89.5} | -1
analyze_test | time | {"Fri Jan 20 16:00:01 2017","Sat Jan 21 16:00:01 2017","Thu Apr 20 16:00:01 2017","Fri Apr 21 16:00:01 2017","Tue Jun 20 16:00:01 2017","Wed Jun 21 16:00:01 2017"} | -1
vacuum_norm | temp | {11,17.1,17.5,18.5,19.1,89.5} | -1
vacuum_norm | time | {"Fri Jan 20 09:00:01 2017","Sat Jan 21 09:00:01 2017","Thu Apr 20 09:00:01 2017","Fri Apr 21 09:00:01 2017","Tue Jun 20 09:00:01 2017","Wed Jun 21 09:00:01 2017"} | -1
vacuum_test | temp | {11,17.1,17.5,18.5,19.1,89.5} | -1
vacuum_test | time | {"Fri Jan 20 16:00:01 2017","Sat Jan 21 16:00:01 2017","Thu Apr 20 16:00:01 2017","Fri Apr 21 16:00:01 2017","Tue Jun 20 16:00:01 2017","Wed Jun 21 16:00:01 2017"} | -1
(6 rows)

0 comments on commit cebe497

Please sign in to comment.