-- -- one_c_temp_memory_catalog_basic -- SET client_min_messages = warning; DO $$ BEGIN IF current_setting('enable_temp_memory_catalog') <> 'off' THEN RAISE EXCEPTION 'unexpected default enable_temp_memory_catalog: %', current_setting('enable_temp_memory_catalog'); END IF; END; $$; CREATE TEMP TABLE tmc_off(id integer); DO $$ DECLARE off_oid oid; rowcount bigint; BEGIN off_oid := to_regclass('pg_temp.tmc_off'); IF off_oid IS NULL THEN RAISE EXCEPTION 'tmc_off is missing while GUC is off'; END IF; SELECT count(*) INTO rowcount FROM pg_catalog.pg_class WHERE oid = off_oid; IF rowcount <> 1 THEN RAISE EXCEPTION 'unexpected physical pg_class rowcount for tmc_off: got %, expected 1', rowcount; END IF; END; $$; DROP TABLE pg_temp.tmc_off; SELECT to_regclass('pg_temp.tmc_mem') IS NULL AS precreate_missing; SET enable_temp_memory_catalog = on; CREATE TEMP SEQUENCE tmc_sequence_control; DO $$ DECLARE seq_oid oid; rowcount bigint; BEGIN seq_oid := to_regclass('pg_temp.tmc_sequence_control'); IF seq_oid IS NULL THEN RAISE EXCEPTION 'tmc_sequence_control is missing'; END IF; SELECT count(*) INTO rowcount FROM pg_catalog.pg_class WHERE oid = seq_oid; IF rowcount <> 0 THEN RAISE EXCEPTION 'unexpected physical pg_class rowcount for tmc_sequence_control: got %, expected 0', rowcount; END IF; END; $$; DROP SEQUENCE pg_temp.tmc_sequence_control; CREATE TEMP TABLE tmc_mem( id integer, payload integer ); INSERT INTO pg_temp.tmc_mem VALUES (1, 10), (2, 20); DO $$ DECLARE mem_oid oid; rowcount bigint; sum_ids bigint; BEGIN SELECT to_regclass('pg_temp.tmc_mem') INTO mem_oid; IF mem_oid IS NULL THEN RAISE EXCEPTION 'tmc_mem is not visible through to_regclass'; END IF; SELECT count(*), sum(id) INTO rowcount, sum_ids FROM pg_temp.tmc_mem; IF rowcount <> 2 OR sum_ids <> 3 THEN RAISE EXCEPTION 'unexpected tmc_mem contents: rowcount %, sum %', rowcount, sum_ids; END IF; SELECT count(*) INTO rowcount FROM pg_catalog.pg_class WHERE oid = mem_oid; IF rowcount <> 0 THEN RAISE EXCEPTION 'unexpected physical pg_class rowcount for tmc_mem: got %, expected 0', rowcount; END IF; SELECT count(*) INTO rowcount FROM pg_catalog.pg_attribute WHERE attrelid = mem_oid AND attnum > 0; IF rowcount <> 0 THEN RAISE EXCEPTION 'unexpected physical pg_attribute rowcount for tmc_mem: got %, expected 0', rowcount; END IF; SELECT count(*) INTO rowcount FROM pg_catalog.pg_type WHERE typrelid = mem_oid; IF rowcount <> 0 THEN RAISE EXCEPTION 'unexpected physical pg_type rowcount for tmc_mem: got %, expected 0', rowcount; END IF; END; $$; SELECT to_regclass('pg_temp.tmc_mem') IS NOT NULL AS prerename_present; SELECT to_regclass('pg_temp.tmc_mem_renamed') IS NULL AS prerenamed_missing; SET enable_temp_memory_catalog = off; ALTER TABLE pg_temp.tmc_mem RENAME TO tmc_mem_renamed; SELECT to_regclass('pg_temp.tmc_mem') IS NULL AS old_name_missing; SELECT to_regclass('pg_temp.tmc_mem_renamed') IS NOT NULL AS new_name_present; CREATE TEMP TABLE tmc_physical_after(id integer); DO $$ DECLARE physical_oid oid; rowcount bigint; BEGIN physical_oid := to_regclass('pg_temp.tmc_physical_after'); IF physical_oid IS NULL THEN RAISE EXCEPTION 'tmc_physical_after is missing while GUC is off'; END IF; SELECT count(*) INTO rowcount FROM pg_catalog.pg_class WHERE oid = physical_oid; IF rowcount <> 1 THEN RAISE EXCEPTION 'unexpected physical pg_class rowcount for tmc_physical_after: got %, expected 1', rowcount; END IF; IF to_regclass('pg_temp.tmc_mem_renamed') IS NULL THEN RAISE EXCEPTION 'tmc_mem_renamed disappeared after creating physical temp table'; END IF; END; $$; DROP TABLE pg_temp.tmc_physical_after; DROP TABLE pg_temp.tmc_mem_renamed; SELECT to_regclass('pg_temp.tmc_mem_renamed') IS NULL AS dropped_memory_missing; SET enable_temp_memory_catalog = on; BEGIN; CREATE TEMP TABLE tmc_rollback(id integer); SELECT to_regclass('pg_temp.tmc_rollback') IS NOT NULL AS rollback_created; ROLLBACK; SELECT to_regclass('pg_temp.tmc_rollback') IS NULL AS rollback_missing; BEGIN; SAVEPOINT tmc_s; CREATE TEMP TABLE tmc_savepoint(id integer); SELECT to_regclass('pg_temp.tmc_savepoint') IS NOT NULL AS savepoint_created; ROLLBACK TO SAVEPOINT tmc_s; RELEASE SAVEPOINT tmc_s; COMMIT; SELECT to_regclass('pg_temp.tmc_savepoint') IS NULL AS savepoint_missing_after_commit; RESET enable_temp_memory_catalog;