--
|
-- one_c_temp_rd
|
--
|
|
SET client_min_messages = warning;
|
|
DROP SCHEMA IF EXISTS one_c_temp_rd CASCADE;
|
CREATE SCHEMA one_c_temp_rd;
|
SET search_path = one_c_temp_rd, public;
|
|
SET temp_buffers = 100;
|
|
DO $$
|
BEGIN
|
IF current_setting('enable_temp_rd_buffers') <> 'off' THEN
|
RAISE EXCEPTION 'unexpected default enable_temp_rd_buffers: %',
|
current_setting('enable_temp_rd_buffers');
|
END IF;
|
END;
|
$$;
|
|
SET enable_temp_rd_buffers = off;
|
|
CREATE TEMP TABLE rd_off(id integer, payload text);
|
ALTER TABLE pg_temp.rd_off ALTER COLUMN payload SET STORAGE PLAIN;
|
|
INSERT INTO pg_temp.rd_off
|
SELECT g, repeat(md5(g::text), 32)
|
FROM generate_series(1, 100) AS g;
|
|
DO $$
|
DECLARE
|
rowcount bigint;
|
BEGIN
|
SELECT count(*) INTO rowcount FROM pg_temp.rd_off;
|
IF rowcount <> 100 THEN
|
RAISE EXCEPTION 'unexpected rd_off rowcount: got %, expected 100',
|
rowcount;
|
END IF;
|
|
IF pg_relation_size('pg_temp.rd_off') <= 32768 THEN
|
RAISE EXCEPTION 'rd_off relation size did not exceed 32768 bytes';
|
END IF;
|
|
IF (pg_stat_file(pg_relation_filepath('pg_temp.rd_off'), true)).size IS NULL THEN
|
RAISE EXCEPTION 'rd_off physical relation file is absent';
|
END IF;
|
END;
|
$$;
|
|
DROP TABLE pg_temp.rd_off;
|
|
SET enable_temp_rd_buffers = on;
|
|
CREATE TEMP TABLE rd_small(id integer, payload text);
|
ALTER TABLE pg_temp.rd_small ALTER COLUMN payload SET STORAGE PLAIN;
|
|
INSERT INTO pg_temp.rd_small
|
SELECT g, md5(g::text)
|
FROM generate_series(1, 20) AS g;
|
|
DO $$
|
DECLARE
|
rowcount bigint;
|
BEGIN
|
SELECT count(*) INTO rowcount FROM pg_temp.rd_small;
|
IF rowcount <> 20 THEN
|
RAISE EXCEPTION 'unexpected rd_small rowcount: got %, expected 20',
|
rowcount;
|
END IF;
|
|
IF pg_relation_size('pg_temp.rd_small') <> 0 THEN
|
RAISE EXCEPTION 'rd_small relation size is not zero: %',
|
pg_relation_size('pg_temp.rd_small');
|
END IF;
|
|
IF (pg_stat_file(pg_relation_filepath('pg_temp.rd_small'), true)).size IS NOT NULL THEN
|
RAISE EXCEPTION 'rd_small physical relation file exists';
|
END IF;
|
END;
|
$$;
|
|
CREATE TEMP TABLE rd_guc_flip(id integer, payload text);
|
ALTER TABLE pg_temp.rd_guc_flip ALTER COLUMN payload SET STORAGE PLAIN;
|
|
INSERT INTO pg_temp.rd_guc_flip
|
VALUES (1, md5('1'));
|
|
SET enable_temp_rd_buffers = off;
|
|
ALTER TABLE pg_temp.rd_guc_flip
|
RENAME TO rd_guc_flip_reopen;
|
|
INSERT INTO pg_temp.rd_guc_flip_reopen
|
SELECT g, md5(g::text)
|
FROM generate_series(2, 20) AS g;
|
|
DO $$
|
DECLARE
|
rowcount bigint;
|
path_size bigint;
|
BEGIN
|
SELECT count(*) INTO rowcount FROM pg_temp.rd_guc_flip_reopen;
|
IF rowcount <> 20 THEN
|
RAISE EXCEPTION 'unexpected rd_guc_flip_reopen rowcount: got %, expected 20',
|
rowcount;
|
END IF;
|
|
IF pg_relation_size('pg_temp.rd_guc_flip_reopen') <> 0 THEN
|
RAISE EXCEPTION 'rd_guc_flip_reopen relation size is not zero: %',
|
pg_relation_size('pg_temp.rd_guc_flip_reopen');
|
END IF;
|
|
SELECT (pg_stat_file(pg_relation_filepath('pg_temp.rd_guc_flip_reopen'), true)).size
|
INTO path_size;
|
IF path_size IS NOT NULL THEN
|
RAISE EXCEPTION 'rd_guc_flip_reopen physical relation file exists: %',
|
path_size;
|
END IF;
|
END;
|
$$;
|
|
DROP TABLE pg_temp.rd_guc_flip_reopen;
|
|
SET enable_temp_rd_buffers = on;
|
|
CREATE TABLE one_c_temp_rd.persistent_small(id integer, payload text);
|
ALTER TABLE one_c_temp_rd.persistent_small ALTER COLUMN payload SET STORAGE PLAIN;
|
|
INSERT INTO one_c_temp_rd.persistent_small
|
SELECT g, md5(g::text)
|
FROM generate_series(1, 5) AS g;
|
|
DO $$
|
DECLARE
|
rowcount bigint;
|
BEGIN
|
SELECT count(*) INTO rowcount FROM one_c_temp_rd.persistent_small;
|
IF rowcount <> 5 THEN
|
RAISE EXCEPTION 'unexpected persistent_small rowcount: got %, expected 5',
|
rowcount;
|
END IF;
|
|
IF (pg_stat_file(pg_relation_filepath('one_c_temp_rd.persistent_small'), true)).size IS NULL THEN
|
RAISE EXCEPTION 'persistent_small physical relation file is absent';
|
END IF;
|
END;
|
$$;
|
|
DROP TABLE one_c_temp_rd.persistent_small;
|
|
CREATE TEMP TABLE rd_aio(id integer, payload text);
|
ALTER TABLE pg_temp.rd_aio ALTER COLUMN payload SET STORAGE PLAIN;
|
|
INSERT INTO pg_temp.rd_aio
|
SELECT g, repeat('a', 300)
|
FROM generate_series(1, 60) AS g;
|
|
DO $$
|
BEGIN
|
IF pg_relation_size('pg_temp.rd_aio') <> 0 THEN
|
RAISE EXCEPTION 'rd_aio relation size is not zero before pressure: %',
|
pg_relation_size('pg_temp.rd_aio');
|
END IF;
|
|
IF (pg_stat_file(pg_relation_filepath('pg_temp.rd_aio'), true)).size IS NOT NULL THEN
|
RAISE EXCEPTION 'rd_aio physical relation file exists before pressure';
|
END IF;
|
END;
|
$$;
|
|
CREATE TEMP TABLE rd_pressure(id integer, payload text);
|
ALTER TABLE pg_temp.rd_pressure ALTER COLUMN payload SET STORAGE PLAIN;
|
|
INSERT INTO pg_temp.rd_pressure
|
SELECT g, repeat('p', 1000)
|
FROM generate_series(1, 6000) AS g;
|
|
DO $$
|
DECLARE
|
rowcount bigint;
|
plan_doc jsonb;
|
local_read_blocks integer;
|
BEGIN
|
SELECT count(*) INTO rowcount FROM pg_temp.rd_pressure;
|
IF rowcount <> 6000 THEN
|
RAISE EXCEPTION 'unexpected rd_pressure rowcount: got %, expected 6000',
|
rowcount;
|
END IF;
|
|
IF (pg_stat_file(pg_relation_filepath('pg_temp.rd_pressure'), true)).size IS NULL THEN
|
RAISE EXCEPTION 'rd_pressure physical relation file is absent';
|
END IF;
|
|
EXECUTE $sql$
|
EXPLAIN (
|
ANALYZE,
|
BUFFERS,
|
COSTS OFF,
|
TIMING OFF,
|
SUMMARY OFF,
|
FORMAT JSON
|
)
|
SELECT count(*) FROM pg_temp.rd_aio
|
$sql$
|
INTO plan_doc;
|
|
local_read_blocks :=
|
COALESCE((plan_doc -> 0 -> 'Plan' ->> 'Local Read Blocks')::integer, 0);
|
|
IF local_read_blocks <= 0 THEN
|
RAISE EXCEPTION 'rd_aio Local Read Blocks not observed: %',
|
local_read_blocks;
|
END IF;
|
|
SELECT count(*) INTO rowcount FROM pg_temp.rd_aio;
|
IF rowcount <> 60 THEN
|
RAISE EXCEPTION 'unexpected rd_aio rowcount: got %, expected 60',
|
rowcount;
|
END IF;
|
|
IF (pg_stat_file(pg_relation_filepath('pg_temp.rd_aio'), true)).size IS NOT NULL THEN
|
RAISE EXCEPTION 'rd_aio physical relation file exists after pressure';
|
END IF;
|
END;
|
$$;
|
|
INSERT INTO pg_temp.rd_small
|
SELECT g,
|
md5(g::text) || repeat('0123456789abcdef', 60)
|
FROM generate_series(21, 120) AS g;
|
|
DO $$
|
DECLARE
|
rowcount bigint;
|
BEGIN
|
SELECT count(*) INTO rowcount FROM pg_temp.rd_small;
|
IF rowcount <> 120 THEN
|
RAISE EXCEPTION 'unexpected rd_small rowcount after overflow: got %, expected 120',
|
rowcount;
|
END IF;
|
|
IF pg_relation_size('pg_temp.rd_small') <= 32768 THEN
|
RAISE EXCEPTION 'rd_small relation size did not exceed 32768 bytes after overflow';
|
END IF;
|
|
IF (pg_stat_file(pg_relation_filepath('pg_temp.rd_small'), true)).size IS NULL THEN
|
RAISE EXCEPTION 'rd_small physical relation file is absent after overflow';
|
END IF;
|
END;
|
$$;
|
|
TRUNCATE pg_temp.rd_small;
|
|
DO $$
|
DECLARE
|
rowcount bigint;
|
BEGIN
|
SELECT count(*) INTO rowcount FROM pg_temp.rd_small;
|
IF rowcount <> 0 THEN
|
RAISE EXCEPTION 'unexpected rd_small rowcount after truncate: got %, expected 0',
|
rowcount;
|
END IF;
|
|
IF pg_relation_size('pg_temp.rd_small') <> 0 THEN
|
RAISE EXCEPTION 'rd_small relation size is not zero after truncate: %',
|
pg_relation_size('pg_temp.rd_small');
|
END IF;
|
|
IF (pg_stat_file(pg_relation_filepath('pg_temp.rd_small'), true)).size IS NOT NULL THEN
|
RAISE EXCEPTION 'rd_small physical relation file exists after truncate';
|
END IF;
|
END;
|
$$;
|
|
INSERT INTO pg_temp.rd_small
|
SELECT g, md5(g::text)
|
FROM generate_series(1, 20) AS g;
|
|
DO $$
|
DECLARE
|
rowcount bigint;
|
BEGIN
|
SELECT count(*) INTO rowcount FROM pg_temp.rd_small;
|
IF rowcount <> 20 THEN
|
RAISE EXCEPTION 'unexpected rd_small rowcount after reset: got %, expected 20',
|
rowcount;
|
END IF;
|
|
IF pg_relation_size('pg_temp.rd_small') <> 0 THEN
|
RAISE EXCEPTION 'rd_small relation size is not zero after reset: %',
|
pg_relation_size('pg_temp.rd_small');
|
END IF;
|
|
IF (pg_stat_file(pg_relation_filepath('pg_temp.rd_small'), true)).size IS NOT NULL THEN
|
RAISE EXCEPTION 'rd_small physical relation file exists after reset';
|
END IF;
|
END;
|
$$;
|
|
DROP TABLE pg_temp.rd_small;
|
|
BEGIN;
|
|
CREATE TEMP TABLE rd_inplace(id integer, payload text);
|
ALTER TABLE pg_temp.rd_inplace ALTER COLUMN payload SET STORAGE PLAIN;
|
|
INSERT INTO pg_temp.rd_inplace
|
SELECT g, repeat(md5(g::text), 32)
|
FROM generate_series(1, 120) AS g;
|
|
DO $$
|
DECLARE
|
rowcount bigint;
|
BEGIN
|
SELECT count(*) INTO rowcount FROM pg_temp.rd_inplace;
|
IF rowcount <> 120 THEN
|
RAISE EXCEPTION 'unexpected rd_inplace rowcount before truncate: got %, expected 120',
|
rowcount;
|
END IF;
|
|
IF pg_relation_size('pg_temp.rd_inplace') <= 32768 THEN
|
RAISE EXCEPTION 'rd_inplace relation size did not exceed 32768 bytes before truncate';
|
END IF;
|
|
IF (pg_stat_file(pg_relation_filepath('pg_temp.rd_inplace'), true)).size IS NULL THEN
|
RAISE EXCEPTION 'rd_inplace physical relation file is absent before truncate';
|
END IF;
|
END;
|
$$;
|
|
TRUNCATE pg_temp.rd_inplace;
|
|
DO $$
|
DECLARE
|
rowcount bigint;
|
BEGIN
|
SELECT count(*) INTO rowcount FROM pg_temp.rd_inplace;
|
IF rowcount <> 0 THEN
|
RAISE EXCEPTION 'unexpected rd_inplace rowcount after truncate: got %, expected 0',
|
rowcount;
|
END IF;
|
|
IF pg_relation_size('pg_temp.rd_inplace') <> 0 THEN
|
RAISE EXCEPTION 'rd_inplace relation size is not zero after truncate: %',
|
pg_relation_size('pg_temp.rd_inplace');
|
END IF;
|
|
IF (pg_stat_file(pg_relation_filepath('pg_temp.rd_inplace'), true)).size IS NOT NULL THEN
|
RAISE EXCEPTION 'rd_inplace physical relation file exists after truncate';
|
END IF;
|
END;
|
$$;
|
|
INSERT INTO pg_temp.rd_inplace
|
SELECT g, md5(g::text)
|
FROM generate_series(1, 20) AS g;
|
|
DO $$
|
DECLARE
|
rowcount bigint;
|
BEGIN
|
SELECT count(*) INTO rowcount FROM pg_temp.rd_inplace;
|
IF rowcount <> 20 THEN
|
RAISE EXCEPTION 'unexpected rd_inplace rowcount after refill: got %, expected 20',
|
rowcount;
|
END IF;
|
|
IF pg_relation_size('pg_temp.rd_inplace') <> 0 THEN
|
RAISE EXCEPTION 'rd_inplace relation size is not zero after refill: %',
|
pg_relation_size('pg_temp.rd_inplace');
|
END IF;
|
|
IF (pg_stat_file(pg_relation_filepath('pg_temp.rd_inplace'), true)).size IS NOT NULL THEN
|
RAISE EXCEPTION 'rd_inplace physical relation file exists after refill';
|
END IF;
|
END;
|
$$;
|
|
DROP TABLE pg_temp.rd_inplace;
|
|
COMMIT;
|
|
DROP TABLE pg_temp.rd_aio;
|
DROP TABLE pg_temp.rd_pressure;
|
|
RESET enable_temp_rd_buffers;
|
RESET search_path;
|
|
DROP SCHEMA one_c_temp_rd CASCADE;
|