--
|
-- one_c_temp_memory_catalog_xact
|
--
|
|
SET client_min_messages = warning;
|
SET enable_temp_memory_catalog = on;
|
|
BEGIN;
|
SAVEPOINT tmc_xact_sp;
|
CREATE TEMP TABLE tmc_xact_sp_table(id integer);
|
INSERT INTO pg_temp.tmc_xact_sp_table VALUES (1);
|
ROLLBACK TO SAVEPOINT tmc_xact_sp;
|
RELEASE SAVEPOINT tmc_xact_sp;
|
COMMIT;
|
|
SELECT to_regclass('pg_temp.tmc_xact_sp_table') IS NULL AS sp_table_missing;
|
|
BEGIN;
|
SAVEPOINT tmc_xact_create_outer;
|
SAVEPOINT tmc_xact_create_inner;
|
CREATE TEMP TABLE tmc_xact_create_rb(id integer, payload integer);
|
INSERT INTO pg_temp.tmc_xact_create_rb VALUES (10, 20);
|
RELEASE SAVEPOINT tmc_xact_create_inner;
|
SELECT id, payload
|
FROM pg_temp.tmc_xact_create_rb;
|
ROLLBACK TO SAVEPOINT tmc_xact_create_outer;
|
RELEASE SAVEPOINT tmc_xact_create_outer;
|
COMMIT;
|
|
SELECT to_regclass('pg_temp.tmc_xact_create_rb') IS NULL AS create_rb_missing;
|
|
BEGIN;
|
SAVEPOINT tmc_xact_create_commit_outer;
|
SAVEPOINT tmc_xact_create_commit_inner;
|
CREATE TEMP TABLE tmc_xact_create_commit(id integer, payload integer);
|
INSERT INTO pg_temp.tmc_xact_create_commit VALUES (11, 22);
|
RELEASE SAVEPOINT tmc_xact_create_commit_inner;
|
RELEASE SAVEPOINT tmc_xact_create_commit_outer;
|
COMMIT;
|
|
SELECT id, payload
|
FROM pg_temp.tmc_xact_create_commit;
|
|
DROP TABLE pg_temp.tmc_xact_create_commit;
|
|
SET enable_temp_memory_catalog = on;
|
CREATE TEMP TABLE tmc_xact_update(
|
a integer,
|
keep integer
|
);
|
INSERT INTO pg_temp.tmc_xact_update VALUES (1, 101);
|
SET enable_temp_memory_catalog = off;
|
|
BEGIN;
|
SAVEPOINT tmc_xact_update_outer;
|
ALTER TABLE pg_temp.tmc_xact_update
|
RENAME COLUMN a TO a_outer;
|
SAVEPOINT tmc_xact_update_inner;
|
ALTER TABLE pg_temp.tmc_xact_update
|
RENAME COLUMN a_outer TO a_inner;
|
RELEASE SAVEPOINT tmc_xact_update_inner;
|
SELECT a_inner, keep
|
FROM pg_temp.tmc_xact_update;
|
ROLLBACK TO SAVEPOINT tmc_xact_update_outer;
|
RELEASE SAVEPOINT tmc_xact_update_outer;
|
COMMIT;
|
|
DO $$
|
DECLARE
|
logical_columns text[];
|
BEGIN
|
IF to_regclass('pg_temp.tmc_xact_update') IS NULL THEN
|
RAISE EXCEPTION 'tmc_xact_update is missing after nested rollback';
|
END IF;
|
|
SELECT array_agg(keys.key ORDER BY keys.key)
|
INTO logical_columns
|
FROM pg_temp.tmc_xact_update AS t
|
CROSS JOIN LATERAL
|
jsonb_object_keys(to_jsonb(t)) AS keys(key);
|
|
IF logical_columns IS DISTINCT FROM ARRAY['a', 'keep']::text[] THEN
|
RAISE EXCEPTION 'unexpected nested rollback logical columns: %',
|
logical_columns;
|
END IF;
|
END;
|
$$;
|
|
SELECT a, keep
|
FROM pg_temp.tmc_xact_update;
|
|
DROP TABLE pg_temp.tmc_xact_update;
|
|
SET enable_temp_memory_catalog = on;
|
CREATE TEMP TABLE tmc_xact_update_commit(
|
a integer,
|
keep integer
|
);
|
INSERT INTO pg_temp.tmc_xact_update_commit VALUES (2, 202);
|
SET enable_temp_memory_catalog = off;
|
|
BEGIN;
|
SAVEPOINT tmc_xact_update_commit_outer;
|
ALTER TABLE pg_temp.tmc_xact_update_commit
|
RENAME COLUMN a TO a_outer;
|
SAVEPOINT tmc_xact_update_commit_inner;
|
ALTER TABLE pg_temp.tmc_xact_update_commit
|
RENAME COLUMN a_outer TO a_inner;
|
RELEASE SAVEPOINT tmc_xact_update_commit_inner;
|
RELEASE SAVEPOINT tmc_xact_update_commit_outer;
|
COMMIT;
|
|
DO $$
|
DECLARE
|
logical_columns text[];
|
BEGIN
|
IF to_regclass('pg_temp.tmc_xact_update_commit') IS NULL THEN
|
RAISE EXCEPTION 'tmc_xact_update_commit is missing after nested commit';
|
END IF;
|
|
SELECT array_agg(keys.key ORDER BY keys.key)
|
INTO logical_columns
|
FROM pg_temp.tmc_xact_update_commit AS t
|
CROSS JOIN LATERAL
|
jsonb_object_keys(to_jsonb(t)) AS keys(key);
|
|
IF logical_columns IS DISTINCT FROM ARRAY['a_inner', 'keep']::text[] THEN
|
RAISE EXCEPTION 'unexpected nested commit logical columns: %',
|
logical_columns;
|
END IF;
|
END;
|
$$;
|
|
SELECT a_inner, keep
|
FROM pg_temp.tmc_xact_update_commit;
|
|
DROP TABLE pg_temp.tmc_xact_update_commit;
|
|
SET enable_temp_memory_catalog = on;
|
CREATE TEMP TABLE tmc_xact_drop_rb(id integer, payload integer);
|
INSERT INTO pg_temp.tmc_xact_drop_rb VALUES (3, 303);
|
SET enable_temp_memory_catalog = off;
|
|
BEGIN;
|
SAVEPOINT tmc_xact_drop_outer;
|
SAVEPOINT tmc_xact_drop_inner;
|
DROP TABLE pg_temp.tmc_xact_drop_rb;
|
RELEASE SAVEPOINT tmc_xact_drop_inner;
|
SELECT to_regclass('pg_temp.tmc_xact_drop_rb') IS NULL AS drop_rb_missing_inside;
|
ROLLBACK TO SAVEPOINT tmc_xact_drop_outer;
|
RELEASE SAVEPOINT tmc_xact_drop_outer;
|
COMMIT;
|
|
SELECT id, payload
|
FROM pg_temp.tmc_xact_drop_rb;
|
|
DROP TABLE pg_temp.tmc_xact_drop_rb;
|
|
SET enable_temp_memory_catalog = on;
|
|
BEGIN;
|
SAVEPOINT tmc_xact_create_drop_s;
|
CREATE TEMP TABLE tmc_xact_create_drop(id integer, payload integer);
|
INSERT INTO pg_temp.tmc_xact_create_drop VALUES (4, 404);
|
DROP TABLE pg_temp.tmc_xact_create_drop;
|
ROLLBACK TO SAVEPOINT tmc_xact_create_drop_s;
|
RELEASE SAVEPOINT tmc_xact_create_drop_s;
|
COMMIT;
|
|
SELECT to_regclass('pg_temp.tmc_xact_create_drop') IS NULL AS create_drop_missing;
|
|
SET enable_temp_memory_catalog = on;
|
CREATE TEMP TABLE tmc_xact_top_update(
|
original integer,
|
keep integer
|
);
|
INSERT INTO pg_temp.tmc_xact_top_update VALUES (5, 505);
|
SET enable_temp_memory_catalog = off;
|
|
BEGIN;
|
ALTER TABLE pg_temp.tmc_xact_top_update
|
RENAME COLUMN original TO temporary_name;
|
ROLLBACK;
|
|
SELECT original, keep
|
FROM pg_temp.tmc_xact_top_update;
|
|
DROP TABLE pg_temp.tmc_xact_top_update;
|
|
SET enable_temp_memory_catalog = on;
|
CREATE TEMP TABLE tmc_xact_top_drop(id integer, payload integer);
|
INSERT INTO pg_temp.tmc_xact_top_drop VALUES (6, 606);
|
SET enable_temp_memory_catalog = off;
|
|
BEGIN;
|
DROP TABLE pg_temp.tmc_xact_top_drop;
|
ROLLBACK;
|
|
SELECT id, payload
|
FROM pg_temp.tmc_xact_top_drop;
|
|
DROP TABLE pg_temp.tmc_xact_top_drop;
|
|
SET enable_temp_memory_catalog = on;
|
|
DO $$
|
DECLARE
|
aborted_oid oid;
|
class_rows bigint;
|
attr_rows bigint;
|
type_rows bigint;
|
BEGIN
|
BEGIN
|
EXECUTE 'CREATE TEMP TABLE tmc_xact_pl_create(id integer, payload integer)';
|
EXECUTE 'INSERT INTO pg_temp.tmc_xact_pl_create VALUES (7, 707)';
|
aborted_oid := to_regclass('pg_temp.tmc_xact_pl_create');
|
|
IF aborted_oid IS NULL THEN
|
RAISE EXCEPTION 'tmc_xact_pl_create is missing before forced rollback';
|
END IF;
|
|
RAISE EXCEPTION USING ERRCODE = 'P9001', MESSAGE = 'forced rollback';
|
EXCEPTION
|
WHEN SQLSTATE 'P9001' THEN
|
NULL;
|
END;
|
|
IF to_regclass('pg_temp.tmc_xact_pl_create') IS NOT NULL THEN
|
RAISE EXCEPTION 'tmc_xact_pl_create survived handled exception';
|
END IF;
|
|
SELECT count(*) INTO class_rows
|
FROM pg_catalog.pg_class
|
WHERE oid = aborted_oid;
|
|
SELECT count(*) INTO attr_rows
|
FROM pg_catalog.pg_attribute
|
WHERE attrelid = aborted_oid;
|
|
SELECT count(*) INTO type_rows
|
FROM pg_catalog.pg_type
|
WHERE typrelid = aborted_oid;
|
|
IF class_rows <> 0 OR attr_rows <> 0 OR type_rows <> 0 THEN
|
RAISE EXCEPTION 'aborted CREATE left physical catalog rows: class %, attr %, type %',
|
class_rows, attr_rows, type_rows;
|
END IF;
|
END;
|
$$;
|
|
DO $$
|
DECLARE
|
i integer;
|
BEGIN
|
FOR i IN 1..20 LOOP
|
BEGIN
|
BEGIN
|
EXECUTE 'CREATE TEMP TABLE tmc_xact_pl_stress(id integer)';
|
EXECUTE format('INSERT INTO pg_temp.tmc_xact_pl_stress VALUES (%s)', i);
|
RAISE EXCEPTION USING ERRCODE = 'P9001', MESSAGE = 'forced rollback';
|
EXCEPTION
|
WHEN SQLSTATE 'P9001' THEN
|
NULL;
|
END;
|
|
IF to_regclass('pg_temp.tmc_xact_pl_stress') IS NOT NULL THEN
|
RAISE EXCEPTION 'tmc_xact_pl_stress survived iteration %', i;
|
END IF;
|
END;
|
END LOOP;
|
END;
|
$$;
|
|
SET enable_temp_memory_catalog = on;
|
CREATE TEMP TABLE tmc_xact_update_stress(
|
value integer,
|
keep integer
|
);
|
INSERT INTO pg_temp.tmc_xact_update_stress VALUES (8, 808);
|
SET enable_temp_memory_catalog = off;
|
|
DO $$
|
DECLARE
|
i integer;
|
observed_value integer;
|
observed_keep integer;
|
BEGIN
|
FOR i IN 1..20 LOOP
|
BEGIN
|
BEGIN
|
EXECUTE 'ALTER TABLE pg_temp.tmc_xact_update_stress RENAME COLUMN value TO value_tmp';
|
RAISE EXCEPTION USING ERRCODE = 'P9001', MESSAGE = 'forced rollback';
|
EXCEPTION
|
WHEN SQLSTATE 'P9001' THEN
|
NULL;
|
END;
|
|
SELECT value, keep
|
INTO observed_value, observed_keep
|
FROM pg_temp.tmc_xact_update_stress;
|
|
IF observed_value <> 8 OR observed_keep <> 808 THEN
|
RAISE EXCEPTION 'unexpected update stress row after iteration %: value %, keep %',
|
i, observed_value, observed_keep;
|
END IF;
|
END;
|
END LOOP;
|
END;
|
$$;
|
|
SELECT value, keep
|
FROM pg_temp.tmc_xact_update_stress;
|
|
DROP TABLE pg_temp.tmc_xact_update_stress;
|
|
SET enable_temp_memory_catalog = on;
|
CREATE TEMP TABLE tmc_xact_drop_stress(id integer, payload integer);
|
INSERT INTO pg_temp.tmc_xact_drop_stress VALUES (9, 909);
|
SET enable_temp_memory_catalog = off;
|
|
DO $$
|
DECLARE
|
i integer;
|
observed_count integer;
|
observed_payload integer;
|
BEGIN
|
FOR i IN 1..10 LOOP
|
BEGIN
|
BEGIN
|
EXECUTE 'DROP TABLE pg_temp.tmc_xact_drop_stress';
|
RAISE EXCEPTION USING ERRCODE = 'P9001', MESSAGE = 'forced rollback';
|
EXCEPTION
|
WHEN SQLSTATE 'P9001' THEN
|
NULL;
|
END;
|
|
SELECT count(*), sum(payload)::integer
|
INTO observed_count, observed_payload
|
FROM pg_temp.tmc_xact_drop_stress;
|
|
IF observed_count <> 1 OR observed_payload <> 909 THEN
|
RAISE EXCEPTION 'unexpected drop stress state after iteration %: count %, payload %',
|
i, observed_count, observed_payload;
|
END IF;
|
END;
|
END LOOP;
|
END;
|
$$;
|
|
SELECT id, payload
|
FROM pg_temp.tmc_xact_drop_stress;
|
|
DROP TABLE pg_temp.tmc_xact_drop_stress;
|
|
SET enable_temp_memory_catalog = on;
|
CREATE TEMP TABLE tmc_xact_inplace(id integer, payload integer);
|
INSERT INTO pg_temp.tmc_xact_inplace
|
SELECT g, g * 10
|
FROM generate_series(1, 32) AS g;
|
SET enable_temp_memory_catalog = off;
|
|
DO $$
|
BEGIN
|
BEGIN
|
EXECUTE 'ANALYZE pg_temp.tmc_xact_inplace';
|
RAISE EXCEPTION USING ERRCODE = 'P9001', MESSAGE = 'forced rollback';
|
EXCEPTION
|
WHEN SQLSTATE 'P9001' THEN
|
NULL;
|
END;
|
END;
|
$$;
|
|
ALTER TABLE pg_temp.tmc_xact_inplace
|
RENAME TO tmc_xact_inplace_renamed;
|
|
DO $$
|
DECLARE
|
plan json;
|
BEGIN
|
EXECUTE 'EXPLAIN (FORMAT JSON) SELECT * FROM pg_temp.tmc_xact_inplace_renamed'
|
INTO plan;
|
|
IF (plan->0->'Plan'->>'Plan Rows')::integer <> 32 THEN
|
RAISE EXCEPTION 'unexpected inplace rollback plan rows: got %, expected 32',
|
plan->0->'Plan'->>'Plan Rows';
|
END IF;
|
END;
|
$$;
|
|
DROP TABLE pg_temp.tmc_xact_inplace_renamed;
|
|
SET enable_temp_memory_catalog = on;
|
|
BEGIN;
|
CREATE TEMP TABLE tmc_xact_on_commit_drop(
|
id integer,
|
payload integer
|
) ON COMMIT DROP;
|
INSERT INTO pg_temp.tmc_xact_on_commit_drop VALUES (10, 1000);
|
COMMIT;
|
|
SELECT to_regclass('pg_temp.tmc_xact_on_commit_drop') IS NULL AS on_commit_drop_missing;
|
|
BEGIN;
|
CREATE TEMP TABLE tmc_xact_on_commit_delete(
|
id integer,
|
payload integer
|
) ON COMMIT DELETE ROWS;
|
INSERT INTO pg_temp.tmc_xact_on_commit_delete VALUES (1, 10), (2, 20), (3, 30);
|
COMMIT;
|
|
SELECT count(*) AS on_commit_delete_count
|
FROM pg_temp.tmc_xact_on_commit_delete;
|
|
DO $$
|
DECLARE
|
rel_oid oid;
|
class_rows bigint;
|
attr_rows bigint;
|
BEGIN
|
rel_oid := to_regclass('pg_temp.tmc_xact_on_commit_delete');
|
IF rel_oid IS NULL THEN
|
RAISE EXCEPTION 'tmc_xact_on_commit_delete is missing after commit';
|
END IF;
|
|
SELECT count(*) INTO class_rows
|
FROM pg_catalog.pg_class
|
WHERE oid = rel_oid;
|
|
SELECT count(*) INTO attr_rows
|
FROM pg_catalog.pg_attribute
|
WHERE attrelid = rel_oid
|
AND attnum > 0
|
AND NOT attisdropped;
|
|
IF class_rows <> 0 OR attr_rows <> 0 THEN
|
RAISE EXCEPTION 'unexpected physical catalog rows for surviving memory table: class %, attr %',
|
class_rows, attr_rows;
|
END IF;
|
END;
|
$$;
|
|
DROP TABLE pg_temp.tmc_xact_on_commit_delete;
|
|
DO $$
|
DECLARE
|
relname text;
|
BEGIN
|
FOREACH relname IN ARRAY ARRAY[
|
'tmc_xact_sp_table',
|
'tmc_xact_create_rb',
|
'tmc_xact_create_commit',
|
'tmc_xact_update',
|
'tmc_xact_update_commit',
|
'tmc_xact_drop_rb',
|
'tmc_xact_create_drop',
|
'tmc_xact_top_update',
|
'tmc_xact_top_drop',
|
'tmc_xact_pl_create',
|
'tmc_xact_pl_stress',
|
'tmc_xact_update_stress',
|
'tmc_xact_drop_stress',
|
'tmc_xact_inplace',
|
'tmc_xact_inplace_renamed',
|
'tmc_xact_on_commit_drop',
|
'tmc_xact_on_commit_delete'
|
] LOOP
|
IF to_regclass(format('pg_temp.%s', relname)) IS NOT NULL THEN
|
RAISE EXCEPTION 'leftover temp relation: %', relname;
|
END IF;
|
END LOOP;
|
END;
|
$$;
|
|
RESET enable_temp_memory_catalog;
|