@@ -253,6 +253,35 @@ SELECT amname FROM pg_class c, pg_am am
253253 heap
254254(1 row)
255255
256+ -- Switching to heap2 adds new dependency entry to the AM.
257+ ALTER TABLE heaptable SET ACCESS METHOD heap2;
258+ SELECT pg_describe_object(classid, objid, objsubid) as obj,
259+ pg_describe_object(refclassid, refobjid, refobjsubid) as objref,
260+ deptype
261+ FROM pg_depend
262+ WHERE classid = 'pg_class'::regclass AND
263+ objid = 'heaptable'::regclass
264+ ORDER BY 1, 2;
265+ obj | objref | deptype
266+ -----------------+---------------------+---------
267+ table heaptable | access method heap2 | n
268+ table heaptable | schema public | n
269+ (2 rows)
270+
271+ -- Switching to heap should not have a dependency entry to the AM.
272+ ALTER TABLE heaptable SET ACCESS METHOD heap;
273+ SELECT pg_describe_object(classid, objid, objsubid) as obj,
274+ pg_describe_object(refclassid, refobjid, refobjsubid) as objref,
275+ deptype
276+ FROM pg_depend
277+ WHERE classid = 'pg_class'::regclass AND
278+ objid = 'heaptable'::regclass
279+ ORDER BY 1, 2;
280+ obj | objref | deptype
281+ -----------------+---------------+---------
282+ table heaptable | schema public | n
283+ (1 row)
284+
256285ALTER TABLE heaptable SET ACCESS METHOD heap2;
257286SELECT amname FROM pg_class c, pg_am am
258287 WHERE c.relam = am.oid AND c.oid = 'heaptable'::regclass;
@@ -267,9 +296,35 @@ SELECT COUNT(a), COUNT(1) FILTER(WHERE a=1) FROM heaptable;
267296 9 | 1
268297(1 row)
269298
299+ -- ALTER MATERIALIZED VIEW SET ACCESS METHOD
300+ CREATE MATERIALIZED VIEW heapmv USING heap AS SELECT * FROM heaptable;
301+ SELECT amname FROM pg_class c, pg_am am
302+ WHERE c.relam = am.oid AND c.oid = 'heapmv'::regclass;
303+ amname
304+ --------
305+ heap
306+ (1 row)
307+
308+ ALTER MATERIALIZED VIEW heapmv SET ACCESS METHOD heap2;
309+ SELECT amname FROM pg_class c, pg_am am
310+ WHERE c.relam = am.oid AND c.oid = 'heapmv'::regclass;
311+ amname
312+ --------
313+ heap2
314+ (1 row)
315+
316+ SELECT COUNT(a), COUNT(1) FILTER(WHERE a=1) FROM heapmv;
317+ count | count
318+ -------+-------
319+ 9 | 1
320+ (1 row)
321+
270322-- No support for multiple subcommands
271323ALTER TABLE heaptable SET ACCESS METHOD heap, SET ACCESS METHOD heap2;
272324ERROR: cannot have multiple SET ACCESS METHOD subcommands
325+ ALTER MATERIALIZED VIEW heapmv SET ACCESS METHOD heap, SET ACCESS METHOD heap2;
326+ ERROR: cannot have multiple SET ACCESS METHOD subcommands
327+ DROP MATERIALIZED VIEW heapmv;
273328DROP TABLE heaptable;
274329-- No support for partitioned tables.
275330CREATE TABLE am_partitioned(x INT, y INT)
0 commit comments