diff --git a/src/test/regress/expected/create_am.out b/src/test/regress/expected/create_am.out index e15ba33..1a3686e 100644 --- a/src/test/regress/expected/create_am.out +++ b/src/test/regress/expected/create_am.out @@ -165,16 +165,98 @@ CREATE SEQUENCE test_seq USING heap2; ERROR: syntax error at or near "USING" LINE 1: CREATE SEQUENCE test_seq USING heap2; ^ +-- +-- Test dependencies of various object types with their table access method. +-- +set default_table_access_method = 'heap2'; +-- Partitioned tables : this should have tableam dependency. +CREATE TABLE parted_heap2 ( a text, b int) PARTITION BY list (a) USING heap2; +CREATE TABLE part1_heap2 PARTITION OF parted_heap2 for VALUES in ('a', 'b'); +-- Create these relation kinds so as to verify that no tableam dependency is +-- created for them, in case of unsupported default_table_access_method. +CREATE VIEW test_view AS SELECT * FROM tbl_heap2; +CREATE SEQUENCE test_seq; +-- Foreign tables. +CREATE FOREIGN DATA WRAPPER fdw_heap2 VALIDATOR postgresql_fdw_validator; +CREATE SERVER fs_heap2 FOREIGN DATA WRAPPER fdw_heap2 ; +CREATE FOREIGN table ft_heap2 () SERVER fs_heap2; +-- Toast tables: Base table should have the dependency, but it's toast table +-- should not. +CREATE TABLE toast_table_heap2(v varchar); +-- Composite types. +CREATE TYPE ct_heap2 AS (id int, v varchar); +\set depend_query 'SELECT pg_describe_object(classid,objid,objsubid) AS obj FROM pg_depend, pg_am WHERE pg_depend.refclassid = $$pg_am$$::regclass AND pg_am.oid = pg_depend.refobjid AND pg_am.amname = $$heap2$$ ORDER BY 1' +-- Show all the dependencies +:depend_query; + obj +---------------------------- + materialized view mv_heap2 + table part1_heap2 + table parted_heap2 + table tblas_heap2 + table tbl_heap2 + table toast_table_heap2 +(6 rows) + -- Drop table access method, but fails as objects depends on it DROP ACCESS METHOD heap2; ERROR: cannot drop access method heap2 because other objects depend on it DETAIL: table tbl_heap2 depends on access method heap2 +view test_view depends on table tbl_heap2 +table tblas_heap2 depends on access method heap2 +materialized view mv_heap2 depends on access method heap2 +table parted_heap2 depends on access method heap2 +table toast_table_heap2 depends on access method heap2 +HINT: Use DROP ... CASCADE to drop the dependent objects too. +-- Drop the dependent objects one by one, and verify the effect on dependencies. +DROP TABLE parted_heap2; +:depend_query; + obj +---------------------------- + materialized view mv_heap2 + table tblas_heap2 + table tbl_heap2 + table toast_table_heap2 +(4 rows) + +DROP ACCESS METHOD heap2; +ERROR: cannot drop access method heap2 because other objects depend on it +DETAIL: table tbl_heap2 depends on access method heap2 +view test_view depends on table tbl_heap2 table tblas_heap2 depends on access method heap2 materialized view mv_heap2 depends on access method heap2 +table toast_table_heap2 depends on access method heap2 +HINT: Use DROP ... CASCADE to drop the dependent objects too. +DROP MATERIALIZED VIEW mv_heap2; +:depend_query; + obj +------------------------- + table tblas_heap2 + table tbl_heap2 + table toast_table_heap2 +(3 rows) + +DROP ACCESS METHOD heap2; +ERROR: cannot drop access method heap2 because other objects depend on it +DETAIL: table tbl_heap2 depends on access method heap2 +view test_view depends on table tbl_heap2 +table tblas_heap2 depends on access method heap2 +table toast_table_heap2 depends on access method heap2 HINT: Use DROP ... CASCADE to drop the dependent objects too. --- Drop table access method with cascade -DROP ACCESS METHOD heap2 CASCADE; -NOTICE: drop cascades to 3 other objects -DETAIL: drop cascades to table tbl_heap2 -drop cascades to table tblas_heap2 -drop cascades to materialized view mv_heap2 +DROP VIEW test_view; +DROP TABLE tbl_heap2; +DROP TABLE tblas_heap2; +DROP TABLE toast_table_heap2; +:depend_query; + obj +----- +(0 rows) + +DROP ACCESS METHOD heap2; +-- cleanup +reset default_table_access_method; +DROP FOREIGN TABLE ft_heap2; +DROP SERVER fs_heap2; +DROP FOREIGN DATA WRAPPER fdw_heap2; +DROP SEQUENCE test_seq; +DROP TYPE ct_heap2; diff --git a/src/test/regress/sql/create_am.sql b/src/test/regress/sql/create_am.sql index 2c7b481..75cb512 100644 --- a/src/test/regress/sql/create_am.sql +++ b/src/test/regress/sql/create_am.sql @@ -108,8 +108,58 @@ CREATE VIEW test_view USING heap2 AS SELECT * FROM tbl_heap2; CREATE SEQUENCE test_seq USING heap2; +-- +-- Test dependencies of various object types with their table access method. +-- + +set default_table_access_method = 'heap2'; + +-- Partitioned tables : this should have tableam dependency. +CREATE TABLE parted_heap2 ( a text, b int) PARTITION BY list (a) USING heap2; +CREATE TABLE part1_heap2 PARTITION OF parted_heap2 for VALUES in ('a', 'b'); + +-- Create these relation kinds so as to verify that no tableam dependency is +-- created for them, in case of unsupported default_table_access_method. +CREATE VIEW test_view AS SELECT * FROM tbl_heap2; +CREATE SEQUENCE test_seq; +-- Foreign tables. +CREATE FOREIGN DATA WRAPPER fdw_heap2 VALIDATOR postgresql_fdw_validator; +CREATE SERVER fs_heap2 FOREIGN DATA WRAPPER fdw_heap2 ; +CREATE FOREIGN table ft_heap2 () SERVER fs_heap2; +-- Toast tables: Base table should have the dependency, but it's toast table +-- should not. +CREATE TABLE toast_table_heap2(v varchar); +-- Composite types. +CREATE TYPE ct_heap2 AS (id int, v varchar); + +\set depend_query 'SELECT pg_describe_object(classid,objid,objsubid) AS obj FROM pg_depend, pg_am WHERE pg_depend.refclassid = $$pg_am$$::regclass AND pg_am.oid = pg_depend.refobjid AND pg_am.amname = $$heap2$$ ORDER BY 1' + +-- Show all the dependencies +:depend_query; + -- Drop table access method, but fails as objects depends on it DROP ACCESS METHOD heap2; --- Drop table access method with cascade -DROP ACCESS METHOD heap2 CASCADE; +-- Drop the dependent objects one by one, and verify the effect on dependencies. +DROP TABLE parted_heap2; +:depend_query; +DROP ACCESS METHOD heap2; + +DROP MATERIALIZED VIEW mv_heap2; +:depend_query; +DROP ACCESS METHOD heap2; + +DROP VIEW test_view; +DROP TABLE tbl_heap2; +DROP TABLE tblas_heap2; +DROP TABLE toast_table_heap2; +:depend_query; +DROP ACCESS METHOD heap2; + +-- cleanup +reset default_table_access_method; +DROP FOREIGN TABLE ft_heap2; +DROP SERVER fs_heap2; +DROP FOREIGN DATA WRAPPER fdw_heap2; +DROP SEQUENCE test_seq; +DROP TYPE ct_heap2;