5 SET client_min_messages = 'error';
6 CREATE EXTENSION IF NOT EXISTS pg_store_plans;
7 DROP TABLE IF EXISTS plans;
8 CREATE TABLE PLANS (id int, title text, plan text, inflated text);
9 SET client_min_messages = 'notice';
10 INSERT INTO PLANS (VALUES
18 next if (!/^###### (Plan ([0-9]+):.*$)/);
19 $title = $1; $plan_no = $2;
25 print "-- ###### $title\n";
27 } elsif ($state == 1) {
31 next if (!/^ *({[^ ].*})$/);
34 if ($plan =~ /'/ || $plan =~ /\\\"/) {
38 # Add escape char for '''
40 # Add escape char for '\"'
41 $plan =~ s/\\\"/\\\\\"/g;
43 print "($plan_no, \'$title\',\n";
44 print " $escape'$plan')";
51 UPDATE plans SET inflated = pg_store_plans_jsonplan(plan);
53 \echo ###### format conversion tests
54 SELECT '### '||'inflate-short '||title||E'\n'||
56 FROM plans WHERE id BETWEEN 1 AND 3 ORDER BY id;
57 SELECT '### '||'yaml-short '||title||E'\n'||
58 pg_store_plans_yamlplan(plan)
59 FROM plans WHERE id BETWEEN 4 AND 6 or id = 1 ORDER BY id;
60 SELECT '### '||'xml-short '||title||E'\n'||
61 pg_store_plans_xmlplan(plan)
62 FROM plans WHERE id BETWEEN 7 AND 9 or id = 1 ORDER BY id;
64 \echo ###### text format output test
65 SELECT '### '||'TEXT-short '||title||E'\n'||
66 pg_store_plans_textplan(plan)
67 FROM plans ORDER BY id;
69 \echo ###### long-json-as-a-source test
70 SELECT '### '||'inflate-long JSON'||title||E'\n'||
71 pg_store_plans_jsonplan(inflated)
72 FROM plans WHERE id BETWEEN 1 AND 3 ORDER BY id;
73 SELECT '### '||'yaml-long JSON '||title||E'\n'||
74 pg_store_plans_yamlplan(inflated)
75 FROM plans WHERE id BETWEEN 4 AND 6 ORDER BY id;
76 SELECT '### '||'xml-long JSON '||title||E'\n'||
77 pg_store_plans_xmlplan(inflated)
78 FROM plans WHERE id BETWEEN 7 AND 9 ORDER BY id;
79 SELECT '### '||'text-long JSON '||title||E'\n'||
80 pg_store_plans_xmlplan(inflated)
81 FROM plans WHERE id BETWEEN 10 AND 12 ORDER BY id;
83 \echo ###### chopped-source test
84 SELECT '### '||'inflate-chopped '||title||E'\n'||
85 pg_store_plans_jsonplan(substring(plan from 1 for char_length(plan) / 3))
86 FROM plans WHERE id BETWEEN 13 AND 15 ORDER BY id;
87 SELECT '### '||'yaml-chopped '||title||E'\n'||
88 pg_store_plans_yamlplan(substring(plan from 1 for char_length(plan) / 3))
89 FROM plans WHERE id BETWEEN 16 AND 18 ORDER BY id;
90 SELECT '### '||'xml-chopped '||title||E'\n'||
91 pg_store_plans_xmlplan(substring(plan from 1 for char_length(plan) / 3))
92 FROM plans WHERE id BETWEEN 19 AND 21 ORDER BY id;
93 SELECT '### '||'text-chopped '||title||E'\n'||
94 pg_store_plans_textplan(substring(plan from 1 for char_length(plan) / 3))
95 FROM plans WHERE id BETWEEN 22 AND 24 ORDER BY id;
97 \echo ###### shorten, normalize test
98 SELECT '### '||'shorten '||title||E'\n'||
99 pg_store_plans_shorten(inflated)
100 FROM plans WHERE id BETWEEN 1 AND 3 ORDER BY id;
101 SELECT '### '||'normalize '||title||E'\n'||
102 pg_store_plans_shorten(inflated)
103 FROM plans WHERE id BETWEEN 1 AND 3 ORDER BY id;
105 \echo ###### round-trip test
106 SELECT COUNT(*), SUM(success)
108 WHEN pg_store_plans_shorten(inflated) = plan THEN 1 ELSE 0