-
Notifications
You must be signed in to change notification settings - Fork 893
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added missing template output tests and also converted others to template due to output changes.
- Loading branch information
1 parent
b514d05
commit dfdb2c8
Showing
89 changed files
with
91,436 additions
and
111 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
-- This file and its contents are licensed under the Apache License 2.0. | ||
-- Please see the included NOTICE for copyright information and | ||
-- LICENSE-APACHE for a copy of the license. | ||
CREATE TABLE cluster_test(time timestamptz, temp float, location int); | ||
SELECT create_hypertable('cluster_test', 'time', chunk_time_interval => interval '1 day'); | ||
NOTICE: adding not-null constraint to column "time" | ||
create_hypertable | ||
--------------------------- | ||
(1,public,cluster_test,t) | ||
(1 row) | ||
|
||
-- Show default indexes | ||
SELECT * FROM test.show_indexes('cluster_test'); | ||
Index | Columns | Expr | Unique | Primary | Exclusion | Tablespace | ||
-----------------------+---------+------+--------+---------+-----------+------------ | ||
cluster_test_time_idx | {time} | | f | f | f | | ||
(1 row) | ||
|
||
-- Create two chunks | ||
INSERT INTO cluster_test VALUES ('2017-01-20T09:00:01', 23.4, 1), | ||
('2017-01-21T09:00:01', 21.3, 2); | ||
-- Run cluster | ||
CLUSTER VERBOSE cluster_test USING cluster_test_time_idx; | ||
INFO: clustering "_timescaledb_internal._hyper_1_1_chunk" using index scan on "_hyper_1_1_chunk_cluster_test_time_idx" | ||
INFO: "_timescaledb_internal._hyper_1_1_chunk": found 0 removable, 1 nonremovable row versions in 1 pages | ||
INFO: clustering "_timescaledb_internal._hyper_1_2_chunk" using index scan on "_hyper_1_2_chunk_cluster_test_time_idx" | ||
INFO: "_timescaledb_internal._hyper_1_2_chunk": found 0 removable, 1 nonremovable row versions in 1 pages | ||
-- Create a third chunk | ||
INSERT INTO cluster_test VALUES ('2017-01-22T09:00:01', 19.5, 3); | ||
-- Show clustered indexes | ||
SELECT indexrelid::regclass, indisclustered | ||
FROM pg_index | ||
WHERE indisclustered = true ORDER BY 1; | ||
indexrelid | indisclustered | ||
--------------------------------------------------------------+---------------- | ||
cluster_test_time_idx | t | ||
_timescaledb_internal._hyper_1_1_chunk_cluster_test_time_idx | t | ||
_timescaledb_internal._hyper_1_2_chunk_cluster_test_time_idx | t | ||
(3 rows) | ||
|
||
-- Reorder just our table | ||
CLUSTER VERBOSE cluster_test; | ||
INFO: clustering "_timescaledb_internal._hyper_1_1_chunk" using sequential scan and sort | ||
INFO: "_timescaledb_internal._hyper_1_1_chunk": found 0 removable, 1 nonremovable row versions in 1 pages | ||
INFO: clustering "_timescaledb_internal._hyper_1_2_chunk" using sequential scan and sort | ||
INFO: "_timescaledb_internal._hyper_1_2_chunk": found 0 removable, 1 nonremovable row versions in 1 pages | ||
INFO: clustering "_timescaledb_internal._hyper_1_3_chunk" using index scan on "_hyper_1_3_chunk_cluster_test_time_idx" | ||
INFO: "_timescaledb_internal._hyper_1_3_chunk": found 0 removable, 1 nonremovable row versions in 1 pages | ||
-- Show clustered indexes, including new chunk | ||
SELECT indexrelid::regclass, indisclustered | ||
FROM pg_index | ||
WHERE indisclustered = true ORDER BY 1; | ||
indexrelid | indisclustered | ||
--------------------------------------------------------------+---------------- | ||
cluster_test_time_idx | t | ||
_timescaledb_internal._hyper_1_1_chunk_cluster_test_time_idx | t | ||
_timescaledb_internal._hyper_1_2_chunk_cluster_test_time_idx | t | ||
_timescaledb_internal._hyper_1_3_chunk_cluster_test_time_idx | t | ||
(4 rows) | ||
|
||
-- Reorder all tables (although will only be our test table) | ||
CLUSTER VERBOSE; | ||
INFO: clustering "_timescaledb_internal._hyper_1_1_chunk" using sequential scan and sort | ||
INFO: "_timescaledb_internal._hyper_1_1_chunk": found 0 removable, 1 nonremovable row versions in 1 pages | ||
INFO: clustering "_timescaledb_internal._hyper_1_2_chunk" using sequential scan and sort | ||
INFO: "_timescaledb_internal._hyper_1_2_chunk": found 0 removable, 1 nonremovable row versions in 1 pages | ||
INFO: clustering "public.cluster_test" using sequential scan and sort | ||
INFO: "public.cluster_test": found 0 removable, 0 nonremovable row versions in 0 pages | ||
INFO: clustering "_timescaledb_internal._hyper_1_3_chunk" using sequential scan and sort | ||
INFO: "_timescaledb_internal._hyper_1_3_chunk": found 0 removable, 1 nonremovable row versions in 1 pages | ||
-- Change the clustered index | ||
CREATE INDEX ON cluster_test (time, location); | ||
CLUSTER VERBOSE cluster_test using cluster_test_time_location_idx; | ||
INFO: clustering "_timescaledb_internal._hyper_1_1_chunk" using sequential scan and sort | ||
INFO: "_timescaledb_internal._hyper_1_1_chunk": found 0 removable, 1 nonremovable row versions in 1 pages | ||
INFO: clustering "_timescaledb_internal._hyper_1_2_chunk" using sequential scan and sort | ||
INFO: "_timescaledb_internal._hyper_1_2_chunk": found 0 removable, 1 nonremovable row versions in 1 pages | ||
INFO: clustering "_timescaledb_internal._hyper_1_3_chunk" using sequential scan and sort | ||
INFO: "_timescaledb_internal._hyper_1_3_chunk": found 0 removable, 1 nonremovable row versions in 1 pages | ||
-- Show updated clustered indexes | ||
SELECT indexrelid::regclass, indisclustered | ||
FROM pg_index | ||
WHERE indisclustered = true ORDER BY 1; | ||
indexrelid | indisclustered | ||
-----------------------------------------------------------------------+---------------- | ||
cluster_test_time_location_idx | t | ||
_timescaledb_internal._hyper_1_1_chunk_cluster_test_time_location_idx | t | ||
_timescaledb_internal._hyper_1_2_chunk_cluster_test_time_location_idx | t | ||
_timescaledb_internal._hyper_1_3_chunk_cluster_test_time_location_idx | t | ||
(4 rows) | ||
|
||
--check the setting of cluster indexes on hypertables and chunks | ||
ALTER TABLE cluster_test CLUSTER ON cluster_test_time_idx; | ||
SELECT indexrelid::regclass, indisclustered | ||
FROM pg_index | ||
WHERE indisclustered = true | ||
ORDER BY 1,2; | ||
indexrelid | indisclustered | ||
--------------------------------------------------------------+---------------- | ||
cluster_test_time_idx | t | ||
_timescaledb_internal._hyper_1_1_chunk_cluster_test_time_idx | t | ||
_timescaledb_internal._hyper_1_2_chunk_cluster_test_time_idx | t | ||
_timescaledb_internal._hyper_1_3_chunk_cluster_test_time_idx | t | ||
(4 rows) | ||
|
||
CLUSTER VERBOSE cluster_test; | ||
INFO: clustering "_timescaledb_internal._hyper_1_1_chunk" using sequential scan and sort | ||
INFO: "_timescaledb_internal._hyper_1_1_chunk": found 0 removable, 1 nonremovable row versions in 1 pages | ||
INFO: clustering "_timescaledb_internal._hyper_1_2_chunk" using sequential scan and sort | ||
INFO: "_timescaledb_internal._hyper_1_2_chunk": found 0 removable, 1 nonremovable row versions in 1 pages | ||
INFO: clustering "_timescaledb_internal._hyper_1_3_chunk" using sequential scan and sort | ||
INFO: "_timescaledb_internal._hyper_1_3_chunk": found 0 removable, 1 nonremovable row versions in 1 pages | ||
ALTER TABLE cluster_test SET WITHOUT CLUSTER; | ||
SELECT indexrelid::regclass, indisclustered | ||
FROM pg_index | ||
WHERE indisclustered = true | ||
ORDER BY 1,2; | ||
indexrelid | indisclustered | ||
------------+---------------- | ||
(0 rows) | ||
|
||
\set ON_ERROR_STOP 0 | ||
CLUSTER VERBOSE cluster_test; | ||
ERROR: there is no previously clustered index for table "cluster_test" | ||
\set ON_ERROR_STOP 1 | ||
ALTER TABLE _timescaledb_internal._hyper_1_1_chunk CLUSTER ON _hyper_1_1_chunk_cluster_test_time_idx; | ||
SELECT indexrelid::regclass, indisclustered | ||
FROM pg_index | ||
WHERE indisclustered = true | ||
ORDER BY 1,2; | ||
indexrelid | indisclustered | ||
--------------------------------------------------------------+---------------- | ||
_timescaledb_internal._hyper_1_1_chunk_cluster_test_time_idx | t | ||
(1 row) | ||
|
||
CLUSTER VERBOSE _timescaledb_internal._hyper_1_1_chunk; | ||
INFO: clustering "_timescaledb_internal._hyper_1_1_chunk" using sequential scan and sort | ||
INFO: "_timescaledb_internal._hyper_1_1_chunk": found 0 removable, 1 nonremovable row versions in 1 pages | ||
ALTER TABLE _timescaledb_internal._hyper_1_1_chunk SET WITHOUT CLUSTER; | ||
SELECT indexrelid::regclass, indisclustered | ||
FROM pg_index | ||
WHERE indisclustered = true | ||
ORDER BY 1,2; | ||
indexrelid | indisclustered | ||
------------+---------------- | ||
(0 rows) | ||
|
||
\set ON_ERROR_STOP 0 | ||
CLUSTER VERBOSE _timescaledb_internal._hyper_1_1_chunk; | ||
ERROR: there is no previously clustered index for table "_hyper_1_1_chunk" | ||
\set ON_ERROR_STOP 1 | ||
-- test alter column type on hypertable with clustering | ||
CREATE TABLE cluster_alter(time timestamp, id text, val int); | ||
CREATE INDEX idstuff ON cluster_alter USING btree (id ASC NULLS LAST, time); | ||
SELECT table_name FROM create_hypertable('cluster_alter', 'time'); | ||
WARNING: column type "timestamp without time zone" used for "time" does not follow best practices | ||
NOTICE: adding not-null constraint to column "time" | ||
table_name | ||
--------------- | ||
cluster_alter | ||
(1 row) | ||
|
||
INSERT INTO cluster_alter VALUES('2020-01-01', '123', 1); | ||
CLUSTER cluster_alter using idstuff; | ||
--attempt the alter table | ||
ALTER TABLE cluster_alter ALTER COLUMN id TYPE int USING id::int; | ||
CLUSTER cluster_alter; | ||
CLUSTER cluster_alter using idstuff; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
-- This file and its contents are licensed under the Apache License 2.0. | ||
-- Please see the included NOTICE for copyright information and | ||
-- LICENSE-APACHE for a copy of the license. | ||
CREATE TABLE cursor_test(time timestamptz, device_id int, temp float); | ||
SELECT create_hypertable('cursor_test','time'); | ||
NOTICE: adding not-null constraint to column "time" | ||
create_hypertable | ||
-------------------------- | ||
(1,public,cursor_test,t) | ||
(1 row) | ||
|
||
INSERT INTO cursor_test SELECT '2000-01-01',1,0.5; | ||
INSERT INTO cursor_test SELECT '2001-01-01',1,0.5; | ||
INSERT INTO cursor_test SELECT '2002-01-01',1,0.5; | ||
\set ON_ERROR_STOP 0 | ||
BEGIN; | ||
DECLARE c1 SCROLL CURSOR FOR SELECT * FROM cursor_test; | ||
FETCH NEXT FROM c1; | ||
time | device_id | temp | ||
------------------------------+-----------+------ | ||
Sat Jan 01 00:00:00 2000 PST | 1 | 0.5 | ||
(1 row) | ||
|
||
-- this will produce an error on PG < 14 because PostgreSQL checks | ||
-- for the existence of a scan node with the relation id for every relation | ||
-- used in the update plan in the plan of the cursor. | ||
UPDATE cursor_test SET temp = 0.7 WHERE CURRENT OF c1; | ||
COMMIT; | ||
-- test cursor with no chunks left after runtime exclusion | ||
BEGIN; | ||
DECLARE c1 SCROLL CURSOR FOR SELECT * FROM cursor_test WHERE time > now(); | ||
UPDATE cursor_test SET temp = 0.7 WHERE CURRENT OF c1; | ||
ERROR: cursor "c1" is not a simply updatable scan of table "_hyper_1_1_chunk" | ||
COMMIT; | ||
-- test cursor with no chunks left after planning exclusion | ||
BEGIN; | ||
DECLARE c1 SCROLL CURSOR FOR SELECT * FROM cursor_test WHERE time > '2010-01-01'; | ||
UPDATE cursor_test SET temp = 0.7 WHERE CURRENT OF c1; | ||
ERROR: cursor "c1" is not a simply updatable scan of table "_hyper_1_1_chunk" | ||
COMMIT; | ||
\set ON_ERROR_STOP 1 | ||
SET timescaledb.enable_constraint_exclusion TO off; | ||
BEGIN; | ||
DECLARE c1 SCROLL CURSOR FOR SELECT * FROM cursor_test; | ||
FETCH NEXT FROM c1; | ||
time | device_id | temp | ||
------------------------------+-----------+------ | ||
Sat Jan 01 00:00:00 2000 PST | 1 | 0.7 | ||
(1 row) | ||
|
||
UPDATE cursor_test SET temp = 0.7 WHERE CURRENT OF c1; | ||
COMMIT; |
Oops, something went wrong.