mirror of https://github.com/citusdata/citus.git
672 lines
27 KiB
Plaintext
672 lines
27 KiB
Plaintext
SHOW server_version \gset
|
|
SELECT substring(:'server_version', '\d+')::int > 11 AS server_version_above_eleven
|
|
\gset
|
|
\if :server_version_above_eleven
|
|
\else
|
|
\q
|
|
\endif
|
|
CREATE SCHEMA alter_table_set_access_method;
|
|
SET search_path TO alter_table_set_access_method;
|
|
SET citus.shard_count TO 4;
|
|
SET citus.shard_replication_factor TO 1;
|
|
SELECT public.run_command_on_coordinator_and_workers($Q$
|
|
CREATE FUNCTION fake_am_handler(internal)
|
|
RETURNS table_am_handler
|
|
AS 'citus'
|
|
LANGUAGE C;
|
|
CREATE ACCESS METHOD fake_am TYPE TABLE HANDLER fake_am_handler;
|
|
$Q$);
|
|
run_command_on_coordinator_and_workers
|
|
---------------------------------------------------------------------
|
|
|
|
(1 row)
|
|
|
|
CREATE TABLE dist_table (a INT, b INT);
|
|
SELECT create_distributed_table ('dist_table', 'a');
|
|
create_distributed_table
|
|
---------------------------------------------------------------------
|
|
|
|
(1 row)
|
|
|
|
INSERT INTO dist_table VALUES (1, 1), (2, 2), (3, 3);
|
|
SELECT table_name, access_method FROM public.citus_tables WHERE table_name::text = 'dist_table' ORDER BY 1;
|
|
table_name | access_method
|
|
---------------------------------------------------------------------
|
|
dist_table | heap
|
|
(1 row)
|
|
|
|
SELECT alter_table_set_access_method('dist_table', 'columnar');
|
|
NOTICE: creating a new table for alter_table_set_access_method.dist_table
|
|
NOTICE: Moving the data of alter_table_set_access_method.dist_table
|
|
NOTICE: Dropping the old alter_table_set_access_method.dist_table
|
|
NOTICE: Renaming the new table to alter_table_set_access_method.dist_table
|
|
alter_table_set_access_method
|
|
---------------------------------------------------------------------
|
|
|
|
(1 row)
|
|
|
|
SELECT table_name, access_method FROM public.citus_tables WHERE table_name::text = 'dist_table' ORDER BY 1;
|
|
table_name | access_method
|
|
---------------------------------------------------------------------
|
|
dist_table | columnar
|
|
(1 row)
|
|
|
|
-- test partitions
|
|
CREATE TABLE partitioned_table (id INT, a INT) PARTITION BY RANGE (id);
|
|
CREATE TABLE partitioned_table_1_5 PARTITION OF partitioned_table FOR VALUES FROM (1) TO (5);
|
|
CREATE TABLE partitioned_table_6_10 PARTITION OF partitioned_table FOR VALUES FROM (6) TO (10);
|
|
SELECT create_distributed_table('partitioned_table', 'id');
|
|
create_distributed_table
|
|
---------------------------------------------------------------------
|
|
|
|
(1 row)
|
|
|
|
INSERT INTO partitioned_table VALUES (2, 12), (7, 2);
|
|
SELECT logicalrelid::text FROM pg_dist_partition WHERE logicalrelid::regclass::text LIKE 'partitioned\_table%' ORDER BY 1;
|
|
logicalrelid
|
|
---------------------------------------------------------------------
|
|
partitioned_table
|
|
partitioned_table_1_5
|
|
partitioned_table_6_10
|
|
(3 rows)
|
|
|
|
SELECT run_command_on_workers($$SELECT COUNT(*) FROM pg_catalog.pg_class WHERE relname LIKE 'partitioned\_table%'$$);
|
|
run_command_on_workers
|
|
---------------------------------------------------------------------
|
|
(localhost,57637,t,6)
|
|
(localhost,57638,t,6)
|
|
(2 rows)
|
|
|
|
SELECT inhrelid::regclass::text FROM pg_catalog.pg_inherits WHERE inhparent = 'partitioned_table'::regclass ORDER BY 1;
|
|
inhrelid
|
|
---------------------------------------------------------------------
|
|
partitioned_table_1_5
|
|
partitioned_table_6_10
|
|
(2 rows)
|
|
|
|
SELECT table_name::text, access_method FROM public.citus_tables WHERE table_name::text LIKE 'partitioned\_table%' ORDER BY 1;
|
|
table_name | access_method
|
|
---------------------------------------------------------------------
|
|
partitioned_table |
|
|
partitioned_table_1_5 | heap
|
|
partitioned_table_6_10 | heap
|
|
(3 rows)
|
|
|
|
SELECT * FROM partitioned_table ORDER BY 1, 2;
|
|
id | a
|
|
---------------------------------------------------------------------
|
|
2 | 12
|
|
7 | 2
|
|
(2 rows)
|
|
|
|
SELECT * FROM partitioned_table_1_5 ORDER BY 1, 2;
|
|
id | a
|
|
---------------------------------------------------------------------
|
|
2 | 12
|
|
(1 row)
|
|
|
|
SELECT * FROM partitioned_table_6_10 ORDER BY 1, 2;
|
|
id | a
|
|
---------------------------------------------------------------------
|
|
7 | 2
|
|
(1 row)
|
|
|
|
-- altering partitioned tables' access methods is not supported
|
|
SELECT alter_table_set_access_method('partitioned_table', 'columnar');
|
|
ERROR: you cannot alter access method of a partitioned table
|
|
-- test altering the partition's access method
|
|
SELECT alter_table_set_access_method('partitioned_table_1_5', 'columnar');
|
|
NOTICE: creating a new table for alter_table_set_access_method.partitioned_table_1_5
|
|
NOTICE: Moving the data of alter_table_set_access_method.partitioned_table_1_5
|
|
NOTICE: Dropping the old alter_table_set_access_method.partitioned_table_1_5
|
|
NOTICE: Renaming the new table to alter_table_set_access_method.partitioned_table_1_5
|
|
alter_table_set_access_method
|
|
---------------------------------------------------------------------
|
|
|
|
(1 row)
|
|
|
|
SELECT logicalrelid::text FROM pg_dist_partition WHERE logicalrelid::regclass::text LIKE 'partitioned\_table%' ORDER BY 1;
|
|
logicalrelid
|
|
---------------------------------------------------------------------
|
|
partitioned_table
|
|
partitioned_table_1_5
|
|
partitioned_table_6_10
|
|
(3 rows)
|
|
|
|
SELECT run_command_on_workers($$SELECT COUNT(*) FROM pg_catalog.pg_class WHERE relname LIKE 'partitioned\_table%'$$);
|
|
run_command_on_workers
|
|
---------------------------------------------------------------------
|
|
(localhost,57637,t,6)
|
|
(localhost,57638,t,6)
|
|
(2 rows)
|
|
|
|
SELECT inhrelid::regclass::text FROM pg_catalog.pg_inherits WHERE inhparent = 'partitioned_table'::regclass ORDER BY 1;
|
|
inhrelid
|
|
---------------------------------------------------------------------
|
|
partitioned_table_1_5
|
|
partitioned_table_6_10
|
|
(2 rows)
|
|
|
|
SELECT table_name::text, access_method FROM public.citus_tables WHERE table_name::text LIKE 'partitioned\_table%' ORDER BY 1;
|
|
table_name | access_method
|
|
---------------------------------------------------------------------
|
|
partitioned_table |
|
|
partitioned_table_1_5 | columnar
|
|
partitioned_table_6_10 | heap
|
|
(3 rows)
|
|
|
|
SELECT * FROM partitioned_table ORDER BY 1, 2;
|
|
id | a
|
|
---------------------------------------------------------------------
|
|
2 | 12
|
|
7 | 2
|
|
(2 rows)
|
|
|
|
SELECT * FROM partitioned_table_1_5 ORDER BY 1, 2;
|
|
id | a
|
|
---------------------------------------------------------------------
|
|
2 | 12
|
|
(1 row)
|
|
|
|
SELECT * FROM partitioned_table_6_10 ORDER BY 1, 2;
|
|
id | a
|
|
---------------------------------------------------------------------
|
|
7 | 2
|
|
(1 row)
|
|
|
|
-- try to compress partitions with an integer partition column
|
|
CALL alter_old_partitions_set_access_method('partitioned_table', '2021-01-01', 'columnar');
|
|
ERROR: partition column of partitioned_table cannot be cast to a timestamptz
|
|
CONTEXT: PL/pgSQL function alter_old_partitions_set_access_method(regclass,timestamp with time zone,name) line 13 at RAISE
|
|
CREATE TABLE time_partitioned (event_time timestamp, event int) partition by range (event_time);
|
|
SELECT create_distributed_table('time_partitioned', 'event_time');
|
|
create_distributed_table
|
|
---------------------------------------------------------------------
|
|
|
|
(1 row)
|
|
|
|
CREATE TABLE time_partitioned_d00 PARTITION OF time_partitioned FOR VALUES FROM ('2000-01-01') TO ('2009-12-31');
|
|
CREATE TABLE time_partitioned_d10 PARTITION OF time_partitioned FOR VALUES FROM ('2010-01-01') TO ('2019-12-31');
|
|
CREATE TABLE time_partitioned_d20 PARTITION OF time_partitioned FOR VALUES FROM ('2020-01-01') TO ('2029-12-31');
|
|
INSERT INTO time_partitioned VALUES ('2005-01-01', 1);
|
|
INSERT INTO time_partitioned VALUES ('2015-01-01', 2);
|
|
INSERT INTO time_partitioned VALUES ('2025-01-01', 3);
|
|
\set VERBOSITY terse
|
|
-- compress no partitions
|
|
CALL alter_old_partitions_set_access_method('time_partitioned', '1999-01-01', 'columnar');
|
|
SELECT partition, access_method FROM time_partitions WHERE parent_table = 'time_partitioned'::regclass ORDER BY partition::text;
|
|
partition | access_method
|
|
---------------------------------------------------------------------
|
|
time_partitioned_d00 | heap
|
|
time_partitioned_d10 | heap
|
|
time_partitioned_d20 | heap
|
|
(3 rows)
|
|
|
|
SELECT event FROM time_partitioned ORDER BY 1;
|
|
event
|
|
---------------------------------------------------------------------
|
|
1
|
|
2
|
|
3
|
|
(3 rows)
|
|
|
|
-- compress 2 old partitions
|
|
CALL alter_old_partitions_set_access_method('time_partitioned', '2021-01-01', 'columnar');
|
|
NOTICE: converting time_partitioned_d00 with start time Sat Jan 01 00:00:00 2000 and end time Thu Dec 31 00:00:00 2009
|
|
NOTICE: creating a new table for alter_table_set_access_method.time_partitioned_d00
|
|
NOTICE: Moving the data of alter_table_set_access_method.time_partitioned_d00
|
|
NOTICE: Dropping the old alter_table_set_access_method.time_partitioned_d00
|
|
NOTICE: Renaming the new table to alter_table_set_access_method.time_partitioned_d00
|
|
NOTICE: converting time_partitioned_d10 with start time Fri Jan 01 00:00:00 2010 and end time Tue Dec 31 00:00:00 2019
|
|
NOTICE: creating a new table for alter_table_set_access_method.time_partitioned_d10
|
|
NOTICE: Moving the data of alter_table_set_access_method.time_partitioned_d10
|
|
NOTICE: Dropping the old alter_table_set_access_method.time_partitioned_d10
|
|
NOTICE: Renaming the new table to alter_table_set_access_method.time_partitioned_d10
|
|
SELECT partition, access_method FROM time_partitions WHERE parent_table = 'time_partitioned'::regclass ORDER BY partition::text;
|
|
partition | access_method
|
|
---------------------------------------------------------------------
|
|
time_partitioned_d00 | columnar
|
|
time_partitioned_d10 | columnar
|
|
time_partitioned_d20 | heap
|
|
(3 rows)
|
|
|
|
SELECT event FROM time_partitioned ORDER BY 1;
|
|
event
|
|
---------------------------------------------------------------------
|
|
1
|
|
2
|
|
3
|
|
(3 rows)
|
|
|
|
-- will not be compressed again
|
|
CALL alter_old_partitions_set_access_method('time_partitioned', '2021-01-01', 'columnar');
|
|
SELECT partition, access_method FROM time_partitions WHERE parent_table = 'time_partitioned'::regclass ORDER BY partition::text;
|
|
partition | access_method
|
|
---------------------------------------------------------------------
|
|
time_partitioned_d00 | columnar
|
|
time_partitioned_d10 | columnar
|
|
time_partitioned_d20 | heap
|
|
(3 rows)
|
|
|
|
SELECT event FROM time_partitioned ORDER BY 1;
|
|
event
|
|
---------------------------------------------------------------------
|
|
1
|
|
2
|
|
3
|
|
(3 rows)
|
|
|
|
-- back to heap
|
|
CALL alter_old_partitions_set_access_method('time_partitioned', '2021-01-01', 'heap');
|
|
NOTICE: converting time_partitioned_d00 with start time Sat Jan 01 00:00:00 2000 and end time Thu Dec 31 00:00:00 2009
|
|
NOTICE: creating a new table for alter_table_set_access_method.time_partitioned_d00
|
|
NOTICE: Moving the data of alter_table_set_access_method.time_partitioned_d00
|
|
NOTICE: Dropping the old alter_table_set_access_method.time_partitioned_d00
|
|
NOTICE: Renaming the new table to alter_table_set_access_method.time_partitioned_d00
|
|
NOTICE: converting time_partitioned_d10 with start time Fri Jan 01 00:00:00 2010 and end time Tue Dec 31 00:00:00 2019
|
|
NOTICE: creating a new table for alter_table_set_access_method.time_partitioned_d10
|
|
NOTICE: Moving the data of alter_table_set_access_method.time_partitioned_d10
|
|
NOTICE: Dropping the old alter_table_set_access_method.time_partitioned_d10
|
|
NOTICE: Renaming the new table to alter_table_set_access_method.time_partitioned_d10
|
|
SELECT partition, access_method FROM time_partitions WHERE parent_table = 'time_partitioned'::regclass ORDER BY partition::text;
|
|
partition | access_method
|
|
---------------------------------------------------------------------
|
|
time_partitioned_d00 | heap
|
|
time_partitioned_d10 | heap
|
|
time_partitioned_d20 | heap
|
|
(3 rows)
|
|
|
|
SELECT event FROM time_partitioned ORDER BY 1;
|
|
event
|
|
---------------------------------------------------------------------
|
|
1
|
|
2
|
|
3
|
|
(3 rows)
|
|
|
|
\set VERBOSITY default
|
|
DROP TABLE time_partitioned;
|
|
-- test altering a table with index to columnar
|
|
-- the index will be dropped
|
|
CREATE TABLE index_table (a INT) ;
|
|
CREATE INDEX idx1 ON index_table (a);
|
|
-- also create an index with statistics
|
|
CREATE INDEX idx2 ON index_table ((a+1));
|
|
ALTER INDEX idx2 ALTER COLUMN 1 SET STATISTICS 300;
|
|
SELECT indexname FROM pg_indexes WHERE schemaname = 'alter_table_set_access_method' AND tablename = 'index_table';
|
|
indexname
|
|
---------------------------------------------------------------------
|
|
idx1
|
|
idx2
|
|
(2 rows)
|
|
|
|
SELECT a.amname FROM pg_class c, pg_am a where c.relname = 'index_table' AND c.relnamespace = 'alter_table_set_access_method'::regnamespace AND c.relam = a.oid;
|
|
amname
|
|
---------------------------------------------------------------------
|
|
heap
|
|
(1 row)
|
|
|
|
SELECT alter_table_set_access_method('index_table', 'columnar');
|
|
NOTICE: the index idx1 on table alter_table_set_access_method.index_table will be dropped, because columnar tables cannot have indexes
|
|
NOTICE: the index idx2 on table alter_table_set_access_method.index_table will be dropped, because columnar tables cannot have indexes
|
|
NOTICE: creating a new table for alter_table_set_access_method.index_table
|
|
NOTICE: Moving the data of alter_table_set_access_method.index_table
|
|
NOTICE: Dropping the old alter_table_set_access_method.index_table
|
|
NOTICE: Renaming the new table to alter_table_set_access_method.index_table
|
|
alter_table_set_access_method
|
|
---------------------------------------------------------------------
|
|
|
|
(1 row)
|
|
|
|
SELECT indexname FROM pg_indexes WHERE schemaname = 'alter_table_set_access_method' AND tablename = 'index_table';
|
|
indexname
|
|
---------------------------------------------------------------------
|
|
(0 rows)
|
|
|
|
SELECT a.amname FROM pg_class c, pg_am a where c.relname = 'index_table' AND c.relnamespace = 'alter_table_set_access_method'::regnamespace AND c.relam = a.oid;
|
|
amname
|
|
---------------------------------------------------------------------
|
|
columnar
|
|
(1 row)
|
|
|
|
-- test different table types
|
|
SET client_min_messages to WARNING;
|
|
SELECT 1 FROM master_add_node('localhost', :master_port, groupId := 0);
|
|
?column?
|
|
---------------------------------------------------------------------
|
|
1
|
|
(1 row)
|
|
|
|
SET client_min_messages to DEFAULT;
|
|
CREATE TABLE table_type_dist (a INT);
|
|
SELECT create_distributed_table('table_type_dist', 'a');
|
|
create_distributed_table
|
|
---------------------------------------------------------------------
|
|
|
|
(1 row)
|
|
|
|
CREATE TABLE table_type_ref (a INT);
|
|
SELECT create_reference_table('table_type_ref');
|
|
create_reference_table
|
|
---------------------------------------------------------------------
|
|
|
|
(1 row)
|
|
|
|
CREATE TABLE table_type_citus_local(a INT);
|
|
SELECT create_citus_local_table('table_type_citus_local');
|
|
create_citus_local_table
|
|
---------------------------------------------------------------------
|
|
|
|
(1 row)
|
|
|
|
CREATE TABLE table_type_pg_local (a INT);
|
|
SELECT table_name, citus_table_type, distribution_column, shard_count, access_method FROM public.citus_tables WHERE table_name::text LIKE 'table\_type%' ORDER BY 1;
|
|
table_name | citus_table_type | distribution_column | shard_count | access_method
|
|
---------------------------------------------------------------------
|
|
table_type_dist | distributed | a | 4 | heap
|
|
table_type_ref | reference | <none> | 1 | heap
|
|
(2 rows)
|
|
|
|
SELECT c.relname, a.amname FROM pg_class c, pg_am a where c.relname SIMILAR TO 'table_type\D*' AND c.relnamespace = 'alter_table_set_access_method'::regnamespace AND c.relam = a.oid;
|
|
relname | amname
|
|
---------------------------------------------------------------------
|
|
table_type_citus_local | heap
|
|
table_type_dist | heap
|
|
table_type_pg_local | heap
|
|
table_type_ref | heap
|
|
(4 rows)
|
|
|
|
SELECT alter_table_set_access_method('table_type_dist', 'fake_am');
|
|
NOTICE: creating a new table for alter_table_set_access_method.table_type_dist
|
|
WARNING: fake_scan_getnextslot
|
|
CONTEXT: SQL statement "SELECT EXISTS (SELECT 1 FROM alter_table_set_access_method.table_type_dist_1533505599)"
|
|
WARNING: fake_scan_getnextslot
|
|
NOTICE: Moving the data of alter_table_set_access_method.table_type_dist
|
|
NOTICE: Dropping the old alter_table_set_access_method.table_type_dist
|
|
NOTICE: Renaming the new table to alter_table_set_access_method.table_type_dist
|
|
alter_table_set_access_method
|
|
---------------------------------------------------------------------
|
|
|
|
(1 row)
|
|
|
|
SELECT alter_table_set_access_method('table_type_ref', 'fake_am');
|
|
NOTICE: creating a new table for alter_table_set_access_method.table_type_ref
|
|
WARNING: fake_scan_getnextslot
|
|
CONTEXT: SQL statement "SELECT EXISTS (SELECT 1 FROM alter_table_set_access_method.table_type_ref_1037855087)"
|
|
WARNING: fake_scan_getnextslot
|
|
NOTICE: Moving the data of alter_table_set_access_method.table_type_ref
|
|
NOTICE: Dropping the old alter_table_set_access_method.table_type_ref
|
|
NOTICE: Renaming the new table to alter_table_set_access_method.table_type_ref
|
|
alter_table_set_access_method
|
|
---------------------------------------------------------------------
|
|
|
|
(1 row)
|
|
|
|
SELECT alter_table_set_access_method('table_type_pg_local', 'fake_am');
|
|
NOTICE: creating a new table for alter_table_set_access_method.table_type_pg_local
|
|
NOTICE: Moving the data of alter_table_set_access_method.table_type_pg_local
|
|
NOTICE: Dropping the old alter_table_set_access_method.table_type_pg_local
|
|
NOTICE: Renaming the new table to alter_table_set_access_method.table_type_pg_local
|
|
alter_table_set_access_method
|
|
---------------------------------------------------------------------
|
|
|
|
(1 row)
|
|
|
|
SELECT alter_table_set_access_method('table_type_citus_local', 'fake_am');
|
|
NOTICE: creating a new table for alter_table_set_access_method.table_type_citus_local
|
|
NOTICE: Moving the data of alter_table_set_access_method.table_type_citus_local
|
|
NOTICE: Dropping the old alter_table_set_access_method.table_type_citus_local
|
|
NOTICE: Renaming the new table to alter_table_set_access_method.table_type_citus_local
|
|
alter_table_set_access_method
|
|
---------------------------------------------------------------------
|
|
|
|
(1 row)
|
|
|
|
SELECT table_name, citus_table_type, distribution_column, shard_count, access_method FROM public.citus_tables WHERE table_name::text LIKE 'table\_type%' ORDER BY 1;
|
|
table_name | citus_table_type | distribution_column | shard_count | access_method
|
|
---------------------------------------------------------------------
|
|
table_type_dist | distributed | a | 4 | fake_am
|
|
table_type_ref | reference | <none> | 1 | fake_am
|
|
(2 rows)
|
|
|
|
SELECT c.relname, a.amname FROM pg_class c, pg_am a where c.relname SIMILAR TO 'table_type\D*' AND c.relnamespace = 'alter_table_set_access_method'::regnamespace AND c.relam = a.oid;
|
|
relname | amname
|
|
---------------------------------------------------------------------
|
|
table_type_citus_local | fake_am
|
|
table_type_dist | fake_am
|
|
table_type_pg_local | fake_am
|
|
table_type_ref | fake_am
|
|
(4 rows)
|
|
|
|
-- test when the parent of a partition has foreign key to a reference table
|
|
create table test_pk(n int primary key);
|
|
create table test_fk_p(i int references test_pk(n)) partition by range(i);
|
|
create table test_fk_p0 partition of test_fk_p for values from (0) to (10);
|
|
create table test_fk_p1 partition of test_fk_p for values from (10) to (20);
|
|
select alter_table_set_access_method('test_fk_p1', 'columnar');
|
|
NOTICE: creating a new table for alter_table_set_access_method.test_fk_p1
|
|
NOTICE: Moving the data of alter_table_set_access_method.test_fk_p1
|
|
NOTICE: Dropping the old alter_table_set_access_method.test_fk_p1
|
|
NOTICE: Renaming the new table to alter_table_set_access_method.test_fk_p1
|
|
ERROR: Foreign keys and AFTER ROW triggers are not supported for columnar tables
|
|
HINT: Consider an AFTER STATEMENT trigger instead.
|
|
CONTEXT: SQL statement "ALTER TABLE alter_table_set_access_method.test_fk_p ATTACH PARTITION alter_table_set_access_method.test_fk_p1 FOR VALUES FROM (10) TO (20);"
|
|
-- test changing into same access method
|
|
CREATE TABLE same_access_method (a INT);
|
|
SELECT alter_table_set_access_method('same_access_method', 'heap');
|
|
ERROR: the access method of alter_table_set_access_method.same_access_method is already heap
|
|
-- test keeping dependent materialized views
|
|
CREATE TABLE mat_view_test (a int);
|
|
INSERT INTO mat_view_test VALUES (1), (2);
|
|
CREATE MATERIALIZED VIEW mat_view AS SELECT * FROM mat_view_test;
|
|
SELECT alter_table_set_access_method('mat_view_test','columnar');
|
|
NOTICE: creating a new table for alter_table_set_access_method.mat_view_test
|
|
NOTICE: Moving the data of alter_table_set_access_method.mat_view_test
|
|
NOTICE: Dropping the old alter_table_set_access_method.mat_view_test
|
|
NOTICE: drop cascades to materialized view mat_view
|
|
CONTEXT: SQL statement "DROP TABLE alter_table_set_access_method.mat_view_test CASCADE"
|
|
NOTICE: Renaming the new table to alter_table_set_access_method.mat_view_test
|
|
alter_table_set_access_method
|
|
---------------------------------------------------------------------
|
|
|
|
(1 row)
|
|
|
|
SELECT * FROM mat_view ORDER BY a;
|
|
a
|
|
---------------------------------------------------------------------
|
|
1
|
|
2
|
|
(2 rows)
|
|
|
|
CREATE TABLE local(a int);
|
|
INSERT INTO local VALUES (3);
|
|
create materialized view m_local as select * from local;
|
|
create view v_local as select * from local;
|
|
CREATE TABLE ref(a int);
|
|
SELECT create_Reference_table('ref');
|
|
create_reference_table
|
|
---------------------------------------------------------------------
|
|
|
|
(1 row)
|
|
|
|
INSERT INTO ref VALUES (4),(5);
|
|
create materialized view m_ref as select * from ref;
|
|
create view v_ref as select * from ref;
|
|
CREATE TABLE dist(a int);
|
|
SELECT create_distributed_table('dist', 'a');
|
|
create_distributed_table
|
|
---------------------------------------------------------------------
|
|
|
|
(1 row)
|
|
|
|
INSERT INTO dist VALUES (7),(9);
|
|
create materialized view m_dist as select * from dist;
|
|
create view v_dist as select * from dist;
|
|
select alter_table_set_access_method('local','columnar');
|
|
NOTICE: creating a new table for alter_table_set_access_method.local
|
|
NOTICE: Moving the data of alter_table_set_access_method.local
|
|
NOTICE: Dropping the old alter_table_set_access_method.local
|
|
NOTICE: drop cascades to 2 other objects
|
|
DETAIL: drop cascades to materialized view m_local
|
|
drop cascades to view v_local
|
|
CONTEXT: SQL statement "DROP TABLE alter_table_set_access_method.local CASCADE"
|
|
NOTICE: Renaming the new table to alter_table_set_access_method.local
|
|
alter_table_set_access_method
|
|
---------------------------------------------------------------------
|
|
|
|
(1 row)
|
|
|
|
select alter_table_set_access_method('ref','columnar');
|
|
NOTICE: creating a new table for alter_table_set_access_method.ref
|
|
NOTICE: Moving the data of alter_table_set_access_method.ref
|
|
NOTICE: Dropping the old alter_table_set_access_method.ref
|
|
NOTICE: drop cascades to 2 other objects
|
|
DETAIL: drop cascades to materialized view m_ref
|
|
drop cascades to view v_ref
|
|
CONTEXT: SQL statement "DROP TABLE alter_table_set_access_method.ref CASCADE"
|
|
NOTICE: Renaming the new table to alter_table_set_access_method.ref
|
|
alter_table_set_access_method
|
|
---------------------------------------------------------------------
|
|
|
|
(1 row)
|
|
|
|
select alter_table_set_access_method('dist','columnar');
|
|
NOTICE: creating a new table for alter_table_set_access_method.dist
|
|
NOTICE: Moving the data of alter_table_set_access_method.dist
|
|
NOTICE: Dropping the old alter_table_set_access_method.dist
|
|
NOTICE: drop cascades to 2 other objects
|
|
DETAIL: drop cascades to materialized view m_dist
|
|
drop cascades to view v_dist
|
|
CONTEXT: SQL statement "DROP TABLE alter_table_set_access_method.dist CASCADE"
|
|
NOTICE: Renaming the new table to alter_table_set_access_method.dist
|
|
alter_table_set_access_method
|
|
---------------------------------------------------------------------
|
|
|
|
(1 row)
|
|
|
|
SELECT alter_distributed_table('dist', shard_count:=1, cascade_to_colocated:=false);
|
|
NOTICE: creating a new table for alter_table_set_access_method.dist
|
|
NOTICE: Moving the data of alter_table_set_access_method.dist
|
|
NOTICE: Dropping the old alter_table_set_access_method.dist
|
|
NOTICE: drop cascades to 2 other objects
|
|
DETAIL: drop cascades to materialized view m_dist
|
|
drop cascades to view v_dist
|
|
CONTEXT: SQL statement "DROP TABLE alter_table_set_access_method.dist CASCADE"
|
|
NOTICE: Renaming the new table to alter_table_set_access_method.dist
|
|
alter_distributed_table
|
|
---------------------------------------------------------------------
|
|
|
|
(1 row)
|
|
|
|
select alter_table_set_access_method('local','heap');
|
|
NOTICE: creating a new table for alter_table_set_access_method.local
|
|
NOTICE: Moving the data of alter_table_set_access_method.local
|
|
NOTICE: Dropping the old alter_table_set_access_method.local
|
|
NOTICE: drop cascades to 2 other objects
|
|
DETAIL: drop cascades to materialized view m_local
|
|
drop cascades to view v_local
|
|
CONTEXT: SQL statement "DROP TABLE alter_table_set_access_method.local CASCADE"
|
|
NOTICE: Renaming the new table to alter_table_set_access_method.local
|
|
alter_table_set_access_method
|
|
---------------------------------------------------------------------
|
|
|
|
(1 row)
|
|
|
|
select alter_table_set_access_method('ref','heap');
|
|
NOTICE: creating a new table for alter_table_set_access_method.ref
|
|
NOTICE: Moving the data of alter_table_set_access_method.ref
|
|
NOTICE: Dropping the old alter_table_set_access_method.ref
|
|
NOTICE: drop cascades to 2 other objects
|
|
DETAIL: drop cascades to materialized view m_ref
|
|
drop cascades to view v_ref
|
|
CONTEXT: SQL statement "DROP TABLE alter_table_set_access_method.ref CASCADE"
|
|
NOTICE: Renaming the new table to alter_table_set_access_method.ref
|
|
alter_table_set_access_method
|
|
---------------------------------------------------------------------
|
|
|
|
(1 row)
|
|
|
|
select alter_table_set_access_method('dist','heap');
|
|
NOTICE: creating a new table for alter_table_set_access_method.dist
|
|
NOTICE: Moving the data of alter_table_set_access_method.dist
|
|
NOTICE: Dropping the old alter_table_set_access_method.dist
|
|
NOTICE: drop cascades to 2 other objects
|
|
DETAIL: drop cascades to materialized view m_dist
|
|
drop cascades to view v_dist
|
|
CONTEXT: SQL statement "DROP TABLE alter_table_set_access_method.dist CASCADE"
|
|
NOTICE: Renaming the new table to alter_table_set_access_method.dist
|
|
alter_table_set_access_method
|
|
---------------------------------------------------------------------
|
|
|
|
(1 row)
|
|
|
|
SELECT * FROM m_local;
|
|
a
|
|
---------------------------------------------------------------------
|
|
3
|
|
(1 row)
|
|
|
|
SELECT * FROM m_ref;
|
|
a
|
|
---------------------------------------------------------------------
|
|
4
|
|
5
|
|
(2 rows)
|
|
|
|
SELECT * FROM m_dist;
|
|
a
|
|
---------------------------------------------------------------------
|
|
7
|
|
9
|
|
(2 rows)
|
|
|
|
SELECT * FROM v_local;
|
|
a
|
|
---------------------------------------------------------------------
|
|
3
|
|
(1 row)
|
|
|
|
SELECT * FROM v_ref;
|
|
a
|
|
---------------------------------------------------------------------
|
|
4
|
|
5
|
|
(2 rows)
|
|
|
|
SELECT * FROM v_dist;
|
|
a
|
|
---------------------------------------------------------------------
|
|
7
|
|
9
|
|
(2 rows)
|
|
|
|
SELECT relname, relkind
|
|
FROM pg_class
|
|
WHERE relname IN (
|
|
'v_dist',
|
|
'v_ref',
|
|
'v_local',
|
|
'm_dist',
|
|
'm_ref',
|
|
'm_local'
|
|
)
|
|
ORDER BY relname ASC;
|
|
relname | relkind
|
|
---------------------------------------------------------------------
|
|
m_dist | m
|
|
m_local | m
|
|
m_ref | m
|
|
v_dist | v
|
|
v_local | v
|
|
v_ref | v
|
|
(6 rows)
|
|
|
|
SET client_min_messages TO WARNING;
|
|
DROP SCHEMA alter_table_set_access_method CASCADE;
|
|
SELECT 1 FROM master_remove_node('localhost', :master_port);
|
|
?column?
|
|
---------------------------------------------------------------------
|
|
1
|
|
(1 row)
|
|
|