-
Notifications
You must be signed in to change notification settings - Fork 900
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ALTER TABLE SET ACCESS METHOD support
This commit allows `ALTER TABLE SET ACCESS METHOD` on a hypertable, which will set the access method of the hypertable to the given access method and also set the compression flag if changing to `hyperstore` access method. In order to set compression when setting the access method, it is necessary to allow several ALTER TABLE commands, which was previously not allowed. To support this, `ProcessUtility` will process each `ALTER TABLE` command in turn and remove it from the list if it is dealt with. If there are any remaining commands in the list after that, it will assume that these are not timescaledb-specific and continue running the normal command and also recurse the ALTER TABLE SET ACCESS METHOD command to the chunks.
- Loading branch information
Showing
13 changed files
with
180 additions
and
36 deletions.
There are no files selected for viewing
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 @@ | ||
Implements: #7295 Support ALTER TABLE SET ACCESS METHOD on hypertable |
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
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
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,77 @@ | ||
-- 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. | ||
-- Test support for setting table access method on hypertables using | ||
-- ALTER TABLE. It should propagate to the chunks. | ||
\c :TEST_DBNAME :ROLE_SUPERUSER | ||
CREATE ACCESS METHOD testam TYPE TABLE HANDLER heap_tableam_handler; | ||
SET ROLE :ROLE_DEFAULT_PERM_USER; | ||
CREATE VIEW chunk_info AS | ||
SELECT hypertable_name AS hypertable, | ||
chunk_name AS chunk, | ||
amname | ||
FROM timescaledb_information.chunks ch | ||
JOIN pg_class cl ON (format('%I.%I', ch.chunk_schema, ch.chunk_name)::regclass = cl.oid) | ||
JOIN pg_am am ON (am.oid = cl.relam); | ||
CREATE TABLE test_table (time timestamptz not null, device int, temp float); | ||
SELECT create_hypertable('test_table', by_range('time')); | ||
create_hypertable | ||
------------------- | ||
(1,t) | ||
(1 row) | ||
|
||
INSERT INTO test_table | ||
SELECT ts, 10 * random(), 100 * random() | ||
FROM generate_series('2001-01-01'::timestamp, '2001-02-01', '1d'::interval) as x(ts); | ||
SELECT cl.relname, amname | ||
FROM pg_class cl JOIN pg_am am ON cl.relam = am.oid | ||
WHERE cl.relname = 'test_table'; | ||
relname | amname | ||
------------+-------- | ||
test_table | heap | ||
(1 row) | ||
|
||
SELECT * FROM chunk_info WHERE hypertable = 'test_table'; | ||
hypertable | chunk | amname | ||
------------+------------------+-------- | ||
test_table | _hyper_1_1_chunk | heap | ||
test_table | _hyper_1_2_chunk | heap | ||
test_table | _hyper_1_3_chunk | heap | ||
test_table | _hyper_1_4_chunk | heap | ||
test_table | _hyper_1_5_chunk | heap | ||
test_table | _hyper_1_6_chunk | heap | ||
(6 rows) | ||
|
||
-- Test setting the access method together with other options. This | ||
-- should not generate an error. | ||
ALTER TABLE test_table | ||
SET ACCESS METHOD testam, | ||
SET (autovacuum_vacuum_threshold = 100); | ||
-- Create more chunks. These will use the new access method, but the | ||
-- old chunks will use the old access method. | ||
INSERT INTO test_table | ||
SELECT ts, 10 * random(), 100 * random() | ||
FROM generate_series('2001-02-01'::timestamp, '2001-03-01', '1d'::interval) as x(ts); | ||
SELECT cl.relname, amname | ||
FROM pg_class cl JOIN pg_am am ON cl.relam = am.oid | ||
WHERE cl.relname = 'test_table'; | ||
relname | amname | ||
------------+-------- | ||
test_table | testam | ||
(1 row) | ||
|
||
SELECT * FROM chunk_info WHERE hypertable = 'test_table'; | ||
hypertable | chunk | amname | ||
------------+-------------------+-------- | ||
test_table | _hyper_1_1_chunk | heap | ||
test_table | _hyper_1_2_chunk | heap | ||
test_table | _hyper_1_3_chunk | heap | ||
test_table | _hyper_1_4_chunk | heap | ||
test_table | _hyper_1_5_chunk | heap | ||
test_table | _hyper_1_6_chunk | heap | ||
test_table | _hyper_1_7_chunk | testam | ||
test_table | _hyper_1_8_chunk | testam | ||
test_table | _hyper_1_9_chunk | testam | ||
test_table | _hyper_1_10_chunk | testam | ||
(10 rows) | ||
|
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
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
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,47 @@ | ||
-- 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. | ||
|
||
-- Test support for setting table access method on hypertables using | ||
-- ALTER TABLE. It should propagate to the chunks. | ||
\c :TEST_DBNAME :ROLE_SUPERUSER | ||
CREATE ACCESS METHOD testam TYPE TABLE HANDLER heap_tableam_handler; | ||
SET ROLE :ROLE_DEFAULT_PERM_USER; | ||
|
||
CREATE VIEW chunk_info AS | ||
SELECT hypertable_name AS hypertable, | ||
chunk_name AS chunk, | ||
amname | ||
FROM timescaledb_information.chunks ch | ||
JOIN pg_class cl ON (format('%I.%I', ch.chunk_schema, ch.chunk_name)::regclass = cl.oid) | ||
JOIN pg_am am ON (am.oid = cl.relam); | ||
|
||
CREATE TABLE test_table (time timestamptz not null, device int, temp float); | ||
|
||
SELECT create_hypertable('test_table', by_range('time')); | ||
|
||
INSERT INTO test_table | ||
SELECT ts, 10 * random(), 100 * random() | ||
FROM generate_series('2001-01-01'::timestamp, '2001-02-01', '1d'::interval) as x(ts); | ||
|
||
SELECT cl.relname, amname | ||
FROM pg_class cl JOIN pg_am am ON cl.relam = am.oid | ||
WHERE cl.relname = 'test_table'; | ||
SELECT * FROM chunk_info WHERE hypertable = 'test_table'; | ||
|
||
-- Test setting the access method together with other options. This | ||
-- should not generate an error. | ||
ALTER TABLE test_table | ||
SET ACCESS METHOD testam, | ||
SET (autovacuum_vacuum_threshold = 100); | ||
|
||
-- Create more chunks. These will use the new access method, but the | ||
-- old chunks will use the old access method. | ||
INSERT INTO test_table | ||
SELECT ts, 10 * random(), 100 * random() | ||
FROM generate_series('2001-02-01'::timestamp, '2001-03-01', '1d'::interval) as x(ts); | ||
|
||
SELECT cl.relname, amname | ||
FROM pg_class cl JOIN pg_am am ON cl.relam = am.oid | ||
WHERE cl.relname = 'test_table'; | ||
SELECT * FROM chunk_info WHERE hypertable = 'test_table'; |
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
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
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
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
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
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