summaryrefslogtreecommitdiffstats
path: root/src/test/regress/sql/hs_primary_extremes.sql
blob: 2051e2e5cf252123f93fcc192d311db8550252ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
--
-- Hot Standby tests
--
-- hs_primary_extremes.sql
--

drop table if exists hs_extreme;
create table hs_extreme (col1 integer);

CREATE OR REPLACE FUNCTION hs_subxids (n integer)
RETURNS void
LANGUAGE plpgsql
AS $$
    BEGIN
      IF n <= 0 THEN RETURN; END IF;
      INSERT INTO hs_extreme VALUES (n);
      PERFORM hs_subxids(n - 1);
      RETURN;
    EXCEPTION WHEN raise_exception THEN NULL; END;
$$;

BEGIN;
SELECT hs_subxids(257);
ROLLBACK;
BEGIN;
SELECT hs_subxids(257);
COMMIT;

set client_min_messages = 'warning';

CREATE OR REPLACE FUNCTION hs_locks_create (n integer)
RETURNS void
LANGUAGE plpgsql
AS $$
    BEGIN
      IF n <= 0 THEN
		CHECKPOINT;
		RETURN;
	  END IF;
      EXECUTE 'CREATE TABLE hs_locks_' || n::text || ' ()';
      PERFORM hs_locks_create(n - 1);
      RETURN;
    EXCEPTION WHEN raise_exception THEN NULL; END;
$$;

CREATE OR REPLACE FUNCTION hs_locks_drop (n integer)
RETURNS void
LANGUAGE plpgsql
AS $$
    BEGIN
      IF n <= 0 THEN
		CHECKPOINT;
		RETURN;
	  END IF;
	  EXECUTE 'DROP TABLE IF EXISTS hs_locks_' || n::text;
      PERFORM hs_locks_drop(n - 1);
      RETURN;
    EXCEPTION WHEN raise_exception THEN NULL; END;
$$;

BEGIN;
SELECT hs_locks_drop(257);
SELECT hs_locks_create(257);
SELECT count(*) > 257 FROM pg_locks;
ROLLBACK;
BEGIN;
SELECT hs_locks_drop(257);
SELECT hs_locks_create(257);
SELECT count(*) > 257 FROM pg_locks;
COMMIT;
SELECT hs_locks_drop(257);

SELECT pg_switch_wal();