--
|
-- one_c_temp_memory_catalog_inplace
|
--
|
|
SET client_min_messages = warning;
|
|
SET enable_temp_memory_catalog = off;
|
|
CREATE TEMP TABLE tmc_inplace_phys(id integer);
|
|
INSERT INTO pg_temp.tmc_inplace_phys
|
SELECT g
|
FROM generate_series(1, 64) AS g;
|
|
BEGIN;
|
SAVEPOINT tmc_inplace_phys_s;
|
ANALYZE pg_temp.tmc_inplace_phys;
|
ROLLBACK TO SAVEPOINT tmc_inplace_phys_s;
|
RELEASE SAVEPOINT tmc_inplace_phys_s;
|
COMMIT;
|
|
ALTER TABLE pg_temp.tmc_inplace_phys
|
RENAME TO tmc_inplace_phys_renamed;
|
|
DO $$
|
DECLARE
|
plan json;
|
BEGIN
|
EXECUTE 'EXPLAIN (FORMAT JSON) SELECT * FROM pg_temp.tmc_inplace_phys_renamed'
|
INTO plan;
|
|
IF plan->0->'Plan'->>'Node Type' <> 'Seq Scan' THEN
|
RAISE EXCEPTION 'unexpected physical control node type: %',
|
plan->0->'Plan'->>'Node Type';
|
END IF;
|
|
IF (plan->0->'Plan'->>'Plan Rows')::integer <> 64 THEN
|
RAISE EXCEPTION 'unexpected physical control plan rows: got %, expected 64',
|
plan->0->'Plan'->>'Plan Rows';
|
END IF;
|
END;
|
$$;
|
|
DROP TABLE pg_temp.tmc_inplace_phys_renamed;
|
|
SET enable_temp_memory_catalog = on;
|
|
CREATE TEMP TABLE tmc_inplace_mem(id integer, payload integer);
|
|
INSERT INTO pg_temp.tmc_inplace_mem
|
SELECT g, g * 10
|
FROM generate_series(1, 64) AS g;
|
|
DO $$
|
DECLARE
|
rel_oid oid;
|
rowcount bigint;
|
BEGIN
|
rel_oid := to_regclass('pg_temp.tmc_inplace_mem');
|
IF rel_oid IS NULL THEN
|
RAISE EXCEPTION 'tmc_inplace_mem is missing';
|
END IF;
|
|
SELECT count(*) INTO rowcount
|
FROM pg_catalog.pg_class
|
WHERE oid = rel_oid;
|
|
IF rowcount <> 0 THEN
|
RAISE EXCEPTION 'unexpected physical pg_class rowcount for tmc_inplace_mem: got %, expected 0',
|
rowcount;
|
END IF;
|
END;
|
$$;
|
|
SET enable_temp_memory_catalog = off;
|
|
BEGIN;
|
SAVEPOINT tmc_inplace_mem_s;
|
ANALYZE pg_temp.tmc_inplace_mem;
|
|
DO $$
|
DECLARE
|
plan json;
|
BEGIN
|
EXECUTE 'EXPLAIN (FORMAT JSON) SELECT * FROM pg_temp.tmc_inplace_mem'
|
INTO plan;
|
|
IF (plan->0->'Plan'->>'Plan Rows')::integer <> 64 THEN
|
RAISE EXCEPTION 'unexpected memory analyze plan rows inside savepoint: got %, expected 64',
|
plan->0->'Plan'->>'Plan Rows';
|
END IF;
|
END;
|
$$;
|
|
ROLLBACK TO SAVEPOINT tmc_inplace_mem_s;
|
RELEASE SAVEPOINT tmc_inplace_mem_s;
|
COMMIT;
|
|
ALTER TABLE pg_temp.tmc_inplace_mem
|
RENAME TO tmc_inplace_mem_renamed;
|
|
DO $$
|
DECLARE
|
plan json;
|
BEGIN
|
EXECUTE 'EXPLAIN (FORMAT JSON) SELECT * FROM pg_temp.tmc_inplace_mem_renamed'
|
INTO plan;
|
|
IF plan->0->'Plan'->>'Node Type' <> 'Seq Scan' THEN
|
RAISE EXCEPTION 'unexpected memory control node type after rename: %',
|
plan->0->'Plan'->>'Node Type';
|
END IF;
|
|
IF (plan->0->'Plan'->>'Plan Rows')::integer <> 64 THEN
|
RAISE EXCEPTION 'unexpected memory control plan rows after rename: got %, expected 64',
|
plan->0->'Plan'->>'Plan Rows';
|
END IF;
|
END;
|
$$;
|
|
ANALYZE pg_temp.tmc_inplace_mem_renamed;
|
ANALYZE pg_temp.tmc_inplace_mem_renamed;
|
|
CREATE INDEX tmc_inplace_mem_idx
|
ON pg_temp.tmc_inplace_mem_renamed USING btree (id);
|
|
SELECT count(*) AS mem_rows, sum(payload) AS mem_payload_sum
|
FROM pg_temp.tmc_inplace_mem_renamed;
|
|
DO $$
|
DECLARE
|
table_oid oid;
|
index_oid oid;
|
parent_rowcount bigint;
|
index_rowcount bigint;
|
BEGIN
|
table_oid := to_regclass('pg_temp.tmc_inplace_mem_renamed');
|
index_oid := to_regclass('pg_temp.tmc_inplace_mem_idx');
|
|
IF table_oid IS NULL THEN
|
RAISE EXCEPTION 'tmc_inplace_mem_renamed is missing after CREATE INDEX';
|
END IF;
|
|
IF index_oid IS NULL THEN
|
RAISE EXCEPTION 'tmc_inplace_mem_idx is missing after CREATE INDEX';
|
END IF;
|
|
SELECT count(*) INTO parent_rowcount
|
FROM pg_catalog.pg_class
|
WHERE oid = table_oid;
|
|
IF parent_rowcount <> 0 THEN
|
RAISE EXCEPTION 'unexpected physical pg_class rowcount for tmc_inplace_mem_renamed: got %, expected 0',
|
parent_rowcount;
|
END IF;
|
|
SELECT count(*) INTO index_rowcount
|
FROM pg_catalog.pg_class
|
WHERE oid = index_oid;
|
|
IF index_rowcount <> 0 THEN
|
RAISE EXCEPTION 'unexpected physical pg_class rowcount for tmc_inplace_mem_idx: got %, expected 0',
|
index_rowcount;
|
END IF;
|
END;
|
$$;
|
|
DROP INDEX pg_temp.tmc_inplace_mem_idx;
|
DROP TABLE pg_temp.tmc_inplace_mem_renamed;
|
|
RESET enable_temp_memory_catalog;
|