Skip to content

Commit ade2159

Browse files
committed
Add regression tests for ALTER MATERIALIZED VIEW with tablespaces
The clauses SET TABLESPACE and ALL IN TABLESPACE are supported in ALTER MATERIALIZED VIEW for a long time, and they behave mostly like ALTER TABLE by reusing the same code paths, but there were zero tests for them. This commit closes the gap with new tests in tablespace.sql. Author: Yugo Nagata Discussion: https://postgr.es/m/20220316133337.5dc9740abfa24c25ec9f67f5@sraoss.co.jp
1 parent 9616da3 commit ade2159

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/test/regress/expected/tablespace.out

+15-1
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,16 @@ SELECT COUNT(*) FROM testschema.atable; -- checks heap
905905
3
906906
(1 row)
907907

908+
-- let's try moving a materialized view from one place to another
909+
CREATE MATERIALIZED VIEW testschema.amv AS SELECT * FROM testschema.atable;
910+
ALTER MATERIALIZED VIEW testschema.amv SET TABLESPACE regress_tblspace;
911+
REFRESH MATERIALIZED VIEW testschema.amv;
912+
SELECT COUNT(*) FROM testschema.amv;
913+
count
914+
-------
915+
3
916+
(1 row)
917+
908918
-- Will fail with bad path
909919
CREATE TABLESPACE regress_badspace LOCATION '/no/such/location';
910920
ERROR: directory "/no/such/location" does not exist
@@ -939,18 +949,22 @@ RESET ROLE;
939949
ALTER TABLESPACE regress_tblspace RENAME TO regress_tblspace_renamed;
940950
ALTER TABLE ALL IN TABLESPACE regress_tblspace_renamed SET TABLESPACE pg_default;
941951
ALTER INDEX ALL IN TABLESPACE regress_tblspace_renamed SET TABLESPACE pg_default;
952+
ALTER MATERIALIZED VIEW ALL IN TABLESPACE regress_tblspace_renamed SET TABLESPACE pg_default;
942953
-- Should show notice that nothing was done
943954
ALTER TABLE ALL IN TABLESPACE regress_tblspace_renamed SET TABLESPACE pg_default;
944955
NOTICE: no matching relations in tablespace "regress_tblspace_renamed" found
956+
ALTER MATERIALIZED VIEW ALL IN TABLESPACE regress_tblspace_renamed SET TABLESPACE pg_default;
957+
NOTICE: no matching relations in tablespace "regress_tblspace_renamed" found
945958
-- Should succeed
946959
DROP TABLESPACE regress_tblspace_renamed;
947960
DROP SCHEMA testschema CASCADE;
948-
NOTICE: drop cascades to 6 other objects
961+
NOTICE: drop cascades to 7 other objects
949962
DETAIL: drop cascades to table testschema.foo
950963
drop cascades to table testschema.asselect
951964
drop cascades to table testschema.asexecute
952965
drop cascades to table testschema.part
953966
drop cascades to table testschema.atable
967+
drop cascades to materialized view testschema.amv
954968
drop cascades to table testschema.tablespace_acl
955969
DROP ROLE regress_tablespace_user1;
956970
DROP ROLE regress_tablespace_user2;

src/test/regress/sql/tablespace.sql

+8
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,12 @@ INSERT INTO testschema.atable VALUES(3); -- ok
380380
INSERT INTO testschema.atable VALUES(1); -- fail (checks index)
381381
SELECT COUNT(*) FROM testschema.atable; -- checks heap
382382

383+
-- let's try moving a materialized view from one place to another
384+
CREATE MATERIALIZED VIEW testschema.amv AS SELECT * FROM testschema.atable;
385+
ALTER MATERIALIZED VIEW testschema.amv SET TABLESPACE regress_tblspace;
386+
REFRESH MATERIALIZED VIEW testschema.amv;
387+
SELECT COUNT(*) FROM testschema.amv;
388+
383389
-- Will fail with bad path
384390
CREATE TABLESPACE regress_badspace LOCATION '/no/such/location';
385391

@@ -414,9 +420,11 @@ ALTER TABLESPACE regress_tblspace RENAME TO regress_tblspace_renamed;
414420

415421
ALTER TABLE ALL IN TABLESPACE regress_tblspace_renamed SET TABLESPACE pg_default;
416422
ALTER INDEX ALL IN TABLESPACE regress_tblspace_renamed SET TABLESPACE pg_default;
423+
ALTER MATERIALIZED VIEW ALL IN TABLESPACE regress_tblspace_renamed SET TABLESPACE pg_default;
417424

418425
-- Should show notice that nothing was done
419426
ALTER TABLE ALL IN TABLESPACE regress_tblspace_renamed SET TABLESPACE pg_default;
427+
ALTER MATERIALIZED VIEW ALL IN TABLESPACE regress_tblspace_renamed SET TABLESPACE pg_default;
420428

421429
-- Should succeed
422430
DROP TABLESPACE regress_tblspace_renamed;

0 commit comments

Comments
 (0)