mirror of
https://github.com/timescale/timescaledb.git
synced 2025-05-20 12:47:40 +08:00
Handle set tablespace on ht with compression
Pass down the set tablespace command to the compressed hypertable.
This commit is contained in:
parent
a399a57af9
commit
c5d4ce7f90
@ -221,10 +221,12 @@ check_alter_table_allowed_on_ht_with_compression(Hypertable *ht, AlterTableStmt
|
||||
case AT_SetRelOptions:
|
||||
case AT_ClusterOn:
|
||||
case AT_DropCluster:
|
||||
case AT_SetTableSpace:
|
||||
/* this is passed down in `process_altertable_set_tablespace_end` */
|
||||
|
||||
/* allow now, improve later */
|
||||
case AT_SetStatistics: /* pass statistics down to compressed? */
|
||||
case AT_SetTableSpace: /* pass down to compressed as well */
|
||||
/* allowed on materialization tables */
|
||||
/* allowed on compression tables */
|
||||
continue;
|
||||
/*
|
||||
* BLOCKED:
|
||||
@ -2258,6 +2260,13 @@ process_altertable_set_tablespace_end(Hypertable *ht, AlterTableCmd *cmd)
|
||||
|
||||
ts_tablespace_attach_internal(&tspc_name, ht->main_table_relid, true);
|
||||
foreach_chunk(ht, process_altertable_chunk, cmd);
|
||||
if (ht->fd.compressed_hypertable_id != INVALID_HYPERTABLE_ID)
|
||||
{
|
||||
Hypertable *compressed_hypertable =
|
||||
ts_hypertable_get_by_id(ht->fd.compressed_hypertable_id);
|
||||
AlterTableInternal(compressed_hypertable->main_table_relid, list_make1(cmd), false);
|
||||
process_altertable_set_tablespace_end(compressed_hypertable, cmd);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -27,6 +27,13 @@ insert into rand_minstd_state values (321);
|
||||
-- Please see the included NOTICE for copyright information and
|
||||
-- LICENSE-TIMESCALE for a copy of the license.
|
||||
\set ECHO errors
|
||||
SET client_min_messages = ERROR;
|
||||
DROP TABLESPACE IF EXISTS tablespace1;
|
||||
DROP TABLESPACE IF EXISTS tablespace2;
|
||||
SET client_min_messages = NOTICE;
|
||||
--test hypertable with tables space
|
||||
CREATE TABLESPACE tablespace1 OWNER :ROLE_DEFAULT_PERM_USER LOCATION :TEST_TABLESPACE1_PATH;
|
||||
CREATE TABLESPACE tablespace2 OWNER :ROLE_DEFAULT_PERM_USER LOCATION :TEST_TABLESPACE2_PATH;
|
||||
\c :TEST_DBNAME :ROLE_DEFAULT_PERM_USER
|
||||
CREATE TABLE test1 ("Time" timestamptz, i integer, b bigint, t text);
|
||||
SELECT table_name from create_hypertable('test1', 'Time', chunk_time_interval=> INTERVAL '1 day');
|
||||
@ -60,6 +67,32 @@ DROP INDEX new_index;
|
||||
ALTER TABLE test1 SET (fillfactor=100);
|
||||
ALTER TABLE test1 RESET (fillfactor);
|
||||
ALTER TABLE test1 ALTER COLUMN b SET STATISTICS 10;
|
||||
SELECT count(*) as "COUNT_CHUNKS_UNCOMPRESSED"
|
||||
FROM _timescaledb_catalog.chunk chunk
|
||||
INNER JOIN _timescaledb_catalog.hypertable hypertable ON (chunk.hypertable_id = hypertable.id)
|
||||
WHERE hypertable.table_name like 'test1' \gset
|
||||
SELECT count(*) as "COUNT_CHUNKS_COMPRESSED"
|
||||
FROM _timescaledb_catalog.chunk chunk
|
||||
INNER JOIN _timescaledb_catalog.hypertable comp_hyper ON (chunk.hypertable_id = comp_hyper.id)
|
||||
INNER JOIN _timescaledb_catalog.hypertable uncomp_hyper ON (comp_hyper.id = uncomp_hyper.compressed_hypertable_id)
|
||||
WHERE uncomp_hyper.table_name like 'test1' \gset
|
||||
ALTER TABLE test1 SET TABLESPACE tablespace1;
|
||||
--all chunks + both the compressed and uncompressed hypertable moved to new tablespace
|
||||
SELECT count(*) = (:COUNT_CHUNKS_UNCOMPRESSED +:COUNT_CHUNKS_COMPRESSED + 2)
|
||||
FROM pg_tables WHERE tablespace = 'tablespace1';
|
||||
?column?
|
||||
----------
|
||||
t
|
||||
(1 row)
|
||||
|
||||
ALTER TABLE test1 SET TABLESPACE tablespace2;
|
||||
SELECT count(*) = (:COUNT_CHUNKS_UNCOMPRESSED +:COUNT_CHUNKS_COMPRESSED + 2)
|
||||
FROM pg_tables WHERE tablespace = 'tablespace2';
|
||||
?column?
|
||||
----------
|
||||
t
|
||||
(1 row)
|
||||
|
||||
--
|
||||
-- DROP CHUNKS
|
||||
--
|
||||
@ -330,3 +363,7 @@ DROP VIEW dependent_1;
|
||||
--DROP TABLE :UNCOMPRESSED_HYPER_NAME CASCADE;
|
||||
--verify that there are no more hypertable remaining
|
||||
--SELECT count(*) FROM _timescaledb_catalog.hypertable hypertable;
|
||||
\c :TEST_DBNAME :ROLE_SUPERUSER
|
||||
DROP TABLE test1;
|
||||
DROP TABLESPACE tablespace1;
|
||||
DROP TABLESPACE tablespace2;
|
||||
|
@ -5,6 +5,16 @@
|
||||
\ir include/rand_generator.sql
|
||||
\c :TEST_DBNAME :ROLE_SUPERUSER
|
||||
\ir include/compression_utils.sql
|
||||
|
||||
|
||||
SET client_min_messages = ERROR;
|
||||
DROP TABLESPACE IF EXISTS tablespace1;
|
||||
DROP TABLESPACE IF EXISTS tablespace2;
|
||||
SET client_min_messages = NOTICE;
|
||||
--test hypertable with tables space
|
||||
CREATE TABLESPACE tablespace1 OWNER :ROLE_DEFAULT_PERM_USER LOCATION :TEST_TABLESPACE1_PATH;
|
||||
CREATE TABLESPACE tablespace2 OWNER :ROLE_DEFAULT_PERM_USER LOCATION :TEST_TABLESPACE2_PATH;
|
||||
|
||||
\c :TEST_DBNAME :ROLE_DEFAULT_PERM_USER
|
||||
|
||||
CREATE TABLE test1 ("Time" timestamptz, i integer, b bigint, t text);
|
||||
@ -36,6 +46,29 @@ ALTER TABLE test1 RESET (fillfactor);
|
||||
ALTER TABLE test1 ALTER COLUMN b SET STATISTICS 10;
|
||||
|
||||
|
||||
SELECT count(*) as "COUNT_CHUNKS_UNCOMPRESSED"
|
||||
FROM _timescaledb_catalog.chunk chunk
|
||||
INNER JOIN _timescaledb_catalog.hypertable hypertable ON (chunk.hypertable_id = hypertable.id)
|
||||
WHERE hypertable.table_name like 'test1' \gset
|
||||
|
||||
SELECT count(*) as "COUNT_CHUNKS_COMPRESSED"
|
||||
FROM _timescaledb_catalog.chunk chunk
|
||||
INNER JOIN _timescaledb_catalog.hypertable comp_hyper ON (chunk.hypertable_id = comp_hyper.id)
|
||||
INNER JOIN _timescaledb_catalog.hypertable uncomp_hyper ON (comp_hyper.id = uncomp_hyper.compressed_hypertable_id)
|
||||
WHERE uncomp_hyper.table_name like 'test1' \gset
|
||||
|
||||
ALTER TABLE test1 SET TABLESPACE tablespace1;
|
||||
|
||||
--all chunks + both the compressed and uncompressed hypertable moved to new tablespace
|
||||
SELECT count(*) = (:COUNT_CHUNKS_UNCOMPRESSED +:COUNT_CHUNKS_COMPRESSED + 2)
|
||||
FROM pg_tables WHERE tablespace = 'tablespace1';
|
||||
|
||||
ALTER TABLE test1 SET TABLESPACE tablespace2;
|
||||
SELECT count(*) = (:COUNT_CHUNKS_UNCOMPRESSED +:COUNT_CHUNKS_COMPRESSED + 2)
|
||||
FROM pg_tables WHERE tablespace = 'tablespace2';
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- DROP CHUNKS
|
||||
--
|
||||
@ -227,3 +260,8 @@ DROP VIEW dependent_1;
|
||||
--DROP TABLE :UNCOMPRESSED_HYPER_NAME CASCADE;
|
||||
--verify that there are no more hypertable remaining
|
||||
--SELECT count(*) FROM _timescaledb_catalog.hypertable hypertable;
|
||||
|
||||
\c :TEST_DBNAME :ROLE_SUPERUSER
|
||||
DROP TABLE test1;
|
||||
DROP TABLESPACE tablespace1;
|
||||
DROP TABLESPACE tablespace2;
|
||||
|
Loading…
x
Reference in New Issue
Block a user