OSDN Git Service

d8318d2df0a5222977c54b81ead29eacb9f44234
[pgdbmsstats/pg_dbms_stats.git] / expected / ut-11.out
1 \pset null '(null)'
2 /*
3  * No.2-1 table definitions.
4  */
5 -- No.2-1-1
6 \d dbms_stats.backup_history
7                                          Table "dbms_stats.backup_history"
8  Column  |           Type           | Collation | Nullable |                        Default                        
9 ---------+--------------------------+-----------+----------+-------------------------------------------------------
10  id      | bigint                   |           | not null | nextval('dbms_stats.backup_history_id_seq'::regclass)
11  time    | timestamp with time zone |           | not null | 
12  unit    | character(1)             |           | not null | 
13  comment | text                     |           |          | 
14 Indexes:
15     "backup_history_pkey" PRIMARY KEY, btree (id)
16 Referenced by:
17     TABLE "dbms_stats.column_stats_backup" CONSTRAINT "column_stats_backup_id_fkey" FOREIGN KEY (id) REFERENCES dbms_stats.backup_history(id) ON DELETE CASCADE
18     TABLE "dbms_stats.relation_stats_backup" CONSTRAINT "relation_stats_backup_id_fkey" FOREIGN KEY (id) REFERENCES dbms_stats.backup_history(id) ON DELETE CASCADE
19
20 -- No.2-1-2
21 \d dbms_stats.column_stats_backup
22                Table "dbms_stats.column_stats_backup"
23    Column    |        Type         | Collation | Nullable | Default 
24 -------------+---------------------+-----------+----------+---------
25  id          | bigint              |           | not null | 
26  statypid    | oid                 |           | not null | 
27  starelid    | oid                 |           | not null | 
28  staattnum   | smallint            |           | not null | 
29  stainherit  | boolean             |           | not null | 
30  stanullfrac | real                |           | not null | 
31  stawidth    | integer             |           | not null | 
32  stadistinct | real                |           | not null | 
33  stakind1    | smallint            |           | not null | 
34  stakind2    | smallint            |           | not null | 
35  stakind3    | smallint            |           | not null | 
36  stakind4    | smallint            |           | not null | 
37  stakind5    | smallint            |           | not null | 
38  staop1      | oid                 |           | not null | 
39  staop2      | oid                 |           | not null | 
40  staop3      | oid                 |           | not null | 
41  staop4      | oid                 |           | not null | 
42  staop5      | oid                 |           | not null | 
43  stanumbers1 | real[]              |           |          | 
44  stanumbers2 | real[]              |           |          | 
45  stanumbers3 | real[]              |           |          | 
46  stanumbers4 | real[]              |           |          | 
47  stanumbers5 | real[]              |           |          | 
48  stavalues1  | dbms_stats.anyarray |           |          | 
49  stavalues2  | dbms_stats.anyarray |           |          | 
50  stavalues3  | dbms_stats.anyarray |           |          | 
51  stavalues4  | dbms_stats.anyarray |           |          | 
52  stavalues5  | dbms_stats.anyarray |           |          | 
53 Indexes:
54     "column_stats_backup_pkey" PRIMARY KEY, btree (id, starelid, staattnum, stainherit)
55 Foreign-key constraints:
56     "column_stats_backup_id_fkey" FOREIGN KEY (id) REFERENCES dbms_stats.backup_history(id) ON DELETE CASCADE
57     "column_stats_backup_id_fkey1" FOREIGN KEY (id, starelid) REFERENCES dbms_stats.relation_stats_backup(id, relid) ON DELETE CASCADE
58
59 -- No.2-1-3
60 \d dbms_stats.column_stats_locked
61                Table "dbms_stats.column_stats_locked"
62    Column    |        Type         | Collation | Nullable | Default 
63 -------------+---------------------+-----------+----------+---------
64  starelid    | oid                 |           | not null | 
65  staattnum   | smallint            |           | not null | 
66  stainherit  | boolean             |           | not null | 
67  stanullfrac | real                |           |          | 
68  stawidth    | integer             |           |          | 
69  stadistinct | real                |           |          | 
70  stakind1    | smallint            |           |          | 
71  stakind2    | smallint            |           |          | 
72  stakind3    | smallint            |           |          | 
73  stakind4    | smallint            |           |          | 
74  stakind5    | smallint            |           |          | 
75  staop1      | oid                 |           |          | 
76  staop2      | oid                 |           |          | 
77  staop3      | oid                 |           |          | 
78  staop4      | oid                 |           |          | 
79  staop5      | oid                 |           |          | 
80  stanumbers1 | real[]              |           |          | 
81  stanumbers2 | real[]              |           |          | 
82  stanumbers3 | real[]              |           |          | 
83  stanumbers4 | real[]              |           |          | 
84  stanumbers5 | real[]              |           |          | 
85  stavalues1  | dbms_stats.anyarray |           |          | 
86  stavalues2  | dbms_stats.anyarray |           |          | 
87  stavalues3  | dbms_stats.anyarray |           |          | 
88  stavalues4  | dbms_stats.anyarray |           |          | 
89  stavalues5  | dbms_stats.anyarray |           |          | 
90 Indexes:
91     "column_stats_locked_pkey" PRIMARY KEY, btree (starelid, staattnum, stainherit)
92 Foreign-key constraints:
93     "column_stats_locked_starelid_fkey" FOREIGN KEY (starelid) REFERENCES dbms_stats.relation_stats_locked(relid) ON DELETE CASCADE
94 Triggers:
95     invalidate_column_cache BEFORE INSERT OR DELETE OR UPDATE ON dbms_stats.column_stats_locked FOR EACH ROW EXECUTE PROCEDURE dbms_stats.invalidate_column_cache()
96
97 -- No.2-1-4
98 \d dbms_stats.relation_stats_backup
99                    Table "dbms_stats.relation_stats_backup"
100       Column      |           Type           | Collation | Nullable | Default 
101 ------------------+--------------------------+-----------+----------+---------
102  id               | bigint                   |           | not null | 
103  relid            | oid                      |           | not null | 
104  relname          | text                     |           | not null | 
105  relpages         | integer                  |           | not null | 
106  reltuples        | real                     |           | not null | 
107  relallvisible    | integer                  |           | not null | 
108  curpages         | integer                  |           | not null | 
109  last_analyze     | timestamp with time zone |           |          | 
110  last_autoanalyze | timestamp with time zone |           |          | 
111 Indexes:
112     "relation_stats_backup_pkey" PRIMARY KEY, btree (id, relid)
113 Foreign-key constraints:
114     "relation_stats_backup_id_fkey" FOREIGN KEY (id) REFERENCES dbms_stats.backup_history(id) ON DELETE CASCADE
115 Referenced by:
116     TABLE "dbms_stats.column_stats_backup" CONSTRAINT "column_stats_backup_id_fkey1" FOREIGN KEY (id, starelid) REFERENCES dbms_stats.relation_stats_backup(id, relid) ON DELETE CASCADE
117
118 -- No.2-1-5
119 \d dbms_stats.relation_stats_locked
120                    Table "dbms_stats.relation_stats_locked"
121       Column      |           Type           | Collation | Nullable | Default 
122 ------------------+--------------------------+-----------+----------+---------
123  relid            | oid                      |           | not null | 
124  relname          | text                     |           | not null | 
125  relpages         | integer                  |           |          | 
126  reltuples        | real                     |           |          | 
127  relallvisible    | integer                  |           |          | 
128  curpages         | integer                  |           |          | 
129  last_analyze     | timestamp with time zone |           |          | 
130  last_autoanalyze | timestamp with time zone |           |          | 
131 Indexes:
132     "relation_stats_locked_pkey" PRIMARY KEY, btree (relid)
133 Referenced by:
134     TABLE "dbms_stats.column_stats_locked" CONSTRAINT "column_stats_locked_starelid_fkey" FOREIGN KEY (starelid) REFERENCES dbms_stats.relation_stats_locked(relid) ON DELETE CASCADE
135 Triggers:
136     invalidate_relation_cache BEFORE INSERT OR DELETE OR UPDATE ON dbms_stats.relation_stats_locked FOR EACH ROW EXECUTE PROCEDURE dbms_stats.invalidate_relation_cache()
137
138 /*
139  * No.2-2 view definitions.
140  */
141 -- No.2-2-1
142 \dS+ dbms_stats.column_stats_effective
143                           View "dbms_stats.column_stats_effective"
144    Column    |        Type         | Collation | Nullable | Default | Storage  | Description 
145 -------------+---------------------+-----------+----------+---------+----------+-------------
146  starelid    | oid                 |           |          |         | plain    | 
147  staattnum   | smallint            |           |          |         | plain    | 
148  stainherit  | boolean             |           |          |         | plain    | 
149  stanullfrac | real                |           |          |         | plain    | 
150  stawidth    | integer             |           |          |         | plain    | 
151  stadistinct | real                |           |          |         | plain    | 
152  stakind1    | smallint            |           |          |         | plain    | 
153  stakind2    | smallint            |           |          |         | plain    | 
154  stakind3    | smallint            |           |          |         | plain    | 
155  stakind4    | smallint            |           |          |         | plain    | 
156  stakind5    | smallint            |           |          |         | plain    | 
157  staop1      | oid                 |           |          |         | plain    | 
158  staop2      | oid                 |           |          |         | plain    | 
159  staop3      | oid                 |           |          |         | plain    | 
160  staop4      | oid                 |           |          |         | plain    | 
161  staop5      | oid                 |           |          |         | plain    | 
162  stanumbers1 | real[]              |           |          |         | extended | 
163  stanumbers2 | real[]              |           |          |         | extended | 
164  stanumbers3 | real[]              |           |          |         | extended | 
165  stanumbers4 | real[]              |           |          |         | extended | 
166  stanumbers5 | real[]              |           |          |         | extended | 
167  stavalues1  | dbms_stats.anyarray |           |          |         | extended | 
168  stavalues2  | dbms_stats.anyarray |           |          |         | extended | 
169  stavalues3  | dbms_stats.anyarray |           |          |         | extended | 
170  stavalues4  | dbms_stats.anyarray |           |          |         | extended | 
171  stavalues5  | dbms_stats.anyarray |           |          |         | extended | 
172 View definition:
173  SELECT m.starelid,
174     m.staattnum,
175     m.stainherit,
176     m.stanullfrac,
177     m.stawidth,
178     m.stadistinct,
179     m.stakind1,
180     m.stakind2,
181     m.stakind3,
182     m.stakind4,
183     m.stakind5,
184     m.staop1,
185     m.staop2,
186     m.staop3,
187     m.staop4,
188     m.staop5,
189     m.stanumbers1,
190     m.stanumbers2,
191     m.stanumbers3,
192     m.stanumbers4,
193     m.stanumbers5,
194     m.stavalues1,
195     m.stavalues2,
196     m.stavalues3,
197     m.stavalues4,
198     m.stavalues5
199    FROM ( SELECT (dbms_stats.merge(v.*, s.*)).starelid AS starelid,
200             (dbms_stats.merge(v.*, s.*)).staattnum AS staattnum,
201             (dbms_stats.merge(v.*, s.*)).stainherit AS stainherit,
202             (dbms_stats.merge(v.*, s.*)).stanullfrac AS stanullfrac,
203             (dbms_stats.merge(v.*, s.*)).stawidth AS stawidth,
204             (dbms_stats.merge(v.*, s.*)).stadistinct AS stadistinct,
205             (dbms_stats.merge(v.*, s.*)).stakind1 AS stakind1,
206             (dbms_stats.merge(v.*, s.*)).stakind2 AS stakind2,
207             (dbms_stats.merge(v.*, s.*)).stakind3 AS stakind3,
208             (dbms_stats.merge(v.*, s.*)).stakind4 AS stakind4,
209             (dbms_stats.merge(v.*, s.*)).stakind5 AS stakind5,
210             (dbms_stats.merge(v.*, s.*)).staop1 AS staop1,
211             (dbms_stats.merge(v.*, s.*)).staop2 AS staop2,
212             (dbms_stats.merge(v.*, s.*)).staop3 AS staop3,
213             (dbms_stats.merge(v.*, s.*)).staop4 AS staop4,
214             (dbms_stats.merge(v.*, s.*)).staop5 AS staop5,
215             (dbms_stats.merge(v.*, s.*)).stanumbers1 AS stanumbers1,
216             (dbms_stats.merge(v.*, s.*)).stanumbers2 AS stanumbers2,
217             (dbms_stats.merge(v.*, s.*)).stanumbers3 AS stanumbers3,
218             (dbms_stats.merge(v.*, s.*)).stanumbers4 AS stanumbers4,
219             (dbms_stats.merge(v.*, s.*)).stanumbers5 AS stanumbers5,
220             (dbms_stats.merge(v.*, s.*)).stavalues1 AS stavalues1,
221             (dbms_stats.merge(v.*, s.*)).stavalues2 AS stavalues2,
222             (dbms_stats.merge(v.*, s.*)).stavalues3 AS stavalues3,
223             (dbms_stats.merge(v.*, s.*)).stavalues4 AS stavalues4,
224             (dbms_stats.merge(v.*, s.*)).stavalues5 AS stavalues5
225            FROM pg_statistic s
226              FULL JOIN dbms_stats.column_stats_locked v USING (starelid, staattnum, stainherit)
227           WHERE NOT dbms_stats.is_system_catalog(starelid::regclass) AND (EXISTS ( SELECT NULL::text
228                    FROM pg_attribute a
229                   WHERE a.attrelid = starelid AND a.attnum = staattnum AND a.attisdropped = false))) m
230   WHERE m.starelid IS NOT NULL;
231
232 -- No.2-2-2
233 \dS+ dbms_stats.relation_stats_effective
234                               View "dbms_stats.relation_stats_effective"
235       Column      |           Type           | Collation | Nullable | Default | Storage  | Description 
236 ------------------+--------------------------+-----------+----------+---------+----------+-------------
237  relid            | oid                      |           |          |         | plain    | 
238  relname          | text                     |           |          |         | extended | 
239  relpages         | integer                  |           |          |         | plain    | 
240  reltuples        | real                     |           |          |         | plain    | 
241  relallvisible    | integer                  |           |          |         | plain    | 
242  curpages         | integer                  |           |          |         | plain    | 
243  last_analyze     | timestamp with time zone |           |          |         | plain    | 
244  last_autoanalyze | timestamp with time zone |           |          |         | plain    | 
245 View definition:
246  SELECT c.oid AS relid,
247     dbms_stats.relname(n.nspname::text, c.relname::text) AS relname,
248     COALESCE(v.relpages, c.relpages) AS relpages,
249     COALESCE(v.reltuples, c.reltuples) AS reltuples,
250     COALESCE(v.relallvisible, c.relallvisible) AS relallvisible,
251     COALESCE(v.curpages, (pg_relation_size(c.oid::regclass) / current_setting('block_size'::text)::integer)::integer) AS curpages,
252     COALESCE(v.last_analyze, pg_stat_get_last_analyze_time(c.oid)) AS last_analyze,
253     COALESCE(v.last_autoanalyze, pg_stat_get_last_autoanalyze_time(c.oid)) AS last_autoanalyze
254    FROM pg_class c
255      JOIN pg_namespace n ON c.relnamespace = n.oid
256      LEFT JOIN dbms_stats.relation_stats_locked v ON v.relid = c.oid
257   WHERE dbms_stats.is_target_relkind(c.relkind) AND NOT dbms_stats.is_system_schema(n.nspname::text);
258
259 -- No.2-2-3
260 \dS+ dbms_stats.stats
261                                         View "dbms_stats.stats"
262          Column         |        Type         | Collation | Nullable | Default | Storage  | Description 
263 ------------------------+---------------------+-----------+----------+---------+----------+-------------
264  schemaname             | name                |           |          |         | plain    | 
265  tablename              | name                |           |          |         | plain    | 
266  attname                | name                |           |          |         | plain    | 
267  inherited              | boolean             |           |          |         | plain    | 
268  null_frac              | real                |           |          |         | plain    | 
269  avg_width              | integer             |           |          |         | plain    | 
270  n_distinct             | real                |           |          |         | plain    | 
271  most_common_vals       | dbms_stats.anyarray |           |          |         | extended | 
272  most_common_freqs      | real[]              |           |          |         | extended | 
273  histogram_bounds       | dbms_stats.anyarray |           |          |         | extended | 
274  correlation            | real                |           |          |         | plain    | 
275  most_common_elems      | dbms_stats.anyarray |           |          |         | extended | 
276  most_common_elem_freqs | real[]              |           |          |         | extended | 
277  elem_count_histogram   | real[]              |           |          |         | extended | 
278 View definition:
279  SELECT n.nspname AS schemaname,
280     c.relname AS tablename,
281     a.attname,
282     s.stainherit AS inherited,
283     s.stanullfrac AS null_frac,
284     s.stawidth AS avg_width,
285     s.stadistinct AS n_distinct,
286         CASE
287             WHEN s.stakind1 = 1 THEN s.stavalues1
288             WHEN s.stakind2 = 1 THEN s.stavalues2
289             WHEN s.stakind3 = 1 THEN s.stavalues3
290             WHEN s.stakind4 = 1 THEN s.stavalues4
291             WHEN s.stakind5 = 1 THEN s.stavalues5
292             ELSE NULL::dbms_stats.anyarray
293         END AS most_common_vals,
294         CASE
295             WHEN s.stakind1 = 1 THEN s.stanumbers1
296             WHEN s.stakind2 = 1 THEN s.stanumbers2
297             WHEN s.stakind3 = 1 THEN s.stanumbers3
298             WHEN s.stakind4 = 1 THEN s.stanumbers4
299             WHEN s.stakind5 = 1 THEN s.stanumbers5
300             ELSE NULL::real[]
301         END AS most_common_freqs,
302         CASE
303             WHEN s.stakind1 = 2 THEN s.stavalues1
304             WHEN s.stakind2 = 2 THEN s.stavalues2
305             WHEN s.stakind3 = 2 THEN s.stavalues3
306             WHEN s.stakind4 = 2 THEN s.stavalues4
307             WHEN s.stakind5 = 2 THEN s.stavalues5
308             ELSE NULL::dbms_stats.anyarray
309         END AS histogram_bounds,
310         CASE
311             WHEN s.stakind1 = 3 THEN s.stanumbers1[1]
312             WHEN s.stakind2 = 3 THEN s.stanumbers2[1]
313             WHEN s.stakind3 = 3 THEN s.stanumbers3[1]
314             WHEN s.stakind4 = 3 THEN s.stanumbers4[1]
315             WHEN s.stakind5 = 3 THEN s.stanumbers5[1]
316             ELSE NULL::real
317         END AS correlation,
318         CASE
319             WHEN s.stakind1 = 4 THEN s.stavalues1
320             WHEN s.stakind2 = 4 THEN s.stavalues2
321             WHEN s.stakind3 = 4 THEN s.stavalues3
322             WHEN s.stakind4 = 4 THEN s.stavalues4
323             WHEN s.stakind5 = 4 THEN s.stavalues5
324             ELSE NULL::dbms_stats.anyarray
325         END AS most_common_elems,
326         CASE
327             WHEN s.stakind1 = 4 THEN s.stanumbers1
328             WHEN s.stakind2 = 4 THEN s.stanumbers2
329             WHEN s.stakind3 = 4 THEN s.stanumbers3
330             WHEN s.stakind4 = 4 THEN s.stanumbers4
331             WHEN s.stakind5 = 4 THEN s.stanumbers5
332             ELSE NULL::real[]
333         END AS most_common_elem_freqs,
334         CASE
335             WHEN s.stakind1 = 5 THEN s.stanumbers1
336             WHEN s.stakind2 = 5 THEN s.stanumbers2
337             WHEN s.stakind3 = 5 THEN s.stanumbers3
338             WHEN s.stakind4 = 5 THEN s.stanumbers4
339             WHEN s.stakind5 = 5 THEN s.stanumbers5
340             ELSE NULL::real[]
341         END AS elem_count_histogram
342    FROM dbms_stats.column_stats_effective s
343      JOIN pg_class c ON c.oid = s.starelid
344      JOIN pg_attribute a ON c.oid = a.attrelid AND a.attnum = s.staattnum
345      LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
346   WHERE NOT a.attisdropped AND has_column_privilege(c.oid, a.attnum, 'select'::text) AND (c.relrowsecurity = false OR NOT row_security_active(c.oid));
347 Options: security_barrier=true
348
349 -- No.2-2-4
350 \dS+ dbms_stats.column_stats_locked
351                                    Table "dbms_stats.column_stats_locked"
352    Column    |        Type         | Collation | Nullable | Default | Storage  | Stats target | Description 
353 -------------+---------------------+-----------+----------+---------+----------+--------------+-------------
354  starelid    | oid                 |           | not null |         | plain    |              | 
355  staattnum   | smallint            |           | not null |         | plain    |              | 
356  stainherit  | boolean             |           | not null |         | plain    |              | 
357  stanullfrac | real                |           |          |         | plain    |              | 
358  stawidth    | integer             |           |          |         | plain    |              | 
359  stadistinct | real                |           |          |         | plain    |              | 
360  stakind1    | smallint            |           |          |         | plain    |              | 
361  stakind2    | smallint            |           |          |         | plain    |              | 
362  stakind3    | smallint            |           |          |         | plain    |              | 
363  stakind4    | smallint            |           |          |         | plain    |              | 
364  stakind5    | smallint            |           |          |         | plain    |              | 
365  staop1      | oid                 |           |          |         | plain    |              | 
366  staop2      | oid                 |           |          |         | plain    |              | 
367  staop3      | oid                 |           |          |         | plain    |              | 
368  staop4      | oid                 |           |          |         | plain    |              | 
369  staop5      | oid                 |           |          |         | plain    |              | 
370  stanumbers1 | real[]              |           |          |         | extended |              | 
371  stanumbers2 | real[]              |           |          |         | extended |              | 
372  stanumbers3 | real[]              |           |          |         | extended |              | 
373  stanumbers4 | real[]              |           |          |         | extended |              | 
374  stanumbers5 | real[]              |           |          |         | extended |              | 
375  stavalues1  | dbms_stats.anyarray |           |          |         | extended |              | 
376  stavalues2  | dbms_stats.anyarray |           |          |         | extended |              | 
377  stavalues3  | dbms_stats.anyarray |           |          |         | extended |              | 
378  stavalues4  | dbms_stats.anyarray |           |          |         | extended |              | 
379  stavalues5  | dbms_stats.anyarray |           |          |         | extended |              | 
380 Indexes:
381     "column_stats_locked_pkey" PRIMARY KEY, btree (starelid, staattnum, stainherit)
382 Foreign-key constraints:
383     "column_stats_locked_starelid_fkey" FOREIGN KEY (starelid) REFERENCES dbms_stats.relation_stats_locked(relid) ON DELETE CASCADE
384 Triggers:
385     invalidate_column_cache BEFORE INSERT OR DELETE OR UPDATE ON dbms_stats.column_stats_locked FOR EACH ROW EXECUTE PROCEDURE dbms_stats.invalidate_column_cache()
386
387 -- No.2-2-5
388 \dS+ dbms_stats.relation_stats_locked
389                                        Table "dbms_stats.relation_stats_locked"
390       Column      |           Type           | Collation | Nullable | Default | Storage  | Stats target | Description 
391 ------------------+--------------------------+-----------+----------+---------+----------+--------------+-------------
392  relid            | oid                      |           | not null |         | plain    |              | 
393  relname          | text                     |           | not null |         | extended |              | 
394  relpages         | integer                  |           |          |         | plain    |              | 
395  reltuples        | real                     |           |          |         | plain    |              | 
396  relallvisible    | integer                  |           |          |         | plain    |              | 
397  curpages         | integer                  |           |          |         | plain    |              | 
398  last_analyze     | timestamp with time zone |           |          |         | plain    |              | 
399  last_autoanalyze | timestamp with time zone |           |          |         | plain    |              | 
400 Indexes:
401     "relation_stats_locked_pkey" PRIMARY KEY, btree (relid)
402 Referenced by:
403     TABLE "dbms_stats.column_stats_locked" CONSTRAINT "column_stats_locked_starelid_fkey" FOREIGN KEY (starelid) REFERENCES dbms_stats.relation_stats_locked(relid) ON DELETE CASCADE
404 Triggers:
405     invalidate_relation_cache BEFORE INSERT OR DELETE OR UPDATE ON dbms_stats.relation_stats_locked FOR EACH ROW EXECUTE PROCEDURE dbms_stats.invalidate_relation_cache()
406
407 /*
408  * No.2-4 dbms_stats.anyarray
409  */
410 -- No.2-4-1
411 SELECT n.nspname, t.typname, t.typlen, t.typbyval, t.typtype,
412        t.typcategory, t.typispreferred, t.typisdefined, t.typdelim,
413        t.typrelid, t.typelem, t.typinput, t.typoutput, t.typreceive,
414        t.typsend, t.typmodin, t.typmodout, t.typanalyze, t.typalign,
415        t.typstorage, t.typnotnull, t.typbasetype, t.typtypmod, t.typndims,
416        t.typcollation, t.typdefaultbin, t.typdefault, t.typacl
417   FROM pg_type t, pg_namespace n
418  WHERE t.typnamespace = n.oid
419    AND n.nspname = 'dbms_stats'
420    AND t.typname = 'anyarray';
421   nspname   | typname  | typlen | typbyval | typtype | typcategory | typispreferred | typisdefined | typdelim | typrelid | typelem |        typinput        |        typoutput        |        typreceive        |         typsend          | typmodin | typmodout | typanalyze | typalign | typstorage | typnotnull | typbasetype | typtypmod | typndims | typcollation | typdefaultbin | typdefault | typacl 
422 ------------+----------+--------+----------+---------+-------------+----------------+--------------+----------+----------+---------+------------------------+-------------------------+--------------------------+--------------------------+----------+-----------+------------+----------+------------+------------+-------------+-----------+----------+--------------+---------------+------------+--------
423  dbms_stats | anyarray |     -1 | f        | b       | P           | f              | t            | ,        |        0 |       0 | dbms_stats.anyarray_in | dbms_stats.anyarray_out | dbms_stats.anyarray_recv | dbms_stats.anyarray_send | -        | -         | -          | d        | x          | f          |           0 |        -1 |        0 |            0 | (null)        | (null)     | (null)
424 (1 row)
425
426 /*
427  * No.5-1 dbms_stats.merge
428  */
429 UPDATE pg_statistic SET
430     stanullfrac = staattnum,
431     stawidth = staattnum,
432     stadistinct = staattnum,
433     stakind1 = 4,
434     stakind2 = 1,
435     stakind3 = 2,
436     stakind4 = 3,
437     stakind5 = 5,
438     staop1 = 14,
439     staop2 = 11,
440     staop3 = 12,
441     staop4 = 13,
442     staop5 = 15,
443     stanumbers1 = ARRAY[staattnum,4],
444     stanumbers2 = ARRAY[staattnum,1],
445     stanumbers3 = ARRAY[staattnum,2],
446     stanumbers4 = ARRAY[staattnum,3],
447     stanumbers5 = ARRAY[staattnum,5],
448     stavalues2 = array_cat(stavalues1,stavalues1),
449     stavalues3 = array_cat(array_cat(stavalues1,stavalues1),stavalues1),
450     stavalues4 = array_cat(array_cat(array_cat(stavalues1,stavalues1),stavalues1),stavalues1)
451    ,stavalues5 = array_cat(array_cat(array_cat(array_cat(stavalues1,stavalues1),stavalues1),stavalues1),stavalues1)
452  WHERE starelid = 'st0'::regclass;
453 SELECT dbms_stats.lock_table_stats('st0');
454  lock_table_stats 
455 ------------------
456  st0
457 (1 row)
458
459 UPDATE dbms_stats.column_stats_locked SET
460     stainherit = 't',
461     stanullfrac = -staattnum,
462     stawidth = -staattnum,
463     stadistinct = -staattnum,
464     stakind1 = 2,
465     stakind2 = 3,
466     stakind3 = 4,
467     stakind4 = 1,
468     stakind5 = 5,
469     staop1 = 22,
470     staop2 = 23,
471     staop3 = 24,
472     staop4 = 21,
473     staop5 = 25,
474     stanumbers1 = ARRAY[-staattnum,22],
475     stanumbers2 = ARRAY[-staattnum,23],
476     stanumbers3 = ARRAY[-staattnum,24],
477     stanumbers4 = ARRAY[-staattnum,21],
478     stanumbers5 = ARRAY[-staattnum,25],
479     stavalues1 = stavalues3,
480     stavalues2 = stavalues2,
481     stavalues3 = stavalues1,
482     stavalues4 = stavalues4
483    ,stavalues5 = stavalues5
484 ;
485 /*
486  * Driver function dbms_stats.merge1
487  */
488 CREATE FUNCTION dbms_stats.merge1(
489     lhs dbms_stats.column_stats_locked,
490     rhs pg_catalog.pg_statistic
491 ) RETURNS integer AS
492 '$libdir/pg_dbms_stats', 'dbms_stats_merge'
493 LANGUAGE C STABLE;
494 SELECT * FROM columns_locked_v
495  WHERE starelid = 'st0'::regclass;
496  starelid | staattnum | attname | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 |        stavalues1         |    stavalues2     | stavalues3 |            stavalues4             |                stavalues5                 
497 ----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+---------------------------+-------------------+------------+-----------------------------------+-------------------------------------------
498  st0      |         1 | id      | t          |          -1 |       -1 |          -1 |        2 |        3 |        4 |        1 |        5 |     22 |     23 |     24 |     21 |     25 | {-1,22}     | {-1,23}     | {-1,24}     | {-1,21}     | {-1,25}     | {1,2,1,2,1,2}             | {1,2,1,2}         | {1,2}      | {1,2,1,2,1,2,1,2}                 | {1,2,1,2,1,2,1,2,1,2}
499  st0      |         2 | name    | t          |          -2 |       -2 |          -2 |        2 |        3 |        4 |        1 |        5 |     22 |     23 |     24 |     21 |     25 | {-2,22}     | {-2,23}     | {-2,24}     | {-2,21}     | {-2,25}     | {"test ","test ","test "} | {"test ","test "} | {"test "}  | {"test ","test ","test ","test "} | {"test ","test ","test ","test ","test "}
500 (2 rows)
501
502 SELECT * FROM plain_columns_statistic_v
503  WHERE starelid = 'st0'::regclass;
504  starelid | staattnum | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 | stavalues1 |    stavalues2     |        stavalues3         |            stavalues4             |                stavalues5                 
505 ----------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------+-------------------+---------------------------+-----------------------------------+-------------------------------------------
506  st0      |         1 | f          |           1 |        1 |           1 |        4 |        1 |        2 |        3 |        5 |     14 |     11 |     12 |     13 |     15 | {1,4}       | {1,1}       | {1,2}       | {1,3}       | {1,5}       | {1,2}      | {1,2,1,2}         | {1,2,1,2,1,2}             | {1,2,1,2,1,2,1,2}                 | {1,2,1,2,1,2,1,2,1,2}
507  st0      |         2 | f          |           2 |        2 |           2 |        4 |        1 |        2 |        3 |        5 |     14 |     11 |     12 |     13 |     15 | {2,4}       | {2,1}       | {2,2}       | {2,3}       | {2,5}       | {"test "}  | {"test ","test "} | {"test ","test ","test "} | {"test ","test ","test ","test "} | {"test ","test ","test ","test ","test "}
508 (2 rows)
509
510 SET client_min_messages TO LOG;
511 -- No.5-1-1
512 SELECT (m.merge).starelid::regclass,
513        (m.merge).staattnum,
514        (m.merge).stainherit,
515        (m.merge).stanullfrac,
516        (m.merge).stawidth,
517        (m.merge).stadistinct,
518        (m.merge).stakind1,
519        (m.merge).stakind2,
520        (m.merge).stakind3,
521        (m.merge).stakind4,
522        (m.merge).stakind5,
523        (m.merge).staop1,
524        (m.merge).staop2,
525        (m.merge).staop3,
526        (m.merge).staop4,
527        (m.merge).staop5,
528        (m.merge).stanumbers1,
529        (m.merge).stanumbers2,
530        (m.merge).stanumbers3,
531        (m.merge).stanumbers4,
532        (m.merge).stanumbers5,
533        (m.merge).stavalues1,
534        (m.merge).stavalues2,
535        (m.merge).stavalues3,
536        (m.merge).stavalues4
537       ,(m.merge).stavalues5
538  FROM (SELECT dbms_stats.merge(NULL, s)
539          FROM pg_statistic s
540         WHERE starelid = 'st0'::regclass
541           AND staattnum = '1'::int2) m;
542  starelid | staattnum | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 | stavalues1 | stavalues2 |  stavalues3   |    stavalues4     |      stavalues5       
543 ----------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------+------------+---------------+-------------------+-----------------------
544  st0      |         1 | f          |           1 |        1 |           1 |        4 |        1 |        2 |        3 |        5 |     14 |     11 |     12 |     13 |     15 | {1,4}       | {1,1}       | {1,2}       | {1,3}       | {1,5}       | {1,2}      | {1,2,1,2}  | {1,2,1,2,1,2} | {1,2,1,2,1,2,1,2} | {1,2,1,2,1,2,1,2,1,2}
545 (1 row)
546
547 -- No.5-1-2
548 SELECT (m.merge).starelid::regclass,
549        (m.merge).staattnum,
550        (m.merge).stainherit,
551        (m.merge).stanullfrac,
552        (m.merge).stawidth,
553        (m.merge).stadistinct,
554        (m.merge).stakind1,
555        (m.merge).stakind2,
556        (m.merge).stakind3,
557        (m.merge).stakind4,
558        (m.merge).stakind5,
559        (m.merge).staop1,
560        (m.merge).staop2,
561        (m.merge).staop3,
562        (m.merge).staop4,
563        (m.merge).staop5,
564        (m.merge).stanumbers1,
565        (m.merge).stanumbers2,
566        (m.merge).stanumbers3,
567        (m.merge).stanumbers4,
568        (m.merge).stanumbers5,
569        (m.merge).stavalues1,
570        (m.merge).stavalues2,
571        (m.merge).stavalues3,
572        (m.merge).stavalues4
573       ,(m.merge).stavalues5
574  FROM (SELECT dbms_stats.merge(v, NULL)
575          FROM dbms_stats.column_stats_locked v
576         WHERE starelid = 'st0'::regclass
577           AND staattnum = '2'::int2) m;
578  starelid | staattnum | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 |        stavalues1         |    stavalues2     | stavalues3 |            stavalues4             |                stavalues5                 
579 ----------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+---------------------------+-------------------+------------+-----------------------------------+-------------------------------------------
580  st0      |         2 | t          |          -2 |       -2 |          -2 |        2 |        3 |        4 |        1 |        5 |     22 |     23 |     24 |     21 |     25 | {-2,22}     | {-2,23}     | {-2,24}     | {-2,21}     | {-2,25}     | {"test ","test ","test "} | {"test ","test "} | {"test "}  | {"test ","test ","test ","test "} | {"test ","test ","test ","test ","test "}
581 (1 row)
582
583 -- No.5-1-3
584 SELECT dbms_stats.merge(NULL, NULL);
585  merge  
586 --------
587  (null)
588 (1 row)
589
590 -- No.5-1-4
591 SELECT (m.merge).starelid::regclass,
592        (m.merge).staattnum,
593        (m.merge).stainherit,
594        (m.merge).stanullfrac,
595        (m.merge).stawidth,
596        (m.merge).stadistinct,
597        (m.merge).stakind1,
598        (m.merge).stakind2,
599        (m.merge).stakind3,
600        (m.merge).stakind4,
601        (m.merge).stakind5,
602        (m.merge).staop1,
603        (m.merge).staop2,
604        (m.merge).staop3,
605        (m.merge).staop4,
606        (m.merge).staop5,
607        (m.merge).stanumbers1,
608        (m.merge).stanumbers2,
609        (m.merge).stanumbers3,
610        (m.merge).stanumbers4,
611        (m.merge).stanumbers5,
612        (m.merge).stavalues1,
613        (m.merge).stavalues2,
614        (m.merge).stavalues3,
615        (m.merge).stavalues4
616       ,(m.merge).stavalues5
617  FROM (SELECT dbms_stats.merge(v, s)
618          FROM dbms_stats.column_stats_locked v,
619               pg_statistic s
620         WHERE v.starelid = 'st0'::regclass
621           AND v.staattnum = '2'::int2
622           AND s.starelid = 'st0'::regclass
623           AND s.staattnum = '1'::int2) m;
624  starelid | staattnum | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 |        stavalues1         |    stavalues2     | stavalues3 |            stavalues4             |                stavalues5                 
625 ----------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+---------------------------+-------------------+------------+-----------------------------------+-------------------------------------------
626  st0      |         2 | t          |          -2 |       -2 |          -2 |        2 |        3 |        4 |        1 |        5 |     22 |     23 |     24 |     21 |     25 | {-2,22}     | {-2,23}     | {-2,24}     | {-2,21}     | {-2,25}     | {"test ","test ","test "} | {"test ","test "} | {"test "}  | {"test ","test ","test ","test "} | {"test ","test ","test ","test ","test "}
627 (1 row)
628
629 -- No.5-1-5
630 SELECT (m.merge).starelid::regclass,
631        (m.merge).staattnum,
632        (m.merge).stainherit,
633        (m.merge).stanullfrac,
634        (m.merge).stawidth,
635        (m.merge).stadistinct,
636        (m.merge).stakind1,
637        (m.merge).stakind2,
638        (m.merge).stakind3,
639        (m.merge).stakind4,
640        (m.merge).stakind5,
641        (m.merge).staop1,
642        (m.merge).staop2,
643        (m.merge).staop3,
644        (m.merge).staop4,
645        (m.merge).staop5,
646        (m.merge).stanumbers1,
647        (m.merge).stanumbers2,
648        (m.merge).stanumbers3,
649        (m.merge).stanumbers4,
650        (m.merge).stanumbers5,
651        (m.merge).stavalues1,
652        (m.merge).stavalues2,
653        (m.merge).stavalues3,
654        (m.merge).stavalues4
655       ,(m.merge).stavalues5
656  FROM (SELECT dbms_stats.merge(v, s)
657          FROM dbms_stats.column_stats_locked v,
658               pg_statistic s
659         WHERE v.starelid = 'st0'::regclass
660           AND v.staattnum = '2'::int2
661           AND s.starelid = 'st0'::regclass
662           AND s.staattnum = '1'::int2) m;
663  starelid | staattnum | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 |        stavalues1         |    stavalues2     | stavalues3 |            stavalues4             |                stavalues5                 
664 ----------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+---------------------------+-------------------+------------+-----------------------------------+-------------------------------------------
665  st0      |         2 | t          |          -2 |       -2 |          -2 |        2 |        3 |        4 |        1 |        5 |     22 |     23 |     24 |     21 |     25 | {-2,22}     | {-2,23}     | {-2,24}     | {-2,21}     | {-2,25}     | {"test ","test ","test "} | {"test ","test "} | {"test "}  | {"test ","test ","test ","test "} | {"test ","test ","test ","test ","test "}
666 (1 row)
667
668 -- No.5-1-6
669 SELECT dbms_stats.merge1(v, s)
670   FROM dbms_stats.column_stats_locked v,
671        pg_statistic s
672  WHERE v.starelid = 'st0'::regclass
673    AND v.staattnum = '2'::int2
674    AND s.starelid = 'st0'::regclass
675    AND s.staattnum = '1'::int2;
676 ERROR:  return type must be a row type
677 -- No.5-1-7
678 SELECT dbms_stats.merge(NULL, (
679        s.starelid::regclass, s.staattnum, s.stainherit,
680        s.stanullfrac, s.stawidth, s.stadistinct,
681        s.stakind1, s.stakind2, s.stakind3, s.stakind4,
682        s.stakind5,
683        s.staop1, s.staop2, s.staop3,
684        s.staop4,
685        NULL, s.stanumbers1, s.stanumbers2, s.stanumbers3, s.stanumbers4,
686        s.stanumbers5,
687        s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
688       ,s.stavalues5
689        ))
690   FROM pg_statistic s
691  WHERE s.starelid = 'st0'::regclass
692    AND s.staattnum = '1'::int2;
693  merge  
694 --------
695  (null)
696 (1 row)
697
698 -- No.5-1-8
699 SELECT (m.merge).starelid::regclass,
700        (m.merge).staattnum,
701        (m.merge).stainherit,
702        (m.merge).stanullfrac,
703        (m.merge).stawidth,
704        (m.merge).stadistinct,
705        (m.merge).stakind1,
706        (m.merge).stakind2,
707        (m.merge).stakind3,
708        (m.merge).stakind4,
709        (m.merge).stakind5,
710        (m.merge).staop1,
711        (m.merge).staop2,
712        (m.merge).staop3,
713        (m.merge).staop4,
714        (m.merge).staop5,
715        (m.merge).stanumbers1,
716        (m.merge).stanumbers2,
717        (m.merge).stanumbers3,
718        (m.merge).stanumbers4,
719        (m.merge).stanumbers5,
720        (m.merge).stavalues1,
721        (m.merge).stavalues2,
722        (m.merge).stavalues3,
723        (m.merge).stavalues4
724       ,(m.merge).stavalues5
725  FROM (SELECT dbms_stats.merge(NULL, (
726               s.starelid::regclass, s.staattnum, s.stainherit,
727               s.stanullfrac, s.stawidth, s.stadistinct,
728               s.stakind1, s.stakind2, s.stakind3, s.stakind4,
729               s.stakind5,
730               s.staop1, s.staop2, s.staop3, s.staop4,
731               s.staop5,
732               NULL, s.stanumbers2, s.stanumbers3, s.stanumbers4,
733               s.stanumbers5,
734               s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
735              ,s.stavalues5
736               ))
737          FROM pg_statistic s
738         WHERE s.starelid = 'st0'::regclass
739           AND s.staattnum = '1'::int2) m;
740  starelid | staattnum | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 | stavalues1 | stavalues2 |  stavalues3   |    stavalues4     |      stavalues5       
741 ----------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------+------------+---------------+-------------------+-----------------------
742  st0      |         1 | f          |           1 |        1 |           1 |        4 |        1 |        2 |        3 |        5 |     14 |     11 |     12 |     13 |     15 | (null)      | {1,1}       | {1,2}       | {1,3}       | {1,5}       | {1,2}      | {1,2,1,2}  | {1,2,1,2,1,2} | {1,2,1,2,1,2,1,2} | {1,2,1,2,1,2,1,2,1,2}
743 (1 row)
744
745 -- No.5-1-9
746 SELECT dbms_stats.merge((
747        v.starelid::regclass, v.staattnum, v.stainherit,
748        v.stanullfrac, v.stawidth, v.stadistinct,
749        v.stakind1, v.stakind2, v.stakind3, v.stakind4,
750        v.stakind5,
751        v.staop1, v.staop2, v.staop3,
752        v.staop4,
753        NULL, v.stanumbers1, v.stanumbers2, v.stanumbers3, v.stanumbers4,
754        v.stanumbers5,
755        v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
756       ,v.stavalues5
757        ), NULL)
758   FROM dbms_stats.column_stats_locked v
759  WHERE v.starelid = 'st0'::regclass
760    AND v.staattnum = '2'::int2;
761  merge  
762 --------
763  (null)
764 (1 row)
765
766 -- No.5-1-10
767 SELECT (m.merge).starelid::regclass,
768        (m.merge).staattnum,
769        (m.merge).stainherit,
770        (m.merge).stanullfrac,
771        (m.merge).stawidth,
772        (m.merge).stadistinct,
773        (m.merge).stakind1,
774        (m.merge).stakind2,
775        (m.merge).stakind3,
776        (m.merge).stakind4,
777        (m.merge).stakind5,
778        (m.merge).staop1,
779        (m.merge).staop2,
780        (m.merge).staop3,
781        (m.merge).staop4,
782        (m.merge).staop5,
783        (m.merge).stanumbers1,
784        (m.merge).stanumbers2,
785        (m.merge).stanumbers3,
786        (m.merge).stanumbers4,
787        (m.merge).stanumbers5,
788        (m.merge).stavalues1,
789        (m.merge).stavalues2,
790        (m.merge).stavalues3,
791        (m.merge).stavalues4
792       ,(m.merge).stavalues5
793  FROM (SELECT dbms_stats.merge((
794               v.starelid::regclass, v.staattnum, v.stainherit,
795               v.stanullfrac, v.stawidth, v.stadistinct,
796               v.stakind1, v.stakind2, v.stakind3, v.stakind4,
797               v.stakind5,
798               v.staop1, v.staop2, v.staop3, v.staop4,
799               v.staop5,
800               NULL, v.stanumbers2, v.stanumbers3, v.stanumbers4,
801               v.stanumbers5,
802               v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
803              ,v.stavalues5
804               ), NULL)
805          FROM dbms_stats.column_stats_locked v
806         WHERE v.starelid = 'st0'::regclass
807           AND v.staattnum = '2'::int2) m;
808  starelid | staattnum | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 |        stavalues1         |    stavalues2     | stavalues3 |            stavalues4             |                stavalues5                 
809 ----------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+---------------------------+-------------------+------------+-----------------------------------+-------------------------------------------
810  st0      |         2 | t          |          -2 |       -2 |          -2 |        2 |        3 |        4 |        1 |        5 |     22 |     23 |     24 |     21 |     25 | (null)      | {-2,23}     | {-2,24}     | {-2,21}     | {-2,25}     | {"test ","test ","test "} | {"test ","test "} | {"test "}  | {"test ","test ","test ","test "} | {"test ","test ","test ","test ","test "}
811 (1 row)
812
813 -- No.5-1-11
814 SELECT dbms_stats.merge((
815        v.starelid::regclass, v.staattnum, v.stainherit,
816        v.stanullfrac, v.stawidth, v.stadistinct,
817        v.stakind1, v.stakind2, v.stakind3, v.stakind4,
818        v.stakind5,
819        v.staop1, v.staop2, v.staop3,
820        v.staop4,
821        NULL, v.stanumbers1, v.stanumbers2, v.stanumbers3, v.stanumbers4,
822        v.stanumbers5,
823        v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
824       ,v.stavalues5
825        ), (
826        s.starelid::regclass, s.staattnum, s.stainherit,
827        s.stanullfrac, s.stawidth, s.stadistinct,
828        s.stakind1, s.stakind2, s.stakind3, s.stakind4,
829        s.stakind5,
830        s.staop1, s.staop2, s.staop3,
831        s.staop4,
832        NULL, s.stanumbers1, s.stanumbers2, s.stanumbers3, s.stanumbers4,
833        s.stanumbers5,
834        s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
835       ,s.stavalues5
836        ))
837   FROM dbms_stats.column_stats_locked v,
838        pg_statistic s
839  WHERE v.starelid = 'st0'::regclass
840    AND v.staattnum = '2'::int2
841    AND s.starelid = 'st0'::regclass
842    AND s.staattnum = '1'::int2;
843 LOG:  pg_dbms_stats: bad statistics
844 DETAIL:  column "staop5" should not be null
845  merge  
846 --------
847  (null)
848 (1 row)
849
850 -- No.5-1-12
851 SELECT (m.merge).starelid::regclass,
852        (m.merge).staattnum,
853        (m.merge).stainherit,
854        (m.merge).stanullfrac,
855        (m.merge).stawidth,
856        (m.merge).stadistinct,
857        (m.merge).stakind1,
858        (m.merge).stakind2,
859        (m.merge).stakind3,
860        (m.merge).stakind4,
861        (m.merge).stakind5,
862        (m.merge).staop1,
863        (m.merge).staop2,
864        (m.merge).staop3,
865        (m.merge).staop4,
866        (m.merge).staop5,
867        (m.merge).stanumbers1,
868        (m.merge).stanumbers2,
869        (m.merge).stanumbers3,
870        (m.merge).stanumbers4,
871        (m.merge).stanumbers5,
872        (m.merge).stavalues1,
873        (m.merge).stavalues2,
874        (m.merge).stavalues3,
875        (m.merge).stavalues4
876       ,(m.merge).stavalues5
877  FROM (SELECT dbms_stats.merge((
878               v.starelid::regclass, v.staattnum, v.stainherit,
879               v.stanullfrac, v.stawidth, v.stadistinct,
880               v.stakind1, v.stakind2, v.stakind3, v.stakind4,
881               v.stakind5,
882               v.staop1, v.staop2, v.staop3, v.staop4,
883               v.staop5,
884               NULL, v.stanumbers2, v.stanumbers3, v.stanumbers4,
885               v.stanumbers5,
886               v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
887              ,v.stavalues5
888               ), (
889               s.starelid::regclass, s.staattnum, s.stainherit,
890               s.stanullfrac, s.stawidth, s.stadistinct,
891               s.stakind1, s.stakind2, s.stakind3, s.stakind4,
892               s.stakind5,
893               s.staop1, s.staop2, s.staop3, s.staop4,
894               s.staop5,
895               NULL, s.stanumbers2, s.stanumbers3, s.stanumbers4,
896               s.stanumbers5,
897               s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
898              ,s.stavalues5
899               ))
900          FROM dbms_stats.column_stats_locked v,
901               pg_statistic s
902         WHERE v.starelid = 'st0'::regclass
903           AND v.staattnum = '2'::int2
904           AND s.starelid = 'st0'::regclass
905           AND s.staattnum = '1'::int2) m;
906  starelid | staattnum | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 |        stavalues1         |    stavalues2     | stavalues3 |            stavalues4             |                stavalues5                 
907 ----------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+---------------------------+-------------------+------------+-----------------------------------+-------------------------------------------
908  st0      |         2 | t          |          -2 |       -2 |          -2 |        2 |        3 |        4 |        1 |        5 |     22 |     23 |     24 |     21 |     25 | (null)      | {-2,23}     | {-2,24}     | {-2,21}     | {-2,25}     | {"test ","test ","test "} | {"test ","test "} | {"test "}  | {"test ","test ","test ","test "} | {"test ","test ","test ","test ","test "}
909 (1 row)
910
911 -- No.5-1-13
912 SELECT (m.merge).starelid::regclass,
913        (m.merge).staattnum,
914        (m.merge).stainherit,
915        (m.merge).stanullfrac,
916        (m.merge).stawidth,
917        (m.merge).stadistinct,
918        (m.merge).stakind1,
919        (m.merge).stakind2,
920        (m.merge).stakind3,
921        (m.merge).stakind4,
922        (m.merge).stakind5,
923        (m.merge).staop1,
924        (m.merge).staop2,
925        (m.merge).staop3,
926        (m.merge).staop4,
927        (m.merge).staop5,
928        (m.merge).stanumbers1,
929        (m.merge).stanumbers2,
930        (m.merge).stanumbers3,
931        (m.merge).stanumbers4,
932        (m.merge).stanumbers5,
933        (m.merge).stavalues1,
934        (m.merge).stavalues2,
935        (m.merge).stavalues3,
936        (m.merge).stavalues4
937       ,(m.merge).stavalues5
938  FROM (SELECT dbms_stats.merge((
939              NULL, NULL, NULL,
940              NULL, NULL, NULL,
941              NULL, NULL, NULL, NULL,
942              NULL, NULL, NULL, NULL,
943              NULL, NULL, NULL, NULL,
944              NULL, NULL, NULL, NULL
945             ,NULL, NULL, NULL, NULL
946              ), s)
947          FROM pg_statistic s
948         WHERE s.starelid = 'st0'::regclass
949           AND s.staattnum = '1'::int2) m;
950  starelid | staattnum | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 | stavalues1 | stavalues2 |  stavalues3   |    stavalues4     |      stavalues5       
951 ----------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------+------------+---------------+-------------------+-----------------------
952  st0      |         1 | f          |           1 |        1 |           1 |        4 |        1 |        2 |        3 |        5 |     14 |     11 |     12 |     13 |     15 | {1,4}       | {1,1}       | {1,2}       | {1,3}       | {1,5}       | {1,2}      | {1,2,1,2}  | {1,2,1,2,1,2} | {1,2,1,2,1,2,1,2} | {1,2,1,2,1,2,1,2,1,2}
953 (1 row)
954
955 -- No.5-1-14
956 SELECT (m.merge).starelid::regclass,
957        (m.merge).staattnum,
958        (m.merge).stainherit,
959        (m.merge).stanullfrac,
960        (m.merge).stawidth,
961        (m.merge).stadistinct,
962        (m.merge).stakind1,
963        (m.merge).stakind2,
964        (m.merge).stakind3,
965        (m.merge).stakind4,
966        (m.merge).stakind5,
967        (m.merge).staop1,
968        (m.merge).staop2,
969        (m.merge).staop3,
970        (m.merge).staop4,
971        (m.merge).staop5,
972        (m.merge).stanumbers1,
973        (m.merge).stanumbers2,
974        (m.merge).stanumbers3,
975        (m.merge).stanumbers4,
976        (m.merge).stanumbers5,
977        (m.merge).stavalues1,
978        (m.merge).stavalues2,
979        (m.merge).stavalues3,
980        (m.merge).stavalues4
981       ,(m.merge).stavalues5
982  FROM (SELECT dbms_stats.merge(v, (
983              NULL, NULL, NULL,
984              NULL, NULL, NULL,
985              NULL, NULL, NULL, NULL,
986              NULL, NULL, NULL, NULL,
987              NULL, NULL, NULL, NULL,
988              NULL, NULL, NULL, NULL,
989              NULL, NULL, NULL, NULL))
990          FROM dbms_stats.column_stats_locked v
991         WHERE v.starelid = 'st0'::regclass
992           AND v.staattnum = '2'::int2) m;
993  starelid | staattnum | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 |        stavalues1         |    stavalues2     | stavalues3 |            stavalues4             |                stavalues5                 
994 ----------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+---------------------------+-------------------+------------+-----------------------------------+-------------------------------------------
995  st0      |         2 | t          |          -2 |       -2 |          -2 |        2 |        3 |        4 |        1 |        5 |     22 |     23 |     24 |     21 |     25 | {-2,22}     | {-2,23}     | {-2,24}     | {-2,21}     | {-2,25}     | {"test ","test ","test "} | {"test ","test "} | {"test "}  | {"test ","test ","test ","test "} | {"test ","test ","test ","test ","test "}
996 (1 row)
997
998 -- No.5-1-15
999 SELECT (m.merge).starelid::regclass,
1000        (m.merge).staattnum,
1001        (m.merge).stainherit,
1002        (m.merge).stanullfrac,
1003        (m.merge).stawidth,
1004        (m.merge).stadistinct,
1005        (m.merge).stakind1,
1006        (m.merge).stakind2,
1007        (m.merge).stakind3,
1008        (m.merge).stakind4,
1009        (m.merge).stakind5,
1010        (m.merge).staop1,
1011        (m.merge).staop2,
1012        (m.merge).staop3,
1013        (m.merge).staop4,
1014        (m.merge).staop5,
1015        (m.merge).stanumbers1,
1016        (m.merge).stanumbers2,
1017        (m.merge).stanumbers3,
1018        (m.merge).stanumbers4,
1019        (m.merge).stanumbers5,
1020        (m.merge).stavalues1,
1021        (m.merge).stavalues2,
1022        (m.merge).stavalues3,
1023        (m.merge).stavalues4
1024       ,(m.merge).stavalues5
1025  FROM (SELECT dbms_stats.merge(v, s)
1026          FROM dbms_stats.column_stats_locked v,
1027               pg_statistic s
1028         WHERE v.starelid = 'st0'::regclass
1029           AND v.staattnum = '2'::int2
1030           AND s.starelid = 'st0'::regclass
1031           AND s.staattnum = '1'::int2) m;
1032  starelid | staattnum | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 |        stavalues1         |    stavalues2     | stavalues3 |            stavalues4             |                stavalues5                 
1033 ----------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+---------------------------+-------------------+------------+-----------------------------------+-------------------------------------------
1034  st0      |         2 | t          |          -2 |       -2 |          -2 |        2 |        3 |        4 |        1 |        5 |     22 |     23 |     24 |     21 |     25 | {-2,22}     | {-2,23}     | {-2,24}     | {-2,21}     | {-2,25}     | {"test ","test ","test "} | {"test ","test "} | {"test "}  | {"test ","test ","test ","test "} | {"test ","test ","test ","test ","test "}
1035 (1 row)
1036
1037 -- No.5-1-16
1038 SELECT dbms_stats.merge((
1039        v.starelid::regclass, v.staattnum, v.stainherit,
1040        v.stanullfrac, v.stawidth, v.stadistinct,
1041        NULL, NULL, NULL, NULL,
1042        NULL, NULL, NULL, NULL,
1043        NULL, NULL, NULL, NULL,
1044        NULL, NULL, NULL, NULL
1045       ,NULL, NULL, NULL, NULL
1046        ), (
1047        s.starelid::regclass, s.staattnum, s.stainherit,
1048        s.stanullfrac, s.stawidth, s.stadistinct,
1049        NULL, NULL, NULL, NULL,
1050        NULL, NULL, NULL, NULL,
1051        NULL, NULL, NULL, NULL,
1052        NULL, NULL, NULL, NULL,
1053        NULL, NULL, NULL, NULL))
1054   FROM dbms_stats.column_stats_locked v,
1055        pg_statistic s
1056  WHERE v.starelid = 'st0'::regclass
1057    AND v.staattnum = '2'::int2
1058    AND s.starelid = 'st0'::regclass
1059    AND s.staattnum = '1'::int2;
1060 LOG:  pg_dbms_stats: bad statistics
1061 DETAIL:  column "stakind1" should not be null
1062  merge  
1063 --------
1064  (null)
1065 (1 row)
1066
1067 -- No.5-1-17
1068 SELECT (m.merge).starelid::regclass,
1069        (m.merge).staattnum,
1070        (m.merge).stainherit,
1071        (m.merge).stanullfrac,
1072        (m.merge).stawidth,
1073        (m.merge).stadistinct,
1074        (m.merge).stakind1,
1075        (m.merge).stakind2,
1076        (m.merge).stakind3,
1077        (m.merge).stakind4,
1078        (m.merge).stakind5,
1079        (m.merge).staop1,
1080        (m.merge).staop2,
1081        (m.merge).staop3,
1082        (m.merge).staop4,
1083        (m.merge).staop5,
1084        (m.merge).stanumbers1,
1085        (m.merge).stanumbers2,
1086        (m.merge).stanumbers3,
1087        (m.merge).stanumbers4,
1088        (m.merge).stanumbers5,
1089        (m.merge).stavalues1,
1090        (m.merge).stavalues2,
1091        (m.merge).stavalues3,
1092        (m.merge).stavalues4
1093       ,(m.merge).stavalues5
1094  FROM (SELECT dbms_stats.merge((
1095               v.starelid::regclass, v.staattnum, v.stainherit,
1096               v.stanullfrac, v.stawidth, v.stadistinct,
1097               v.stakind1, v.stakind2, v.stakind3, v.stakind4,
1098               v.stakind5,
1099               v.staop1, v.staop2, v.staop3,
1100               v.staop4,
1101               NULL, v.stanumbers1, v.stanumbers2, v.stanumbers3, v.stanumbers4,
1102               v.stanumbers5,
1103               v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
1104              ,v.stavalues5
1105               ), (
1106               s.starelid::regclass, s.staattnum, s.stainherit,
1107               s.stanullfrac, s.stawidth, s.stadistinct,
1108               s.stakind1, s.stakind2, s.stakind3, s.stakind4,
1109               s.stakind5,
1110               s.staop1, s.staop2, s.staop3, s.staop4,
1111               s.staop5,
1112               s.stanumbers1, s.stanumbers2, s.stanumbers3, s.stanumbers4,
1113               s.stanumbers5,
1114               s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
1115              ,s.stavalues5
1116               ))
1117          FROM dbms_stats.column_stats_locked v,
1118               pg_statistic s
1119         WHERE v.starelid = 'st0'::regclass
1120           AND v.staattnum = '1'::int2
1121           AND s.starelid = 'st0'::regclass
1122           AND s.staattnum = '1'::int2) m;
1123  starelid | staattnum | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 | stavalues1 | stavalues2 |  stavalues3   |    stavalues4     |      stavalues5       
1124 ----------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------+------------+---------------+-------------------+-----------------------
1125  st0      |         1 | t          |          -1 |       -1 |          -1 |        4 |        1 |        2 |        3 |        5 |     14 |     11 |     12 |     13 |     15 | {1,4}       | {1,1}       | {1,2}       | {1,3}       | {1,5}       | {1,2}      | {1,2,1,2}  | {1,2,1,2,1,2} | {1,2,1,2,1,2,1,2} | {1,2,1,2,1,2,1,2,1,2}
1126 (1 row)
1127
1128 -- No.5-1-18
1129 SELECT dbms_stats.merge((
1130        v.starelid::regclass, v.staattnum, v.stainherit,
1131        v.stanullfrac, v.stawidth, v.stadistinct,
1132        v.stakind1, v.stakind2, v.stakind3, v.stakind4,
1133        v.stakind5,
1134        v.staop1, v.staop2, v.staop3,
1135        v.staop4,
1136        NULL, v.stanumbers1, v.stanumbers2, v.stanumbers3, v.stanumbers4,
1137        v.stanumbers5,
1138        v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
1139       ,v.stavalues5
1140        ), (
1141        s.starelid::regclass, s.staattnum, s.stainherit,
1142        s.stanullfrac, s.stawidth, s.stadistinct,
1143        s.stakind1, s.stakind2, s.stakind3, s.stakind4,
1144        s.stakind5,
1145        s.staop1, s.staop2, s.staop3,
1146        s.staop4,
1147        NULL, s.stanumbers1, s.stanumbers2, s.stanumbers3, s.stanumbers4,
1148        s.stanumbers5,
1149        s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
1150       ,s.stavalues5
1151        ))
1152   FROM dbms_stats.column_stats_locked v,
1153        pg_statistic s
1154  WHERE v.starelid = 'st0'::regclass
1155    AND v.staattnum = '1'::int2
1156    AND s.starelid = 'st0'::regclass
1157    AND s.staattnum = '1'::int2;
1158 LOG:  pg_dbms_stats: bad statistics
1159 DETAIL:  column "staop5" should not be null
1160  merge  
1161 --------
1162  (null)
1163 (1 row)
1164
1165 -- No.5-1-19
1166 SELECT (m.merge).starelid::regclass,
1167        (m.merge).staattnum,
1168        (m.merge).stainherit,
1169        (m.merge).stanullfrac,
1170        (m.merge).stawidth,
1171        (m.merge).stadistinct,
1172        (m.merge).stakind1,
1173        (m.merge).stakind2,
1174        (m.merge).stakind3,
1175        (m.merge).stakind4,
1176        (m.merge).stakind5,
1177        (m.merge).staop1,
1178        (m.merge).staop2,
1179        (m.merge).staop3,
1180        (m.merge).staop4,
1181        (m.merge).staop5,
1182        (m.merge).stanumbers1,
1183        (m.merge).stanumbers2,
1184        (m.merge).stanumbers3,
1185        (m.merge).stanumbers4,
1186        (m.merge).stanumbers5,
1187        (m.merge).stavalues1,
1188        (m.merge).stavalues2,
1189        (m.merge).stavalues3,
1190        (m.merge).stavalues4
1191       ,(m.merge).stavalues5
1192  FROM (SELECT dbms_stats.merge((
1193               v.starelid::regclass, v.staattnum, v.stainherit,
1194               v.stanullfrac, v.stawidth, v.stadistinct,
1195               '1', '1', '1', '1',
1196               '1',
1197               v.staop1, v.staop2, v.staop3, v.staop4,
1198               v.staop5,
1199               v.stanumbers1, v.stanumbers2, v.stanumbers3, v.stanumbers4,
1200               v.stanumbers5,
1201               v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
1202              ,v.stavalues5
1203               ), (
1204               s.starelid::regclass, s.staattnum, s.stainherit,
1205               s.stanullfrac, s.stawidth, s.stadistinct,
1206               '1', '1', '1', '1',
1207               '1',
1208               s.staop1, s.staop2, s.staop3, s.staop4,
1209               s.staop5,
1210               s.stanumbers1, s.stanumbers2, s.stanumbers3, s.stanumbers4,
1211               s.stanumbers5,
1212               s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
1213              ,s.stavalues5
1214               ))
1215          FROM dbms_stats.column_stats_locked v,
1216               pg_statistic s
1217         WHERE v.starelid = 'st0'::regclass
1218           AND v.staattnum = '2'::int2
1219           AND s.starelid = 'st0'::regclass
1220           AND s.staattnum = '1'::int2) m;
1221  starelid | staattnum | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 |        stavalues1         |    stavalues2     | stavalues3 |            stavalues4             |                stavalues5                 
1222 ----------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+---------------------------+-------------------+------------+-----------------------------------+-------------------------------------------
1223  st0      |         2 | t          |          -2 |       -2 |          -2 |        1 |        1 |        1 |        1 |        1 |     22 |     23 |     24 |     21 |     25 | {-2,22}     | {-2,23}     | {-2,24}     | {-2,21}     | {-2,25}     | {"test ","test ","test "} | {"test ","test "} | {"test "}  | {"test ","test ","test ","test "} | {"test ","test ","test ","test ","test "}
1224 (1 row)
1225
1226 -- No.5-1-20
1227 SELECT (m.merge).starelid::regclass,
1228        (m.merge).staattnum,
1229        (m.merge).stainherit,
1230        (m.merge).stanullfrac,
1231        (m.merge).stawidth,
1232        (m.merge).stadistinct,
1233        (m.merge).stakind1,
1234        (m.merge).stakind2,
1235        (m.merge).stakind3,
1236        (m.merge).stakind4,
1237        (m.merge).stakind5,
1238        (m.merge).staop1,
1239        (m.merge).staop2,
1240        (m.merge).staop3,
1241        (m.merge).staop4,
1242        (m.merge).staop5,
1243        (m.merge).stanumbers1,
1244        (m.merge).stanumbers2,
1245        (m.merge).stanumbers3,
1246        (m.merge).stanumbers4,
1247        (m.merge).stanumbers5,
1248        (m.merge).stavalues1,
1249        (m.merge).stavalues2,
1250        (m.merge).stavalues3,
1251        (m.merge).stavalues4
1252       ,(m.merge).stavalues5
1253  FROM (SELECT dbms_stats.merge((v.starelid::regclass, v.staattnum, v.stainherit,
1254               v.stanullfrac, v.stawidth, v.stadistinct,
1255               '2', '2', '2', '2',
1256               '2',
1257               v.staop1, v.staop2, v.staop3, v.staop4,
1258               v.staop5,
1259               v.stanumbers1, v.stanumbers2, v.stanumbers3, v.stanumbers4,
1260               v.stanumbers5,
1261               v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
1262              ,v.stavalues5
1263               ), (
1264               s.starelid::regclass, s.staattnum, s.stainherit,
1265               s.stanullfrac, s.stawidth, s.stadistinct,
1266               '2', '2', '2', '2',
1267               '2',
1268               s.staop1, s.staop2, s.staop3, s.staop4,
1269               s.staop5,
1270               s.stanumbers1, s.stanumbers2, s.stanumbers3, s.stanumbers4,
1271               s.stanumbers5,
1272               s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
1273              ,s.stavalues5
1274               ))
1275          FROM dbms_stats.column_stats_locked v,
1276               pg_statistic s
1277         WHERE v.starelid = 'st0'::regclass
1278           AND v.staattnum = '2'::int2
1279           AND s.starelid = 'st0'::regclass
1280           AND s.staattnum = '1'::int2) m;
1281  starelid | staattnum | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 |        stavalues1         |    stavalues2     | stavalues3 |            stavalues4             |                stavalues5                 
1282 ----------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+---------------------------+-------------------+------------+-----------------------------------+-------------------------------------------
1283  st0      |         2 | t          |          -2 |       -2 |          -2 |        2 |        2 |        2 |        2 |        2 |     22 |     23 |     24 |     21 |     25 | {-2,22}     | {-2,23}     | {-2,24}     | {-2,21}     | {-2,25}     | {"test ","test ","test "} | {"test ","test "} | {"test "}  | {"test ","test ","test ","test "} | {"test ","test ","test ","test ","test "}
1284 (1 row)
1285
1286 -- No.5-1-21
1287 SELECT dbms_stats.merge((v.starelid::regclass, '2', v.stainherit,
1288               v.stanullfrac, v.stawidth, v.stadistinct,
1289               '1', '1', '1', '1',
1290               '1',
1291               v.staop1, v.staop2, v.staop3, v.staop4,
1292               v.staop5,
1293               v.stanumbers1, v.stanumbers2, v.stanumbers3, v.stanumbers4,
1294               v.stanumbers5,
1295               v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
1296              ,v.stavalues5
1297               ), (
1298               s.starelid::regclass, s.staattnum, s.stainherit,
1299               s.stanullfrac, s.stawidth, s.stadistinct,
1300               '1', '1', '1', '1',
1301               '1',
1302               s.staop1, s.staop2, s.staop3, s.staop4,
1303               s.staop5,
1304               s.stanumbers1, s.stanumbers2, s.stanumbers3, s.stanumbers4,
1305               s.stanumbers5,
1306               s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
1307              ,s.stavalues5
1308               ))
1309          FROM dbms_stats.column_stats_locked v,
1310               pg_statistic s
1311         WHERE v.starelid = 'st0'::regclass
1312           AND v.staattnum = '1'::int2
1313           AND s.starelid = 'st0'::regclass
1314           AND s.staattnum = '1'::int2;
1315 LOG:  pg_dbms_stats: bad column type
1316 DETAIL:  type of column "name" has been changed
1317 HINT:  need to execute dbms_stats.unlock('st0', 'name')
1318  merge  
1319 --------
1320  (null)
1321 (1 row)
1322
1323 -- No.5-1-22
1324 SELECT dbms_stats.merge((v.starelid::regclass, '2', v.stainherit,
1325               v.stanullfrac, v.stawidth, v.stadistinct,
1326               '2', '2', '2', '2',
1327               '2',
1328               v.staop1, v.staop2, v.staop3, v.staop4,
1329               v.staop5,
1330               v.stanumbers1, v.stanumbers2, v.stanumbers3, v.stanumbers4,
1331               v.stanumbers5,
1332               v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
1333              ,v.stavalues5
1334               ), (
1335               s.starelid::regclass, s.staattnum, s.stainherit,
1336               s.stanullfrac, s.stawidth, s.stadistinct,
1337               '2', '2', '2', '2',
1338               '2',
1339               s.staop1, s.staop2, s.staop3, s.staop4,
1340               s.staop5,
1341               s.stanumbers1, s.stanumbers2, s.stanumbers3, s.stanumbers4,
1342               s.stanumbers5,
1343               s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
1344              ,s.stavalues5
1345               ))
1346          FROM dbms_stats.column_stats_locked v,
1347               pg_statistic s
1348         WHERE v.starelid = 'st0'::regclass
1349           AND v.staattnum = '1'::int2
1350           AND s.starelid = 'st0'::regclass
1351           AND s.staattnum = '1'::int2;
1352 LOG:  pg_dbms_stats: bad column type
1353 DETAIL:  type of column "name" has been changed
1354 HINT:  need to execute dbms_stats.unlock('st0', 'name')
1355  merge  
1356 --------
1357  (null)
1358 (1 row)
1359
1360 RESET client_min_messages;
1361 SELECT dbms_stats.unlock_database_stats();
1362  unlock_database_stats 
1363 -----------------------
1364  st0
1365 (1 row)
1366
1367 /*
1368  * No.6-4 dbms_stats.is_target_relkind
1369  */
1370 -- No.6-4- 10-11
1371 SELECT dbms_stats.is_target_relkind(k::"char")
1372  FROM (VALUES ('r'), ('i'), ('f'), ('m'),
1373                           ('S'), ('t'), ('v'), ('c')) t(k);
1374  is_target_relkind 
1375 -------------------
1376  t
1377  t
1378  t
1379  t
1380  f
1381  f
1382  f
1383  f
1384 (8 rows)
1385
1386 /*
1387  * No.7-1 dbms_stats.backup
1388  */
1389 DELETE FROM dbms_stats.backup_history;
1390 INSERT INTO dbms_stats.backup_history(id, time, unit) values(1, '2012-01-01', 'd');
1391 -- No.7-1-9
1392 SELECT dbms_stats.backup(1, 's0.sft0'::regclass, NULL);
1393  backup 
1394 --------
1395       1
1396 (1 row)
1397
1398 SELECT count(*) FROM dbms_stats.relation_stats_backup;
1399  count 
1400 -------
1401      1
1402 (1 row)
1403
1404 SELECT count(*) FROM dbms_stats.column_stats_backup;
1405  count 
1406 -------
1407      1
1408 (1 row)
1409
1410 -- No.7-1-10
1411 DELETE FROM dbms_stats.relation_stats_backup;
1412 SELECT dbms_stats.backup(1, 's0.smv0'::regclass, NULL);
1413  backup 
1414 --------
1415       1
1416 (1 row)
1417
1418 SELECT count(*) FROM dbms_stats.relation_stats_backup;
1419  count 
1420 -------
1421      1
1422 (1 row)
1423
1424 SELECT count(*) FROM dbms_stats.column_stats_backup;
1425  count 
1426 -------
1427      3
1428 (1 row)
1429
1430 -- No.7-1-12
1431 DELETE FROM dbms_stats.relation_stats_backup;
1432 SELECT dbms_stats.backup(1, NULL, 1::int2);
1433  backup 
1434 --------
1435       1
1436 (1 row)
1437
1438 SELECT relid::regclass FROM dbms_stats.relation_stats_backup
1439  GROUP BY relid
1440  ORDER BY relid;
1441    relid    
1442 ------------
1443  pt0
1444  pt0_idx
1445  st0
1446  st0_idx
1447  st1
1448  s0.st0
1449  s0.st0_idx
1450  s0.st1
1451  s0.st1_idx
1452  s0.st2
1453  s0.st2_idx
1454  s1.st0
1455  st1_idx
1456  st1_exp
1457  s0.sft0
1458  s0.smv0
1459 (16 rows)
1460
1461 SELECT starelid::regclass, staattnum FROM dbms_stats.column_stats_backup
1462  GROUP BY starelid, staattnum
1463  ORDER BY starelid, staattnum;
1464  starelid | staattnum 
1465 ----------+-----------
1466  st0      |         1
1467  st1      |         1
1468  s0.st0   |         1
1469  s0.st1   |         1
1470  s0.st2   |         1
1471  s1.st0   |         1
1472  st1_exp  |         1
1473  s0.sft0  |         1
1474  s0.smv0  |         1
1475 (9 rows)
1476
1477 -- No.7-1-14
1478 DELETE FROM dbms_stats.relation_stats_backup;
1479 SELECT dbms_stats.backup(1, NULL::regclass, NULL);
1480  backup 
1481 --------
1482       1
1483 (1 row)
1484
1485 SELECT relid::regclass FROM dbms_stats.relation_stats_backup
1486  GROUP BY relid
1487  ORDER BY relid;
1488    relid    
1489 ------------
1490  pt0
1491  pt0_idx
1492  st0
1493  st0_idx
1494  st1
1495  s0.st0
1496  s0.st0_idx
1497  s0.st1
1498  s0.st1_idx
1499  s0.st2
1500  s0.st2_idx
1501  s1.st0
1502  st1_idx
1503  st1_exp
1504  s0.sft0
1505  s0.smv0
1506 (16 rows)
1507
1508 SELECT starelid::regclass, staattnum FROM dbms_stats.column_stats_backup
1509  GROUP BY starelid, staattnum
1510  ORDER BY starelid, staattnum;
1511  starelid | staattnum 
1512 ----------+-----------
1513  st0      |         1
1514  st0      |         2
1515  st1      |         1
1516  st1      |         2
1517  s0.st0   |         1
1518  s0.st0   |         2
1519  s0.st1   |         1
1520  s0.st1   |         2
1521  s0.st2   |         1
1522  s0.st2   |         2
1523  s1.st0   |         1
1524  s1.st0   |         2
1525  st1_exp  |         1
1526  s0.sft0  |         1
1527  s0.smv0  |         1
1528  s0.smv0  |         2
1529  s0.smv0  |         3
1530 (17 rows)
1531
1532 -- No.7-1-18
1533 DELETE FROM dbms_stats.relation_stats_backup;
1534 \! psql contrib_regression -c "SELECT dbms_stats.backup(NULL, 's0.st0'::regclass, NULL)" > results/ut_no2_1_17.out 2>&1
1535 SELECT count(*) FROM dbms_stats.relation_stats_backup;
1536  count 
1537 -------
1538      0
1539 (1 row)
1540
1541 SELECT count(*) FROM dbms_stats.column_stats_backup;
1542  count 
1543 -------
1544      0
1545 (1 row)
1546
1547 /*
1548  * No.8-1 dbms_stats.backup
1549  */
1550 SELECT setval('dbms_stats.backup_history_id_seq',1, false);
1551  setval 
1552 --------
1553       1
1554 (1 row)
1555
1556 /*
1557  * Stab function dbms_stats.backup
1558  */
1559 ALTER FUNCTION dbms_stats.backup(
1560     backup_id int8,
1561     relid regclass,
1562     attnum int2)
1563     RENAME TO truth_func_backup;
1564 CREATE OR REPLACE FUNCTION dbms_stats.backup(
1565     backup_id int8,
1566     regclass,
1567     attnum int2)
1568 RETURNS int8 AS
1569 $$
1570 BEGIN
1571     RAISE NOTICE 'arguments are %, %, %', $1, $2, $3;
1572     RETURN 1;
1573 END;
1574 $$
1575 LANGUAGE plpgsql;
1576 -- No.8-1-1
1577 DELETE FROM dbms_stats.backup_history;
1578 SELECT dbms_stats.backup('s0.st0'::regclass, 'id', 'dummy comment');
1579 NOTICE:  arguments are 1, s0.st0, 1
1580  backup 
1581 --------
1582       1
1583 (1 row)
1584
1585 SELECT id, unit, comment FROM dbms_stats.backup_history;
1586  id | unit |    comment    
1587 ----+------+---------------
1588   1 | c    | dummy comment
1589 (1 row)
1590
1591 -- No.8-1-2
1592 DELETE FROM dbms_stats.backup_history;
1593 SELECT dbms_stats.backup('s0.st0'::regclass, NULL, 'dummy comment');
1594 NOTICE:  arguments are 2, s0.st0, <NULL>
1595  backup 
1596 --------
1597       1
1598 (1 row)
1599
1600 SELECT id, unit, comment FROM dbms_stats.backup_history;
1601  id | unit |    comment    
1602 ----+------+---------------
1603   2 | t    | dummy comment
1604 (1 row)
1605
1606 -- No.8-1-3
1607 DELETE FROM dbms_stats.backup_history;
1608 SELECT dbms_stats.backup(NULL::regclass, 'id', 'dummy comment');
1609 ERROR:  relation required
1610 CONTEXT:  PL/pgSQL function dbms_stats.backup(regclass,text,text) line 9 at RAISE
1611 SELECT id, unit, comment FROM dbms_stats.backup_history;
1612  id | unit | comment 
1613 ----+------+---------
1614 (0 rows)
1615
1616 -- No.8-1-4
1617 DELETE FROM dbms_stats.backup_history;
1618 SELECT dbms_stats.backup(NULL::regclass, NULL, 'dummy comment');
1619 NOTICE:  arguments are 3, <NULL>, <NULL>
1620  backup 
1621 --------
1622       1
1623 (1 row)
1624
1625 SELECT id, unit, comment FROM dbms_stats.backup_history;
1626  id | unit |    comment    
1627 ----+------+---------------
1628   3 | d    | dummy comment
1629 (1 row)
1630
1631 -- No.8-1-5
1632 DELETE FROM dbms_stats.backup_history;
1633 SELECT dbms_stats.backup(0, NULL, 'dummy comment');
1634 ERROR:  relation "-" not found
1635 CONTEXT:  PL/pgSQL function dbms_stats.backup(regclass,text,text) line 15 at RAISE
1636 SELECT id, unit, comment FROM dbms_stats.backup_history;
1637  id | unit | comment 
1638 ----+------+---------
1639 (0 rows)
1640
1641 -- No.8-1-6
1642 DELETE FROM dbms_stats.backup_history;
1643 SELECT dbms_stats.backup('s0.st0'::regclass, NULL, 'dummy comment');
1644 NOTICE:  arguments are 4, s0.st0, <NULL>
1645  backup 
1646 --------
1647       1
1648 (1 row)
1649
1650 SELECT id, unit, comment FROM dbms_stats.backup_history;
1651  id | unit |    comment    
1652 ----+------+---------------
1653   4 | t    | dummy comment
1654 (1 row)
1655
1656 -- No.8-1-7
1657 DELETE FROM dbms_stats.backup_history;
1658 SELECT dbms_stats.backup(
1659     'pg_toast.pg_toast_2618'::regclass,
1660     NULL,
1661     'dummy comment');
1662 ERROR:  relation of relkind "t" cannot have statistics to backup: "pg_toast.pg_toast_2618"
1663 HINT:  Only tables(r), materialized views(m), foreign tables(f) and indexes(i) are allowed.
1664 CONTEXT:  PL/pgSQL function dbms_stats.backup(regclass,text,text) line 18 at RAISE
1665 SELECT id, unit, comment FROM dbms_stats.backup_history;
1666  id | unit | comment 
1667 ----+------+---------
1668 (0 rows)
1669
1670 -- No.8-1-8
1671 DELETE FROM dbms_stats.backup_history;
1672 SELECT dbms_stats.backup('s0.st0_idx'::regclass, NULL, 'dummy comment');
1673 NOTICE:  arguments are 5, s0.st0_idx, <NULL>
1674  backup 
1675 --------
1676       1
1677 (1 row)
1678
1679 SELECT id, unit, comment FROM dbms_stats.backup_history;
1680  id | unit |    comment    
1681 ----+------+---------------
1682   5 | t    | dummy comment
1683 (1 row)
1684
1685 -- No.8-1-9
1686 DELETE FROM dbms_stats.backup_history;
1687 SELECT dbms_stats.backup('s0.ss0'::regclass, NULL, 'dummy comment');
1688 ERROR:  relation of relkind "S" cannot have statistics to backup: "s0.ss0"
1689 HINT:  Only tables(r), materialized views(m), foreign tables(f) and indexes(i) are allowed.
1690 CONTEXT:  PL/pgSQL function dbms_stats.backup(regclass,text,text) line 18 at RAISE
1691 SELECT id, unit, comment FROM dbms_stats.backup_history;
1692  id | unit | comment 
1693 ----+------+---------
1694 (0 rows)
1695
1696 -- No.8-1-10
1697 DELETE FROM dbms_stats.backup_history;
1698 SELECT dbms_stats.backup('s0.sc0'::regclass, NULL, 'dummy comment');
1699 ERROR:  relation of relkind "c" cannot have statistics to backup: "s0.sc0"
1700 HINT:  Only tables(r), materialized views(m), foreign tables(f) and indexes(i) are allowed.
1701 CONTEXT:  PL/pgSQL function dbms_stats.backup(regclass,text,text) line 18 at RAISE
1702 SELECT id, unit, comment FROM dbms_stats.backup_history;
1703  id | unit | comment 
1704 ----+------+---------
1705 (0 rows)
1706
1707 -- No.8-1-11
1708 DELETE FROM dbms_stats.backup_history;
1709 SELECT dbms_stats.backup('s0.sft0'::regclass, NULL, 'dummy comment');
1710 NOTICE:  arguments are 6, s0.sft0, <NULL>
1711  backup 
1712 --------
1713       1
1714 (1 row)
1715
1716 SELECT id, unit, comment FROM dbms_stats.backup_history;
1717  id | unit |    comment    
1718 ----+------+---------------
1719   6 | t    | dummy comment
1720 (1 row)
1721
1722 -- No.8-1-12
1723 DELETE FROM dbms_stats.backup_history;
1724 SELECT dbms_stats.backup('s0.smv0'::regclass, NULL, 'dummy comment');
1725 NOTICE:  arguments are 7, s0.smv0, <NULL>
1726  backup 
1727 --------
1728       1
1729 (1 row)
1730
1731 SELECT id, unit, comment FROM dbms_stats.backup_history;
1732  id | unit |    comment    
1733 ----+------+---------------
1734   7 | t    | dummy comment
1735 (1 row)
1736
1737 -- No.8-1-13
1738 DELETE FROM dbms_stats.backup_history;
1739 SELECT dbms_stats.backup('pg_catalog.pg_class'::regclass, NULL, 'dummy comment');
1740 ERROR:  backing up statistics is inhibited for system catalogs: "pg_class"
1741 CONTEXT:  PL/pgSQL function dbms_stats.backup(regclass,text,text) line 23 at RAISE
1742 SELECT id, unit, comment FROM dbms_stats.backup_history;
1743  id | unit | comment 
1744 ----+------+---------
1745 (0 rows)
1746
1747 -- No.8-1-14
1748 DELETE FROM dbms_stats.backup_history;
1749 SELECT dbms_stats.backup('s0.st0'::regclass, 'dummy', 'dummy comment');
1750 ERROR:  column "dummy" not found in relation "s0.st0"
1751 CONTEXT:  PL/pgSQL function dbms_stats.backup(regclass,text,text) line 29 at RAISE
1752 SELECT id, unit, comment FROM dbms_stats.backup_history;
1753  id | unit | comment 
1754 ----+------+---------
1755 (0 rows)
1756
1757 -- No.8-1-15
1758 DELETE FROM dbms_stats.backup_history;
1759 DELETE FROM pg_statistic
1760  WHERE starelid = 's0.st0'::regclass
1761    AND staattnum = 1::int2;
1762 SELECT count(*) FROM dbms_stats.column_stats_effective
1763  WHERE starelid = 's0.st0'::regclass
1764    AND staattnum = 1::int2;
1765  count 
1766 -------
1767      0
1768 (1 row)
1769
1770 SELECT dbms_stats.backup('s0.st0'::regclass, 'id', 'dummy comment');
1771 ERROR:  no statistics available for column "id" of relation "s0.st0"
1772 CONTEXT:  PL/pgSQL function dbms_stats.backup(regclass,text,text) line 32 at RAISE
1773 SELECT id, unit, comment FROM dbms_stats.backup_history;
1774  id | unit | comment 
1775 ----+------+---------
1776 (0 rows)
1777
1778 /*
1779  * Stab function dbms_stats.backup
1780  */
1781 ALTER FUNCTION dbms_stats.backup(
1782     relid regclass,
1783     attname text,
1784     comment text)
1785     RENAME TO truth_func_backup;
1786 CREATE OR REPLACE FUNCTION dbms_stats.backup(
1787     relid regclass DEFAULT NULL,
1788     attname text DEFAULT NULL,
1789     comment text DEFAULT NULL)
1790 RETURNS int8 AS
1791 $$
1792 BEGIN
1793     IF $3 = '<NULL>' THEN
1794         RAISE NOTICE 'third argument is not NULL but string "<NULL>"';
1795     END IF;
1796     RAISE NOTICE 'arguments are %, %, %', $1, $2, $3;
1797     RETURN 1;
1798 END;
1799 $$
1800 LANGUAGE plpgsql;
1801 /*
1802  * No.8-3 dbms_stats.backup_schema_stats
1803  */
1804 SELECT setval('dbms_stats.backup_history_id_seq',9, false);
1805  setval 
1806 --------
1807       9
1808 (1 row)
1809
1810 -- No.8-3-1
1811 SELECT dbms_stats.backup_schema_stats('s0', 'comment');
1812 NOTICE:  arguments are 9, s0.st0, <NULL>
1813 NOTICE:  arguments are 9, s0.st0_idx, <NULL>
1814 NOTICE:  arguments are 9, s0.st1, <NULL>
1815 NOTICE:  arguments are 9, s0.st1_idx, <NULL>
1816 NOTICE:  arguments are 9, s0.st2, <NULL>
1817 NOTICE:  arguments are 9, s0.st2_idx, <NULL>
1818 NOTICE:  arguments are 9, s0.sft0, <NULL>
1819 NOTICE:  arguments are 9, s0.smv0, <NULL>
1820  backup_schema_stats 
1821 ---------------------
1822                    9
1823 (1 row)
1824
1825 SELECT id, unit, comment FROM dbms_stats.backup_history
1826  ORDER BY id DESC
1827  LIMIT 1;
1828  id | unit | comment 
1829 ----+------+---------
1830   9 | s    | comment
1831 (1 row)
1832
1833 -- No.8-3-2
1834 SELECT dbms_stats.backup_schema_stats('s00', 'comment');
1835 ERROR:  schema "s00" not found
1836 CONTEXT:  PL/pgSQL function dbms_stats.backup_schema_stats(text,text) line 7 at RAISE
1837 SELECT id, unit, comment FROM dbms_stats.backup_history
1838  ORDER BY id DESC
1839  LIMIT 1;
1840  id | unit | comment 
1841 ----+------+---------
1842   9 | s    | comment
1843 (1 row)
1844
1845 -- No.8-3-3
1846 SELECT dbms_stats.backup_schema_stats('pg_catalog', 'comment');
1847 ERROR:  backing up statistics is inhibited for system schemas: "pg_catalog"
1848 CONTEXT:  PL/pgSQL function dbms_stats.backup_schema_stats(text,text) line 10 at RAISE
1849 SELECT id, unit, comment FROM dbms_stats.backup_history
1850  ORDER BY id DESC
1851  LIMIT 1;
1852  id | unit | comment 
1853 ----+------+---------
1854   9 | s    | comment
1855 (1 row)
1856
1857 /*
1858  * Delete stab function dbms_stats.backup
1859  */
1860 DROP FUNCTION dbms_stats.backup(
1861     backup_id int8,
1862     regclass,
1863     attnum int2);
1864 ALTER FUNCTION dbms_stats.truth_func_backup(
1865     backup_id int8,
1866     regclass,
1867     attnum int2)
1868     RENAME TO backup;
1869 DROP FUNCTION dbms_stats.backup(
1870     regclass,
1871     attname text,
1872     comment text);
1873 ALTER FUNCTION dbms_stats.truth_func_backup(
1874     regclass,
1875     attname text,
1876     comment text)
1877     RENAME TO backup;
1878 VACUUM ANALYZE;
1879 /*
1880  * create backup statistics state A
1881  */
1882 DELETE FROM dbms_stats.backup_history;
1883 INSERT INTO dbms_stats.backup_history(id, time, unit)
1884     VALUES (1, '2012-02-29 23:59:56.999999', 'd');
1885 SELECT setval('dbms_stats.backup_history_id_seq',1);
1886  setval 
1887 --------
1888       1
1889 (1 row)
1890
1891 SELECT dbms_stats.backup();
1892  backup 
1893 --------
1894       2
1895 (1 row)
1896
1897 UPDATE dbms_stats.backup_history
1898    SET time = '2012-02-29 23:59:57'
1899  WHERE id = 2;
1900 SELECT dbms_stats.backup('s0.st0');
1901  backup 
1902 --------
1903       3
1904 (1 row)
1905
1906 UPDATE dbms_stats.backup_history
1907    SET time = '2012-02-29 23:59:57.000001'
1908  WHERE id = 3;
1909 SELECT dbms_stats.backup();
1910  backup 
1911 --------
1912       4
1913 (1 row)
1914
1915 UPDATE dbms_stats.backup_history
1916    SET time = '2012-02-29 23:59:58'
1917  WHERE id = 4;
1918 DELETE FROM dbms_stats.relation_stats_backup
1919  WHERE id = 4;
1920 SELECT dbms_stats.backup('s0.st0', 'id');
1921  backup 
1922 --------
1923       5
1924 (1 row)
1925
1926 UPDATE dbms_stats.backup_history
1927    SET time = '2012-03-01 00:00:00'
1928  WHERE id = 5;
1929 SELECT dbms_stats.backup('s0.st0');
1930  backup 
1931 --------
1932       6
1933 (1 row)
1934
1935 UPDATE dbms_stats.backup_history
1936    SET time = '2012-03-01 00:00:02'
1937  WHERE id = 6;
1938 SELECT dbms_stats.backup('public.st0');
1939  backup 
1940 --------
1941       7
1942 (1 row)
1943
1944 UPDATE dbms_stats.backup_history
1945    SET time = '2012-03-01 00:00:04'
1946  WHERE id = 7;
1947 INSERT INTO dbms_stats.backup_history(time, unit)
1948     VALUES ('2012-03-01 00:00:06', 's');
1949 SELECT dbms_stats.backup(8, c.oid, NULL)
1950   FROM pg_catalog.pg_class c,
1951        pg_catalog.pg_namespace n
1952  WHERE n.nspname = 's0'
1953    AND c.relnamespace = n.oid
1954    AND c.relkind IN ('r', 'i');
1955  backup 
1956 --------
1957       8
1958       8
1959       8
1960       8
1961       8
1962       8
1963 (6 rows)
1964
1965 SELECT * FROM dbms_stats.backup_history
1966  ORDER BY id;
1967  id |                time                 | unit | comment 
1968 ----+-------------------------------------+------+---------
1969   1 | Wed Feb 29 23:59:56.999999 2012 PST | d    | (null)
1970   2 | Wed Feb 29 23:59:57 2012 PST        | d    | (null)
1971   3 | Wed Feb 29 23:59:57.000001 2012 PST | t    | (null)
1972   4 | Wed Feb 29 23:59:58 2012 PST        | d    | (null)
1973   5 | Thu Mar 01 00:00:00 2012 PST        | c    | (null)
1974   6 | Thu Mar 01 00:00:02 2012 PST        | t    | (null)
1975   7 | Thu Mar 01 00:00:04 2012 PST        | t    | (null)
1976   8 | Thu Mar 01 00:00:06 2012 PST        | s    | (null)
1977 (8 rows)
1978
1979 SELECT * FROM relations_backup_v;
1980  id |   relid    |    relname     | relpages | reltuples | relallvisible | curpages 
1981 ----+------------+----------------+----------+-----------+---------------+----------
1982   2 | pt0        | public.pt0     |        0 |         0 |             0 |        0
1983   2 | pt0_idx    | public.pt0_idx |        2 |         0 |             0 |        2
1984   2 | st0        | public.st0     |        1 |         2 |             1 |        1
1985   2 | st0_idx    | public.st0_idx |        2 |         2 |             0 |        2
1986   2 | st1        | public.st1     |       45 |     10000 |            45 |       45
1987   2 | s0.st0     | s0.st0         |        1 |         2 |             1 |        1
1988   2 | s0.st0_idx | s0.st0_idx     |        2 |         2 |             0 |        2
1989   2 | s0.st1     | s0.st1         |        1 |         3 |             1 |        1
1990   2 | s0.st1_idx | s0.st1_idx     |        2 |         3 |             0 |        2
1991   2 | s0.st2     | s0.st2         |        1 |         3 |             1 |        1
1992   2 | s0.st2_idx | s0.st2_idx     |        2 |         3 |             0 |        2
1993   2 | s1.st0     | s1.st0         |        1 |         4 |             1 |        1
1994   2 | st1_idx    | public.st1_idx |       30 |     10000 |             0 |       30
1995   2 | st1_exp    | public.st1_exp |       30 |     10000 |             0 |       30
1996   2 | s0.sft0    | s0.sft0        |        1 |        10 |             0 |        0
1997   2 | s0.smv0    | s0.smv0        |        1 |         2 |             1 |        1
1998   3 | s0.st0     | s0.st0         |        1 |         2 |             1 |        1
1999   5 | s0.st0     | s0.st0         |        1 |         2 |             1 |        1
2000   6 | s0.st0     | s0.st0         |        1 |         2 |             1 |        1
2001   7 | st0        | public.st0     |        1 |         2 |             1 |        1
2002   8 | s0.st0     | s0.st0         |        1 |         2 |             1 |        1
2003   8 | s0.st0_idx | s0.st0_idx     |        2 |         2 |             0 |        2
2004   8 | s0.st1     | s0.st1         |        1 |         3 |             1 |        1
2005   8 | s0.st1_idx | s0.st1_idx     |        2 |         3 |             0 |        2
2006   8 | s0.st2     | s0.st2         |        1 |         3 |             1 |        1
2007   8 | s0.st2_idx | s0.st2_idx     |        2 |         3 |             0 |        2
2008 (26 rows)
2009
2010 SELECT * FROM columns_backup_v;
2011  id | statypid | starelid | staattnum | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 |      stanumbers1       | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 |       stavalues1       | stavalues2 | stavalues3 | stavalues4 | stavalues5 
2012 ----+----------+----------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+------------------------+-------------+-------------+-------------+-------------+------------------------+------------+------------+------------+------------
2013   2 |       23 | st0      |         1 | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)                 | {1}         | (null)      | (null)      | (null)      | {1,2}                  | (null)     | (null)     | (null)     | (null)
2014   2 |     1042 | st0      |         2 | f          |           0 |        6 |        -0.5 |        1 |        3 |        0 |        0 |        0 |   1054 |   1058 |      0 |      0 |      0 | {1}                    | {1}         | (null)      | (null)      | (null)      | {"test "}              | (null)     | (null)     | (null)     | (null)
2015   2 |       23 | st1      |         1 | f          |           0 |        4 |           3 |        1 |        3 |        0 |        0 |        0 |     96 |     97 |      0 |      0 |      0 | {0.3334,0.3333,0.3333} | {0.3332}    | (null)      | (null)      | (null)      | {1,0,2}                | (null)     | (null)     | (null)     | (null)
2016   2 |       25 | st1      |         2 | f          |           0 |        2 |           3 |        1 |        3 |        0 |        0 |        0 |     98 |    664 |      0 |      0 |      0 | {0.3334,0.3333,0.3333} | {0.3332}    | (null)      | (null)      | (null)      | {1,0,2}                | (null)     | (null)     | (null)     | (null)
2017   2 |       23 | s0.st0   |         1 | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)                 | {1}         | (null)      | (null)      | (null)      | {1,2}                  | (null)     | (null)     | (null)     | (null)
2018   2 |       23 | s0.st0   |         1 | t          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)                 | {1}         | (null)      | (null)      | (null)      | {1,2,4,5,6}            | (null)     | (null)     | (null)     | (null)
2019   2 |       23 | s0.st0   |         2 | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)                 | {1}         | (null)      | (null)      | (null)      | {10,20}                | (null)     | (null)     | (null)     | (null)
2020   2 |       23 | s0.st0   |         2 | t          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)                 | {1}         | (null)      | (null)      | (null)      | {10,20,40,50,60}       | (null)     | (null)     | (null)     | (null)
2021   2 |       23 | s0.st1   |         1 | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)                 | {1}         | (null)      | (null)      | (null)      | {4,5,6}                | (null)     | (null)     | (null)     | (null)
2022   2 |       23 | s0.st1   |         2 | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)                 | {1}         | (null)      | (null)      | (null)      | {40,50,60}             | (null)     | (null)     | (null)     | (null)
2023   2 |       23 | s0.st2   |         1 | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)                 | {1}         | (null)      | (null)      | (null)      | {1,2,3}                | (null)     | (null)     | (null)     | (null)
2024   2 |       25 | s0.st2   |         2 | f          |           0 |        5 |          -1 |        2 |        3 |        0 |        0 |        0 |    664 |    664 |      0 |      0 |      0 | (null)                 | {0.5}       | (null)      | (null)      | (null)      | {1,comment,test}       | (null)     | (null)     | (null)     | (null)
2025   2 |       23 | s1.st0   |         1 | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)                 | {1}         | (null)      | (null)      | (null)      | {1,2,3,4}              | (null)     | (null)     | (null)     | (null)
2026   2 |       23 | s1.st0   |         2 | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)                 | {1}         | (null)      | (null)      | (null)      | {15,25,35,45}          | (null)     | (null)     | (null)     | (null)
2027   2 |       25 | st1_exp  |         1 | f          |           0 |        5 |           3 |        1 |        3 |        0 |        0 |        0 |     98 |    664 |      0 |      0 |      0 | {0.3334,0.3333,0.3333} | {0.3332}    | (null)      | (null)      | (null)      | {1,0,2}                | (null)     | (null)     | (null)     | (null)
2028   2 |       23 | s0.sft0  |         1 | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)                 | {1}         | (null)      | (null)      | (null)      | {1,2,3,4,5,6,7,8,9,10} | (null)     | (null)     | (null)     | (null)
2029   2 |       23 | s0.smv0  |         1 | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)                 | {1}         | (null)      | (null)      | (null)      | {1,2}                  | (null)     | (null)     | (null)     | (null)
2030   2 |       23 | s0.smv0  |         2 | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)                 | {1}         | (null)      | (null)      | (null)      | {10,20}                | (null)     | (null)     | (null)     | (null)
2031   2 |       25 | s0.smv0  |         3 | f          |           0 |        3 |          -1 |        2 |        3 |        0 |        0 |        0 |    664 |    664 |      0 |      0 |      0 | (null)                 | {1}         | (null)      | (null)      | (null)      | {1,test}               | (null)     | (null)     | (null)     | (null)
2032   3 |       23 | s0.st0   |         1 | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)                 | {1}         | (null)      | (null)      | (null)      | {1,2}                  | (null)     | (null)     | (null)     | (null)
2033   3 |       23 | s0.st0   |         1 | t          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)                 | {1}         | (null)      | (null)      | (null)      | {1,2,4,5,6}            | (null)     | (null)     | (null)     | (null)
2034   3 |       23 | s0.st0   |         2 | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)                 | {1}         | (null)      | (null)      | (null)      | {10,20}                | (null)     | (null)     | (null)     | (null)
2035   3 |       23 | s0.st0   |         2 | t          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)                 | {1}         | (null)      | (null)      | (null)      | {10,20,40,50,60}       | (null)     | (null)     | (null)     | (null)
2036   5 |       23 | s0.st0   |         1 | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)                 | {1}         | (null)      | (null)      | (null)      | {1,2}                  | (null)     | (null)     | (null)     | (null)
2037   5 |       23 | s0.st0   |         1 | t          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)                 | {1}         | (null)      | (null)      | (null)      | {1,2,4,5,6}            | (null)     | (null)     | (null)     | (null)
2038   6 |       23 | s0.st0   |         1 | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)                 | {1}         | (null)      | (null)      | (null)      | {1,2}                  | (null)     | (null)     | (null)     | (null)
2039   6 |       23 | s0.st0   |         1 | t          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)                 | {1}         | (null)      | (null)      | (null)      | {1,2,4,5,6}            | (null)     | (null)     | (null)     | (null)
2040   6 |       23 | s0.st0   |         2 | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)                 | {1}         | (null)      | (null)      | (null)      | {10,20}                | (null)     | (null)     | (null)     | (null)
2041   6 |       23 | s0.st0   |         2 | t          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)                 | {1}         | (null)      | (null)      | (null)      | {10,20,40,50,60}       | (null)     | (null)     | (null)     | (null)
2042   7 |       23 | st0      |         1 | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)                 | {1}         | (null)      | (null)      | (null)      | {1,2}                  | (null)     | (null)     | (null)     | (null)
2043   7 |     1042 | st0      |         2 | f          |           0 |        6 |        -0.5 |        1 |        3 |        0 |        0 |        0 |   1054 |   1058 |      0 |      0 |      0 | {1}                    | {1}         | (null)      | (null)      | (null)      | {"test "}              | (null)     | (null)     | (null)     | (null)
2044   8 |       23 | s0.st0   |         1 | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)                 | {1}         | (null)      | (null)      | (null)      | {1,2}                  | (null)     | (null)     | (null)     | (null)
2045   8 |       23 | s0.st0   |         1 | t          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)                 | {1}         | (null)      | (null)      | (null)      | {1,2,4,5,6}            | (null)     | (null)     | (null)     | (null)
2046   8 |       23 | s0.st0   |         2 | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)                 | {1}         | (null)      | (null)      | (null)      | {10,20}                | (null)     | (null)     | (null)     | (null)
2047   8 |       23 | s0.st0   |         2 | t          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)                 | {1}         | (null)      | (null)      | (null)      | {10,20,40,50,60}       | (null)     | (null)     | (null)     | (null)
2048   8 |       23 | s0.st1   |         1 | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)                 | {1}         | (null)      | (null)      | (null)      | {4,5,6}                | (null)     | (null)     | (null)     | (null)
2049   8 |       23 | s0.st1   |         2 | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)                 | {1}         | (null)      | (null)      | (null)      | {40,50,60}             | (null)     | (null)     | (null)     | (null)
2050   8 |       23 | s0.st2   |         1 | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)                 | {1}         | (null)      | (null)      | (null)      | {1,2,3}                | (null)     | (null)     | (null)     | (null)
2051   8 |       25 | s0.st2   |         2 | f          |           0 |        5 |          -1 |        2 |        3 |        0 |        0 |        0 |    664 |    664 |      0 |      0 |      0 | (null)                 | {0.5}       | (null)      | (null)      | (null)      | {1,comment,test}       | (null)     | (null)     | (null)     | (null)
2052 (39 rows)
2053
2054 VACUUM ANALYZE;
2055 /*
2056  * No.9-1 dbms_stats.restore
2057  */
2058 -- No.9-1-1
2059 DELETE FROM dbms_stats.relation_stats_locked;
2060 VACUUM dbms_stats.relation_stats_locked;  -- in order to avoid auto vacuum
2061 BEGIN;
2062 SELECT * FROM internal_locks;
2063  relation | mode 
2064 ----------+------
2065 (0 rows)
2066
2067 SELECT dbms_stats.restore(2, 's0.st0', NULL);
2068  restore 
2069 ---------
2070  s0.st0
2071 (1 row)
2072
2073 SELECT * FROM internal_locks;
2074              relation             |       mode       
2075 ----------------------------------+------------------
2076  dbms_stats.backup_history        | RowShareLock
2077  dbms_stats.column_stats_backup   | AccessShareLock
2078  dbms_stats.column_stats_locked   | RowExclusiveLock
2079  dbms_stats.relation_stats_backup | AccessShareLock
2080  dbms_stats.relation_stats_backup | RowShareLock
2081  dbms_stats.relation_stats_locked | RowExclusiveLock
2082  dbms_stats.relation_stats_locked | RowShareLock
2083 (7 rows)
2084
2085 COMMIT;
2086 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
2087  GROUP BY relid
2088  ORDER BY relid;
2089  relid  
2090 --------
2091  s0.st0
2092 (1 row)
2093
2094 SELECT starelid, attname, stainherit FROM columns_locked_v c;
2095  starelid | attname | stainherit 
2096 ----------+---------+------------
2097  s0.st0   | id      | f
2098  s0.st0   | id      | t
2099  s0.st0   | num     | f
2100  s0.st0   | num     | t
2101 (4 rows)
2102
2103 -- No.9-1-2
2104 DELETE FROM dbms_stats.relation_stats_locked;
2105 SELECT dbms_stats.restore(2, 'st0', NULL);
2106  restore 
2107 ---------
2108  st0
2109 (1 row)
2110
2111 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
2112  GROUP BY relid
2113  ORDER BY relid;
2114  relid 
2115 -------
2116  st0
2117 (1 row)
2118
2119 SELECT starelid, attname, stainherit FROM columns_locked_v c;
2120  starelid | attname | stainherit 
2121 ----------+---------+------------
2122  st0      | id      | f
2123  st0      | name    | f
2124 (2 rows)
2125
2126 -- No.9-1-3
2127 DELETE FROM dbms_stats.relation_stats_locked;
2128 SELECT dbms_stats.restore(2, 's00.s0', NULL);
2129 ERROR:  schema "s00" does not exist
2130 LINE 1: SELECT dbms_stats.restore(2, 's00.s0', NULL);
2131                                      ^
2132 SELECT count(*) FROM dbms_stats.column_stats_locked;
2133  count 
2134 -------
2135      0
2136 (1 row)
2137
2138 SELECT count(*) FROM dbms_stats.relation_stats_locked;
2139  count 
2140 -------
2141      0
2142 (1 row)
2143
2144 -- No.9-1-4
2145 DELETE FROM dbms_stats.relation_stats_locked;
2146 SELECT dbms_stats.restore(NULL, 's0.st0', NULL);
2147 ERROR:  backup id required
2148 CONTEXT:  PL/pgSQL function dbms_stats.restore(bigint,regclass,text) line 12 at RAISE
2149 SELECT count(*) FROM dbms_stats.column_stats_locked;
2150  count 
2151 -------
2152      0
2153 (1 row)
2154
2155 SELECT count(*) FROM dbms_stats.relation_stats_locked;
2156  count 
2157 -------
2158      0
2159 (1 row)
2160
2161 -- No.9-1-5
2162 DELETE FROM dbms_stats.relation_stats_locked;
2163 SELECT dbms_stats.restore(2, 's0.st0', 'id');
2164  restore 
2165 ---------
2166  s0.st0
2167 (1 row)
2168
2169 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
2170  GROUP BY relid
2171  ORDER BY relid;
2172  relid  
2173 --------
2174  s0.st0
2175 (1 row)
2176
2177 SELECT starelid, attname, stainherit FROM columns_locked_v c;
2178  starelid | attname | stainherit 
2179 ----------+---------+------------
2180  s0.st0   | id      | f
2181  s0.st0   | id      | t
2182 (2 rows)
2183
2184 -- No.9-1-6
2185 DELETE FROM dbms_stats.relation_stats_locked;
2186 SELECT dbms_stats.restore(2, NULL, 'id');
2187 ERROR:  relation required
2188 CONTEXT:  PL/pgSQL function dbms_stats.restore(bigint,regclass,text) line 15 at RAISE
2189 SELECT count(*) FROM dbms_stats.column_stats_locked;
2190  count 
2191 -------
2192      0
2193 (1 row)
2194
2195 SELECT count(*) FROM dbms_stats.relation_stats_locked;
2196  count 
2197 -------
2198      0
2199 (1 row)
2200
2201 -- No.9-1-7
2202 DELETE FROM dbms_stats.relation_stats_locked;
2203 SELECT dbms_stats.restore(2, 's0.st0', NULL);
2204  restore 
2205 ---------
2206  s0.st0
2207 (1 row)
2208
2209 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
2210  GROUP BY relid
2211  ORDER BY relid;
2212  relid  
2213 --------
2214  s0.st0
2215 (1 row)
2216
2217 SELECT starelid, attname, stainherit FROM columns_locked_v c;
2218  starelid | attname | stainherit 
2219 ----------+---------+------------
2220  s0.st0   | id      | f
2221  s0.st0   | id      | t
2222  s0.st0   | num     | f
2223  s0.st0   | num     | t
2224 (4 rows)
2225
2226 -- No.9-1-8
2227 DELETE FROM dbms_stats.relation_stats_locked;
2228 SELECT dbms_stats.restore(2, NULL, NULL);
2229   restore   
2230 ------------
2231  pt0
2232  pt0_idx
2233  s0.sft0
2234  s0.smv0
2235  s0.st0
2236  s0.st0_idx
2237  s0.st1
2238  s0.st1_idx
2239  s0.st2
2240  s0.st2_idx
2241  s1.st0
2242  st0
2243  st0_idx
2244  st1
2245  st1_exp
2246  st1_idx
2247 (16 rows)
2248
2249 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
2250  GROUP BY relid
2251  ORDER BY relid;
2252    relid    
2253 ------------
2254  pt0
2255  pt0_idx
2256  st0
2257  st0_idx
2258  st1
2259  s0.st0
2260  s0.st0_idx
2261  s0.st1
2262  s0.st1_idx
2263  s0.st2
2264  s0.st2_idx
2265  s1.st0
2266  st1_idx
2267  st1_exp
2268  s0.sft0
2269  s0.smv0
2270 (16 rows)
2271
2272 SELECT starelid, attname, stainherit FROM columns_locked_v c;
2273  starelid | attname | stainherit 
2274 ----------+---------+------------
2275  st0      | id      | f
2276  st0      | name    | f
2277  st1      | val     | f
2278  st1      | str     | f
2279  s0.st0   | id      | f
2280  s0.st0   | id      | t
2281  s0.st0   | num     | f
2282  s0.st0   | num     | t
2283  s0.st1   | id      | f
2284  s0.st1   | num     | f
2285  s0.st2   | id      | f
2286  s0.st2   | txt     | f
2287  s1.st0   | id      | f
2288  s1.st0   | num     | f
2289  st1_exp  | lower   | f
2290  s0.sft0  | id      | f
2291  s0.smv0  | id      | f
2292  s0.smv0  | num     | f
2293  s0.smv0  | txt     | f
2294 (19 rows)
2295
2296 -- No.9-1-9
2297 DELETE FROM dbms_stats.relation_stats_locked;
2298 SELECT dbms_stats.restore(0, 's0.st0', NULL);
2299 ERROR:  backup id 0 not found
2300 CONTEXT:  PL/pgSQL function dbms_stats.restore(bigint,regclass,text) line 19 at RAISE
2301 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
2302  GROUP BY relid
2303  ORDER BY relid;
2304  relid 
2305 -------
2306 (0 rows)
2307
2308 SELECT starelid, attname, stainherit FROM columns_locked_v c;
2309  starelid | attname | stainherit 
2310 ----------+---------+------------
2311 (0 rows)
2312
2313 -- No.9-1-10
2314 DELETE FROM dbms_stats.relation_stats_locked;
2315 SELECT dbms_stats.restore(2, 0, 'id');
2316 ERROR:  relation "-" not found
2317 CONTEXT:  PL/pgSQL function dbms_stats.restore(bigint,regclass,text) line 24 at RAISE
2318 SELECT count(*) FROM dbms_stats.column_stats_locked;
2319  count 
2320 -------
2321      0
2322 (1 row)
2323
2324 SELECT count(*) FROM dbms_stats.relation_stats_locked;
2325  count 
2326 -------
2327      0
2328 (1 row)
2329
2330 -- No.9-1-11
2331 DELETE FROM dbms_stats.relation_stats_locked;
2332 SELECT dbms_stats.restore(1, 's0.st0', NULL);
2333 ERROR:  statistics of relation "s0.st0" not found in any backups before backup id = 1
2334 CONTEXT:  PL/pgSQL function dbms_stats.restore(bigint,regclass,text) line 29 at RAISE
2335 SELECT count(*) FROM dbms_stats.column_stats_locked;
2336  count 
2337 -------
2338      0
2339 (1 row)
2340
2341 SELECT count(*) FROM dbms_stats.relation_stats_locked;
2342  count 
2343 -------
2344      0
2345 (1 row)
2346
2347 -- No.9-1-12
2348 DELETE FROM dbms_stats.relation_stats_locked;
2349 SELECT dbms_stats.restore(2, 's0.st0', 'dummy');
2350 ERROR:  column "dummy" not found in relation s0.st0
2351 CONTEXT:  PL/pgSQL function dbms_stats.restore(bigint,regclass,text) line 35 at RAISE
2352 SELECT count(*) FROM dbms_stats.column_stats_locked;
2353  count 
2354 -------
2355      0
2356 (1 row)
2357
2358 SELECT count(*) FROM dbms_stats.relation_stats_locked;
2359  count 
2360 -------
2361      0
2362 (1 row)
2363
2364 -- No.9-1-13
2365 DELETE FROM dbms_stats.relation_stats_locked;
2366 SELECT dbms_stats.restore(1, 's0.st0', 'id');
2367 ERROR:  statistics of relation "s0.st0" not found in any backups before backup id = 1
2368 CONTEXT:  PL/pgSQL function dbms_stats.restore(bigint,regclass,text) line 29 at RAISE
2369 SELECT count(*) FROM dbms_stats.column_stats_locked;
2370  count 
2371 -------
2372      0
2373 (1 row)
2374
2375 SELECT count(*) FROM dbms_stats.relation_stats_locked;
2376  count 
2377 -------
2378      0
2379 (1 row)
2380
2381 -- No.9-1-15
2382 DELETE FROM dbms_stats.relation_stats_locked;
2383 ALTER TABLE s1.st0 DROP COLUMN id;
2384 SELECT dbms_stats.restore(2, 's1.st0', 'id');
2385 ERROR:  column "id" not found in relation s1.st0
2386 CONTEXT:  PL/pgSQL function dbms_stats.restore(bigint,regclass,text) line 35 at RAISE
2387 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
2388  GROUP BY relid
2389  ORDER BY relid;
2390  relid 
2391 -------
2392 (0 rows)
2393
2394 SELECT starelid, attname, stainherit FROM columns_locked_v c;
2395  starelid | attname | stainherit 
2396 ----------+---------+------------
2397 (0 rows)
2398
2399 -- No.9-1-14
2400 DELETE FROM dbms_stats.relation_stats_locked;
2401 \set s1_st0_oid `psql contrib_regression -tA -c "SELECT c.oid FROM pg_class c, pg_namespace n WHERE c.relnamespace = n.oid AND n.nspname = 's1' AND c.relname = 'st0';"`
2402 DROP TABLE s1.st0;
2403 -- SELECT dbms_stats.restore(2, :s1_st0_oid, NULL);
2404 -- To avoid test unstability caused by relation id alloction, the test
2405 -- above is omitted.
2406 SELECT count(*) FROM dbms_stats.relation_stats_locked;
2407  count 
2408 -------
2409      0
2410 (1 row)
2411
2412 SELECT count(*) FROM dbms_stats.column_stats_locked;
2413  count 
2414 -------
2415      0
2416 (1 row)
2417
2418 CREATE TABLE s1.st0(id integer, num integer);
2419 INSERT INTO s1.st0 VALUES (1, 15), (2, 25), (3, 35), (4, 45);
2420 VACUUM ANALYZE;
2421 -- No.9-1-16
2422 DELETE FROM dbms_stats.relation_stats_locked;
2423 SELECT dbms_stats.restore(2, 's0.st0', NULL);
2424  restore 
2425 ---------
2426  s0.st0
2427 (1 row)
2428
2429 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
2430  GROUP BY relid
2431  ORDER BY relid;
2432  relid  
2433 --------
2434  s0.st0
2435 (1 row)
2436
2437 SELECT starelid, attname, stainherit FROM columns_locked_v c;
2438  starelid | attname | stainherit 
2439 ----------+---------+------------
2440  s0.st0   | id      | f
2441  s0.st0   | id      | t
2442  s0.st0   | num     | f
2443  s0.st0   | num     | t
2444 (4 rows)
2445
2446 -- No.9-1-17
2447 DELETE FROM dbms_stats.relation_stats_locked;
2448 INSERT INTO dbms_stats.relation_stats_backup(
2449                id, relid, relname, relpages, reltuples,
2450                relallvisible,
2451                curpages)
2452      VALUES (2,
2453              'pg_toast.pg_toast_2618'::regclass,
2454              'pg_toast.pg_toast_2618', 1, 1,
2455              1,
2456              1);
2457 SELECT * FROM relations_backup_v
2458  WHERE id = 2
2459    AND relname = 'pg_toast.pg_toast_2618';
2460  id |         relid          |        relname         | relpages | reltuples | relallvisible | curpages 
2461 ----+------------------------+------------------------+----------+-----------+---------------+----------
2462   2 | pg_toast.pg_toast_2618 | pg_toast.pg_toast_2618 |        1 |         1 |             1 |        1
2463 (1 row)
2464
2465 SELECT dbms_stats.restore(2, 'pg_toast.pg_toast_2618', NULL);
2466  restore 
2467 ---------
2468 (0 rows)
2469
2470 SELECT count(*) FROM dbms_stats.column_stats_locked;
2471  count 
2472 -------
2473      0
2474 (1 row)
2475
2476 SELECT count(*) FROM dbms_stats.relation_stats_locked;
2477  count 
2478 -------
2479      0
2480 (1 row)
2481
2482 DELETE FROM dbms_stats.relation_stats_backup
2483  WHERE id = 2
2484    AND relname = 'pg_toast.pg_toast_2618';
2485 -- No.9-1-18
2486 DELETE FROM dbms_stats.relation_stats_locked;
2487 SELECT dbms_stats.restore(2, 's0.st0_idx', NULL);
2488   restore   
2489 ------------
2490  s0.st0_idx
2491 (1 row)
2492
2493 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
2494  GROUP BY relid
2495  ORDER BY relid;
2496    relid    
2497 ------------
2498  s0.st0_idx
2499 (1 row)
2500
2501 SELECT starelid, attname, stainherit FROM columns_locked_v c;
2502  starelid | attname | stainherit 
2503 ----------+---------+------------
2504 (0 rows)
2505
2506 -- No.9-1-19
2507 DELETE FROM dbms_stats.relation_stats_locked;
2508 INSERT INTO dbms_stats.relation_stats_backup(
2509                id, relid, relname, relpages, reltuples,
2510                relallvisible,
2511                curpages)
2512      VALUES (2, 's0.ss0'::regclass, 's0.ss0', 1, 1,
2513              1,
2514              1);
2515 SELECT * FROM relations_backup_v
2516  WHERE id = 2
2517    AND relname = 's0.ss0';
2518  id | relid  | relname | relpages | reltuples | relallvisible | curpages 
2519 ----+--------+---------+----------+-----------+---------------+----------
2520   2 | s0.ss0 | s0.ss0  |        1 |         1 |             1 |        1
2521 (1 row)
2522
2523 SELECT dbms_stats.restore(2, 's0.ss0', NULL);
2524  restore 
2525 ---------
2526 (0 rows)
2527
2528 SELECT count(*) FROM dbms_stats.column_stats_locked;
2529  count 
2530 -------
2531      0
2532 (1 row)
2533
2534 SELECT count(*) FROM dbms_stats.relation_stats_locked;
2535  count 
2536 -------
2537      0
2538 (1 row)
2539
2540 DELETE FROM dbms_stats.relation_stats_backup
2541  WHERE id = 2
2542    AND relname = 's0.ss0';
2543 -- No.9-1-20
2544 DELETE FROM dbms_stats.relation_stats_locked;
2545 INSERT INTO dbms_stats.relation_stats_backup(
2546                id, relid, relname, relpages, reltuples,
2547                relallvisible,
2548                curpages)
2549      VALUES (2, 's0.sc0'::regclass, 's0.sc0', 1, 1,
2550              1,
2551              1);
2552 SELECT * FROM relations_backup_v
2553  WHERE id = 2
2554    AND relname = 's0.sc0';
2555  id | relid  | relname | relpages | reltuples | relallvisible | curpages 
2556 ----+--------+---------+----------+-----------+---------------+----------
2557   2 | s0.sc0 | s0.sc0  |        1 |         1 |             1 |        1
2558 (1 row)
2559
2560 SELECT dbms_stats.restore(2, 's0.sc0', NULL);
2561  restore 
2562 ---------
2563 (0 rows)
2564
2565 SELECT count(*) FROM dbms_stats.column_stats_locked;
2566  count 
2567 -------
2568      0
2569 (1 row)
2570
2571 SELECT count(*) FROM dbms_stats.relation_stats_locked;
2572  count 
2573 -------
2574      0
2575 (1 row)
2576
2577 DELETE FROM dbms_stats.relation_stats_backup
2578  WHERE id = 2
2579    AND relname = 's0.sc0';
2580 -- No.9-1-21
2581 DELETE FROM dbms_stats.relation_stats_locked;
2582 INSERT INTO dbms_stats.relation_stats_backup(
2583                id, relid, relname, relpages, reltuples,
2584                relallvisible,
2585                curpages)
2586      VALUES (3, 's0.sft0'::regclass, 's0.sft0', 1, 1,
2587              1,
2588              1);
2589 SELECT * FROM relations_backup_v
2590  WHERE id = 3
2591    AND relname = 's0.sft0';
2592  id |  relid  | relname | relpages | reltuples | relallvisible | curpages 
2593 ----+---------+---------+----------+-----------+---------------+----------
2594   3 | s0.sft0 | s0.sft0 |        1 |         1 |             1 |        1
2595 (1 row)
2596
2597 SELECT dbms_stats.restore(2, 's0.sft0', NULL);
2598  restore 
2599 ---------
2600  s0.sft0
2601 (1 row)
2602
2603 SELECT count(*) FROM dbms_stats.column_stats_locked;
2604  count 
2605 -------
2606      1
2607 (1 row)
2608
2609 SELECT count(*) FROM dbms_stats.relation_stats_locked;
2610  count 
2611 -------
2612      1
2613 (1 row)
2614
2615 DELETE FROM dbms_stats.relation_stats_backup
2616  WHERE id = 3
2617    AND relname = 's0.sft0';
2618 -- No.9-1-22
2619 DELETE FROM dbms_stats.relation_stats_locked;
2620 INSERT INTO dbms_stats.relation_stats_backup(
2621                id, relid, relname, relpages, reltuples,
2622                relallvisible,
2623                curpages)
2624      VALUES (3, 's0.smv0'::regclass, 's0.smv0', 1, 1,
2625              1,
2626              1);
2627 SELECT * FROM relations_backup_v
2628  WHERE id = 3
2629    AND relname = 's0.smv0';
2630  id |  relid  | relname | relpages | reltuples | relallvisible | curpages 
2631 ----+---------+---------+----------+-----------+---------------+----------
2632   3 | s0.smv0 | s0.smv0 |        1 |         1 |             1 |        1
2633 (1 row)
2634
2635 SELECT dbms_stats.restore(2, 's0.smv0', NULL);
2636  restore 
2637 ---------
2638  s0.smv0
2639 (1 row)
2640
2641 SELECT count(*) FROM dbms_stats.column_stats_locked;
2642  count 
2643 -------
2644      3
2645 (1 row)
2646
2647 SELECT count(*) FROM dbms_stats.relation_stats_locked;
2648  count 
2649 -------
2650      1
2651 (1 row)
2652
2653 DELETE FROM dbms_stats.relation_stats_backup
2654  WHERE id = 3
2655    AND relname = 's0.smv0';
2656 -- No.9-1-23
2657 DELETE FROM dbms_stats.relation_stats_locked;
2658 INSERT INTO dbms_stats.relation_stats_backup(
2659                id, relid, relname, relpages, reltuples,
2660                relallvisible,
2661                curpages)
2662      VALUES (2, 'pg_catalog.pg_class'::regclass, 'pg_catalog.pg_class', 1, 1,
2663              1,
2664              1);
2665 SELECT * FROM relations_backup_v
2666  WHERE id = 2
2667    AND relname = 'pg_catalog.pg_class';
2668  id |  relid   |       relname       | relpages | reltuples | relallvisible | curpages 
2669 ----+----------+---------------------+----------+-----------+---------------+----------
2670   2 | pg_class | pg_catalog.pg_class |        1 |         1 |             1 |        1
2671 (1 row)
2672
2673 SELECT dbms_stats.restore(2, 'pg_catalog.pg_class', NULL);
2674  restore 
2675 ---------
2676 (0 rows)
2677
2678 SELECT count(*) FROM dbms_stats.column_stats_locked;
2679  count 
2680 -------
2681      0
2682 (1 row)
2683
2684 SELECT count(*) FROM dbms_stats.relation_stats_locked;
2685  count 
2686 -------
2687      0
2688 (1 row)
2689
2690 DELETE FROM dbms_stats.relation_stats_backup
2691  WHERE id = 2
2692    AND relname = 'pg_catalog.pg_class';
2693 -- No.9-1-24
2694 DELETE FROM dbms_stats.relation_stats_locked;
2695 INSERT INTO dbms_stats.relation_stats_locked(relid, relname)
2696     VALUES ('s0.st0'::regclass, 's0.st0');
2697 INSERT INTO dbms_stats.column_stats_locked(starelid, staattnum, stainherit)
2698      SELECT starelid::regclass, staattnum, stainherit
2699        FROM dbms_stats.column_stats_effective
2700       WHERE starelid = 's0.st0'::regclass;
2701 SELECT id, unit, comment FROM dbms_stats.backup_history
2702  WHERE id = 2;
2703  id | unit | comment 
2704 ----+------+---------
2705   2 | d    | (null)
2706 (1 row)
2707
2708 SELECT * FROM columns_locked_v;
2709  starelid | staattnum | attname | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 | stavalues1 | stavalues2 | stavalues3 | stavalues4 | stavalues5 
2710 ----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------+------------+------------+------------+------------
2711  s0.st0   |         1 | id      | f          |      (null) |   (null) |      (null) |   (null) |   (null) |   (null) |   (null) |   (null) | (null) | (null) | (null) | (null) | (null) | (null)      | (null)      | (null)      | (null)      | (null)      | (null)     | (null)     | (null)     | (null)     | (null)
2712  s0.st0   |         1 | id      | t          |      (null) |   (null) |      (null) |   (null) |   (null) |   (null) |   (null) |   (null) | (null) | (null) | (null) | (null) | (null) | (null)      | (null)      | (null)      | (null)      | (null)      | (null)     | (null)     | (null)     | (null)     | (null)
2713  s0.st0   |         2 | num     | f          |      (null) |   (null) |      (null) |   (null) |   (null) |   (null) |   (null) |   (null) | (null) | (null) | (null) | (null) | (null) | (null)      | (null)      | (null)      | (null)      | (null)      | (null)     | (null)     | (null)     | (null)     | (null)
2714  s0.st0   |         2 | num     | t          |      (null) |   (null) |      (null) |   (null) |   (null) |   (null) |   (null) |   (null) | (null) | (null) | (null) | (null) | (null) | (null)      | (null)      | (null)      | (null)      | (null)      | (null)     | (null)     | (null)     | (null)     | (null)
2715 (4 rows)
2716
2717 SELECT * FROM relations_locked_v;
2718  relid  | relname | relpages | reltuples | relallvisible | curpages 
2719 --------+---------+----------+-----------+---------------+----------
2720  s0.st0 | s0.st0  |   (null) |    (null) |        (null) |   (null)
2721 (1 row)
2722
2723 SELECT dbms_stats.restore(2, 's0.st0', NULL);
2724  restore 
2725 ---------
2726  s0.st0
2727 (1 row)
2728
2729 SELECT * FROM relations_locked_v;
2730  relid  | relname | relpages | reltuples | relallvisible | curpages 
2731 --------+---------+----------+-----------+---------------+----------
2732  s0.st0 | s0.st0  |        1 |         2 |             1 |        1
2733 (1 row)
2734
2735 SELECT * FROM columns_locked_v;
2736  starelid | staattnum | attname | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 |    stavalues1    | stavalues2 | stavalues3 | stavalues4 | stavalues5 
2737 ----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------------+------------+------------+------------+------------
2738  s0.st0   |         1 | id      | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {1,2}            | (null)     | (null)     | (null)     | (null)
2739  s0.st0   |         1 | id      | t          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {1,2,4,5,6}      | (null)     | (null)     | (null)     | (null)
2740  s0.st0   |         2 | num     | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {10,20}          | (null)     | (null)     | (null)     | (null)
2741  s0.st0   |         2 | num     | t          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {10,20,40,50,60} | (null)     | (null)     | (null)     | (null)
2742 (4 rows)
2743
2744 -- No.9-1-25
2745 DELETE FROM dbms_stats.relation_stats_locked;
2746 SELECT id, unit, comment FROM dbms_stats.backup_history
2747  WHERE id = 2;
2748  id | unit | comment 
2749 ----+------+---------
2750   2 | d    | (null)
2751 (1 row)
2752
2753 SELECT dbms_stats.restore(2, 's0.st0', NULL);
2754  restore 
2755 ---------
2756  s0.st0
2757 (1 row)
2758
2759 SELECT * FROM relations_locked_v;
2760  relid  | relname | relpages | reltuples | relallvisible | curpages 
2761 --------+---------+----------+-----------+---------------+----------
2762  s0.st0 | s0.st0  |        1 |         2 |             1 |        1
2763 (1 row)
2764
2765 SELECT * FROM columns_locked_v;
2766  starelid | staattnum | attname | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 |    stavalues1    | stavalues2 | stavalues3 | stavalues4 | stavalues5 
2767 ----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------------+------------+------------+------------+------------
2768  s0.st0   |         1 | id      | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {1,2}            | (null)     | (null)     | (null)     | (null)
2769  s0.st0   |         1 | id      | t          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {1,2,4,5,6}      | (null)     | (null)     | (null)     | (null)
2770  s0.st0   |         2 | num     | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {10,20}          | (null)     | (null)     | (null)     | (null)
2771  s0.st0   |         2 | num     | t          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {10,20,40,50,60} | (null)     | (null)     | (null)     | (null)
2772 (4 rows)
2773
2774 /*
2775  * Stab function dbms_stats.restore
2776  */
2777 CREATE OR REPLACE FUNCTION dbms_stats.restore(
2778     backup_id int8,
2779     relid regclass DEFAULT NULL,
2780     attname text DEFAULT NULL)
2781 RETURNS SETOF regclass AS
2782 $$
2783 BEGIN
2784     RAISE NOTICE 'arguments are "%, %, %"', $1, $2, $3;
2785     RETURN QUERY
2786         SELECT c.oid::regclass
2787           FROM pg_class c, dbms_stats.relation_stats_backup b
2788          WHERE (c.oid = $2 OR $2 IS NULL)
2789            AND c.oid = b.relid
2790            AND c.relkind IN ('r', 'i')
2791            AND (b.id <= $1 OR $1 IS NOT NULL)
2792          GROUP BY c.oid
2793          ORDER BY c.oid::regclass::text;
2794 END;
2795 $$
2796 LANGUAGE plpgsql;
2797 /*
2798  * No.10-1 dbms_stats.restore_database_stats
2799  */
2800 -- No.10-1-1
2801 SELECT dbms_stats.restore_database_stats('2012-02-29 23:59:57');
2802 NOTICE:  arguments are "2, pt0, <NULL>"
2803 NOTICE:  arguments are "2, pt0_idx, <NULL>"
2804 NOTICE:  arguments are "2, st0, <NULL>"
2805 NOTICE:  arguments are "2, st0_idx, <NULL>"
2806 NOTICE:  arguments are "2, st1, <NULL>"
2807 NOTICE:  arguments are "2, s0.st0, <NULL>"
2808 NOTICE:  arguments are "2, s0.st0_idx, <NULL>"
2809 NOTICE:  arguments are "2, s0.st1, <NULL>"
2810 NOTICE:  arguments are "2, s0.st1_idx, <NULL>"
2811 NOTICE:  arguments are "2, s0.st2, <NULL>"
2812 NOTICE:  arguments are "2, s0.st2_idx, <NULL>"
2813 NOTICE:  arguments are "2, st1_idx, <NULL>"
2814 NOTICE:  arguments are "2, st1_exp, <NULL>"
2815 NOTICE:  arguments are "2, s0.sft0, <NULL>"
2816 NOTICE:  arguments are "2, s0.smv0, <NULL>"
2817  restore_database_stats 
2818 ------------------------
2819  pt0
2820  pt0_idx
2821  st0
2822  st0_idx
2823  st1
2824  s0.st0
2825  s0.st0_idx
2826  s0.st1
2827  s0.st1_idx
2828  s0.st2
2829  s0.st2_idx
2830  st1_idx
2831  st1_exp
2832 (13 rows)
2833
2834 -- No.10-1-2
2835 SELECT dbms_stats.restore_database_stats('2012-02-29 23:59:57.000002');
2836 NOTICE:  arguments are "2, pt0, <NULL>"
2837 NOTICE:  arguments are "2, pt0_idx, <NULL>"
2838 NOTICE:  arguments are "2, st0, <NULL>"
2839 NOTICE:  arguments are "2, st0_idx, <NULL>"
2840 NOTICE:  arguments are "2, st1, <NULL>"
2841 NOTICE:  arguments are "3, s0.st0, <NULL>"
2842 NOTICE:  arguments are "2, s0.st0_idx, <NULL>"
2843 NOTICE:  arguments are "2, s0.st1, <NULL>"
2844 NOTICE:  arguments are "2, s0.st1_idx, <NULL>"
2845 NOTICE:  arguments are "2, s0.st2, <NULL>"
2846 NOTICE:  arguments are "2, s0.st2_idx, <NULL>"
2847 NOTICE:  arguments are "2, st1_idx, <NULL>"
2848 NOTICE:  arguments are "2, st1_exp, <NULL>"
2849 NOTICE:  arguments are "2, s0.sft0, <NULL>"
2850 NOTICE:  arguments are "2, s0.smv0, <NULL>"
2851  restore_database_stats 
2852 ------------------------
2853  pt0
2854  pt0_idx
2855  st0
2856  st0_idx
2857  st1
2858  s0.st0
2859  s0.st0_idx
2860  s0.st1
2861  s0.st1_idx
2862  s0.st2
2863  s0.st2_idx
2864  st1_idx
2865  st1_exp
2866 (13 rows)
2867
2868 -- No.10-1-3
2869 SELECT dbms_stats.restore_database_stats('2012-01-01 00:00:00');
2870  restore_database_stats 
2871 ------------------------
2872 (0 rows)
2873
2874 --#No.10-1-4 is skipped after lock tests
2875 --#No.10-1-5 is skipped after lock tests
2876 -- No.10-1-6
2877 SELECT dbms_stats.restore_database_stats('2012-02-29 23:59:57');
2878 NOTICE:  arguments are "2, pt0, <NULL>"
2879 NOTICE:  arguments are "2, pt0_idx, <NULL>"
2880 NOTICE:  arguments are "2, st0, <NULL>"
2881 NOTICE:  arguments are "2, st0_idx, <NULL>"
2882 NOTICE:  arguments are "2, st1, <NULL>"
2883 NOTICE:  arguments are "2, s0.st0, <NULL>"
2884 NOTICE:  arguments are "2, s0.st0_idx, <NULL>"
2885 NOTICE:  arguments are "2, s0.st1, <NULL>"
2886 NOTICE:  arguments are "2, s0.st1_idx, <NULL>"
2887 NOTICE:  arguments are "2, s0.st2, <NULL>"
2888 NOTICE:  arguments are "2, s0.st2_idx, <NULL>"
2889 NOTICE:  arguments are "2, st1_idx, <NULL>"
2890 NOTICE:  arguments are "2, st1_exp, <NULL>"
2891 NOTICE:  arguments are "2, s0.sft0, <NULL>"
2892 NOTICE:  arguments are "2, s0.smv0, <NULL>"
2893  restore_database_stats 
2894 ------------------------
2895  pt0
2896  pt0_idx
2897  st0
2898  st0_idx
2899  st1
2900  s0.st0
2901  s0.st0_idx
2902  s0.st1
2903  s0.st1_idx
2904  s0.st2
2905  s0.st2_idx
2906  st1_idx
2907  st1_exp
2908 (13 rows)
2909
2910 /*
2911  * No.10-2 dbms_stats.restore_schema_stats
2912  */
2913 -- No.10-2-1
2914 SELECT dbms_stats.restore_schema_stats('s0', '2012-02-29 23:59:57');
2915 NOTICE:  arguments are "2, s0.st0, <NULL>"
2916 NOTICE:  arguments are "2, s0.st0_idx, <NULL>"
2917 NOTICE:  arguments are "2, s0.st1, <NULL>"
2918 NOTICE:  arguments are "2, s0.st1_idx, <NULL>"
2919 NOTICE:  arguments are "2, s0.st2, <NULL>"
2920 NOTICE:  arguments are "2, s0.st2_idx, <NULL>"
2921 NOTICE:  arguments are "2, s0.sft0, <NULL>"
2922 NOTICE:  arguments are "2, s0.smv0, <NULL>"
2923  restore_schema_stats 
2924 ----------------------
2925  s0.st0
2926  s0.st0_idx
2927  s0.st1
2928  s0.st1_idx
2929  s0.st2
2930  s0.st2_idx
2931 (6 rows)
2932
2933 -- No.10-2-2
2934 SELECT dbms_stats.restore_schema_stats('s0', '2012-02-29 23:59:57.000002');
2935 NOTICE:  arguments are "3, s0.st0, <NULL>"
2936 NOTICE:  arguments are "2, s0.st0_idx, <NULL>"
2937 NOTICE:  arguments are "2, s0.st1, <NULL>"
2938 NOTICE:  arguments are "2, s0.st1_idx, <NULL>"
2939 NOTICE:  arguments are "2, s0.st2, <NULL>"
2940 NOTICE:  arguments are "2, s0.st2_idx, <NULL>"
2941 NOTICE:  arguments are "2, s0.sft0, <NULL>"
2942 NOTICE:  arguments are "2, s0.smv0, <NULL>"
2943  restore_schema_stats 
2944 ----------------------
2945  s0.st0
2946  s0.st0_idx
2947  s0.st1
2948  s0.st1_idx
2949  s0.st2
2950  s0.st2_idx
2951 (6 rows)
2952
2953 -- No.10-2-3
2954 SELECT dbms_stats.restore_schema_stats('s0', '2012-01-01 00:00:00');
2955  restore_schema_stats 
2956 ----------------------
2957 (0 rows)
2958
2959 --#No.10-2-4 is skipped after lock tests
2960 --#No.10-2-5 is skipped after lock tests
2961 -- No.10-2-6
2962 SELECT dbms_stats.restore_schema_stats('s0', '2012-02-29 23:59:57');
2963 NOTICE:  arguments are "2, s0.st0, <NULL>"
2964 NOTICE:  arguments are "2, s0.st0_idx, <NULL>"
2965 NOTICE:  arguments are "2, s0.st1, <NULL>"
2966 NOTICE:  arguments are "2, s0.st1_idx, <NULL>"
2967 NOTICE:  arguments are "2, s0.st2, <NULL>"
2968 NOTICE:  arguments are "2, s0.st2_idx, <NULL>"
2969 NOTICE:  arguments are "2, s0.sft0, <NULL>"
2970 NOTICE:  arguments are "2, s0.smv0, <NULL>"
2971  restore_schema_stats 
2972 ----------------------
2973  s0.st0
2974  s0.st0_idx
2975  s0.st1
2976  s0.st1_idx
2977  s0.st2
2978  s0.st2_idx
2979 (6 rows)
2980
2981 -- No.10-2-7
2982 SELECT dbms_stats.restore_schema_stats('s0', '2012-02-29 23:59:57');
2983 NOTICE:  arguments are "2, s0.st0, <NULL>"
2984 NOTICE:  arguments are "2, s0.st0_idx, <NULL>"
2985 NOTICE:  arguments are "2, s0.st1, <NULL>"
2986 NOTICE:  arguments are "2, s0.st1_idx, <NULL>"
2987 NOTICE:  arguments are "2, s0.st2, <NULL>"
2988 NOTICE:  arguments are "2, s0.st2_idx, <NULL>"
2989 NOTICE:  arguments are "2, s0.sft0, <NULL>"
2990 NOTICE:  arguments are "2, s0.smv0, <NULL>"
2991  restore_schema_stats 
2992 ----------------------
2993  s0.st0
2994  s0.st0_idx
2995  s0.st1
2996  s0.st1_idx
2997  s0.st2
2998  s0.st2_idx
2999 (6 rows)
3000
3001 --#No.10-2-8 is skipped after lock tests
3002 -- No.10-2-9
3003 SELECT dbms_stats.restore_schema_stats('s00', '2012-02-29 23:59:57');
3004 ERROR:  schema "s00" not found
3005 CONTEXT:  PL/pgSQL function dbms_stats.restore_schema_stats(text,timestamp with time zone) line 4 at RAISE
3006 -- No.10-2-10
3007 SELECT dbms_stats.restore_schema_stats('pg_catalog', '2012-02-29 23:59:57');
3008 ERROR:  restoring statistics is inhibited for system schemas: "pg_catalog"
3009 CONTEXT:  PL/pgSQL function dbms_stats.restore_schema_stats(text,timestamp with time zone) line 7 at RAISE
3010 /*
3011  * No.10-7 dbms_stats.restore_stats
3012  */
3013 -- No.10-7-1
3014 DELETE FROM dbms_stats.relation_stats_locked;
3015 SELECT dbms_stats.restore_stats(NULL);
3016  restore_stats 
3017 ---------------
3018 (0 rows)
3019
3020 -- No.10-7-2
3021 DELETE FROM dbms_stats.relation_stats_locked;
3022 SELECT dbms_stats.restore_stats(0);
3023 ERROR:  backup id 0 not found
3024 CONTEXT:  PL/pgSQL function dbms_stats.restore_stats(bigint) line 10 at RAISE
3025 -- No.10-7-3
3026 DELETE FROM dbms_stats.relation_stats_locked;
3027 VACUUM dbms_stats.relation_stats_locked;  -- in order to avoid auto vacuum
3028 BEGIN;
3029 SELECT * FROM internal_locks;
3030  relation | mode 
3031 ----------+------
3032 (0 rows)
3033
3034 SELECT dbms_stats.restore_stats(2);
3035  restore_stats 
3036 ---------------
3037  pt0
3038  pt0_idx
3039  s0.sft0
3040  s0.smv0
3041  s0.st0
3042  s0.st0_idx
3043  s0.st1
3044  s0.st1_idx
3045  s0.st2
3046  s0.st2_idx
3047  st0
3048  st0_idx
3049  st1
3050  st1_exp
3051  st1_idx
3052 (15 rows)
3053
3054 SELECT * FROM internal_locks;
3055              relation             |       mode       
3056 ----------------------------------+------------------
3057  dbms_stats.backup_history        | AccessShareLock
3058  dbms_stats.column_stats_backup   | AccessShareLock
3059  dbms_stats.column_stats_locked   | RowExclusiveLock
3060  dbms_stats.relation_stats_backup | AccessShareLock
3061  dbms_stats.relation_stats_backup | RowShareLock
3062  dbms_stats.relation_stats_locked | ExclusiveLock
3063  dbms_stats.relation_stats_locked | RowExclusiveLock
3064  dbms_stats.relation_stats_locked | RowShareLock
3065 (8 rows)
3066
3067 COMMIT;
3068 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
3069  GROUP BY relid
3070  ORDER BY relid;
3071    relid    
3072 ------------
3073  pt0
3074  pt0_idx
3075  st0
3076  st0_idx
3077  st1
3078  s0.st0
3079  s0.st0_idx
3080  s0.st1
3081  s0.st1_idx
3082  s0.st2
3083  s0.st2_idx
3084  st1_idx
3085  st1_exp
3086  s0.sft0
3087  s0.smv0
3088 (15 rows)
3089
3090 SELECT starelid, attname, stainherit FROM columns_locked_v c;
3091  starelid | attname | stainherit 
3092 ----------+---------+------------
3093  st0      | id      | f
3094  st0      | name    | f
3095  st1      | val     | f
3096  st1      | str     | f
3097  s0.st0   | id      | f
3098  s0.st0   | id      | t
3099  s0.st0   | num     | f
3100  s0.st0   | num     | t
3101  s0.st1   | id      | f
3102  s0.st1   | num     | f
3103  s0.st2   | id      | f
3104  s0.st2   | txt     | f
3105  st1_exp  | lower   | f
3106  s0.sft0  | id      | f
3107  s0.smv0  | id      | f
3108  s0.smv0  | num     | f
3109  s0.smv0  | txt     | f
3110 (17 rows)
3111
3112 -- No.10-7-4
3113 DELETE FROM dbms_stats.relation_stats_locked;
3114 INSERT INTO dbms_stats.relation_stats_locked(relid, relname)
3115      SELECT relid::regclass, relname
3116        FROM dbms_stats.relation_stats_effective;
3117 INSERT INTO dbms_stats.column_stats_locked(starelid, staattnum, stainherit)
3118      SELECT starelid::regclass, staattnum, stainherit
3119        FROM dbms_stats.column_stats_effective;
3120 SELECT id, unit, comment FROM dbms_stats.backup_history
3121  WHERE id = 8;
3122  id | unit | comment 
3123 ----+------+---------
3124   8 | s    | (null)
3125 (1 row)
3126
3127 SELECT * FROM columns_locked_v;
3128  starelid | staattnum | attname | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 | stavalues1 | stavalues2 | stavalues3 | stavalues4 | stavalues5 
3129 ----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------+------------+------------+------------+------------
3130  st0      |         1 | id      | f          |      (null) |   (null) |      (null) |   (null) |   (null) |   (null) |   (null) |   (null) | (null) | (null) | (null) | (null) | (null) | (null)      | (null)      | (null)      | (null)      | (null)      | (null)     | (null)     | (null)     | (null)     | (null)
3131  st0      |         2 | name    | f          |      (null) |   (null) |      (null) |   (null) |   (null) |   (null) |   (null) |   (null) | (null) | (null) | (null) | (null) | (null) | (null)      | (null)      | (null)      | (null)      | (null)      | (null)     | (null)     | (null)     | (null)     | (null)
3132  st1      |         1 | val     | f          |      (null) |   (null) |      (null) |   (null) |   (null) |   (null) |   (null) |   (null) | (null) | (null) | (null) | (null) | (null) | (null)      | (null)      | (null)      | (null)      | (null)      | (null)     | (null)     | (null)     | (null)     | (null)
3133  st1      |         2 | str     | f          |      (null) |   (null) |      (null) |   (null) |   (null) |   (null) |   (null) |   (null) | (null) | (null) | (null) | (null) | (null) | (null)      | (null)      | (null)      | (null)      | (null)      | (null)     | (null)     | (null)     | (null)     | (null)
3134  s0.st0   |         1 | id      | f          |      (null) |   (null) |      (null) |   (null) |   (null) |   (null) |   (null) |   (null) | (null) | (null) | (null) | (null) | (null) | (null)      | (null)      | (null)      | (null)      | (null)      | (null)     | (null)     | (null)     | (null)     | (null)
3135  s0.st0   |         1 | id      | t          |      (null) |   (null) |      (null) |   (null) |   (null) |   (null) |   (null) |   (null) | (null) | (null) | (null) | (null) | (null) | (null)      | (null)      | (null)      | (null)      | (null)      | (null)     | (null)     | (null)     | (null)     | (null)
3136  s0.st0   |         2 | num     | f          |      (null) |   (null) |      (null) |   (null) |   (null) |   (null) |   (null) |   (null) | (null) | (null) | (null) | (null) | (null) | (null)      | (null)      | (null)      | (null)      | (null)      | (null)     | (null)     | (null)     | (null)     | (null)
3137  s0.st0   |         2 | num     | t          |      (null) |   (null) |      (null) |   (null) |   (null) |   (null) |   (null) |   (null) | (null) | (null) | (null) | (null) | (null) | (null)      | (null)      | (null)      | (null)      | (null)      | (null)     | (null)     | (null)     | (null)     | (null)
3138  s0.st1   |         1 | id      | f          |      (null) |   (null) |      (null) |   (null) |   (null) |   (null) |   (null) |   (null) | (null) | (null) | (null) | (null) | (null) | (null)      | (null)      | (null)      | (null)      | (null)      | (null)     | (null)     | (null)     | (null)     | (null)
3139  s0.st1   |         2 | num     | f          |      (null) |   (null) |      (null) |   (null) |   (null) |   (null) |   (null) |   (null) | (null) | (null) | (null) | (null) | (null) | (null)      | (null)      | (null)      | (null)      | (null)      | (null)     | (null)     | (null)     | (null)     | (null)
3140  s0.st2   |         1 | id      | f          |      (null) |   (null) |      (null) |   (null) |   (null) |   (null) |   (null) |   (null) | (null) | (null) | (null) | (null) | (null) | (null)      | (null)      | (null)      | (null)      | (null)      | (null)     | (null)     | (null)     | (null)     | (null)
3141  s0.st2   |         2 | txt     | f          |      (null) |   (null) |      (null) |   (null) |   (null) |   (null) |   (null) |   (null) | (null) | (null) | (null) | (null) | (null) | (null)      | (null)      | (null)      | (null)      | (null)      | (null)     | (null)     | (null)     | (null)     | (null)
3142  st1_exp  |         1 | lower   | f          |      (null) |   (null) |      (null) |   (null) |   (null) |   (null) |   (null) |   (null) | (null) | (null) | (null) | (null) | (null) | (null)      | (null)      | (null)      | (null)      | (null)      | (null)     | (null)     | (null)     | (null)     | (null)
3143  s0.sft0  |         1 | id      | f          |      (null) |   (null) |      (null) |   (null) |   (null) |   (null) |   (null) |   (null) | (null) | (null) | (null) | (null) | (null) | (null)      | (null)      | (null)      | (null)      | (null)      | (null)     | (null)     | (null)     | (null)     | (null)
3144  s0.smv0  |         1 | id      | f          |      (null) |   (null) |      (null) |   (null) |   (null) |   (null) |   (null) |   (null) | (null) | (null) | (null) | (null) | (null) | (null)      | (null)      | (null)      | (null)      | (null)      | (null)     | (null)     | (null)     | (null)     | (null)
3145  s0.smv0  |         2 | num     | f          |      (null) |   (null) |      (null) |   (null) |   (null) |   (null) |   (null) |   (null) | (null) | (null) | (null) | (null) | (null) | (null)      | (null)      | (null)      | (null)      | (null)      | (null)     | (null)     | (null)     | (null)     | (null)
3146  s0.smv0  |         3 | txt     | f          |      (null) |   (null) |      (null) |   (null) |   (null) |   (null) |   (null) |   (null) | (null) | (null) | (null) | (null) | (null) | (null)      | (null)      | (null)      | (null)      | (null)      | (null)     | (null)     | (null)     | (null)     | (null)
3147  s1.st0   |         1 | id      | f          |      (null) |   (null) |      (null) |   (null) |   (null) |   (null) |   (null) |   (null) | (null) | (null) | (null) | (null) | (null) | (null)      | (null)      | (null)      | (null)      | (null)      | (null)     | (null)     | (null)     | (null)     | (null)
3148  s1.st0   |         2 | num     | f          |      (null) |   (null) |      (null) |   (null) |   (null) |   (null) |   (null) |   (null) | (null) | (null) | (null) | (null) | (null) | (null)      | (null)      | (null)      | (null)      | (null)      | (null)     | (null)     | (null)     | (null)     | (null)
3149 (19 rows)
3150
3151 SELECT * FROM relations_locked_v;
3152    relid    |    relname     | relpages | reltuples | relallvisible | curpages 
3153 ------------+----------------+----------+-----------+---------------+----------
3154  pt0        | public.pt0     |   (null) |    (null) |        (null) |   (null)
3155  pt0_idx    | public.pt0_idx |   (null) |    (null) |        (null) |   (null)
3156  st0        | public.st0     |   (null) |    (null) |        (null) |   (null)
3157  st0_idx    | public.st0_idx |   (null) |    (null) |        (null) |   (null)
3158  st1        | public.st1     |   (null) |    (null) |        (null) |   (null)
3159  s0.st0     | s0.st0         |   (null) |    (null) |        (null) |   (null)
3160  s0.st0_idx | s0.st0_idx     |   (null) |    (null) |        (null) |   (null)
3161  s0.st1     | s0.st1         |   (null) |    (null) |        (null) |   (null)
3162  s0.st1_idx | s0.st1_idx     |   (null) |    (null) |        (null) |   (null)
3163  s0.st2     | s0.st2         |   (null) |    (null) |        (null) |   (null)
3164  s0.st2_idx | s0.st2_idx     |   (null) |    (null) |        (null) |   (null)
3165  st1_idx    | public.st1_idx |   (null) |    (null) |        (null) |   (null)
3166  st1_exp    | public.st1_exp |   (null) |    (null) |        (null) |   (null)
3167  s0.sft0    | s0.sft0        |   (null) |    (null) |        (null) |   (null)
3168  s0.smv0    | s0.smv0        |   (null) |    (null) |        (null) |   (null)
3169  s1.st0     | s1.st0         |   (null) |    (null) |        (null) |   (null)
3170 (16 rows)
3171
3172 SELECT dbms_stats.restore_stats(8);
3173  restore_stats 
3174 ---------------
3175  s0.st0
3176  s0.st0_idx
3177  s0.st1
3178  s0.st1_idx
3179  s0.st2
3180  s0.st2_idx
3181 (6 rows)
3182
3183 SELECT * FROM relations_locked_v;
3184    relid    |    relname     | relpages | reltuples | relallvisible | curpages 
3185 ------------+----------------+----------+-----------+---------------+----------
3186  pt0        | public.pt0     |   (null) |    (null) |        (null) |   (null)
3187  pt0_idx    | public.pt0_idx |   (null) |    (null) |        (null) |   (null)
3188  st0        | public.st0     |   (null) |    (null) |        (null) |   (null)
3189  st0_idx    | public.st0_idx |   (null) |    (null) |        (null) |   (null)
3190  st1        | public.st1     |   (null) |    (null) |        (null) |   (null)
3191  s0.st0     | s0.st0         |        1 |         2 |             1 |        1
3192  s0.st0_idx | s0.st0_idx     |        2 |         2 |             0 |        2
3193  s0.st1     | s0.st1         |        1 |         3 |             1 |        1
3194  s0.st1_idx | s0.st1_idx     |        2 |         3 |             0 |        2
3195  s0.st2     | s0.st2         |        1 |         3 |             1 |        1
3196  s0.st2_idx | s0.st2_idx     |        2 |         3 |             0 |        2
3197  st1_idx    | public.st1_idx |   (null) |    (null) |        (null) |   (null)
3198  st1_exp    | public.st1_exp |   (null) |    (null) |        (null) |   (null)
3199  s0.sft0    | s0.sft0        |   (null) |    (null) |        (null) |   (null)
3200  s0.smv0    | s0.smv0        |   (null) |    (null) |        (null) |   (null)
3201  s1.st0     | s1.st0         |   (null) |    (null) |        (null) |   (null)
3202 (16 rows)
3203
3204 SELECT * FROM columns_locked_v;
3205  starelid | staattnum | attname | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 |    stavalues1    | stavalues2 | stavalues3 | stavalues4 | stavalues5 
3206 ----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------------+------------+------------+------------+------------
3207  st0      |         1 | id      | f          |      (null) |   (null) |      (null) |   (null) |   (null) |   (null) |   (null) |   (null) | (null) | (null) | (null) | (null) | (null) | (null)      | (null)      | (null)      | (null)      | (null)      | (null)           | (null)     | (null)     | (null)     | (null)
3208  st0      |         2 | name    | f          |      (null) |   (null) |      (null) |   (null) |   (null) |   (null) |   (null) |   (null) | (null) | (null) | (null) | (null) | (null) | (null)      | (null)      | (null)      | (null)      | (null)      | (null)           | (null)     | (null)     | (null)     | (null)
3209  st1      |         1 | val     | f          |      (null) |   (null) |      (null) |   (null) |   (null) |   (null) |   (null) |   (null) | (null) | (null) | (null) | (null) | (null) | (null)      | (null)      | (null)      | (null)      | (null)      | (null)           | (null)     | (null)     | (null)     | (null)
3210  st1      |         2 | str     | f          |      (null) |   (null) |      (null) |   (null) |   (null) |   (null) |   (null) |   (null) | (null) | (null) | (null) | (null) | (null) | (null)      | (null)      | (null)      | (null)      | (null)      | (null)           | (null)     | (null)     | (null)     | (null)
3211  s0.st0   |         1 | id      | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {1,2}            | (null)     | (null)     | (null)     | (null)
3212  s0.st0   |         1 | id      | t          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {1,2,4,5,6}      | (null)     | (null)     | (null)     | (null)
3213  s0.st0   |         2 | num     | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {10,20}          | (null)     | (null)     | (null)     | (null)
3214  s0.st0   |         2 | num     | t          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {10,20,40,50,60} | (null)     | (null)     | (null)     | (null)
3215  s0.st1   |         1 | id      | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {4,5,6}          | (null)     | (null)     | (null)     | (null)
3216  s0.st1   |         2 | num     | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {40,50,60}       | (null)     | (null)     | (null)     | (null)
3217  s0.st2   |         1 | id      | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {1,2,3}          | (null)     | (null)     | (null)     | (null)
3218  s0.st2   |         2 | txt     | f          |           0 |        5 |          -1 |        2 |        3 |        0 |        0 |        0 |    664 |    664 |      0 |      0 |      0 | (null)      | {0.5}       | (null)      | (null)      | (null)      | {1,comment,test} | (null)     | (null)     | (null)     | (null)
3219  st1_exp  |         1 | lower   | f          |      (null) |   (null) |      (null) |   (null) |   (null) |   (null) |   (null) |   (null) | (null) | (null) | (null) | (null) | (null) | (null)      | (null)      | (null)      | (null)      | (null)      | (null)           | (null)     | (null)     | (null)     | (null)
3220  s0.sft0  |         1 | id      | f          |      (null) |   (null) |      (null) |   (null) |   (null) |   (null) |   (null) |   (null) | (null) | (null) | (null) | (null) | (null) | (null)      | (null)      | (null)      | (null)      | (null)      | (null)           | (null)     | (null)     | (null)     | (null)
3221  s0.smv0  |         1 | id      | f          |      (null) |   (null) |      (null) |   (null) |   (null) |   (null) |   (null) |   (null) | (null) | (null) | (null) | (null) | (null) | (null)      | (null)      | (null)      | (null)      | (null)      | (null)           | (null)     | (null)     | (null)     | (null)
3222  s0.smv0  |         2 | num     | f          |      (null) |   (null) |      (null) |   (null) |   (null) |   (null) |   (null) |   (null) | (null) | (null) | (null) | (null) | (null) | (null)      | (null)      | (null)      | (null)      | (null)      | (null)           | (null)     | (null)     | (null)     | (null)
3223  s0.smv0  |         3 | txt     | f          |      (null) |   (null) |      (null) |   (null) |   (null) |   (null) |   (null) |   (null) | (null) | (null) | (null) | (null) | (null) | (null)      | (null)      | (null)      | (null)      | (null)      | (null)           | (null)     | (null)     | (null)     | (null)
3224  s1.st0   |         1 | id      | f          |      (null) |   (null) |      (null) |   (null) |   (null) |   (null) |   (null) |   (null) | (null) | (null) | (null) | (null) | (null) | (null)      | (null)      | (null)      | (null)      | (null)      | (null)           | (null)     | (null)     | (null)     | (null)
3225  s1.st0   |         2 | num     | f          |      (null) |   (null) |      (null) |   (null) |   (null) |   (null) |   (null) |   (null) | (null) | (null) | (null) | (null) | (null) | (null)      | (null)      | (null)      | (null)      | (null)      | (null)           | (null)     | (null)     | (null)     | (null)
3226 (19 rows)
3227
3228 -- No.10-7-5
3229 DELETE FROM dbms_stats.relation_stats_locked;
3230 SELECT id, unit, comment FROM dbms_stats.backup_history
3231  WHERE id = 8;
3232  id | unit | comment 
3233 ----+------+---------
3234   8 | s    | (null)
3235 (1 row)
3236
3237 SELECT dbms_stats.restore_stats(8);
3238  restore_stats 
3239 ---------------
3240  s0.st0
3241  s0.st0_idx
3242  s0.st1
3243  s0.st1_idx
3244  s0.st2
3245  s0.st2_idx
3246 (6 rows)
3247
3248 SELECT * FROM relations_locked_v;
3249    relid    |  relname   | relpages | reltuples | relallvisible | curpages 
3250 ------------+------------+----------+-----------+---------------+----------
3251  s0.st0     | s0.st0     |        1 |         2 |             1 |        1
3252  s0.st0_idx | s0.st0_idx |        2 |         2 |             0 |        2
3253  s0.st1     | s0.st1     |        1 |         3 |             1 |        1
3254  s0.st1_idx | s0.st1_idx |        2 |         3 |             0 |        2
3255  s0.st2     | s0.st2     |        1 |         3 |             1 |        1
3256  s0.st2_idx | s0.st2_idx |        2 |         3 |             0 |        2
3257 (6 rows)
3258
3259 SELECT * FROM columns_locked_v;
3260  starelid | staattnum | attname | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 |    stavalues1    | stavalues2 | stavalues3 | stavalues4 | stavalues5 
3261 ----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------------+------------+------------+------------+------------
3262  s0.st0   |         1 | id      | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {1,2}            | (null)     | (null)     | (null)     | (null)
3263  s0.st0   |         1 | id      | t          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {1,2,4,5,6}      | (null)     | (null)     | (null)     | (null)
3264  s0.st0   |         2 | num     | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {10,20}          | (null)     | (null)     | (null)     | (null)
3265  s0.st0   |         2 | num     | t          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {10,20,40,50,60} | (null)     | (null)     | (null)     | (null)
3266  s0.st1   |         1 | id      | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {4,5,6}          | (null)     | (null)     | (null)     | (null)
3267  s0.st1   |         2 | num     | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {40,50,60}       | (null)     | (null)     | (null)     | (null)
3268  s0.st2   |         1 | id      | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {1,2,3}          | (null)     | (null)     | (null)     | (null)
3269  s0.st2   |         2 | txt     | f          |           0 |        5 |          -1 |        2 |        3 |        0 |        0 |        0 |    664 |    664 |      0 |      0 |      0 | (null)      | {0.5}       | (null)      | (null)      | (null)      | {1,comment,test} | (null)     | (null)     | (null)     | (null)
3270 (8 rows)
3271
3272 /*
3273  * No.11-1 dbms_stats.lock(relid, attname)
3274  */
3275 -- No.11-1-1
3276 DELETE FROM dbms_stats.relation_stats_locked;
3277 SELECT dbms_stats.lock(NULL, NULL);
3278 ERROR:  relation required
3279 CONTEXT:  PL/pgSQL function dbms_stats.lock(regclass,text) line 8 at RAISE
3280 -- No.11-1-2
3281 ALTER FUNCTION dbms_stats.lock(relid regclass)
3282     RENAME TO truth_lock;
3283 CREATE FUNCTION dbms_stats.lock(relid regclass)
3284 RETURNS regclass AS
3285 $$
3286 BEGIN
3287         RAISE NOTICE 'arguments are %', $1;
3288         RETURN $1;
3289 END
3290 $$
3291 LANGUAGE plpgsql;
3292 DELETE FROM dbms_stats.relation_stats_locked;
3293 SELECT dbms_stats.lock('s0.st0', NULL);
3294 NOTICE:  arguments are s0.st0
3295   lock  
3296 --------
3297  s0.st0
3298 (1 row)
3299
3300 DROP FUNCTION dbms_stats.lock(relid regclass);
3301 ALTER FUNCTION dbms_stats.truth_lock(relid regclass)
3302     RENAME TO lock;
3303 -- No.11-1-3
3304 DELETE FROM dbms_stats.relation_stats_locked;
3305 SELECT dbms_stats.lock(NULL, 'id');
3306 ERROR:  relation required
3307 CONTEXT:  PL/pgSQL function dbms_stats.lock(regclass,text) line 8 at RAISE
3308 -- No.11-1-4
3309 DELETE FROM dbms_stats.relation_stats_locked;
3310 SELECT dbms_stats.lock('s0.st0', 'id');
3311   lock  
3312 --------
3313  s0.st0
3314 (1 row)
3315
3316 SELECT * FROM relations_locked_v;
3317  relid  | relname | relpages | reltuples | relallvisible | curpages 
3318 --------+---------+----------+-----------+---------------+----------
3319  s0.st0 | s0.st0  |   (null) |    (null) |        (null) |   (null)
3320 (1 row)
3321
3322 SELECT * FROM columns_locked_v c;
3323  starelid | staattnum | attname | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 | stavalues1  | stavalues2 | stavalues3 | stavalues4 | stavalues5 
3324 ----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+-------------+------------+------------+------------+------------
3325  s0.st0   |         1 | id      | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {1,2}       | (null)     | (null)     | (null)     | (null)
3326  s0.st0   |         1 | id      | t          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {1,2,4,5,6} | (null)     | (null)     | (null)     | (null)
3327 (2 rows)
3328
3329 -- No.11-1-5
3330 DELETE FROM dbms_stats.relation_stats_locked;
3331 SELECT dbms_stats.lock(0, 'id');
3332 ERROR:  relation "-" not found
3333 CONTEXT:  PL/pgSQL function dbms_stats.lock(regclass,text) line 15 at RAISE
3334 -- No.11-1-6
3335 DELETE FROM dbms_stats.relation_stats_locked;
3336 SELECT dbms_stats.lock('s0.st0', 'id');
3337   lock  
3338 --------
3339  s0.st0
3340 (1 row)
3341
3342 SELECT * FROM relations_locked_v;
3343  relid  | relname | relpages | reltuples | relallvisible | curpages 
3344 --------+---------+----------+-----------+---------------+----------
3345  s0.st0 | s0.st0  |   (null) |    (null) |        (null) |   (null)
3346 (1 row)
3347
3348 SELECT * FROM columns_locked_v c;
3349  starelid | staattnum | attname | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 | stavalues1  | stavalues2 | stavalues3 | stavalues4 | stavalues5 
3350 ----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+-------------+------------+------------+------------+------------
3351  s0.st0   |         1 | id      | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {1,2}       | (null)     | (null)     | (null)     | (null)
3352  s0.st0   |         1 | id      | t          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {1,2,4,5,6} | (null)     | (null)     | (null)     | (null)
3353 (2 rows)
3354
3355 -- No.11-1-7
3356 DELETE FROM dbms_stats.relation_stats_locked;
3357 SELECT dbms_stats.lock('pg_toast.pg_toast_2618', 'id');
3358 ERROR:  "pg_toast.pg_toast_2618" must be a table or an index
3359 CONTEXT:  PL/pgSQL function dbms_stats.lock(regclass,text) line 18 at RAISE
3360 -- No.11-1-8
3361 DELETE FROM dbms_stats.relation_stats_locked;
3362 SELECT dbms_stats.lock('s0.st0_idx', 'id');
3363 ERROR:  "s0.st0_idx" must be an expression index
3364 CONTEXT:  PL/pgSQL function dbms_stats.lock(regclass,text) line 21 at RAISE
3365 -- No.11-1-9
3366 DELETE FROM dbms_stats.relation_stats_locked;
3367 SELECT dbms_stats.lock('st1_exp', 'lower');
3368   lock   
3369 ---------
3370  st1_exp
3371 (1 row)
3372
3373 SELECT * FROM relations_locked_v;
3374   relid  |    relname     | relpages | reltuples | relallvisible | curpages 
3375 ---------+----------------+----------+-----------+---------------+----------
3376  st1_exp | public.st1_exp |   (null) |    (null) |        (null) |   (null)
3377 (1 row)
3378
3379 SELECT * FROM columns_locked_v c;
3380  starelid | staattnum | attname | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 |      stanumbers1       | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 | stavalues1 | stavalues2 | stavalues3 | stavalues4 | stavalues5 
3381 ----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+------------------------+-------------+-------------+-------------+-------------+------------+------------+------------+------------+------------
3382  st1_exp  |         1 | lower   | f          |           0 |        5 |           3 |        1 |        3 |        0 |        0 |        0 |     98 |    664 |      0 |      0 |      0 | {0.3334,0.3333,0.3333} | {0.3332}    | (null)      | (null)      | (null)      | {1,0,2}    | (null)     | (null)     | (null)     | (null)
3383 (1 row)
3384
3385 DELETE FROM dbms_stats.relation_stats_locked;
3386 -- No.11-1-10
3387 DELETE FROM dbms_stats.relation_stats_locked;
3388 SELECT dbms_stats.lock('s0.ss0', 'id');
3389 ERROR:  "s0.ss0" must be a table or an index
3390 CONTEXT:  PL/pgSQL function dbms_stats.lock(regclass,text) line 18 at RAISE
3391 -- No.11-1-11
3392 DELETE FROM dbms_stats.relation_stats_locked;
3393 SELECT dbms_stats.lock('s0.sc0', 'id');
3394 ERROR:  "s0.sc0" must be a table or an index
3395 CONTEXT:  PL/pgSQL function dbms_stats.lock(regclass,text) line 18 at RAISE
3396 -- No.11-1-12
3397 DELETE FROM dbms_stats.relation_stats_locked;
3398 SELECT dbms_stats.lock('s0.sft0', 'id');
3399   lock   
3400 ---------
3401  s0.sft0
3402 (1 row)
3403
3404 SELECT * FROM relations_locked_v;
3405   relid  | relname | relpages | reltuples | relallvisible | curpages 
3406 ---------+---------+----------+-----------+---------------+----------
3407  s0.sft0 | s0.sft0 |   (null) |    (null) |        (null) |   (null)
3408 (1 row)
3409
3410 SELECT * FROM columns_locked_v c;
3411  starelid | staattnum | attname | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 |       stavalues1       | stavalues2 | stavalues3 | stavalues4 | stavalues5 
3412 ----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------------------+------------+------------+------------+------------
3413  s0.sft0  |         1 | id      | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {1,2,3,4,5,6,7,8,9,10} | (null)     | (null)     | (null)     | (null)
3414 (1 row)
3415
3416 -- No.11-1-13
3417 DELETE FROM dbms_stats.relation_stats_locked;
3418 SELECT dbms_stats.lock('s0.smv0', 'id');
3419   lock   
3420 ---------
3421  s0.smv0
3422 (1 row)
3423
3424 SELECT * FROM relations_locked_v;
3425   relid  | relname | relpages | reltuples | relallvisible | curpages 
3426 ---------+---------+----------+-----------+---------------+----------
3427  s0.smv0 | s0.smv0 |   (null) |    (null) |        (null) |   (null)
3428 (1 row)
3429
3430 SELECT * FROM columns_locked_v c;
3431  starelid | staattnum | attname | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 | stavalues1 | stavalues2 | stavalues3 | stavalues4 | stavalues5 
3432 ----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------+------------+------------+------------+------------
3433  s0.smv0  |         1 | id      | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {1,2}      | (null)     | (null)     | (null)     | (null)
3434 (1 row)
3435
3436 -- No.11-1-14
3437 DELETE FROM dbms_stats.relation_stats_locked;
3438 SELECT dbms_stats.lock('pg_catalog.pg_class', 'id');
3439 ERROR:  locking statistics is inhibited for system catalogs: "pg_class"
3440 CONTEXT:  PL/pgSQL function dbms_stats.lock(regclass,text) line 24 at RAISE
3441 -- No.11-1-15
3442 DELETE FROM dbms_stats.relation_stats_locked;
3443 SELECT dbms_stats.lock('s0.st0', 'dummy');
3444 ERROR:  column "dummy" not found in relation "s0.st0"
3445 CONTEXT:  PL/pgSQL function dbms_stats.lock(regclass,text) line 29 at RAISE
3446 -- No.11-1-16
3447 DELETE FROM dbms_stats.relation_stats_locked;
3448 DELETE FROM pg_statistic
3449  WHERE starelid = 's0.st0'::regclass;
3450 SELECT dbms_stats.lock('s0.st0', 'id');
3451 ERROR:  no statistics available for column "id" of relation "s0.st0"
3452 CONTEXT:  PL/pgSQL function dbms_stats.lock(regclass,text) line 120 at RAISE
3453 VACUUM ANALYZE;
3454 -- No.11-1-17
3455 DELETE FROM dbms_stats.relation_stats_locked;
3456 INSERT INTO dbms_stats.relation_stats_locked(
3457     relid, relname, relpages, reltuples,
3458     relallvisible,
3459     curpages)
3460     VALUES('s0.st0'::regclass, 's0.st0', 1, 1640,
3461            1,
3462            1);
3463 SELECT dbms_stats.lock_column_stats('s0.st0','id');
3464  lock_column_stats 
3465 -------------------
3466  s0.st0
3467 (1 row)
3468
3469 UPDATE dbms_stats.column_stats_locked
3470    SET (stanullfrac, stawidth, stadistinct,
3471         stakind1, stakind2, stakind3, stakind4,
3472         stakind5,
3473         staop1, staop2, staop3, staop4,
3474         staop5,
3475         stanumbers1, stanumbers2, stanumbers3, stanumbers4,
3476         stanumbers5,
3477         stavalues1, stavalues2, stavalues3, stavalues4
3478        ,stavalues5
3479        ) = (
3480         NULL, NULL, NULL,
3481         NULL, NULL, NULL, NULL,
3482         NULL, NULL, NULL, NULL,
3483         NULL, NULL, NULL, NULL,
3484         NULL, NULL, NULL, NULL,
3485         NULL, NULL, NULL, NULL)
3486  WHERE starelid = 's0.st0'::regclass;
3487 SELECT dbms_stats.lock('s0.st0', 'id');
3488   lock  
3489 --------
3490  s0.st0
3491 (1 row)
3492
3493 SELECT * FROM relations_locked_v;
3494  relid  | relname | relpages | reltuples | relallvisible | curpages 
3495 --------+---------+----------+-----------+---------------+----------
3496  s0.st0 | s0.st0  |        1 |      1640 |             1 |        1
3497 (1 row)
3498
3499 SELECT * FROM columns_locked_v c;
3500  starelid | staattnum | attname | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 | stavalues1  | stavalues2 | stavalues3 | stavalues4 | stavalues5 
3501 ----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+-------------+------------+------------+------------+------------
3502  s0.st0   |         1 | id      | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {1,2}       | (null)     | (null)     | (null)     | (null)
3503  s0.st0   |         1 | id      | t          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {1,2,4,5,6} | (null)     | (null)     | (null)     | (null)
3504 (2 rows)
3505
3506 -- No.11-1-18
3507 DELETE FROM dbms_stats.relation_stats_locked;
3508 SELECT dbms_stats.lock('s0.st0', 'id');
3509   lock  
3510 --------
3511  s0.st0
3512 (1 row)
3513
3514 SELECT * FROM relations_locked_v
3515  WHERE relid = 's0.st0'::regclass;
3516  relid  | relname | relpages | reltuples | relallvisible | curpages 
3517 --------+---------+----------+-----------+---------------+----------
3518  s0.st0 | s0.st0  |   (null) |    (null) |        (null) |   (null)
3519 (1 row)
3520
3521 SELECT starelid, attname, stainherit FROM columns_locked_v c;
3522  starelid | attname | stainherit 
3523 ----------+---------+------------
3524  s0.st0   | id      | f
3525  s0.st0   | id      | t
3526 (2 rows)
3527
3528 /*
3529  * No.11-2 dbms_stats.lock(relid)
3530  */
3531 -- No.11-2-1
3532 DELETE FROM dbms_stats.relation_stats_locked;
3533 VACUUM dbms_stats.relation_stats_locked;  -- in order to avoid auto vacuum
3534 BEGIN;
3535 SELECT * FROM internal_locks;
3536  relation | mode 
3537 ----------+------
3538 (0 rows)
3539
3540 SELECT dbms_stats.lock('s0.st0');
3541   lock  
3542 --------
3543  s0.st0
3544 (1 row)
3545
3546 SELECT * FROM relations_locked_v;
3547  relid  | relname | relpages | reltuples | relallvisible | curpages 
3548 --------+---------+----------+-----------+---------------+----------
3549  s0.st0 | s0.st0  |        1 |         2 |             1 |        1
3550 (1 row)
3551
3552 SELECT * FROM columns_locked_v c;
3553  starelid | staattnum | attname | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 |    stavalues1    | stavalues2 | stavalues3 | stavalues4 | stavalues5 
3554 ----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------------+------------+------------+------------+------------
3555  s0.st0   |         1 | id      | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {1,2}            | (null)     | (null)     | (null)     | (null)
3556  s0.st0   |         1 | id      | t          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {1,2,4,5,6}      | (null)     | (null)     | (null)     | (null)
3557  s0.st0   |         2 | num     | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {10,20}          | (null)     | (null)     | (null)     | (null)
3558  s0.st0   |         2 | num     | t          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {10,20,40,50,60} | (null)     | (null)     | (null)     | (null)
3559 (4 rows)
3560
3561 SELECT * FROM internal_locks;
3562              relation             |       mode       
3563 ----------------------------------+------------------
3564  dbms_stats.column_stats_locked   | AccessShareLock
3565  dbms_stats.column_stats_locked   | RowExclusiveLock
3566  dbms_stats.relation_stats_locked | AccessShareLock
3567  dbms_stats.relation_stats_locked | RowExclusiveLock
3568  dbms_stats.relation_stats_locked | RowShareLock
3569 (5 rows)
3570
3571 COMMIT;
3572 -- No.11-2-2
3573 DELETE FROM dbms_stats.relation_stats_locked;
3574 SELECT dbms_stats.lock(NULL);
3575 ERROR:  relation required
3576 CONTEXT:  PL/pgSQL function dbms_stats.lock(regclass) line 7 at RAISE
3577 -- No.11-2-3
3578 DELETE FROM dbms_stats.relation_stats_locked;
3579 SELECT dbms_stats.lock('0');
3580 ERROR:  relation "-" not found
3581 CONTEXT:  PL/pgSQL function dbms_stats.lock(regclass) line 11 at RAISE
3582 -- No.11-2-4
3583 DELETE FROM dbms_stats.relation_stats_locked;
3584 SELECT dbms_stats.lock('s0.st0');
3585   lock  
3586 --------
3587  s0.st0
3588 (1 row)
3589
3590 SELECT * FROM relations_locked_v;
3591  relid  | relname | relpages | reltuples | relallvisible | curpages 
3592 --------+---------+----------+-----------+---------------+----------
3593  s0.st0 | s0.st0  |        1 |         2 |             1 |        1
3594 (1 row)
3595
3596 SELECT * FROM columns_locked_v c;
3597  starelid | staattnum | attname | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 |    stavalues1    | stavalues2 | stavalues3 | stavalues4 | stavalues5 
3598 ----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------------+------------+------------+------------+------------
3599  s0.st0   |         1 | id      | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {1,2}            | (null)     | (null)     | (null)     | (null)
3600  s0.st0   |         1 | id      | t          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {1,2,4,5,6}      | (null)     | (null)     | (null)     | (null)
3601  s0.st0   |         2 | num     | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {10,20}          | (null)     | (null)     | (null)     | (null)
3602  s0.st0   |         2 | num     | t          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {10,20,40,50,60} | (null)     | (null)     | (null)     | (null)
3603 (4 rows)
3604
3605 -- No.11-2-5
3606 DELETE FROM dbms_stats.relation_stats_locked;
3607 SELECT dbms_stats.lock('pg_toast.pg_toast_2618');
3608 ERROR:  locking statistics is not allowed for relations with relkind "t": "pg_toast.pg_toast_2618"
3609 HINT:  Only tables(r, m, f) and indexes(i) are lockable.
3610 CONTEXT:  PL/pgSQL function dbms_stats.lock(regclass) line 14 at RAISE
3611 -- No.11-2-6
3612 DELETE FROM dbms_stats.relation_stats_locked;
3613 SELECT dbms_stats.lock('s0.st0_idx');
3614     lock    
3615 ------------
3616  s0.st0_idx
3617 (1 row)
3618
3619 SELECT * FROM relations_locked_v;
3620    relid    |  relname   | relpages | reltuples | relallvisible | curpages 
3621 ------------+------------+----------+-----------+---------------+----------
3622  s0.st0_idx | s0.st0_idx |        2 |         2 |             0 |        2
3623 (1 row)
3624
3625 SELECT * FROM columns_locked_v c;
3626  starelid | staattnum | attname | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 | stavalues1 | stavalues2 | stavalues3 | stavalues4 | stavalues5 
3627 ----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------+------------+------------+------------+------------
3628 (0 rows)
3629
3630 -- No.11-2-7
3631 DELETE FROM dbms_stats.relation_stats_locked;
3632 SELECT dbms_stats.lock('s0.ss0');
3633 ERROR:  locking statistics is not allowed for relations with relkind "S": "s0.ss0"
3634 HINT:  Only tables(r, m, f) and indexes(i) are lockable.
3635 CONTEXT:  PL/pgSQL function dbms_stats.lock(regclass) line 14 at RAISE
3636 -- No.11-2-8
3637 DELETE FROM dbms_stats.relation_stats_locked;
3638 SELECT dbms_stats.lock('s0.sc0');
3639 ERROR:  locking statistics is not allowed for relations with relkind "c": "s0.sc0"
3640 HINT:  Only tables(r, m, f) and indexes(i) are lockable.
3641 CONTEXT:  PL/pgSQL function dbms_stats.lock(regclass) line 14 at RAISE
3642 -- No.11-2-9
3643 DELETE FROM dbms_stats.relation_stats_locked;
3644 SELECT dbms_stats.lock('s0.sft0');
3645   lock   
3646 ---------
3647  s0.sft0
3648 (1 row)
3649
3650 SELECT * FROM relations_locked_v;
3651   relid  | relname | relpages | reltuples | relallvisible | curpages 
3652 ---------+---------+----------+-----------+---------------+----------
3653  s0.sft0 | s0.sft0 |        1 |        10 |             0 |        0
3654 (1 row)
3655
3656 SELECT * FROM columns_locked_v c;
3657  starelid | staattnum | attname | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 |       stavalues1       | stavalues2 | stavalues3 | stavalues4 | stavalues5 
3658 ----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------------------+------------+------------+------------+------------
3659  s0.sft0  |         1 | id      | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {1,2,3,4,5,6,7,8,9,10} | (null)     | (null)     | (null)     | (null)
3660 (1 row)
3661
3662 -- No.11-2-10
3663 DELETE FROM dbms_stats.relation_stats_locked;
3664 SELECT dbms_stats.lock('s0.smv0');
3665   lock   
3666 ---------
3667  s0.smv0
3668 (1 row)
3669
3670 SELECT * FROM relations_locked_v;
3671   relid  | relname | relpages | reltuples | relallvisible | curpages 
3672 ---------+---------+----------+-----------+---------------+----------
3673  s0.smv0 | s0.smv0 |        1 |         2 |             1 |        1
3674 (1 row)
3675
3676 SELECT * FROM columns_locked_v c;
3677  starelid | staattnum | attname | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 | stavalues1 | stavalues2 | stavalues3 | stavalues4 | stavalues5 
3678 ----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------+------------+------------+------------+------------
3679  s0.smv0  |         1 | id      | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {1,2}      | (null)     | (null)     | (null)     | (null)
3680  s0.smv0  |         2 | num     | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {10,20}    | (null)     | (null)     | (null)     | (null)
3681  s0.smv0  |         3 | txt     | f          |           0 |        3 |          -1 |        2 |        3 |        0 |        0 |        0 |    664 |    664 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {1,test}   | (null)     | (null)     | (null)     | (null)
3682 (3 rows)
3683
3684 -- No.11-2-11
3685 DELETE FROM dbms_stats.relation_stats_locked;
3686 SELECT dbms_stats.lock('pg_catalog.pg_class');
3687 ERROR:  locking statistics is not allowed for system catalogs: "pg_class"
3688 CONTEXT:  PL/pgSQL function dbms_stats.lock(regclass) line 18 at RAISE
3689 -- No.11-2-12
3690 DELETE FROM dbms_stats.relation_stats_locked;
3691 SELECT dbms_stats.lock_table_stats('s0.st0');
3692  lock_table_stats 
3693 ------------------
3694  s0.st0
3695 (1 row)
3696
3697 UPDATE dbms_stats.relation_stats_locked
3698    SET (relpages, reltuples,
3699         relallvisible,
3700         curpages)
3701      = (NULL, NULL, NULL
3702        ,NULL
3703        )
3704  WHERE relid = 's0.st0'::regclass;
3705 SELECT dbms_stats.lock('s0.st0');
3706   lock  
3707 --------
3708  s0.st0
3709 (1 row)
3710
3711 SELECT * FROM relations_locked_v;
3712  relid  | relname | relpages | reltuples | relallvisible | curpages 
3713 --------+---------+----------+-----------+---------------+----------
3714  s0.st0 | s0.st0  |        1 |         2 |             1 |        1
3715 (1 row)
3716
3717 SELECT * FROM columns_locked_v c;
3718  starelid | staattnum | attname | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 |    stavalues1    | stavalues2 | stavalues3 | stavalues4 | stavalues5 
3719 ----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------------+------------+------------+------------+------------
3720  s0.st0   |         1 | id      | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {1,2}            | (null)     | (null)     | (null)     | (null)
3721  s0.st0   |         1 | id      | t          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {1,2,4,5,6}      | (null)     | (null)     | (null)     | (null)
3722  s0.st0   |         2 | num     | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {10,20}          | (null)     | (null)     | (null)     | (null)
3723  s0.st0   |         2 | num     | t          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {10,20,40,50,60} | (null)     | (null)     | (null)     | (null)
3724 (4 rows)
3725
3726 -- No.11-2-13
3727 DELETE FROM dbms_stats.relation_stats_locked;
3728 SELECT dbms_stats.lock('s0.st0');
3729   lock  
3730 --------
3731  s0.st0
3732 (1 row)
3733
3734 SELECT * FROM relations_locked_v;
3735  relid  | relname | relpages | reltuples | relallvisible | curpages 
3736 --------+---------+----------+-----------+---------------+----------
3737  s0.st0 | s0.st0  |        1 |         2 |             1 |        1
3738 (1 row)
3739
3740 SELECT * FROM columns_locked_v c;
3741  starelid | staattnum | attname | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 |    stavalues1    | stavalues2 | stavalues3 | stavalues4 | stavalues5 
3742 ----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------------+------------+------------+------------+------------
3743  s0.st0   |         1 | id      | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {1,2}            | (null)     | (null)     | (null)     | (null)
3744  s0.st0   |         1 | id      | t          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {1,2,4,5,6}      | (null)     | (null)     | (null)     | (null)
3745  s0.st0   |         2 | num     | f          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {10,20}          | (null)     | (null)     | (null)     | (null)
3746  s0.st0   |         2 | num     | t          |           0 |        4 |          -1 |        2 |        3 |        0 |        0 |        0 |     97 |     97 |      0 |      0 |      0 | (null)      | {1}         | (null)      | (null)      | (null)      | {10,20,40,50,60} | (null)     | (null)     | (null)     | (null)
3747 (4 rows)
3748
3749 /*
3750  * Stab function dbms_stats.lock
3751  */
3752 ALTER FUNCTION dbms_stats.lock(relid regclass)
3753     RENAME TO truth_lock;
3754 CREATE FUNCTION dbms_stats.lock(relid regclass)
3755 RETURNS regclass AS
3756 $$
3757 BEGIN
3758     RAISE NOTICE 'arguments are %', $1;
3759     RETURN $1;
3760 END
3761 $$
3762 LANGUAGE plpgsql;
3763 ALTER FUNCTION dbms_stats.lock(relid regclass, attname text)
3764     RENAME TO truth_lock;
3765 CREATE FUNCTION dbms_stats.lock(
3766     relid regclass,
3767     attname text)
3768 RETURNS regclass AS
3769 $$
3770 BEGIN
3771     RAISE NOTICE 'arguments are %, %', $1, $2;
3772     RETURN $1;
3773 END
3774 $$
3775 LANGUAGE plpgsql;
3776 /*
3777  * No.12-1 dbms_stats.lock_database_stats
3778  */
3779 -- No.12-1-1
3780 SELECT dbms_stats.lock_database_stats();
3781 NOTICE:  arguments are pt0
3782 NOTICE:  arguments are pt0_idx
3783 NOTICE:  arguments are st0
3784 NOTICE:  arguments are st0_idx
3785 NOTICE:  arguments are st1
3786 NOTICE:  arguments are s0.st0
3787 NOTICE:  arguments are s0.st0_idx
3788 NOTICE:  arguments are s0.st1
3789 NOTICE:  arguments are s0.st1_idx
3790 NOTICE:  arguments are s0.st2
3791 NOTICE:  arguments are s0.st2_idx
3792 NOTICE:  arguments are st1_idx
3793 NOTICE:  arguments are st1_exp
3794 NOTICE:  arguments are s0.sft0
3795 NOTICE:  arguments are s0.smv0
3796 NOTICE:  arguments are s1.st0
3797  lock_database_stats 
3798 ---------------------
3799  pt0
3800  pt0_idx
3801  st0
3802  st0_idx
3803  st1
3804  s0.st0
3805  s0.st0_idx
3806  s0.st1
3807  s0.st1_idx
3808  s0.st2
3809  s0.st2_idx
3810  st1_idx
3811  st1_exp
3812  s0.sft0
3813  s0.smv0
3814  s1.st0
3815 (16 rows)
3816
3817 /*
3818  * No.12-2 dbms_stats.lock_schema_stats
3819  */
3820 -- No.12-2-1
3821 SELECT dbms_stats.lock_schema_stats('s0');
3822 NOTICE:  arguments are s0.st0
3823 NOTICE:  arguments are s0.st0_idx
3824 NOTICE:  arguments are s0.st1
3825 NOTICE:  arguments are s0.st1_idx
3826 NOTICE:  arguments are s0.st2
3827 NOTICE:  arguments are s0.st2_idx
3828 NOTICE:  arguments are s0.sft0
3829 NOTICE:  arguments are s0.smv0
3830  lock_schema_stats 
3831 -------------------
3832  s0.st0
3833  s0.st0_idx
3834  s0.st1
3835  s0.st1_idx
3836  s0.st2
3837  s0.st2_idx
3838  s0.sft0
3839  s0.smv0
3840 (8 rows)
3841
3842 -- No.12-2-2
3843 SELECT dbms_stats.lock_schema_stats('s00');
3844 ERROR:  schema "s00" not found
3845 CONTEXT:  PL/pgSQL function dbms_stats.lock_schema_stats(text) line 4 at RAISE
3846 -- No.12-2-3
3847 SELECT dbms_stats.lock_schema_stats('pg_catalog');
3848 ERROR:  locking statistics is not allowed for system schemas: "pg_catalog"
3849 CONTEXT:  PL/pgSQL function dbms_stats.lock_schema_stats(text) line 7 at RAISE
3850 /*
3851  * No.12-3 dbms_stats.lock_table_stats(regclass)
3852  */
3853 -- No.12-3-1
3854 SELECT dbms_stats.lock_table_stats('s0.st0');
3855 NOTICE:  arguments are s0.st0
3856  lock_table_stats 
3857 ------------------
3858  s0.st0
3859 (1 row)
3860
3861 -- No.12-3-2
3862 SELECT dbms_stats.lock_table_stats('st0');
3863 NOTICE:  arguments are st0
3864  lock_table_stats 
3865 ------------------
3866  st0
3867 (1 row)
3868
3869 -- No.12-3-3
3870 SELECT dbms_stats.lock_table_stats('s00.s0');
3871 ERROR:  schema "s00" does not exist
3872 LINE 1: SELECT dbms_stats.lock_table_stats('s00.s0');
3873                                            ^
3874 /*
3875  * No.12-4 dbms_stats.lock_table_stats(schemaname, tablename)
3876  */
3877 -- No.12-4-1
3878 SELECT dbms_stats.lock_table_stats('s0', 'st0');
3879 NOTICE:  arguments are s0.st0
3880  lock_table_stats 
3881 ------------------
3882  s0.st0
3883 (1 row)
3884
3885 /*
3886  * No.12-5 dbms_stats.lock_column_stats(regclass, attname)
3887  */
3888 -- No.12-5-1
3889 SELECT dbms_stats.lock_column_stats('s0.st0', 'id');
3890 NOTICE:  arguments are s0.st0, id
3891  lock_column_stats 
3892 -------------------
3893  s0.st0
3894 (1 row)
3895
3896 -- No.12-5-2
3897 SELECT dbms_stats.lock_column_stats('st0', 'id');
3898 NOTICE:  arguments are st0, id
3899  lock_column_stats 
3900 -------------------
3901  st0
3902 (1 row)
3903
3904 -- No.12-5-3
3905 SELECT dbms_stats.lock_column_stats('s00.s0', 'id');
3906 ERROR:  schema "s00" does not exist
3907 LINE 1: SELECT dbms_stats.lock_column_stats('s00.s0', 'id');
3908                                             ^
3909 /*
3910  * No.12-6 dbms_stats.lock_column_stats(schemaname, tablename, int2)
3911  */
3912 -- No.12-6-1
3913 SELECT dbms_stats.lock_column_stats('s0', 'st0', 'id');
3914 NOTICE:  arguments are s0.st0, id
3915  lock_column_stats 
3916 -------------------
3917  s0.st0
3918 (1 row)
3919
3920 /*
3921  * Delete Stab function lock
3922  */
3923 DROP FUNCTION dbms_stats.lock(relid regclass);
3924 ALTER FUNCTION dbms_stats.truth_lock(relid regclass)
3925     RENAME TO lock;
3926 DROP FUNCTION dbms_stats.lock(relid regclass, attname text);
3927 ALTER FUNCTION dbms_stats.truth_lock(relid regclass, attname text)
3928     RENAME TO lock;
3929 /*
3930  * No.13-1 dbms_stats.unlock
3931  */
3932 -- No.13-1-1
3933 DELETE FROM dbms_stats.relation_stats_locked;
3934 SELECT dbms_stats.lock_database_stats();
3935  lock_database_stats 
3936 ---------------------
3937  pt0
3938  pt0_idx
3939  st0
3940  st0_idx
3941  st1
3942  s0.st0
3943  s0.st0_idx
3944  s0.st1
3945  s0.st1_idx
3946  s0.st2
3947  s0.st2_idx
3948  st1_idx
3949  st1_exp
3950  s0.sft0
3951  s0.smv0
3952  s1.st0
3953 (16 rows)
3954
3955 SELECT * FROM dbms_stats.backup_history
3956  ORDER BY id;
3957  id |                time                 | unit | comment 
3958 ----+-------------------------------------+------+---------
3959   1 | Wed Feb 29 23:59:56.999999 2012 PST | d    | (null)
3960   2 | Wed Feb 29 23:59:57 2012 PST        | d    | (null)
3961   3 | Wed Feb 29 23:59:57.000001 2012 PST | t    | (null)
3962   4 | Wed Feb 29 23:59:58 2012 PST        | d    | (null)
3963   5 | Thu Mar 01 00:00:00 2012 PST        | c    | (null)
3964   6 | Thu Mar 01 00:00:02 2012 PST        | t    | (null)
3965   7 | Thu Mar 01 00:00:04 2012 PST        | t    | (null)
3966   8 | Thu Mar 01 00:00:06 2012 PST        | s    | (null)
3967 (8 rows)
3968
3969 SELECT count(*) FROM dbms_stats.relation_stats_backup;
3970  count 
3971 -------
3972     26
3973 (1 row)
3974
3975 SELECT count(*) FROM dbms_stats.column_stats_backup;
3976  count 
3977 -------
3978     39
3979 (1 row)
3980
3981 SELECT dbms_stats.unlock();
3982    unlock   
3983 ------------
3984  pt0
3985  pt0_idx
3986  st0
3987  st0_idx
3988  st1
3989  s0.st0
3990  s0.st0_idx
3991  s0.st1
3992  s0.st1_idx
3993  s0.st2
3994  s0.st2_idx
3995  st1_idx
3996  st1_exp
3997  s0.sft0
3998  s0.smv0
3999  s1.st0
4000 (16 rows)
4001
4002 SELECT count(*) FROM dbms_stats.relation_stats_locked;
4003  count 
4004 -------
4005      0
4006 (1 row)
4007
4008 SELECT count(*) FROM dbms_stats.column_stats_locked;
4009  count 
4010 -------
4011      0
4012 (1 row)
4013
4014 SELECT * FROM dbms_stats.backup_history
4015  ORDER BY id;
4016  id |                time                 | unit | comment 
4017 ----+-------------------------------------+------+---------
4018   1 | Wed Feb 29 23:59:56.999999 2012 PST | d    | (null)
4019   2 | Wed Feb 29 23:59:57 2012 PST        | d    | (null)
4020   3 | Wed Feb 29 23:59:57.000001 2012 PST | t    | (null)
4021   4 | Wed Feb 29 23:59:58 2012 PST        | d    | (null)
4022   5 | Thu Mar 01 00:00:00 2012 PST        | c    | (null)
4023   6 | Thu Mar 01 00:00:02 2012 PST        | t    | (null)
4024   7 | Thu Mar 01 00:00:04 2012 PST        | t    | (null)
4025   8 | Thu Mar 01 00:00:06 2012 PST        | s    | (null)
4026 (8 rows)
4027
4028 SELECT count(*) FROM dbms_stats.relation_stats_backup;
4029  count 
4030 -------
4031     26
4032 (1 row)
4033
4034 SELECT count(*) FROM dbms_stats.column_stats_backup;
4035  count 
4036 -------
4037     39
4038 (1 row)
4039
4040 -- No.13-1-2
4041 DELETE FROM dbms_stats.relation_stats_locked;
4042 SELECT dbms_stats.lock_database_stats();
4043  lock_database_stats 
4044 ---------------------
4045  pt0
4046  pt0_idx
4047  st0
4048  st0_idx
4049  st1
4050  s0.st0
4051  s0.st0_idx
4052  s0.st1
4053  s0.st1_idx
4054  s0.st2
4055  s0.st2_idx
4056  st1_idx
4057  st1_exp
4058  s0.sft0
4059  s0.smv0
4060  s1.st0
4061 (16 rows)
4062
4063 SELECT dbms_stats.unlock();
4064    unlock   
4065 ------------
4066  pt0
4067  pt0_idx
4068  st0
4069  st0_idx
4070  st1
4071  s0.st0
4072  s0.st0_idx
4073  s0.st1
4074  s0.st1_idx
4075  s0.st2
4076  s0.st2_idx
4077  st1_idx
4078  st1_exp
4079  s0.sft0
4080  s0.smv0
4081  s1.st0
4082 (16 rows)
4083
4084 SELECT count(*) FROM dbms_stats.relation_stats_locked;
4085  count 
4086 -------
4087      0
4088 (1 row)
4089
4090 SELECT count(*) FROM dbms_stats.column_stats_locked;
4091  count 
4092 -------
4093      0
4094 (1 row)
4095
4096 -- No.13-1-3
4097 DELETE FROM dbms_stats.relation_stats_locked;
4098 SELECT dbms_stats.lock_database_stats();
4099  lock_database_stats 
4100 ---------------------
4101  pt0
4102  pt0_idx
4103  st0
4104  st0_idx
4105  st1
4106  s0.st0
4107  s0.st0_idx
4108  s0.st1
4109  s0.st1_idx
4110  s0.st2
4111  s0.st2_idx
4112  st1_idx
4113  st1_exp
4114  s0.sft0
4115  s0.smv0
4116  s1.st0
4117 (16 rows)
4118
4119 DELETE FROM dbms_stats.column_stats_locked;
4120 SELECT dbms_stats.unlock();
4121    unlock   
4122 ------------
4123  pt0
4124  pt0_idx
4125  st0
4126  st0_idx
4127  st1
4128  s0.st0
4129  s0.st0_idx
4130  s0.st1
4131  s0.st1_idx
4132  s0.st2
4133  s0.st2_idx
4134  st1_idx
4135  st1_exp
4136  s0.sft0
4137  s0.smv0
4138  s1.st0
4139 (16 rows)
4140
4141 SELECT count(*) FROM dbms_stats.relation_stats_locked;
4142  count 
4143 -------
4144      0
4145 (1 row)
4146
4147 SELECT count(*) FROM dbms_stats.column_stats_locked;
4148  count 
4149 -------
4150      0
4151 (1 row)
4152
4153 -- No.13-1-4
4154 DELETE FROM dbms_stats.relation_stats_locked;
4155 SELECT dbms_stats.unlock();
4156  unlock 
4157 --------
4158 (0 rows)
4159
4160 SELECT count(*) FROM dbms_stats.relation_stats_locked;
4161  count 
4162 -------
4163      0
4164 (1 row)
4165
4166 SELECT count(*) FROM dbms_stats.column_stats_locked;
4167  count 
4168 -------
4169      0
4170 (1 row)
4171
4172 -- No.13-1-5
4173 DELETE FROM dbms_stats.relation_stats_locked;
4174 SELECT dbms_stats.lock_database_stats();
4175  lock_database_stats 
4176 ---------------------
4177  pt0
4178  pt0_idx
4179  st0
4180  st0_idx
4181  st1
4182  s0.st0
4183  s0.st0_idx
4184  s0.st1
4185  s0.st1_idx
4186  s0.st2
4187  s0.st2_idx
4188  st1_idx
4189  st1_exp
4190  s0.sft0
4191  s0.smv0
4192  s1.st0
4193 (16 rows)
4194
4195 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
4196  GROUP BY relid
4197  ORDER BY relid;
4198    relid    
4199 ------------
4200  pt0
4201  pt0_idx
4202  st0
4203  st0_idx
4204  st1
4205  s0.st0
4206  s0.st0_idx
4207  s0.st1
4208  s0.st1_idx
4209  s0.st2
4210  s0.st2_idx
4211  st1_idx
4212  st1_exp
4213  s0.sft0
4214  s0.smv0
4215  s1.st0
4216 (16 rows)
4217
4218 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
4219  GROUP BY starelid
4220  ORDER BY starelid;
4221  starelid | count 
4222 ----------+-------
4223  st0      |     2
4224  st1      |     2
4225  s0.st0   |     4
4226  s0.st1   |     2
4227  s0.st2   |     2
4228  st1_exp  |     1
4229  s0.sft0  |     1
4230  s0.smv0  |     3
4231  s1.st0   |     2
4232 (9 rows)
4233
4234 SELECT dbms_stats.unlock('s0.st0');
4235  unlock 
4236 --------
4237  s0.st0
4238 (1 row)
4239
4240 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
4241  GROUP BY relid
4242  ORDER BY relid;
4243    relid    
4244 ------------
4245  pt0
4246  pt0_idx
4247  st0
4248  st0_idx
4249  st1
4250  s0.st0_idx
4251  s0.st1
4252  s0.st1_idx
4253  s0.st2
4254  s0.st2_idx
4255  st1_idx
4256  st1_exp
4257  s0.sft0
4258  s0.smv0
4259  s1.st0
4260 (15 rows)
4261
4262 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
4263  GROUP BY starelid
4264  ORDER BY starelid;
4265  starelid | count 
4266 ----------+-------
4267  st0      |     2
4268  st1      |     2
4269  s0.st1   |     2
4270  s0.st2   |     2
4271  st1_exp  |     1
4272  s0.sft0  |     1
4273  s0.smv0  |     3
4274  s1.st0   |     2
4275 (8 rows)
4276
4277 -- No.13-1-6
4278 DELETE FROM dbms_stats.relation_stats_locked;
4279 SELECT dbms_stats.lock_database_stats();
4280  lock_database_stats 
4281 ---------------------
4282  pt0
4283  pt0_idx
4284  st0
4285  st0_idx
4286  st1
4287  s0.st0
4288  s0.st0_idx
4289  s0.st1
4290  s0.st1_idx
4291  s0.st2
4292  s0.st2_idx
4293  st1_idx
4294  st1_exp
4295  s0.sft0
4296  s0.smv0
4297  s1.st0
4298 (16 rows)
4299
4300 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
4301  GROUP BY relid
4302  ORDER BY relid;
4303    relid    
4304 ------------
4305  pt0
4306  pt0_idx
4307  st0
4308  st0_idx
4309  st1
4310  s0.st0
4311  s0.st0_idx
4312  s0.st1
4313  s0.st1_idx
4314  s0.st2
4315  s0.st2_idx
4316  st1_idx
4317  st1_exp
4318  s0.sft0
4319  s0.smv0
4320  s1.st0
4321 (16 rows)
4322
4323 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
4324  GROUP BY starelid
4325  ORDER BY starelid;
4326  starelid | count 
4327 ----------+-------
4328  st0      |     2
4329  st1      |     2
4330  s0.st0   |     4
4331  s0.st1   |     2
4332  s0.st2   |     2
4333  st1_exp  |     1
4334  s0.sft0  |     1
4335  s0.smv0  |     3
4336  s1.st0   |     2
4337 (9 rows)
4338
4339 SELECT dbms_stats.unlock('st0');
4340  unlock 
4341 --------
4342  st0
4343 (1 row)
4344
4345 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
4346  GROUP BY relid
4347  ORDER BY relid;
4348    relid    
4349 ------------
4350  pt0
4351  pt0_idx
4352  st0_idx
4353  st1
4354  s0.st0
4355  s0.st0_idx
4356  s0.st1
4357  s0.st1_idx
4358  s0.st2
4359  s0.st2_idx
4360  st1_idx
4361  st1_exp
4362  s0.sft0
4363  s0.smv0
4364  s1.st0
4365 (15 rows)
4366
4367 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
4368  GROUP BY starelid
4369  ORDER BY starelid;
4370  starelid | count 
4371 ----------+-------
4372  st1      |     2
4373  s0.st0   |     4
4374  s0.st1   |     2
4375  s0.st2   |     2
4376  st1_exp  |     1
4377  s0.sft0  |     1
4378  s0.smv0  |     3
4379  s1.st0   |     2
4380 (8 rows)
4381
4382 -- No.13-1-7
4383 DELETE FROM dbms_stats.relation_stats_locked;
4384 SELECT dbms_stats.lock_database_stats();
4385  lock_database_stats 
4386 ---------------------
4387  pt0
4388  pt0_idx
4389  st0
4390  st0_idx
4391  st1
4392  s0.st0
4393  s0.st0_idx
4394  s0.st1
4395  s0.st1_idx
4396  s0.st2
4397  s0.st2_idx
4398  st1_idx
4399  st1_exp
4400  s0.sft0
4401  s0.smv0
4402  s1.st0
4403 (16 rows)
4404
4405 SELECT count(*) FROM dbms_stats.relation_stats_locked;
4406  count 
4407 -------
4408     16
4409 (1 row)
4410
4411 SELECT count(*) FROM dbms_stats.column_stats_locked;
4412  count 
4413 -------
4414     19
4415 (1 row)
4416
4417 SELECT dbms_stats.unlock('s00.s0');
4418 ERROR:  schema "s00" does not exist
4419 LINE 1: SELECT dbms_stats.unlock('s00.s0');
4420                                  ^
4421 SELECT count(*) FROM dbms_stats.relation_stats_locked;
4422  count 
4423 -------
4424     16
4425 (1 row)
4426
4427 SELECT count(*) FROM dbms_stats.column_stats_locked;
4428  count 
4429 -------
4430     19
4431 (1 row)
4432
4433 -- No.13-1-8
4434 DELETE FROM dbms_stats.relation_stats_locked;
4435 SELECT dbms_stats.lock_database_stats();
4436  lock_database_stats 
4437 ---------------------
4438  pt0
4439  pt0_idx
4440  st0
4441  st0_idx
4442  st1
4443  s0.st0
4444  s0.st0_idx
4445  s0.st1
4446  s0.st1_idx
4447  s0.st2
4448  s0.st2_idx
4449  st1_idx
4450  st1_exp
4451  s0.sft0
4452  s0.smv0
4453  s1.st0
4454 (16 rows)
4455
4456 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
4457  GROUP BY relid
4458  ORDER BY relid;
4459    relid    
4460 ------------
4461  pt0
4462  pt0_idx
4463  st0
4464  st0_idx
4465  st1
4466  s0.st0
4467  s0.st0_idx
4468  s0.st1
4469  s0.st1_idx
4470  s0.st2
4471  s0.st2_idx
4472  st1_idx
4473  st1_exp
4474  s0.sft0
4475  s0.smv0
4476  s1.st0
4477 (16 rows)
4478
4479 SELECT starelid, attname, stainherit FROM columns_locked_v c;
4480  starelid | attname | stainherit 
4481 ----------+---------+------------
4482  st0      | id      | f
4483  st0      | name    | f
4484  st1      | val     | f
4485  st1      | str     | f
4486  s0.st0   | id      | f
4487  s0.st0   | id      | t
4488  s0.st0   | num     | f
4489  s0.st0   | num     | t
4490  s0.st1   | id      | f
4491  s0.st1   | num     | f
4492  s0.st2   | id      | f
4493  s0.st2   | txt     | f
4494  st1_exp  | lower   | f
4495  s0.sft0  | id      | f
4496  s0.smv0  | id      | f
4497  s0.smv0  | num     | f
4498  s0.smv0  | txt     | f
4499  s1.st0   | id      | f
4500  s1.st0   | num     | f
4501 (19 rows)
4502
4503 SELECT dbms_stats.unlock('s0.st0', 'id');
4504  unlock 
4505 --------
4506  s0.st0
4507 (1 row)
4508
4509 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
4510  GROUP BY relid
4511  ORDER BY relid;
4512    relid    
4513 ------------
4514  pt0
4515  pt0_idx
4516  st0
4517  st0_idx
4518  st1
4519  s0.st0
4520  s0.st0_idx
4521  s0.st1
4522  s0.st1_idx
4523  s0.st2
4524  s0.st2_idx
4525  st1_idx
4526  st1_exp
4527  s0.sft0
4528  s0.smv0
4529  s1.st0
4530 (16 rows)
4531
4532 SELECT starelid, attname, stainherit FROM columns_locked_v c;
4533  starelid | attname | stainherit 
4534 ----------+---------+------------
4535  st0      | id      | f
4536  st0      | name    | f
4537  st1      | val     | f
4538  st1      | str     | f
4539  s0.st0   | num     | f
4540  s0.st0   | num     | t
4541  s0.st1   | id      | f
4542  s0.st1   | num     | f
4543  s0.st2   | id      | f
4544  s0.st2   | txt     | f
4545  st1_exp  | lower   | f
4546  s0.sft0  | id      | f
4547  s0.smv0  | id      | f
4548  s0.smv0  | num     | f
4549  s0.smv0  | txt     | f
4550  s1.st0   | id      | f
4551  s1.st0   | num     | f
4552 (17 rows)
4553
4554 -- No.13-1-9
4555 DELETE FROM dbms_stats.relation_stats_locked;
4556 SELECT dbms_stats.lock_database_stats();
4557  lock_database_stats 
4558 ---------------------
4559  pt0
4560  pt0_idx
4561  st0
4562  st0_idx
4563  st1
4564  s0.st0
4565  s0.st0_idx
4566  s0.st1
4567  s0.st1_idx
4568  s0.st2
4569  s0.st2_idx
4570  st1_idx
4571  st1_exp
4572  s0.sft0
4573  s0.smv0
4574  s1.st0
4575 (16 rows)
4576
4577 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
4578  GROUP BY relid
4579  ORDER BY relid;
4580    relid    
4581 ------------
4582  pt0
4583  pt0_idx
4584  st0
4585  st0_idx
4586  st1
4587  s0.st0
4588  s0.st0_idx
4589  s0.st1
4590  s0.st1_idx
4591  s0.st2
4592  s0.st2_idx
4593  st1_idx
4594  st1_exp
4595  s0.sft0
4596  s0.smv0
4597  s1.st0
4598 (16 rows)
4599
4600 SELECT starelid, attname, stainherit FROM columns_locked_v c;
4601  starelid | attname | stainherit 
4602 ----------+---------+------------
4603  st0      | id      | f
4604  st0      | name    | f
4605  st1      | val     | f
4606  st1      | str     | f
4607  s0.st0   | id      | f
4608  s0.st0   | id      | t
4609  s0.st0   | num     | f
4610  s0.st0   | num     | t
4611  s0.st1   | id      | f
4612  s0.st1   | num     | f
4613  s0.st2   | id      | f
4614  s0.st2   | txt     | f
4615  st1_exp  | lower   | f
4616  s0.sft0  | id      | f
4617  s0.smv0  | id      | f
4618  s0.smv0  | num     | f
4619  s0.smv0  | txt     | f
4620  s1.st0   | id      | f
4621  s1.st0   | num     | f
4622 (19 rows)
4623
4624 SELECT dbms_stats.unlock('s0.st0', 'dummy');
4625 ERROR:  column "dummy" not found in relation "s0.st0"
4626 CONTEXT:  PL/pgSQL function dbms_stats.unlock(regclass,text) line 19 at RAISE
4627 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
4628  GROUP BY relid
4629  ORDER BY relid;
4630    relid    
4631 ------------
4632  pt0
4633  pt0_idx
4634  st0
4635  st0_idx
4636  st1
4637  s0.st0
4638  s0.st0_idx
4639  s0.st1
4640  s0.st1_idx
4641  s0.st2
4642  s0.st2_idx
4643  st1_idx
4644  st1_exp
4645  s0.sft0
4646  s0.smv0
4647  s1.st0
4648 (16 rows)
4649
4650 SELECT starelid, attname, stainherit FROM columns_locked_v c;
4651  starelid | attname | stainherit 
4652 ----------+---------+------------
4653  st0      | id      | f
4654  st0      | name    | f
4655  st1      | val     | f
4656  st1      | str     | f
4657  s0.st0   | id      | f
4658  s0.st0   | id      | t
4659  s0.st0   | num     | f
4660  s0.st0   | num     | t
4661  s0.st1   | id      | f
4662  s0.st1   | num     | f
4663  s0.st2   | id      | f
4664  s0.st2   | txt     | f
4665  st1_exp  | lower   | f
4666  s0.sft0  | id      | f
4667  s0.smv0  | id      | f
4668  s0.smv0  | num     | f
4669  s0.smv0  | txt     | f
4670  s1.st0   | id      | f
4671  s1.st0   | num     | f
4672 (19 rows)
4673
4674 -- No.13-1-10
4675 DELETE FROM dbms_stats.relation_stats_locked;
4676 SELECT dbms_stats.lock_database_stats();
4677  lock_database_stats 
4678 ---------------------
4679  pt0
4680  pt0_idx
4681  st0
4682  st0_idx
4683  st1
4684  s0.st0
4685  s0.st0_idx
4686  s0.st1
4687  s0.st1_idx
4688  s0.st2
4689  s0.st2_idx
4690  st1_idx
4691  st1_exp
4692  s0.sft0
4693  s0.smv0
4694  s1.st0
4695 (16 rows)
4696
4697 DELETE FROM dbms_stats.column_stats_locked;
4698 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
4699  GROUP BY relid
4700  ORDER BY relid;
4701    relid    
4702 ------------
4703  pt0
4704  pt0_idx
4705  st0
4706  st0_idx
4707  st1
4708  s0.st0
4709  s0.st0_idx
4710  s0.st1
4711  s0.st1_idx
4712  s0.st2
4713  s0.st2_idx
4714  st1_idx
4715  st1_exp
4716  s0.sft0
4717  s0.smv0
4718  s1.st0
4719 (16 rows)
4720
4721 SELECT dbms_stats.unlock('s0.st0', 'id');
4722  unlock 
4723 --------
4724  s0.st0
4725 (1 row)
4726
4727 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
4728  GROUP BY relid
4729  ORDER BY relid;
4730    relid    
4731 ------------
4732  pt0
4733  pt0_idx
4734  st0
4735  st0_idx
4736  st1
4737  s0.st0
4738  s0.st0_idx
4739  s0.st1
4740  s0.st1_idx
4741  s0.st2
4742  s0.st2_idx
4743  st1_idx
4744  st1_exp
4745  s0.sft0
4746  s0.smv0
4747  s1.st0
4748 (16 rows)
4749
4750 SELECT starelid::regclass, staattnum FROM dbms_stats.column_stats_locked
4751  GROUP BY starelid, staattnum
4752  ORDER BY starelid, staattnum;
4753  starelid | staattnum 
4754 ----------+-----------
4755 (0 rows)
4756
4757 -- No.13-1-11
4758 DELETE FROM dbms_stats.relation_stats_locked;
4759 SELECT dbms_stats.lock_database_stats();
4760  lock_database_stats 
4761 ---------------------
4762  pt0
4763  pt0_idx
4764  st0
4765  st0_idx
4766  st1
4767  s0.st0
4768  s0.st0_idx
4769  s0.st1
4770  s0.st1_idx
4771  s0.st2
4772  s0.st2_idx
4773  st1_idx
4774  st1_exp
4775  s0.sft0
4776  s0.smv0
4777  s1.st0
4778 (16 rows)
4779
4780 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
4781  GROUP BY relid
4782  ORDER BY relid;
4783    relid    
4784 ------------
4785  pt0
4786  pt0_idx
4787  st0
4788  st0_idx
4789  st1
4790  s0.st0
4791  s0.st0_idx
4792  s0.st1
4793  s0.st1_idx
4794  s0.st2
4795  s0.st2_idx
4796  st1_idx
4797  st1_exp
4798  s0.sft0
4799  s0.smv0
4800  s1.st0
4801 (16 rows)
4802
4803 SELECT starelid::regclass, staattnum FROM dbms_stats.column_stats_locked
4804  GROUP BY starelid, staattnum
4805  ORDER BY starelid, staattnum;
4806  starelid | staattnum 
4807 ----------+-----------
4808  st0      |         1
4809  st0      |         2
4810  st1      |         1
4811  st1      |         2
4812  s0.st0   |         1
4813  s0.st0   |         2
4814  s0.st1   |         1
4815  s0.st1   |         2
4816  s0.st2   |         1
4817  s0.st2   |         2
4818  st1_exp  |         1
4819  s0.sft0  |         1
4820  s0.smv0  |         1
4821  s0.smv0  |         2
4822  s0.smv0  |         3
4823  s1.st0   |         1
4824  s1.st0   |         2
4825 (17 rows)
4826
4827 SELECT dbms_stats.unlock(NULL, 'id');
4828 ERROR:  relation required
4829 CONTEXT:  PL/pgSQL function dbms_stats.unlock(regclass,text) line 7 at RAISE
4830 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
4831  GROUP BY relid
4832  ORDER BY relid;
4833    relid    
4834 ------------
4835  pt0
4836  pt0_idx
4837  st0
4838  st0_idx
4839  st1
4840  s0.st0
4841  s0.st0_idx
4842  s0.st1
4843  s0.st1_idx
4844  s0.st2
4845  s0.st2_idx
4846  st1_idx
4847  st1_exp
4848  s0.sft0
4849  s0.smv0
4850  s1.st0
4851 (16 rows)
4852
4853 SELECT starelid::regclass, staattnum FROM dbms_stats.column_stats_locked
4854  GROUP BY starelid, staattnum
4855  ORDER BY starelid, staattnum;
4856  starelid | staattnum 
4857 ----------+-----------
4858  st0      |         1
4859  st0      |         2
4860  st1      |         1
4861  st1      |         2
4862  s0.st0   |         1
4863  s0.st0   |         2
4864  s0.st1   |         1
4865  s0.st1   |         2
4866  s0.st2   |         1
4867  s0.st2   |         2
4868  st1_exp  |         1
4869  s0.sft0  |         1
4870  s0.smv0  |         1
4871  s0.smv0  |         2
4872  s0.smv0  |         3
4873  s1.st0   |         1
4874  s1.st0   |         2
4875 (17 rows)
4876
4877 -- No.13-1-12
4878 DELETE FROM dbms_stats.relation_stats_locked;
4879 SELECT dbms_stats.lock_database_stats();
4880  lock_database_stats 
4881 ---------------------
4882  pt0
4883  pt0_idx
4884  st0
4885  st0_idx
4886  st1
4887  s0.st0
4888  s0.st0_idx
4889  s0.st1
4890  s0.st1_idx
4891  s0.st2
4892  s0.st2_idx
4893  st1_idx
4894  st1_exp
4895  s0.sft0
4896  s0.smv0
4897  s1.st0
4898 (16 rows)
4899
4900 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
4901  GROUP BY relid
4902  ORDER BY relid;
4903    relid    
4904 ------------
4905  pt0
4906  pt0_idx
4907  st0
4908  st0_idx
4909  st1
4910  s0.st0
4911  s0.st0_idx
4912  s0.st1
4913  s0.st1_idx
4914  s0.st2
4915  s0.st2_idx
4916  st1_idx
4917  st1_exp
4918  s0.sft0
4919  s0.smv0
4920  s1.st0
4921 (16 rows)
4922
4923 SELECT starelid::regclass, staattnum FROM dbms_stats.column_stats_locked
4924  GROUP BY starelid, staattnum
4925  ORDER BY starelid, staattnum;
4926  starelid | staattnum 
4927 ----------+-----------
4928  st0      |         1
4929  st0      |         2
4930  st1      |         1
4931  st1      |         2
4932  s0.st0   |         1
4933  s0.st0   |         2
4934  s0.st1   |         1
4935  s0.st1   |         2
4936  s0.st2   |         1
4937  s0.st2   |         2
4938  st1_exp  |         1
4939  s0.sft0  |         1
4940  s0.smv0  |         1
4941  s0.smv0  |         2
4942  s0.smv0  |         3
4943  s1.st0   |         1
4944  s1.st0   |         2
4945 (17 rows)
4946
4947 SELECT dbms_stats.unlock('s0.st0', NULL);
4948  unlock 
4949 --------
4950  s0.st0
4951 (1 row)
4952
4953 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
4954  GROUP BY relid
4955  ORDER BY relid;
4956    relid    
4957 ------------
4958  pt0
4959  pt0_idx
4960  st0
4961  st0_idx
4962  st1
4963  s0.st0_idx
4964  s0.st1
4965  s0.st1_idx
4966  s0.st2
4967  s0.st2_idx
4968  st1_idx
4969  st1_exp
4970  s0.sft0
4971  s0.smv0
4972  s1.st0
4973 (15 rows)
4974
4975 SELECT starelid::regclass, staattnum FROM dbms_stats.column_stats_locked
4976  GROUP BY starelid, staattnum
4977  ORDER BY starelid, staattnum;
4978  starelid | staattnum 
4979 ----------+-----------
4980  st0      |         1
4981  st0      |         2
4982  st1      |         1
4983  st1      |         2
4984  s0.st1   |         1
4985  s0.st1   |         2
4986  s0.st2   |         1
4987  s0.st2   |         2
4988  st1_exp  |         1
4989  s0.sft0  |         1
4990  s0.smv0  |         1
4991  s0.smv0  |         2
4992  s0.smv0  |         3
4993  s1.st0   |         1
4994  s1.st0   |         2
4995 (15 rows)
4996
4997 -- No.13-1-13
4998 DELETE FROM dbms_stats.relation_stats_locked;
4999 VACUUM dbms_stats.relation_stats_locked;  -- in order to avoid auto vacuum
5000 SELECT dbms_stats.lock_database_stats();
5001  lock_database_stats 
5002 ---------------------
5003  pt0
5004  pt0_idx
5005  st0
5006  st0_idx
5007  st1
5008  s0.st0
5009  s0.st0_idx
5010  s0.st1
5011  s0.st1_idx
5012  s0.st2
5013  s0.st2_idx
5014  st1_idx
5015  st1_exp
5016  s0.sft0
5017  s0.smv0
5018  s1.st0
5019 (16 rows)
5020
5021 SELECT count(*) FROM dbms_stats.relation_stats_locked;
5022  count 
5023 -------
5024     16
5025 (1 row)
5026
5027 SELECT count(*) FROM dbms_stats.column_stats_locked;
5028  count 
5029 -------
5030     19
5031 (1 row)
5032
5033 BEGIN;
5034 SELECT * FROM internal_locks;
5035  relation | mode 
5036 ----------+------
5037 (0 rows)
5038
5039 SELECT dbms_stats.unlock();
5040    unlock   
5041 ------------
5042  pt0
5043  pt0_idx
5044  st0
5045  st0_idx
5046  st1
5047  s0.st0
5048  s0.st0_idx
5049  s0.st1
5050  s0.st1_idx
5051  s0.st2
5052  s0.st2_idx
5053  st1_idx
5054  st1_exp
5055  s0.sft0
5056  s0.smv0
5057  s1.st0
5058 (16 rows)
5059
5060 SELECT * FROM internal_locks;
5061              relation             |       mode       
5062 ----------------------------------+------------------
5063  dbms_stats.column_stats_locked   | RowExclusiveLock
5064  dbms_stats.relation_stats_locked | AccessShareLock
5065  dbms_stats.relation_stats_locked | RowExclusiveLock
5066  dbms_stats.relation_stats_locked | RowShareLock
5067 (4 rows)
5068
5069 COMMIT;
5070 SELECT count(*) FROM dbms_stats.relation_stats_locked;
5071  count 
5072 -------
5073      0
5074 (1 row)
5075
5076 SELECT count(*) FROM dbms_stats.column_stats_locked;
5077  count 
5078 -------
5079      0
5080 (1 row)
5081
5082 /*
5083  * No.14-1 dbms_stats.unlock_database_stats
5084  */
5085 -- No.14-1-1
5086 DELETE FROM dbms_stats.relation_stats_locked;
5087 SELECT dbms_stats.lock_database_stats();
5088  lock_database_stats 
5089 ---------------------
5090  pt0
5091  pt0_idx
5092  st0
5093  st0_idx
5094  st1
5095  s0.st0
5096  s0.st0_idx
5097  s0.st1
5098  s0.st1_idx
5099  s0.st2
5100  s0.st2_idx
5101  st1_idx
5102  st1_exp
5103  s0.sft0
5104  s0.smv0
5105  s1.st0
5106 (16 rows)
5107
5108 SELECT * FROM dbms_stats.backup_history
5109  ORDER BY id;
5110  id |                time                 | unit | comment 
5111 ----+-------------------------------------+------+---------
5112   1 | Wed Feb 29 23:59:56.999999 2012 PST | d    | (null)
5113   2 | Wed Feb 29 23:59:57 2012 PST        | d    | (null)
5114   3 | Wed Feb 29 23:59:57.000001 2012 PST | t    | (null)
5115   4 | Wed Feb 29 23:59:58 2012 PST        | d    | (null)
5116   5 | Thu Mar 01 00:00:00 2012 PST        | c    | (null)
5117   6 | Thu Mar 01 00:00:02 2012 PST        | t    | (null)
5118   7 | Thu Mar 01 00:00:04 2012 PST        | t    | (null)
5119   8 | Thu Mar 01 00:00:06 2012 PST        | s    | (null)
5120 (8 rows)
5121
5122 SELECT count(*) FROM dbms_stats.relation_stats_backup;
5123  count 
5124 -------
5125     26
5126 (1 row)
5127
5128 SELECT count(*) FROM dbms_stats.column_stats_backup;
5129  count 
5130 -------
5131     39
5132 (1 row)
5133
5134 SELECT count(*) FROM dbms_stats.relation_stats_locked;
5135  count 
5136 -------
5137     16
5138 (1 row)
5139
5140 SELECT count(*) FROM dbms_stats.column_stats_locked;
5141  count 
5142 -------
5143     19
5144 (1 row)
5145
5146 SELECT dbms_stats.unlock_database_stats();
5147  unlock_database_stats 
5148 -----------------------
5149  pt0
5150  pt0_idx
5151  st0
5152  st0_idx
5153  st1
5154  s0.st0
5155  s0.st0_idx
5156  s0.st1
5157  s0.st1_idx
5158  s0.st2
5159  s0.st2_idx
5160  st1_idx
5161  st1_exp
5162  s0.sft0
5163  s0.smv0
5164  s1.st0
5165 (16 rows)
5166
5167 SELECT count(*) FROM dbms_stats.relation_stats_locked;
5168  count 
5169 -------
5170      0
5171 (1 row)
5172
5173 SELECT count(*) FROM dbms_stats.column_stats_locked;
5174  count 
5175 -------
5176      0
5177 (1 row)
5178
5179 SELECT * FROM dbms_stats.backup_history
5180  ORDER BY id;
5181  id |                time                 | unit | comment 
5182 ----+-------------------------------------+------+---------
5183   1 | Wed Feb 29 23:59:56.999999 2012 PST | d    | (null)
5184   2 | Wed Feb 29 23:59:57 2012 PST        | d    | (null)
5185   3 | Wed Feb 29 23:59:57.000001 2012 PST | t    | (null)
5186   4 | Wed Feb 29 23:59:58 2012 PST        | d    | (null)
5187   5 | Thu Mar 01 00:00:00 2012 PST        | c    | (null)
5188   6 | Thu Mar 01 00:00:02 2012 PST        | t    | (null)
5189   7 | Thu Mar 01 00:00:04 2012 PST        | t    | (null)
5190   8 | Thu Mar 01 00:00:06 2012 PST        | s    | (null)
5191 (8 rows)
5192
5193 SELECT count(*) FROM dbms_stats.relation_stats_backup;
5194  count 
5195 -------
5196     26
5197 (1 row)
5198
5199 SELECT count(*) FROM dbms_stats.column_stats_backup;
5200  count 
5201 -------
5202     39
5203 (1 row)
5204
5205 -- No.14-1-2
5206 DELETE FROM dbms_stats.relation_stats_locked;
5207 SELECT dbms_stats.lock_database_stats();
5208  lock_database_stats 
5209 ---------------------
5210  pt0
5211  pt0_idx
5212  st0
5213  st0_idx
5214  st1
5215  s0.st0
5216  s0.st0_idx
5217  s0.st1
5218  s0.st1_idx
5219  s0.st2
5220  s0.st2_idx
5221  st1_idx
5222  st1_exp
5223  s0.sft0
5224  s0.smv0
5225  s1.st0
5226 (16 rows)
5227
5228 DELETE FROM dbms_stats.column_stats_locked;
5229 SELECT count(*) FROM dbms_stats.relation_stats_locked;
5230  count 
5231 -------
5232     16
5233 (1 row)
5234
5235 SELECT dbms_stats.unlock_database_stats();
5236  unlock_database_stats 
5237 -----------------------
5238  pt0
5239  pt0_idx
5240  st0
5241  st0_idx
5242  st1
5243  s0.st0
5244  s0.st0_idx
5245  s0.st1
5246  s0.st1_idx
5247  s0.st2
5248  s0.st2_idx
5249  st1_idx
5250  st1_exp
5251  s0.sft0
5252  s0.smv0
5253  s1.st0
5254 (16 rows)
5255
5256 SELECT count(*) FROM dbms_stats.relation_stats_locked;
5257  count 
5258 -------
5259      0
5260 (1 row)
5261
5262 SELECT count(*) FROM dbms_stats.column_stats_locked;
5263  count 
5264 -------
5265      0
5266 (1 row)
5267
5268 -- No.14-1-3
5269 DELETE FROM dbms_stats.relation_stats_locked;
5270 SELECT dbms_stats.unlock_database_stats();
5271  unlock_database_stats 
5272 -----------------------
5273 (0 rows)
5274
5275 SELECT count(*) FROM dbms_stats.relation_stats_locked;
5276  count 
5277 -------
5278      0
5279 (1 row)
5280
5281 SELECT count(*) FROM dbms_stats.column_stats_locked;
5282  count 
5283 -------
5284      0
5285 (1 row)
5286
5287 -- No.14-1-4
5288 DELETE FROM dbms_stats.relation_stats_locked;
5289 VACUUM dbms_stats.relation_stats_locked;  -- in order to avoid auto vacuum
5290 SELECT dbms_stats.lock_database_stats();
5291  lock_database_stats 
5292 ---------------------
5293  pt0
5294  pt0_idx
5295  st0
5296  st0_idx
5297  st1
5298  s0.st0
5299  s0.st0_idx
5300  s0.st1
5301  s0.st1_idx
5302  s0.st2
5303  s0.st2_idx
5304  st1_idx
5305  st1_exp
5306  s0.sft0
5307  s0.smv0
5308  s1.st0
5309 (16 rows)
5310
5311 SELECT count(*) FROM dbms_stats.relation_stats_locked;
5312  count 
5313 -------
5314     16
5315 (1 row)
5316
5317 SELECT count(*) FROM dbms_stats.column_stats_locked;
5318  count 
5319 -------
5320     19
5321 (1 row)
5322
5323 BEGIN;
5324 SELECT * FROM internal_locks;
5325  relation | mode 
5326 ----------+------
5327 (0 rows)
5328
5329 SELECT dbms_stats.unlock_database_stats();
5330  unlock_database_stats 
5331 -----------------------
5332  pt0
5333  pt0_idx
5334  st0
5335  st0_idx
5336  st1
5337  s0.st0
5338  s0.st0_idx
5339  s0.st1
5340  s0.st1_idx
5341  s0.st2
5342  s0.st2_idx
5343  st1_idx
5344  st1_exp
5345  s0.sft0
5346  s0.smv0
5347  s1.st0
5348 (16 rows)
5349
5350 SELECT * FROM internal_locks;
5351              relation             |       mode       
5352 ----------------------------------+------------------
5353  dbms_stats.column_stats_locked   | RowExclusiveLock
5354  dbms_stats.relation_stats_locked | AccessShareLock
5355  dbms_stats.relation_stats_locked | ExclusiveLock
5356  dbms_stats.relation_stats_locked | RowExclusiveLock
5357 (4 rows)
5358
5359 COMMIT;
5360 SELECT count(*) FROM dbms_stats.relation_stats_locked;
5361  count 
5362 -------
5363      0
5364 (1 row)
5365
5366 SELECT count(*) FROM dbms_stats.column_stats_locked;
5367  count 
5368 -------
5369      0
5370 (1 row)
5371
5372 /*
5373  * No.14-2 dbms_stats.unlock_schema_stats
5374  */
5375 -- No.14-2-1
5376 DELETE FROM dbms_stats.relation_stats_locked;
5377 SELECT dbms_stats.lock_database_stats();
5378  lock_database_stats 
5379 ---------------------
5380  pt0
5381  pt0_idx
5382  st0
5383  st0_idx
5384  st1
5385  s0.st0
5386  s0.st0_idx
5387  s0.st1
5388  s0.st1_idx
5389  s0.st2
5390  s0.st2_idx
5391  st1_idx
5392  st1_exp
5393  s0.sft0
5394  s0.smv0
5395  s1.st0
5396 (16 rows)
5397
5398 SELECT * FROM dbms_stats.backup_history
5399  ORDER BY id;
5400  id |                time                 | unit | comment 
5401 ----+-------------------------------------+------+---------
5402   1 | Wed Feb 29 23:59:56.999999 2012 PST | d    | (null)
5403   2 | Wed Feb 29 23:59:57 2012 PST        | d    | (null)
5404   3 | Wed Feb 29 23:59:57.000001 2012 PST | t    | (null)
5405   4 | Wed Feb 29 23:59:58 2012 PST        | d    | (null)
5406   5 | Thu Mar 01 00:00:00 2012 PST        | c    | (null)
5407   6 | Thu Mar 01 00:00:02 2012 PST        | t    | (null)
5408   7 | Thu Mar 01 00:00:04 2012 PST        | t    | (null)
5409   8 | Thu Mar 01 00:00:06 2012 PST        | s    | (null)
5410 (8 rows)
5411
5412 SELECT count(*) FROM dbms_stats.relation_stats_backup;
5413  count 
5414 -------
5415     26
5416 (1 row)
5417
5418 SELECT count(*) FROM dbms_stats.column_stats_backup;
5419  count 
5420 -------
5421     39
5422 (1 row)
5423
5424 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
5425  GROUP BY relid
5426  ORDER BY relid;
5427    relid    
5428 ------------
5429  pt0
5430  pt0_idx
5431  st0
5432  st0_idx
5433  st1
5434  s0.st0
5435  s0.st0_idx
5436  s0.st1
5437  s0.st1_idx
5438  s0.st2
5439  s0.st2_idx
5440  st1_idx
5441  st1_exp
5442  s0.sft0
5443  s0.smv0
5444  s1.st0
5445 (16 rows)
5446
5447 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
5448  GROUP BY starelid
5449  ORDER BY starelid;
5450  starelid | count 
5451 ----------+-------
5452  st0      |     2
5453  st1      |     2
5454  s0.st0   |     4
5455  s0.st1   |     2
5456  s0.st2   |     2
5457  st1_exp  |     1
5458  s0.sft0  |     1
5459  s0.smv0  |     3
5460  s1.st0   |     2
5461 (9 rows)
5462
5463 SELECT dbms_stats.unlock_schema_stats('s0');
5464  unlock_schema_stats 
5465 ---------------------
5466  s0.st0
5467  s0.st0_idx
5468  s0.st1
5469  s0.st1_idx
5470  s0.st2
5471  s0.st2_idx
5472  s0.sft0
5473  s0.smv0
5474 (8 rows)
5475
5476 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
5477  GROUP BY relid
5478  ORDER BY relid;
5479   relid  
5480 ---------
5481  pt0
5482  pt0_idx
5483  st0
5484  st0_idx
5485  st1
5486  st1_idx
5487  st1_exp
5488  s1.st0
5489 (8 rows)
5490
5491 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
5492  GROUP BY starelid
5493  ORDER BY starelid;
5494  starelid | count 
5495 ----------+-------
5496  st0      |     2
5497  st1      |     2
5498  st1_exp  |     1
5499  s1.st0   |     2
5500 (4 rows)
5501
5502 SELECT * FROM dbms_stats.backup_history
5503  ORDER BY id;
5504  id |                time                 | unit | comment 
5505 ----+-------------------------------------+------+---------
5506   1 | Wed Feb 29 23:59:56.999999 2012 PST | d    | (null)
5507   2 | Wed Feb 29 23:59:57 2012 PST        | d    | (null)
5508   3 | Wed Feb 29 23:59:57.000001 2012 PST | t    | (null)
5509   4 | Wed Feb 29 23:59:58 2012 PST        | d    | (null)
5510   5 | Thu Mar 01 00:00:00 2012 PST        | c    | (null)
5511   6 | Thu Mar 01 00:00:02 2012 PST        | t    | (null)
5512   7 | Thu Mar 01 00:00:04 2012 PST        | t    | (null)
5513   8 | Thu Mar 01 00:00:06 2012 PST        | s    | (null)
5514 (8 rows)
5515
5516 SELECT count(*) FROM dbms_stats.relation_stats_backup;
5517  count 
5518 -------
5519     26
5520 (1 row)
5521
5522 SELECT count(*) FROM dbms_stats.column_stats_backup;
5523  count 
5524 -------
5525     39
5526 (1 row)
5527
5528 -- No.14-2-2
5529 DELETE FROM dbms_stats.relation_stats_locked;
5530 SELECT dbms_stats.lock_database_stats();
5531  lock_database_stats 
5532 ---------------------
5533  pt0
5534  pt0_idx
5535  st0
5536  st0_idx
5537  st1
5538  s0.st0
5539  s0.st0_idx
5540  s0.st1
5541  s0.st1_idx
5542  s0.st2
5543  s0.st2_idx
5544  st1_idx
5545  st1_exp
5546  s0.sft0
5547  s0.smv0
5548  s1.st0
5549 (16 rows)
5550
5551 DELETE FROM dbms_stats.column_stats_locked;
5552 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
5553  GROUP BY relid
5554  ORDER BY relid;
5555    relid    
5556 ------------
5557  pt0
5558  pt0_idx
5559  st0
5560  st0_idx
5561  st1
5562  s0.st0
5563  s0.st0_idx
5564  s0.st1
5565  s0.st1_idx
5566  s0.st2
5567  s0.st2_idx
5568  st1_idx
5569  st1_exp
5570  s0.sft0
5571  s0.smv0
5572  s1.st0
5573 (16 rows)
5574
5575 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
5576  GROUP BY starelid
5577  ORDER BY starelid;
5578  starelid | count 
5579 ----------+-------
5580 (0 rows)
5581
5582 SELECT dbms_stats.unlock_schema_stats('s0');
5583  unlock_schema_stats 
5584 ---------------------
5585  s0.st0
5586  s0.st0_idx
5587  s0.st1
5588  s0.st1_idx
5589  s0.st2
5590  s0.st2_idx
5591  s0.sft0
5592  s0.smv0
5593 (8 rows)
5594
5595 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
5596  GROUP BY relid
5597  ORDER BY relid;
5598   relid  
5599 ---------
5600  pt0
5601  pt0_idx
5602  st0
5603  st0_idx
5604  st1
5605  st1_idx
5606  st1_exp
5607  s1.st0
5608 (8 rows)
5609
5610 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
5611  GROUP BY starelid
5612  ORDER BY starelid;
5613  starelid | count 
5614 ----------+-------
5615 (0 rows)
5616
5617 -- No.14-2-3
5618 DELETE FROM dbms_stats.relation_stats_locked;
5619 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
5620  GROUP BY relid
5621  ORDER BY relid;
5622  relid 
5623 -------
5624 (0 rows)
5625
5626 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
5627  GROUP BY starelid
5628  ORDER BY starelid;
5629  starelid | count 
5630 ----------+-------
5631 (0 rows)
5632
5633 SELECT dbms_stats.unlock_schema_stats('s0');
5634  unlock_schema_stats 
5635 ---------------------
5636 (0 rows)
5637
5638 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
5639  GROUP BY relid
5640  ORDER BY relid;
5641  relid 
5642 -------
5643 (0 rows)
5644
5645 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
5646  GROUP BY starelid
5647  ORDER BY starelid;
5648  starelid | count 
5649 ----------+-------
5650 (0 rows)
5651
5652 -- No.14-2-4
5653 DELETE FROM dbms_stats.relation_stats_locked;
5654 SELECT dbms_stats.lock_database_stats();
5655  lock_database_stats 
5656 ---------------------
5657  pt0
5658  pt0_idx
5659  st0
5660  st0_idx
5661  st1
5662  s0.st0
5663  s0.st0_idx
5664  s0.st1
5665  s0.st1_idx
5666  s0.st2
5667  s0.st2_idx
5668  st1_idx
5669  st1_exp
5670  s0.sft0
5671  s0.smv0
5672  s1.st0
5673 (16 rows)
5674
5675 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
5676  GROUP BY relid
5677  ORDER BY relid;
5678    relid    
5679 ------------
5680  pt0
5681  pt0_idx
5682  st0
5683  st0_idx
5684  st1
5685  s0.st0
5686  s0.st0_idx
5687  s0.st1
5688  s0.st1_idx
5689  s0.st2
5690  s0.st2_idx
5691  st1_idx
5692  st1_exp
5693  s0.sft0
5694  s0.smv0
5695  s1.st0
5696 (16 rows)
5697
5698 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
5699  GROUP BY starelid
5700  ORDER BY starelid;
5701  starelid | count 
5702 ----------+-------
5703  st0      |     2
5704  st1      |     2
5705  s0.st0   |     4
5706  s0.st1   |     2
5707  s0.st2   |     2
5708  st1_exp  |     1
5709  s0.sft0  |     1
5710  s0.smv0  |     3
5711  s1.st0   |     2
5712 (9 rows)
5713
5714 SELECT dbms_stats.unlock_schema_stats('s0');
5715  unlock_schema_stats 
5716 ---------------------
5717  s0.st0
5718  s0.st0_idx
5719  s0.st1
5720  s0.st1_idx
5721  s0.st2
5722  s0.st2_idx
5723  s0.sft0
5724  s0.smv0
5725 (8 rows)
5726
5727 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
5728  GROUP BY relid
5729  ORDER BY relid;
5730   relid  
5731 ---------
5732  pt0
5733  pt0_idx
5734  st0
5735  st0_idx
5736  st1
5737  st1_idx
5738  st1_exp
5739  s1.st0
5740 (8 rows)
5741
5742 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
5743  GROUP BY starelid
5744  ORDER BY starelid;
5745  starelid | count 
5746 ----------+-------
5747  st0      |     2
5748  st1      |     2
5749  st1_exp  |     1
5750  s1.st0   |     2
5751 (4 rows)
5752
5753 -- No.14-2-5
5754 DELETE FROM dbms_stats.relation_stats_locked;
5755 SELECT dbms_stats.lock_database_stats();
5756  lock_database_stats 
5757 ---------------------
5758  pt0
5759  pt0_idx
5760  st0
5761  st0_idx
5762  st1
5763  s0.st0
5764  s0.st0_idx
5765  s0.st1
5766  s0.st1_idx
5767  s0.st2
5768  s0.st2_idx
5769  st1_idx
5770  st1_exp
5771  s0.sft0
5772  s0.smv0
5773  s1.st0
5774 (16 rows)
5775
5776 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
5777  GROUP BY relid
5778  ORDER BY relid;
5779    relid    
5780 ------------
5781  pt0
5782  pt0_idx
5783  st0
5784  st0_idx
5785  st1
5786  s0.st0
5787  s0.st0_idx
5788  s0.st1
5789  s0.st1_idx
5790  s0.st2
5791  s0.st2_idx
5792  st1_idx
5793  st1_exp
5794  s0.sft0
5795  s0.smv0
5796  s1.st0
5797 (16 rows)
5798
5799 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
5800  GROUP BY starelid
5801  ORDER BY starelid;
5802  starelid | count 
5803 ----------+-------
5804  st0      |     2
5805  st1      |     2
5806  s0.st0   |     4
5807  s0.st1   |     2
5808  s0.st2   |     2
5809  st1_exp  |     1
5810  s0.sft0  |     1
5811  s0.smv0  |     3
5812  s1.st0   |     2
5813 (9 rows)
5814
5815 SELECT dbms_stats.unlock_schema_stats('s00');
5816 ERROR:  schema "s00" not found
5817 CONTEXT:  PL/pgSQL function dbms_stats.unlock_schema_stats(text) line 6 at RAISE
5818 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
5819  GROUP BY relid
5820  ORDER BY relid;
5821    relid    
5822 ------------
5823  pt0
5824  pt0_idx
5825  st0
5826  st0_idx
5827  st1
5828  s0.st0
5829  s0.st0_idx
5830  s0.st1
5831  s0.st1_idx
5832  s0.st2
5833  s0.st2_idx
5834  st1_idx
5835  st1_exp
5836  s0.sft0
5837  s0.smv0
5838  s1.st0
5839 (16 rows)
5840
5841 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
5842  GROUP BY starelid
5843  ORDER BY starelid;
5844  starelid | count 
5845 ----------+-------
5846  st0      |     2
5847  st1      |     2
5848  s0.st0   |     4
5849  s0.st1   |     2
5850  s0.st2   |     2
5851  st1_exp  |     1
5852  s0.sft0  |     1
5853  s0.smv0  |     3
5854  s1.st0   |     2
5855 (9 rows)
5856
5857 -- No.14-2-6
5858 DELETE FROM dbms_stats.relation_stats_locked;
5859 SELECT dbms_stats.lock_database_stats();
5860  lock_database_stats 
5861 ---------------------
5862  pt0
5863  pt0_idx
5864  st0
5865  st0_idx
5866  st1
5867  s0.st0
5868  s0.st0_idx
5869  s0.st1
5870  s0.st1_idx
5871  s0.st2
5872  s0.st2_idx
5873  st1_idx
5874  st1_exp
5875  s0.sft0
5876  s0.smv0
5877  s1.st0
5878 (16 rows)
5879
5880 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
5881  GROUP BY relid
5882  ORDER BY relid;
5883    relid    
5884 ------------
5885  pt0
5886  pt0_idx
5887  st0
5888  st0_idx
5889  st1
5890  s0.st0
5891  s0.st0_idx
5892  s0.st1
5893  s0.st1_idx
5894  s0.st2
5895  s0.st2_idx
5896  st1_idx
5897  st1_exp
5898  s0.sft0
5899  s0.smv0
5900  s1.st0
5901 (16 rows)
5902
5903 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
5904  GROUP BY starelid
5905  ORDER BY starelid;
5906  starelid | count 
5907 ----------+-------
5908  st0      |     2
5909  st1      |     2
5910  s0.st0   |     4
5911  s0.st1   |     2
5912  s0.st2   |     2
5913  st1_exp  |     1
5914  s0.sft0  |     1
5915  s0.smv0  |     3
5916  s1.st0   |     2
5917 (9 rows)
5918
5919 SELECT dbms_stats.unlock_schema_stats('pg_catalog');
5920 ERROR:  unlocking statistics is not allowed for system schemas: "pg_catalog"
5921 CONTEXT:  PL/pgSQL function dbms_stats.unlock_schema_stats(text) line 9 at RAISE
5922 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
5923  GROUP BY relid
5924  ORDER BY relid;
5925    relid    
5926 ------------
5927  pt0
5928  pt0_idx
5929  st0
5930  st0_idx
5931  st1
5932  s0.st0
5933  s0.st0_idx
5934  s0.st1
5935  s0.st1_idx
5936  s0.st2
5937  s0.st2_idx
5938  st1_idx
5939  st1_exp
5940  s0.sft0
5941  s0.smv0
5942  s1.st0
5943 (16 rows)
5944
5945 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
5946  GROUP BY starelid
5947  ORDER BY starelid;
5948  starelid | count 
5949 ----------+-------
5950  st0      |     2
5951  st1      |     2
5952  s0.st0   |     4
5953  s0.st1   |     2
5954  s0.st2   |     2
5955  st1_exp  |     1
5956  s0.sft0  |     1
5957  s0.smv0  |     3
5958  s1.st0   |     2
5959 (9 rows)
5960
5961 -- No.14-2-7
5962 DELETE FROM dbms_stats.relation_stats_locked;
5963 SELECT dbms_stats.lock_database_stats();
5964  lock_database_stats 
5965 ---------------------
5966  pt0
5967  pt0_idx
5968  st0
5969  st0_idx
5970  st1
5971  s0.st0
5972  s0.st0_idx
5973  s0.st1
5974  s0.st1_idx
5975  s0.st2
5976  s0.st2_idx
5977  st1_idx
5978  st1_exp
5979  s0.sft0
5980  s0.smv0
5981  s1.st0
5982 (16 rows)
5983
5984 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
5985  GROUP BY relid
5986  ORDER BY relid;
5987    relid    
5988 ------------
5989  pt0
5990  pt0_idx
5991  st0
5992  st0_idx
5993  st1
5994  s0.st0
5995  s0.st0_idx
5996  s0.st1
5997  s0.st1_idx
5998  s0.st2
5999  s0.st2_idx
6000  st1_idx
6001  st1_exp
6002  s0.sft0
6003  s0.smv0
6004  s1.st0
6005 (16 rows)
6006
6007 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
6008  GROUP BY starelid
6009  ORDER BY starelid;
6010  starelid | count 
6011 ----------+-------
6012  st0      |     2
6013  st1      |     2
6014  s0.st0   |     4
6015  s0.st1   |     2
6016  s0.st2   |     2
6017  st1_exp  |     1
6018  s0.sft0  |     1
6019  s0.smv0  |     3
6020  s1.st0   |     2
6021 (9 rows)
6022
6023 SELECT dbms_stats.unlock_schema_stats(NULL);
6024  unlock_schema_stats 
6025 ---------------------
6026 (0 rows)
6027
6028 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
6029  GROUP BY relid
6030  ORDER BY relid;
6031    relid    
6032 ------------
6033  pt0
6034  pt0_idx
6035  st0
6036  st0_idx
6037  st1
6038  s0.st0
6039  s0.st0_idx
6040  s0.st1
6041  s0.st1_idx
6042  s0.st2
6043  s0.st2_idx
6044  st1_idx
6045  st1_exp
6046  s0.sft0
6047  s0.smv0
6048  s1.st0
6049 (16 rows)
6050
6051 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
6052  GROUP BY starelid
6053  ORDER BY starelid;
6054  starelid | count 
6055 ----------+-------
6056  st0      |     2
6057  st1      |     2
6058  s0.st0   |     4
6059  s0.st1   |     2
6060  s0.st2   |     2
6061  st1_exp  |     1
6062  s0.sft0  |     1
6063  s0.smv0  |     3
6064  s1.st0   |     2
6065 (9 rows)
6066
6067 -- No.14-2-8
6068 DELETE FROM dbms_stats.relation_stats_locked;
6069 VACUUM dbms_stats.relation_stats_locked;  -- in order to avoid auto vacuum
6070 SELECT dbms_stats.lock_database_stats();
6071  lock_database_stats 
6072 ---------------------
6073  pt0
6074  pt0_idx
6075  st0
6076  st0_idx
6077  st1
6078  s0.st0
6079  s0.st0_idx
6080  s0.st1
6081  s0.st1_idx
6082  s0.st2
6083  s0.st2_idx
6084  st1_idx
6085  st1_exp
6086  s0.sft0
6087  s0.smv0
6088  s1.st0
6089 (16 rows)
6090
6091 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
6092  GROUP BY relid
6093  ORDER BY relid;
6094    relid    
6095 ------------
6096  pt0
6097  pt0_idx
6098  st0
6099  st0_idx
6100  st1
6101  s0.st0
6102  s0.st0_idx
6103  s0.st1
6104  s0.st1_idx
6105  s0.st2
6106  s0.st2_idx
6107  st1_idx
6108  st1_exp
6109  s0.sft0
6110  s0.smv0
6111  s1.st0
6112 (16 rows)
6113
6114 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
6115  GROUP BY starelid
6116  ORDER BY starelid;
6117  starelid | count 
6118 ----------+-------
6119  st0      |     2
6120  st1      |     2
6121  s0.st0   |     4
6122  s0.st1   |     2
6123  s0.st2   |     2
6124  st1_exp  |     1
6125  s0.sft0  |     1
6126  s0.smv0  |     3
6127  s1.st0   |     2
6128 (9 rows)
6129
6130 BEGIN;
6131 SELECT * FROM internal_locks;
6132  relation | mode 
6133 ----------+------
6134 (0 rows)
6135
6136 SELECT dbms_stats.unlock_schema_stats('s0');
6137  unlock_schema_stats 
6138 ---------------------
6139  s0.st0
6140  s0.st0_idx
6141  s0.st1
6142  s0.st1_idx
6143  s0.st2
6144  s0.st2_idx
6145  s0.sft0
6146  s0.smv0
6147 (8 rows)
6148
6149 SELECT * FROM internal_locks;
6150              relation             |       mode       
6151 ----------------------------------+------------------
6152  dbms_stats.column_stats_locked   | RowExclusiveLock
6153  dbms_stats.relation_stats_locked | RowExclusiveLock
6154  dbms_stats.relation_stats_locked | RowShareLock
6155 (3 rows)
6156
6157 COMMIT;
6158 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
6159  GROUP BY relid
6160  ORDER BY relid;
6161   relid  
6162 ---------
6163  pt0
6164  pt0_idx
6165  st0
6166  st0_idx
6167  st1
6168  st1_idx
6169  st1_exp
6170  s1.st0
6171 (8 rows)
6172
6173 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
6174  GROUP BY starelid
6175  ORDER BY starelid;
6176  starelid | count 
6177 ----------+-------
6178  st0      |     2
6179  st1      |     2
6180  st1_exp  |     1
6181  s1.st0   |     2
6182 (4 rows)
6183
6184 /*
6185  * No.14-3 dbms_stats.unlock_table_stats(regclass)
6186  */
6187 -- No.14-3-1
6188 DELETE FROM dbms_stats.relation_stats_locked;
6189 SELECT dbms_stats.lock_database_stats();
6190  lock_database_stats 
6191 ---------------------
6192  pt0
6193  pt0_idx
6194  st0
6195  st0_idx
6196  st1
6197  s0.st0
6198  s0.st0_idx
6199  s0.st1
6200  s0.st1_idx
6201  s0.st2
6202  s0.st2_idx
6203  st1_idx
6204  st1_exp
6205  s0.sft0
6206  s0.smv0
6207  s1.st0
6208 (16 rows)
6209
6210 SELECT * FROM dbms_stats.backup_history
6211  ORDER BY id;
6212  id |                time                 | unit | comment 
6213 ----+-------------------------------------+------+---------
6214   1 | Wed Feb 29 23:59:56.999999 2012 PST | d    | (null)
6215   2 | Wed Feb 29 23:59:57 2012 PST        | d    | (null)
6216   3 | Wed Feb 29 23:59:57.000001 2012 PST | t    | (null)
6217   4 | Wed Feb 29 23:59:58 2012 PST        | d    | (null)
6218   5 | Thu Mar 01 00:00:00 2012 PST        | c    | (null)
6219   6 | Thu Mar 01 00:00:02 2012 PST        | t    | (null)
6220   7 | Thu Mar 01 00:00:04 2012 PST        | t    | (null)
6221   8 | Thu Mar 01 00:00:06 2012 PST        | s    | (null)
6222 (8 rows)
6223
6224 SELECT count(*) FROM dbms_stats.relation_stats_backup;
6225  count 
6226 -------
6227     26
6228 (1 row)
6229
6230 SELECT count(*) FROM dbms_stats.column_stats_backup;
6231  count 
6232 -------
6233     39
6234 (1 row)
6235
6236 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
6237  GROUP BY relid
6238  ORDER BY relid;
6239    relid    
6240 ------------
6241  pt0
6242  pt0_idx
6243  st0
6244  st0_idx
6245  st1
6246  s0.st0
6247  s0.st0_idx
6248  s0.st1
6249  s0.st1_idx
6250  s0.st2
6251  s0.st2_idx
6252  st1_idx
6253  st1_exp
6254  s0.sft0
6255  s0.smv0
6256  s1.st0
6257 (16 rows)
6258
6259 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
6260  GROUP BY starelid
6261  ORDER BY starelid;
6262  starelid | count 
6263 ----------+-------
6264  st0      |     2
6265  st1      |     2
6266  s0.st0   |     4
6267  s0.st1   |     2
6268  s0.st2   |     2
6269  st1_exp  |     1
6270  s0.sft0  |     1
6271  s0.smv0  |     3
6272  s1.st0   |     2
6273 (9 rows)
6274
6275 SELECT dbms_stats.unlock_table_stats('s0.st0');
6276  unlock_table_stats 
6277 --------------------
6278  s0.st0
6279 (1 row)
6280
6281 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
6282  GROUP BY relid
6283  ORDER BY relid;
6284    relid    
6285 ------------
6286  pt0
6287  pt0_idx
6288  st0
6289  st0_idx
6290  st1
6291  s0.st0_idx
6292  s0.st1
6293  s0.st1_idx
6294  s0.st2
6295  s0.st2_idx
6296  st1_idx
6297  st1_exp
6298  s0.sft0
6299  s0.smv0
6300  s1.st0
6301 (15 rows)
6302
6303 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
6304  GROUP BY starelid
6305  ORDER BY starelid;
6306  starelid | count 
6307 ----------+-------
6308  st0      |     2
6309  st1      |     2
6310  s0.st1   |     2
6311  s0.st2   |     2
6312  st1_exp  |     1
6313  s0.sft0  |     1
6314  s0.smv0  |     3
6315  s1.st0   |     2
6316 (8 rows)
6317
6318 SELECT * FROM dbms_stats.backup_history
6319  ORDER BY id;
6320  id |                time                 | unit | comment 
6321 ----+-------------------------------------+------+---------
6322   1 | Wed Feb 29 23:59:56.999999 2012 PST | d    | (null)
6323   2 | Wed Feb 29 23:59:57 2012 PST        | d    | (null)
6324   3 | Wed Feb 29 23:59:57.000001 2012 PST | t    | (null)
6325   4 | Wed Feb 29 23:59:58 2012 PST        | d    | (null)
6326   5 | Thu Mar 01 00:00:00 2012 PST        | c    | (null)
6327   6 | Thu Mar 01 00:00:02 2012 PST        | t    | (null)
6328   7 | Thu Mar 01 00:00:04 2012 PST        | t    | (null)
6329   8 | Thu Mar 01 00:00:06 2012 PST        | s    | (null)
6330 (8 rows)
6331
6332 SELECT count(*) FROM dbms_stats.relation_stats_backup;
6333  count 
6334 -------
6335     26
6336 (1 row)
6337
6338 SELECT count(*) FROM dbms_stats.column_stats_backup;
6339  count 
6340 -------
6341     39
6342 (1 row)
6343
6344 -- No.14-3-2
6345 DELETE FROM dbms_stats.relation_stats_locked;
6346 SELECT dbms_stats.lock_database_stats();
6347  lock_database_stats 
6348 ---------------------
6349  pt0
6350  pt0_idx
6351  st0
6352  st0_idx
6353  st1
6354  s0.st0
6355  s0.st0_idx
6356  s0.st1
6357  s0.st1_idx
6358  s0.st2
6359  s0.st2_idx
6360  st1_idx
6361  st1_exp
6362  s0.sft0
6363  s0.smv0
6364  s1.st0
6365 (16 rows)
6366
6367 DELETE FROM dbms_stats.column_stats_locked;
6368 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
6369  GROUP BY relid
6370  ORDER BY relid;
6371    relid    
6372 ------------
6373  pt0
6374  pt0_idx
6375  st0
6376  st0_idx
6377  st1
6378  s0.st0
6379  s0.st0_idx
6380  s0.st1
6381  s0.st1_idx
6382  s0.st2
6383  s0.st2_idx
6384  st1_idx
6385  st1_exp
6386  s0.sft0
6387  s0.smv0
6388  s1.st0
6389 (16 rows)
6390
6391 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
6392  GROUP BY starelid
6393  ORDER BY starelid;
6394  starelid | count 
6395 ----------+-------
6396 (0 rows)
6397
6398 SELECT dbms_stats.unlock_table_stats('s0.st0');
6399  unlock_table_stats 
6400 --------------------
6401  s0.st0
6402 (1 row)
6403
6404 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
6405  GROUP BY relid
6406  ORDER BY relid;
6407    relid    
6408 ------------
6409  pt0
6410  pt0_idx
6411  st0
6412  st0_idx
6413  st1
6414  s0.st0_idx
6415  s0.st1
6416  s0.st1_idx
6417  s0.st2
6418  s0.st2_idx
6419  st1_idx
6420  st1_exp
6421  s0.sft0
6422  s0.smv0
6423  s1.st0
6424 (15 rows)
6425
6426 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
6427  GROUP BY starelid
6428  ORDER BY starelid;
6429  starelid | count 
6430 ----------+-------
6431 (0 rows)
6432
6433 -- No.14-3-3
6434 DELETE FROM dbms_stats.relation_stats_locked;
6435 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
6436  GROUP BY relid
6437  ORDER BY relid;
6438  relid 
6439 -------
6440 (0 rows)
6441
6442 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
6443  GROUP BY starelid
6444  ORDER BY starelid;
6445  starelid | count 
6446 ----------+-------
6447 (0 rows)
6448
6449 SELECT dbms_stats.unlock_table_stats('s0.st0');
6450  unlock_table_stats 
6451 --------------------
6452 (0 rows)
6453
6454 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
6455  GROUP BY relid
6456  ORDER BY relid;
6457  relid 
6458 -------
6459 (0 rows)
6460
6461 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
6462  GROUP BY starelid
6463  ORDER BY starelid;
6464  starelid | count 
6465 ----------+-------
6466 (0 rows)
6467
6468 -- No.14-3-4
6469 DELETE FROM dbms_stats.relation_stats_locked;
6470 SELECT dbms_stats.lock_database_stats();
6471  lock_database_stats 
6472 ---------------------
6473  pt0
6474  pt0_idx
6475  st0
6476  st0_idx
6477  st1
6478  s0.st0
6479  s0.st0_idx
6480  s0.st1
6481  s0.st1_idx
6482  s0.st2
6483  s0.st2_idx
6484  st1_idx
6485  st1_exp
6486  s0.sft0
6487  s0.smv0
6488  s1.st0
6489 (16 rows)
6490
6491 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
6492  GROUP BY relid
6493  ORDER BY relid;
6494    relid    
6495 ------------
6496  pt0
6497  pt0_idx
6498  st0
6499  st0_idx
6500  st1
6501  s0.st0
6502  s0.st0_idx
6503  s0.st1
6504  s0.st1_idx
6505  s0.st2
6506  s0.st2_idx
6507  st1_idx
6508  st1_exp
6509  s0.sft0
6510  s0.smv0
6511  s1.st0
6512 (16 rows)
6513
6514 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
6515  GROUP BY starelid
6516  ORDER BY starelid;
6517  starelid | count 
6518 ----------+-------
6519  st0      |     2
6520  st1      |     2
6521  s0.st0   |     4
6522  s0.st1   |     2
6523  s0.st2   |     2
6524  st1_exp  |     1
6525  s0.sft0  |     1
6526  s0.smv0  |     3
6527  s1.st0   |     2
6528 (9 rows)
6529
6530 SELECT dbms_stats.unlock_table_stats('s0.st0');
6531  unlock_table_stats 
6532 --------------------
6533  s0.st0
6534 (1 row)
6535
6536 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
6537  GROUP BY relid
6538  ORDER BY relid;
6539    relid    
6540 ------------
6541  pt0
6542  pt0_idx
6543  st0
6544  st0_idx
6545  st1
6546  s0.st0_idx
6547  s0.st1
6548  s0.st1_idx
6549  s0.st2
6550  s0.st2_idx
6551  st1_idx
6552  st1_exp
6553  s0.sft0
6554  s0.smv0
6555  s1.st0
6556 (15 rows)
6557
6558 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
6559  GROUP BY starelid
6560  ORDER BY starelid;
6561  starelid | count 
6562 ----------+-------
6563  st0      |     2
6564  st1      |     2
6565  s0.st1   |     2
6566  s0.st2   |     2
6567  st1_exp  |     1
6568  s0.sft0  |     1
6569  s0.smv0  |     3
6570  s1.st0   |     2
6571 (8 rows)
6572
6573 -- No.14-3-5
6574 DELETE FROM dbms_stats.relation_stats_locked;
6575 SELECT dbms_stats.lock_database_stats();
6576  lock_database_stats 
6577 ---------------------
6578  pt0
6579  pt0_idx
6580  st0
6581  st0_idx
6582  st1
6583  s0.st0
6584  s0.st0_idx
6585  s0.st1
6586  s0.st1_idx
6587  s0.st2
6588  s0.st2_idx
6589  st1_idx
6590  st1_exp
6591  s0.sft0
6592  s0.smv0
6593  s1.st0
6594 (16 rows)
6595
6596 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
6597  GROUP BY relid
6598  ORDER BY relid;
6599    relid    
6600 ------------
6601  pt0
6602  pt0_idx
6603  st0
6604  st0_idx
6605  st1
6606  s0.st0
6607  s0.st0_idx
6608  s0.st1
6609  s0.st1_idx
6610  s0.st2
6611  s0.st2_idx
6612  st1_idx
6613  st1_exp
6614  s0.sft0
6615  s0.smv0
6616  s1.st0
6617 (16 rows)
6618
6619 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
6620  GROUP BY starelid
6621  ORDER BY starelid;
6622  starelid | count 
6623 ----------+-------
6624  st0      |     2
6625  st1      |     2
6626  s0.st0   |     4
6627  s0.st1   |     2
6628  s0.st2   |     2
6629  st1_exp  |     1
6630  s0.sft0  |     1
6631  s0.smv0  |     3
6632  s1.st0   |     2
6633 (9 rows)
6634
6635 SELECT dbms_stats.unlock_table_stats('st0');
6636  unlock_table_stats 
6637 --------------------
6638  st0
6639 (1 row)
6640
6641 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
6642  GROUP BY relid
6643  ORDER BY relid;
6644    relid    
6645 ------------
6646  pt0
6647  pt0_idx
6648  st0_idx
6649  st1
6650  s0.st0
6651  s0.st0_idx
6652  s0.st1
6653  s0.st1_idx
6654  s0.st2
6655  s0.st2_idx
6656  st1_idx
6657  st1_exp
6658  s0.sft0
6659  s0.smv0
6660  s1.st0
6661 (15 rows)
6662
6663 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
6664  GROUP BY starelid
6665  ORDER BY starelid;
6666  starelid | count 
6667 ----------+-------
6668  st1      |     2
6669  s0.st0   |     4
6670  s0.st1   |     2
6671  s0.st2   |     2
6672  st1_exp  |     1
6673  s0.sft0  |     1
6674  s0.smv0  |     3
6675  s1.st0   |     2
6676 (8 rows)
6677
6678 -- No.14-3-6
6679 DELETE FROM dbms_stats.relation_stats_locked;
6680 SELECT dbms_stats.lock_database_stats();
6681  lock_database_stats 
6682 ---------------------
6683  pt0
6684  pt0_idx
6685  st0
6686  st0_idx
6687  st1
6688  s0.st0
6689  s0.st0_idx
6690  s0.st1
6691  s0.st1_idx
6692  s0.st2
6693  s0.st2_idx
6694  st1_idx
6695  st1_exp
6696  s0.sft0
6697  s0.smv0
6698  s1.st0
6699 (16 rows)
6700
6701 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
6702  GROUP BY relid
6703  ORDER BY relid;
6704    relid    
6705 ------------
6706  pt0
6707  pt0_idx
6708  st0
6709  st0_idx
6710  st1
6711  s0.st0
6712  s0.st0_idx
6713  s0.st1
6714  s0.st1_idx
6715  s0.st2
6716  s0.st2_idx
6717  st1_idx
6718  st1_exp
6719  s0.sft0
6720  s0.smv0
6721  s1.st0
6722 (16 rows)
6723
6724 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
6725  GROUP BY starelid
6726  ORDER BY starelid;
6727  starelid | count 
6728 ----------+-------
6729  st0      |     2
6730  st1      |     2
6731  s0.st0   |     4
6732  s0.st1   |     2
6733  s0.st2   |     2
6734  st1_exp  |     1
6735  s0.sft0  |     1
6736  s0.smv0  |     3
6737  s1.st0   |     2
6738 (9 rows)
6739
6740 SELECT dbms_stats.unlock_table_stats('s00.s0');
6741 ERROR:  schema "s00" does not exist
6742 LINE 1: SELECT dbms_stats.unlock_table_stats('s00.s0');
6743                                              ^
6744 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
6745  GROUP BY relid
6746  ORDER BY relid;
6747    relid    
6748 ------------
6749  pt0
6750  pt0_idx
6751  st0
6752  st0_idx
6753  st1
6754  s0.st0
6755  s0.st0_idx
6756  s0.st1
6757  s0.st1_idx
6758  s0.st2
6759  s0.st2_idx
6760  st1_idx
6761  st1_exp
6762  s0.sft0
6763  s0.smv0
6764  s1.st0
6765 (16 rows)
6766
6767 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
6768  GROUP BY starelid
6769  ORDER BY starelid;
6770  starelid | count 
6771 ----------+-------
6772  st0      |     2
6773  st1      |     2
6774  s0.st0   |     4
6775  s0.st1   |     2
6776  s0.st2   |     2
6777  st1_exp  |     1
6778  s0.sft0  |     1
6779  s0.smv0  |     3
6780  s1.st0   |     2
6781 (9 rows)
6782
6783 -- No.14-3-7
6784 DELETE FROM dbms_stats.relation_stats_locked;
6785 SELECT dbms_stats.lock_database_stats();
6786  lock_database_stats 
6787 ---------------------
6788  pt0
6789  pt0_idx
6790  st0
6791  st0_idx
6792  st1
6793  s0.st0
6794  s0.st0_idx
6795  s0.st1
6796  s0.st1_idx
6797  s0.st2
6798  s0.st2_idx
6799  st1_idx
6800  st1_exp
6801  s0.sft0
6802  s0.smv0
6803  s1.st0
6804 (16 rows)
6805
6806 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
6807  GROUP BY relid
6808  ORDER BY relid;
6809    relid    
6810 ------------
6811  pt0
6812  pt0_idx
6813  st0
6814  st0_idx
6815  st1
6816  s0.st0
6817  s0.st0_idx
6818  s0.st1
6819  s0.st1_idx
6820  s0.st2
6821  s0.st2_idx
6822  st1_idx
6823  st1_exp
6824  s0.sft0
6825  s0.smv0
6826  s1.st0
6827 (16 rows)
6828
6829 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
6830  GROUP BY starelid
6831  ORDER BY starelid;
6832  starelid | count 
6833 ----------+-------
6834  st0      |     2
6835  st1      |     2
6836  s0.st0   |     4
6837  s0.st1   |     2
6838  s0.st2   |     2
6839  st1_exp  |     1
6840  s0.sft0  |     1
6841  s0.smv0  |     3
6842  s1.st0   |     2
6843 (9 rows)
6844
6845 SELECT dbms_stats.unlock_table_stats(NULL);
6846  unlock_table_stats 
6847 --------------------
6848 (0 rows)
6849
6850 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
6851  GROUP BY relid
6852  ORDER BY relid;
6853    relid    
6854 ------------
6855  pt0
6856  pt0_idx
6857  st0
6858  st0_idx
6859  st1
6860  s0.st0
6861  s0.st0_idx
6862  s0.st1
6863  s0.st1_idx
6864  s0.st2
6865  s0.st2_idx
6866  st1_idx
6867  st1_exp
6868  s0.sft0
6869  s0.smv0
6870  s1.st0
6871 (16 rows)
6872
6873 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
6874  GROUP BY starelid
6875  ORDER BY starelid;
6876  starelid | count 
6877 ----------+-------
6878  st0      |     2
6879  st1      |     2
6880  s0.st0   |     4
6881  s0.st1   |     2
6882  s0.st2   |     2
6883  st1_exp  |     1
6884  s0.sft0  |     1
6885  s0.smv0  |     3
6886  s1.st0   |     2
6887 (9 rows)
6888
6889 -- No.14-3-8
6890 DELETE FROM dbms_stats.relation_stats_locked;
6891 VACUUM dbms_stats.relation_stats_locked;  -- in order to avoid auto vacuum
6892 SELECT dbms_stats.lock_database_stats();
6893  lock_database_stats 
6894 ---------------------
6895  pt0
6896  pt0_idx
6897  st0
6898  st0_idx
6899  st1
6900  s0.st0
6901  s0.st0_idx
6902  s0.st1
6903  s0.st1_idx
6904  s0.st2
6905  s0.st2_idx
6906  st1_idx
6907  st1_exp
6908  s0.sft0
6909  s0.smv0
6910  s1.st0
6911 (16 rows)
6912
6913 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
6914  GROUP BY relid
6915  ORDER BY relid;
6916    relid    
6917 ------------
6918  pt0
6919  pt0_idx
6920  st0
6921  st0_idx
6922  st1
6923  s0.st0
6924  s0.st0_idx
6925  s0.st1
6926  s0.st1_idx
6927  s0.st2
6928  s0.st2_idx
6929  st1_idx
6930  st1_exp
6931  s0.sft0
6932  s0.smv0
6933  s1.st0
6934 (16 rows)
6935
6936 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
6937  GROUP BY starelid
6938  ORDER BY starelid;
6939  starelid | count 
6940 ----------+-------
6941  st0      |     2
6942  st1      |     2
6943  s0.st0   |     4
6944  s0.st1   |     2
6945  s0.st2   |     2
6946  st1_exp  |     1
6947  s0.sft0  |     1
6948  s0.smv0  |     3
6949  s1.st0   |     2
6950 (9 rows)
6951
6952 BEGIN;
6953 SELECT * FROM internal_locks;
6954  relation | mode 
6955 ----------+------
6956 (0 rows)
6957
6958 SELECT dbms_stats.unlock_table_stats('s0.st0');
6959  unlock_table_stats 
6960 --------------------
6961  s0.st0
6962 (1 row)
6963
6964 SELECT * FROM internal_locks;
6965              relation             |       mode       
6966 ----------------------------------+------------------
6967  dbms_stats.column_stats_locked   | RowExclusiveLock
6968  dbms_stats.relation_stats_locked | RowExclusiveLock
6969 (2 rows)
6970
6971 COMMIT;
6972 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
6973  GROUP BY relid
6974  ORDER BY relid;
6975    relid    
6976 ------------
6977  pt0
6978  pt0_idx
6979  st0
6980  st0_idx
6981  st1
6982  s0.st0_idx
6983  s0.st1
6984  s0.st1_idx
6985  s0.st2
6986  s0.st2_idx
6987  st1_idx
6988  st1_exp
6989  s0.sft0
6990  s0.smv0
6991  s1.st0
6992 (15 rows)
6993
6994 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
6995  GROUP BY starelid
6996  ORDER BY starelid;
6997  starelid | count 
6998 ----------+-------
6999  st0      |     2
7000  st1      |     2
7001  s0.st1   |     2
7002  s0.st2   |     2
7003  st1_exp  |     1
7004  s0.sft0  |     1
7005  s0.smv0  |     3
7006  s1.st0   |     2
7007 (8 rows)
7008
7009 /*
7010  * No.14-4 dbms_stats.unlock_table_stats(schemaname, tablename)
7011  */
7012 -- No.14-4-1
7013 DELETE FROM dbms_stats.relation_stats_locked;
7014 SELECT dbms_stats.lock_database_stats();
7015  lock_database_stats 
7016 ---------------------
7017  pt0
7018  pt0_idx
7019  st0
7020  st0_idx
7021  st1
7022  s0.st0
7023  s0.st0_idx
7024  s0.st1
7025  s0.st1_idx
7026  s0.st2
7027  s0.st2_idx
7028  st1_idx
7029  st1_exp
7030  s0.sft0
7031  s0.smv0
7032  s1.st0
7033 (16 rows)
7034
7035 SELECT * FROM dbms_stats.backup_history
7036  ORDER BY id;
7037  id |                time                 | unit | comment 
7038 ----+-------------------------------------+------+---------
7039   1 | Wed Feb 29 23:59:56.999999 2012 PST | d    | (null)
7040   2 | Wed Feb 29 23:59:57 2012 PST        | d    | (null)
7041   3 | Wed Feb 29 23:59:57.000001 2012 PST | t    | (null)
7042   4 | Wed Feb 29 23:59:58 2012 PST        | d    | (null)
7043   5 | Thu Mar 01 00:00:00 2012 PST        | c    | (null)
7044   6 | Thu Mar 01 00:00:02 2012 PST        | t    | (null)
7045   7 | Thu Mar 01 00:00:04 2012 PST        | t    | (null)
7046   8 | Thu Mar 01 00:00:06 2012 PST        | s    | (null)
7047 (8 rows)
7048
7049 SELECT count(*) FROM dbms_stats.relation_stats_backup;
7050  count 
7051 -------
7052     26
7053 (1 row)
7054
7055 SELECT count(*) FROM dbms_stats.column_stats_backup;
7056  count 
7057 -------
7058     39
7059 (1 row)
7060
7061 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
7062  GROUP BY relid
7063  ORDER BY relid;
7064    relid    
7065 ------------
7066  pt0
7067  pt0_idx
7068  st0
7069  st0_idx
7070  st1
7071  s0.st0
7072  s0.st0_idx
7073  s0.st1
7074  s0.st1_idx
7075  s0.st2
7076  s0.st2_idx
7077  st1_idx
7078  st1_exp
7079  s0.sft0
7080  s0.smv0
7081  s1.st0
7082 (16 rows)
7083
7084 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
7085  GROUP BY starelid
7086  ORDER BY starelid;
7087  starelid | count 
7088 ----------+-------
7089  st0      |     2
7090  st1      |     2
7091  s0.st0   |     4
7092  s0.st1   |     2
7093  s0.st2   |     2
7094  st1_exp  |     1
7095  s0.sft0  |     1
7096  s0.smv0  |     3
7097  s1.st0   |     2
7098 (9 rows)
7099
7100 SELECT dbms_stats.unlock_table_stats('s0','st0');
7101  unlock_table_stats 
7102 --------------------
7103  s0.st0
7104 (1 row)
7105
7106 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
7107  GROUP BY relid
7108  ORDER BY relid;
7109    relid    
7110 ------------
7111  pt0
7112  pt0_idx
7113  st0
7114  st0_idx
7115  st1
7116  s0.st0_idx
7117  s0.st1
7118  s0.st1_idx
7119  s0.st2
7120  s0.st2_idx
7121  st1_idx
7122  st1_exp
7123  s0.sft0
7124  s0.smv0
7125  s1.st0
7126 (15 rows)
7127
7128 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
7129  GROUP BY starelid
7130  ORDER BY starelid;
7131  starelid | count 
7132 ----------+-------
7133  st0      |     2
7134  st1      |     2
7135  s0.st1   |     2
7136  s0.st2   |     2
7137  st1_exp  |     1
7138  s0.sft0  |     1
7139  s0.smv0  |     3
7140  s1.st0   |     2
7141 (8 rows)
7142
7143 SELECT * FROM dbms_stats.backup_history
7144  ORDER BY id;
7145  id |                time                 | unit | comment 
7146 ----+-------------------------------------+------+---------
7147   1 | Wed Feb 29 23:59:56.999999 2012 PST | d    | (null)
7148   2 | Wed Feb 29 23:59:57 2012 PST        | d    | (null)
7149   3 | Wed Feb 29 23:59:57.000001 2012 PST | t    | (null)
7150   4 | Wed Feb 29 23:59:58 2012 PST        | d    | (null)
7151   5 | Thu Mar 01 00:00:00 2012 PST        | c    | (null)
7152   6 | Thu Mar 01 00:00:02 2012 PST        | t    | (null)
7153   7 | Thu Mar 01 00:00:04 2012 PST        | t    | (null)
7154   8 | Thu Mar 01 00:00:06 2012 PST        | s    | (null)
7155 (8 rows)
7156
7157 SELECT count(*) FROM dbms_stats.relation_stats_backup;
7158  count 
7159 -------
7160     26
7161 (1 row)
7162
7163 SELECT count(*) FROM dbms_stats.column_stats_backup;
7164  count 
7165 -------
7166     39
7167 (1 row)
7168
7169 -- No.14-4-2
7170 DELETE FROM dbms_stats.relation_stats_locked;
7171 SELECT dbms_stats.lock_database_stats();
7172  lock_database_stats 
7173 ---------------------
7174  pt0
7175  pt0_idx
7176  st0
7177  st0_idx
7178  st1
7179  s0.st0
7180  s0.st0_idx
7181  s0.st1
7182  s0.st1_idx
7183  s0.st2
7184  s0.st2_idx
7185  st1_idx
7186  st1_exp
7187  s0.sft0
7188  s0.smv0
7189  s1.st0
7190 (16 rows)
7191
7192 DELETE FROM dbms_stats.column_stats_locked;
7193 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
7194  GROUP BY relid
7195  ORDER BY relid;
7196    relid    
7197 ------------
7198  pt0
7199  pt0_idx
7200  st0
7201  st0_idx
7202  st1
7203  s0.st0
7204  s0.st0_idx
7205  s0.st1
7206  s0.st1_idx
7207  s0.st2
7208  s0.st2_idx
7209  st1_idx
7210  st1_exp
7211  s0.sft0
7212  s0.smv0
7213  s1.st0
7214 (16 rows)
7215
7216 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
7217  GROUP BY starelid
7218  ORDER BY starelid;
7219  starelid | count 
7220 ----------+-------
7221 (0 rows)
7222
7223 SELECT dbms_stats.unlock_table_stats('s0', 'st0');
7224  unlock_table_stats 
7225 --------------------
7226  s0.st0
7227 (1 row)
7228
7229 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
7230  GROUP BY relid
7231  ORDER BY relid;
7232    relid    
7233 ------------
7234  pt0
7235  pt0_idx
7236  st0
7237  st0_idx
7238  st1
7239  s0.st0_idx
7240  s0.st1
7241  s0.st1_idx
7242  s0.st2
7243  s0.st2_idx
7244  st1_idx
7245  st1_exp
7246  s0.sft0
7247  s0.smv0
7248  s1.st0
7249 (15 rows)
7250
7251 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
7252  GROUP BY starelid
7253  ORDER BY starelid;
7254  starelid | count 
7255 ----------+-------
7256 (0 rows)
7257
7258 -- No.14-4-3
7259 DELETE FROM dbms_stats.relation_stats_locked;
7260 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
7261  GROUP BY relid
7262  ORDER BY relid;
7263  relid 
7264 -------
7265 (0 rows)
7266
7267 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
7268  GROUP BY starelid
7269  ORDER BY starelid;
7270  starelid | count 
7271 ----------+-------
7272 (0 rows)
7273
7274 SELECT dbms_stats.unlock_table_stats('s0', 'st0');
7275  unlock_table_stats 
7276 --------------------
7277 (0 rows)
7278
7279 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
7280  GROUP BY relid
7281  ORDER BY relid;
7282  relid 
7283 -------
7284 (0 rows)
7285
7286 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
7287  GROUP BY starelid
7288  ORDER BY starelid;
7289  starelid | count 
7290 ----------+-------
7291 (0 rows)
7292
7293 -- No.14-4-4
7294 DELETE FROM dbms_stats.relation_stats_locked;
7295 SELECT dbms_stats.lock_database_stats();
7296  lock_database_stats 
7297 ---------------------
7298  pt0
7299  pt0_idx
7300  st0
7301  st0_idx
7302  st1
7303  s0.st0
7304  s0.st0_idx
7305  s0.st1
7306  s0.st1_idx
7307  s0.st2
7308  s0.st2_idx
7309  st1_idx
7310  st1_exp
7311  s0.sft0
7312  s0.smv0
7313  s1.st0
7314 (16 rows)
7315
7316 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
7317  GROUP BY relid
7318  ORDER BY relid;
7319    relid    
7320 ------------
7321  pt0
7322  pt0_idx
7323  st0
7324  st0_idx
7325  st1
7326  s0.st0
7327  s0.st0_idx
7328  s0.st1
7329  s0.st1_idx
7330  s0.st2
7331  s0.st2_idx
7332  st1_idx
7333  st1_exp
7334  s0.sft0
7335  s0.smv0
7336  s1.st0
7337 (16 rows)
7338
7339 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
7340  GROUP BY starelid
7341  ORDER BY starelid;
7342  starelid | count 
7343 ----------+-------
7344  st0      |     2
7345  st1      |     2
7346  s0.st0   |     4
7347  s0.st1   |     2
7348  s0.st2   |     2
7349  st1_exp  |     1
7350  s0.sft0  |     1
7351  s0.smv0  |     3
7352  s1.st0   |     2
7353 (9 rows)
7354
7355 SELECT dbms_stats.unlock_table_stats('s0', 'st0');
7356  unlock_table_stats 
7357 --------------------
7358  s0.st0
7359 (1 row)
7360
7361 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
7362  GROUP BY relid
7363  ORDER BY relid;
7364    relid    
7365 ------------
7366  pt0
7367  pt0_idx
7368  st0
7369  st0_idx
7370  st1
7371  s0.st0_idx
7372  s0.st1
7373  s0.st1_idx
7374  s0.st2
7375  s0.st2_idx
7376  st1_idx
7377  st1_exp
7378  s0.sft0
7379  s0.smv0
7380  s1.st0
7381 (15 rows)
7382
7383 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
7384  GROUP BY starelid
7385  ORDER BY starelid;
7386  starelid | count 
7387 ----------+-------
7388  st0      |     2
7389  st1      |     2
7390  s0.st1   |     2
7391  s0.st2   |     2
7392  st1_exp  |     1
7393  s0.sft0  |     1
7394  s0.smv0  |     3
7395  s1.st0   |     2
7396 (8 rows)
7397
7398 -- No.14-4-5
7399 DELETE FROM dbms_stats.relation_stats_locked;
7400 SELECT dbms_stats.lock_database_stats();
7401  lock_database_stats 
7402 ---------------------
7403  pt0
7404  pt0_idx
7405  st0
7406  st0_idx
7407  st1
7408  s0.st0
7409  s0.st0_idx
7410  s0.st1
7411  s0.st1_idx
7412  s0.st2
7413  s0.st2_idx
7414  st1_idx
7415  st1_exp
7416  s0.sft0
7417  s0.smv0
7418  s1.st0
7419 (16 rows)
7420
7421 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
7422  GROUP BY relid
7423  ORDER BY relid;
7424    relid    
7425 ------------
7426  pt0
7427  pt0_idx
7428  st0
7429  st0_idx
7430  st1
7431  s0.st0
7432  s0.st0_idx
7433  s0.st1
7434  s0.st1_idx
7435  s0.st2
7436  s0.st2_idx
7437  st1_idx
7438  st1_exp
7439  s0.sft0
7440  s0.smv0
7441  s1.st0
7442 (16 rows)
7443
7444 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
7445  GROUP BY starelid
7446  ORDER BY starelid;
7447  starelid | count 
7448 ----------+-------
7449  st0      |     2
7450  st1      |     2
7451  s0.st0   |     4
7452  s0.st1   |     2
7453  s0.st2   |     2
7454  st1_exp  |     1
7455  s0.sft0  |     1
7456  s0.smv0  |     3
7457  s1.st0   |     2
7458 (9 rows)
7459
7460 SELECT dbms_stats.unlock_table_stats('s00', 's0');
7461 ERROR:  schema "s00" does not exist
7462 CONTEXT:  SQL function "unlock_table_stats" statement 1
7463 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
7464  GROUP BY relid
7465  ORDER BY relid;
7466    relid    
7467 ------------
7468  pt0
7469  pt0_idx
7470  st0
7471  st0_idx
7472  st1
7473  s0.st0
7474  s0.st0_idx
7475  s0.st1
7476  s0.st1_idx
7477  s0.st2
7478  s0.st2_idx
7479  st1_idx
7480  st1_exp
7481  s0.sft0
7482  s0.smv0
7483  s1.st0
7484 (16 rows)
7485
7486 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
7487  GROUP BY starelid
7488  ORDER BY starelid;
7489  starelid | count 
7490 ----------+-------
7491  st0      |     2
7492  st1      |     2
7493  s0.st0   |     4
7494  s0.st1   |     2
7495  s0.st2   |     2
7496  st1_exp  |     1
7497  s0.sft0  |     1
7498  s0.smv0  |     3
7499  s1.st0   |     2
7500 (9 rows)
7501
7502 -- No.14-4-6
7503 DELETE FROM dbms_stats.relation_stats_locked;
7504 SELECT dbms_stats.lock_database_stats();
7505  lock_database_stats 
7506 ---------------------
7507  pt0
7508  pt0_idx
7509  st0
7510  st0_idx
7511  st1
7512  s0.st0
7513  s0.st0_idx
7514  s0.st1
7515  s0.st1_idx
7516  s0.st2
7517  s0.st2_idx
7518  st1_idx
7519  st1_exp
7520  s0.sft0
7521  s0.smv0
7522  s1.st0
7523 (16 rows)
7524
7525 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
7526  GROUP BY relid
7527  ORDER BY relid;
7528    relid    
7529 ------------
7530  pt0
7531  pt0_idx
7532  st0
7533  st0_idx
7534  st1
7535  s0.st0
7536  s0.st0_idx
7537  s0.st1
7538  s0.st1_idx
7539  s0.st2
7540  s0.st2_idx
7541  st1_idx
7542  st1_exp
7543  s0.sft0
7544  s0.smv0
7545  s1.st0
7546 (16 rows)
7547
7548 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
7549  GROUP BY starelid
7550  ORDER BY starelid;
7551  starelid | count 
7552 ----------+-------
7553  st0      |     2
7554  st1      |     2
7555  s0.st0   |     4
7556  s0.st1   |     2
7557  s0.st2   |     2
7558  st1_exp  |     1
7559  s0.sft0  |     1
7560  s0.smv0  |     3
7561  s1.st0   |     2
7562 (9 rows)
7563
7564 SELECT dbms_stats.unlock_table_stats(NULL, 'st0');
7565  unlock_table_stats 
7566 --------------------
7567 (0 rows)
7568
7569 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
7570  GROUP BY relid
7571  ORDER BY relid;
7572    relid    
7573 ------------
7574  pt0
7575  pt0_idx
7576  st0
7577  st0_idx
7578  st1
7579  s0.st0
7580  s0.st0_idx
7581  s0.st1
7582  s0.st1_idx
7583  s0.st2
7584  s0.st2_idx
7585  st1_idx
7586  st1_exp
7587  s0.sft0
7588  s0.smv0
7589  s1.st0
7590 (16 rows)
7591
7592 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
7593  GROUP BY starelid
7594  ORDER BY starelid;
7595  starelid | count 
7596 ----------+-------
7597  st0      |     2
7598  st1      |     2
7599  s0.st0   |     4
7600  s0.st1   |     2
7601  s0.st2   |     2
7602  st1_exp  |     1
7603  s0.sft0  |     1
7604  s0.smv0  |     3
7605  s1.st0   |     2
7606 (9 rows)
7607
7608 -- No.14-4-7
7609 DELETE FROM dbms_stats.relation_stats_locked;
7610 SELECT dbms_stats.lock_database_stats();
7611  lock_database_stats 
7612 ---------------------
7613  pt0
7614  pt0_idx
7615  st0
7616  st0_idx
7617  st1
7618  s0.st0
7619  s0.st0_idx
7620  s0.st1
7621  s0.st1_idx
7622  s0.st2
7623  s0.st2_idx
7624  st1_idx
7625  st1_exp
7626  s0.sft0
7627  s0.smv0
7628  s1.st0
7629 (16 rows)
7630
7631 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
7632  GROUP BY relid
7633  ORDER BY relid;
7634    relid    
7635 ------------
7636  pt0
7637  pt0_idx
7638  st0
7639  st0_idx
7640  st1
7641  s0.st0
7642  s0.st0_idx
7643  s0.st1
7644  s0.st1_idx
7645  s0.st2
7646  s0.st2_idx
7647  st1_idx
7648  st1_exp
7649  s0.sft0
7650  s0.smv0
7651  s1.st0
7652 (16 rows)
7653
7654 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
7655  GROUP BY starelid
7656  ORDER BY starelid;
7657  starelid | count 
7658 ----------+-------
7659  st0      |     2
7660  st1      |     2
7661  s0.st0   |     4
7662  s0.st1   |     2
7663  s0.st2   |     2
7664  st1_exp  |     1
7665  s0.sft0  |     1
7666  s0.smv0  |     3
7667  s1.st0   |     2
7668 (9 rows)
7669
7670 SELECT dbms_stats.unlock_table_stats('s0', NULL);
7671  unlock_table_stats 
7672 --------------------
7673 (0 rows)
7674
7675 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
7676  GROUP BY relid
7677  ORDER BY relid;
7678    relid    
7679 ------------
7680  pt0
7681  pt0_idx
7682  st0
7683  st0_idx
7684  st1
7685  s0.st0
7686  s0.st0_idx
7687  s0.st1
7688  s0.st1_idx
7689  s0.st2
7690  s0.st2_idx
7691  st1_idx
7692  st1_exp
7693  s0.sft0
7694  s0.smv0
7695  s1.st0
7696 (16 rows)
7697
7698 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
7699  GROUP BY starelid
7700  ORDER BY starelid;
7701  starelid | count 
7702 ----------+-------
7703  st0      |     2
7704  st1      |     2
7705  s0.st0   |     4
7706  s0.st1   |     2
7707  s0.st2   |     2
7708  st1_exp  |     1
7709  s0.sft0  |     1
7710  s0.smv0  |     3
7711  s1.st0   |     2
7712 (9 rows)
7713
7714 -- No.14-4-8
7715 DELETE FROM dbms_stats.relation_stats_locked;
7716 VACUUM dbms_stats.relation_stats_locked;  -- in order to avoid auto vacuum
7717 SELECT dbms_stats.lock_database_stats();
7718  lock_database_stats 
7719 ---------------------
7720  pt0
7721  pt0_idx
7722  st0
7723  st0_idx
7724  st1
7725  s0.st0
7726  s0.st0_idx
7727  s0.st1
7728  s0.st1_idx
7729  s0.st2
7730  s0.st2_idx
7731  st1_idx
7732  st1_exp
7733  s0.sft0
7734  s0.smv0
7735  s1.st0
7736 (16 rows)
7737
7738 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
7739  GROUP BY relid
7740  ORDER BY relid;
7741    relid    
7742 ------------
7743  pt0
7744  pt0_idx
7745  st0
7746  st0_idx
7747  st1
7748  s0.st0
7749  s0.st0_idx
7750  s0.st1
7751  s0.st1_idx
7752  s0.st2
7753  s0.st2_idx
7754  st1_idx
7755  st1_exp
7756  s0.sft0
7757  s0.smv0
7758  s1.st0
7759 (16 rows)
7760
7761 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
7762  GROUP BY starelid
7763  ORDER BY starelid;
7764  starelid | count 
7765 ----------+-------
7766  st0      |     2
7767  st1      |     2
7768  s0.st0   |     4
7769  s0.st1   |     2
7770  s0.st2   |     2
7771  st1_exp  |     1
7772  s0.sft0  |     1
7773  s0.smv0  |     3
7774  s1.st0   |     2
7775 (9 rows)
7776
7777 BEGIN;
7778 SELECT * FROM internal_locks;
7779  relation | mode 
7780 ----------+------
7781 (0 rows)
7782
7783 SELECT dbms_stats.unlock_table_stats('s0', 'st0');
7784  unlock_table_stats 
7785 --------------------
7786  s0.st0
7787 (1 row)
7788
7789 SELECT * FROM internal_locks;
7790              relation             |       mode       
7791 ----------------------------------+------------------
7792  dbms_stats.column_stats_locked   | RowExclusiveLock
7793  dbms_stats.relation_stats_locked | RowExclusiveLock
7794 (2 rows)
7795
7796 COMMIT;
7797 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
7798  GROUP BY relid
7799  ORDER BY relid;
7800    relid    
7801 ------------
7802  pt0
7803  pt0_idx
7804  st0
7805  st0_idx
7806  st1
7807  s0.st0_idx
7808  s0.st1
7809  s0.st1_idx
7810  s0.st2
7811  s0.st2_idx
7812  st1_idx
7813  st1_exp
7814  s0.sft0
7815  s0.smv0
7816  s1.st0
7817 (15 rows)
7818
7819 SELECT starelid::regclass, count(*) FROM dbms_stats.column_stats_locked
7820  GROUP BY starelid
7821  ORDER BY starelid;
7822  starelid | count 
7823 ----------+-------
7824  st0      |     2
7825  st1      |     2
7826  s0.st1   |     2
7827  s0.st2   |     2
7828  st1_exp  |     1
7829  s0.sft0  |     1
7830  s0.smv0  |     3
7831  s1.st0   |     2
7832 (8 rows)
7833
7834 /*
7835  * No.14-5 dbms_stats.unlock_column_stats(regclass, attname)
7836  */
7837 -- No.14-5-1
7838 DELETE FROM dbms_stats.relation_stats_locked;
7839 SELECT dbms_stats.lock_database_stats();
7840  lock_database_stats 
7841 ---------------------
7842  pt0
7843  pt0_idx
7844  st0
7845  st0_idx
7846  st1
7847  s0.st0
7848  s0.st0_idx
7849  s0.st1
7850  s0.st1_idx
7851  s0.st2
7852  s0.st2_idx
7853  st1_idx
7854  st1_exp
7855  s0.sft0
7856  s0.smv0
7857  s1.st0
7858 (16 rows)
7859
7860 SELECT * FROM dbms_stats.backup_history
7861  ORDER BY id;
7862  id |                time                 | unit | comment 
7863 ----+-------------------------------------+------+---------
7864   1 | Wed Feb 29 23:59:56.999999 2012 PST | d    | (null)
7865   2 | Wed Feb 29 23:59:57 2012 PST        | d    | (null)
7866   3 | Wed Feb 29 23:59:57.000001 2012 PST | t    | (null)
7867   4 | Wed Feb 29 23:59:58 2012 PST        | d    | (null)
7868   5 | Thu Mar 01 00:00:00 2012 PST        | c    | (null)
7869   6 | Thu Mar 01 00:00:02 2012 PST        | t    | (null)
7870   7 | Thu Mar 01 00:00:04 2012 PST        | t    | (null)
7871   8 | Thu Mar 01 00:00:06 2012 PST        | s    | (null)
7872 (8 rows)
7873
7874 SELECT count(*) FROM dbms_stats.relation_stats_backup;
7875  count 
7876 -------
7877     26
7878 (1 row)
7879
7880 SELECT count(*) FROM dbms_stats.column_stats_backup;
7881  count 
7882 -------
7883     39
7884 (1 row)
7885
7886 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
7887  GROUP BY relid
7888  ORDER BY relid;
7889    relid    
7890 ------------
7891  pt0
7892  pt0_idx
7893  st0
7894  st0_idx
7895  st1
7896  s0.st0
7897  s0.st0_idx
7898  s0.st1
7899  s0.st1_idx
7900  s0.st2
7901  s0.st2_idx
7902  st1_idx
7903  st1_exp
7904  s0.sft0
7905  s0.smv0
7906  s1.st0
7907 (16 rows)
7908
7909 SELECT starelid, attname, stainherit FROM columns_locked_v c;
7910  starelid | attname | stainherit 
7911 ----------+---------+------------
7912  st0      | id      | f
7913  st0      | name    | f
7914  st1      | val     | f
7915  st1      | str     | f
7916  s0.st0   | id      | f
7917  s0.st0   | id      | t
7918  s0.st0   | num     | f
7919  s0.st0   | num     | t
7920  s0.st1   | id      | f
7921  s0.st1   | num     | f
7922  s0.st2   | id      | f
7923  s0.st2   | txt     | f
7924  st1_exp  | lower   | f
7925  s0.sft0  | id      | f
7926  s0.smv0  | id      | f
7927  s0.smv0  | num     | f
7928  s0.smv0  | txt     | f
7929  s1.st0   | id      | f
7930  s1.st0   | num     | f
7931 (19 rows)
7932
7933 SELECT dbms_stats.unlock_column_stats('s0.st0', 'id');
7934  unlock_column_stats 
7935 ---------------------
7936  s0.st0
7937 (1 row)
7938
7939 SELECT starelid, attname, stainherit FROM columns_locked_v c;
7940  starelid | attname | stainherit 
7941 ----------+---------+------------
7942  st0      | id      | f
7943  st0      | name    | f
7944  st1      | val     | f
7945  st1      | str     | f
7946  s0.st0   | num     | f
7947  s0.st0   | num     | t
7948  s0.st1   | id      | f
7949  s0.st1   | num     | f
7950  s0.st2   | id      | f
7951  s0.st2   | txt     | f
7952  st1_exp  | lower   | f
7953  s0.sft0  | id      | f
7954  s0.smv0  | id      | f
7955  s0.smv0  | num     | f
7956  s0.smv0  | txt     | f
7957  s1.st0   | id      | f
7958  s1.st0   | num     | f
7959 (17 rows)
7960
7961 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
7962  GROUP BY relid
7963  ORDER BY relid;
7964    relid    
7965 ------------
7966  pt0
7967  pt0_idx
7968  st0
7969  st0_idx
7970  st1
7971  s0.st0
7972  s0.st0_idx
7973  s0.st1
7974  s0.st1_idx
7975  s0.st2
7976  s0.st2_idx
7977  st1_idx
7978  st1_exp
7979  s0.sft0
7980  s0.smv0
7981  s1.st0
7982 (16 rows)
7983
7984 SELECT * FROM dbms_stats.backup_history
7985  ORDER BY id;
7986  id |                time                 | unit | comment 
7987 ----+-------------------------------------+------+---------
7988   1 | Wed Feb 29 23:59:56.999999 2012 PST | d    | (null)
7989   2 | Wed Feb 29 23:59:57 2012 PST        | d    | (null)
7990   3 | Wed Feb 29 23:59:57.000001 2012 PST | t    | (null)
7991   4 | Wed Feb 29 23:59:58 2012 PST        | d    | (null)
7992   5 | Thu Mar 01 00:00:00 2012 PST        | c    | (null)
7993   6 | Thu Mar 01 00:00:02 2012 PST        | t    | (null)
7994   7 | Thu Mar 01 00:00:04 2012 PST        | t    | (null)
7995   8 | Thu Mar 01 00:00:06 2012 PST        | s    | (null)
7996 (8 rows)
7997
7998 SELECT count(*) FROM dbms_stats.relation_stats_backup;
7999  count 
8000 -------
8001     26
8002 (1 row)
8003
8004 SELECT count(*) FROM dbms_stats.column_stats_backup;
8005  count 
8006 -------
8007     39
8008 (1 row)
8009
8010 -- No.14-5-2
8011 DELETE FROM dbms_stats.relation_stats_locked;
8012 SELECT dbms_stats.lock_database_stats();
8013  lock_database_stats 
8014 ---------------------
8015  pt0
8016  pt0_idx
8017  st0
8018  st0_idx
8019  st1
8020  s0.st0
8021  s0.st0_idx
8022  s0.st1
8023  s0.st1_idx
8024  s0.st2
8025  s0.st2_idx
8026  st1_idx
8027  st1_exp
8028  s0.sft0
8029  s0.smv0
8030  s1.st0
8031 (16 rows)
8032
8033 DELETE FROM dbms_stats.column_stats_locked;
8034 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
8035  GROUP BY relid
8036  ORDER BY relid;
8037    relid    
8038 ------------
8039  pt0
8040  pt0_idx
8041  st0
8042  st0_idx
8043  st1
8044  s0.st0
8045  s0.st0_idx
8046  s0.st1
8047  s0.st1_idx
8048  s0.st2
8049  s0.st2_idx
8050  st1_idx
8051  st1_exp
8052  s0.sft0
8053  s0.smv0
8054  s1.st0
8055 (16 rows)
8056
8057 SELECT dbms_stats.unlock_column_stats('s0.st0', 'id');
8058  unlock_column_stats 
8059 ---------------------
8060  s0.st0
8061 (1 row)
8062
8063 SELECT count(*) FROM dbms_stats.column_stats_locked;
8064  count 
8065 -------
8066      0
8067 (1 row)
8068
8069 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
8070  GROUP BY relid
8071  ORDER BY relid;
8072    relid    
8073 ------------
8074  pt0
8075  pt0_idx
8076  st0
8077  st0_idx
8078  st1
8079  s0.st0
8080  s0.st0_idx
8081  s0.st1
8082  s0.st1_idx
8083  s0.st2
8084  s0.st2_idx
8085  st1_idx
8086  st1_exp
8087  s0.sft0
8088  s0.smv0
8089  s1.st0
8090 (16 rows)
8091
8092 -- No.14-5-3
8093 DELETE FROM dbms_stats.relation_stats_locked;
8094 SELECT dbms_stats.lock_database_stats();
8095  lock_database_stats 
8096 ---------------------
8097  pt0
8098  pt0_idx
8099  st0
8100  st0_idx
8101  st1
8102  s0.st0
8103  s0.st0_idx
8104  s0.st1
8105  s0.st1_idx
8106  s0.st2
8107  s0.st2_idx
8108  st1_idx
8109  st1_exp
8110  s0.sft0
8111  s0.smv0
8112  s1.st0
8113 (16 rows)
8114
8115 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
8116  GROUP BY relid
8117  ORDER BY relid;
8118    relid    
8119 ------------
8120  pt0
8121  pt0_idx
8122  st0
8123  st0_idx
8124  st1
8125  s0.st0
8126  s0.st0_idx
8127  s0.st1
8128  s0.st1_idx
8129  s0.st2
8130  s0.st2_idx
8131  st1_idx
8132  st1_exp
8133  s0.sft0
8134  s0.smv0
8135  s1.st0
8136 (16 rows)
8137
8138 SELECT starelid, attname, stainherit FROM columns_locked_v c;
8139  starelid | attname | stainherit 
8140 ----------+---------+------------
8141  st0      | id      | f
8142  st0      | name    | f
8143  st1      | val     | f
8144  st1      | str     | f
8145  s0.st0   | id      | f
8146  s0.st0   | id      | t
8147  s0.st0   | num     | f
8148  s0.st0   | num     | t
8149  s0.st1   | id      | f
8150  s0.st1   | num     | f
8151  s0.st2   | id      | f
8152  s0.st2   | txt     | f
8153  st1_exp  | lower   | f
8154  s0.sft0  | id      | f
8155  s0.smv0  | id      | f
8156  s0.smv0  | num     | f
8157  s0.smv0  | txt     | f
8158  s1.st0   | id      | f
8159  s1.st0   | num     | f
8160 (19 rows)
8161
8162 SELECT dbms_stats.unlock_column_stats('s0.st0', 'id');
8163  unlock_column_stats 
8164 ---------------------
8165  s0.st0
8166 (1 row)
8167
8168 SELECT starelid, attname, stainherit FROM columns_locked_v c;
8169  starelid | attname | stainherit 
8170 ----------+---------+------------
8171  st0      | id      | f
8172  st0      | name    | f
8173  st1      | val     | f
8174  st1      | str     | f
8175  s0.st0   | num     | f
8176  s0.st0   | num     | t
8177  s0.st1   | id      | f
8178  s0.st1   | num     | f
8179  s0.st2   | id      | f
8180  s0.st2   | txt     | f
8181  st1_exp  | lower   | f
8182  s0.sft0  | id      | f
8183  s0.smv0  | id      | f
8184  s0.smv0  | num     | f
8185  s0.smv0  | txt     | f
8186  s1.st0   | id      | f
8187  s1.st0   | num     | f
8188 (17 rows)
8189
8190 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
8191  GROUP BY relid
8192  ORDER BY relid;
8193    relid    
8194 ------------
8195  pt0
8196  pt0_idx
8197  st0
8198  st0_idx
8199  st1
8200  s0.st0
8201  s0.st0_idx
8202  s0.st1
8203  s0.st1_idx
8204  s0.st2
8205  s0.st2_idx
8206  st1_idx
8207  st1_exp
8208  s0.sft0
8209  s0.smv0
8210  s1.st0
8211 (16 rows)
8212
8213 -- No.14-5-4
8214 DELETE FROM dbms_stats.relation_stats_locked;
8215 SELECT dbms_stats.lock_database_stats();
8216  lock_database_stats 
8217 ---------------------
8218  pt0
8219  pt0_idx
8220  st0
8221  st0_idx
8222  st1
8223  s0.st0
8224  s0.st0_idx
8225  s0.st1
8226  s0.st1_idx
8227  s0.st2
8228  s0.st2_idx
8229  st1_idx
8230  st1_exp
8231  s0.sft0
8232  s0.smv0
8233  s1.st0
8234 (16 rows)
8235
8236 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
8237  GROUP BY relid
8238  ORDER BY relid;
8239    relid    
8240 ------------
8241  pt0
8242  pt0_idx
8243  st0
8244  st0_idx
8245  st1
8246  s0.st0
8247  s0.st0_idx
8248  s0.st1
8249  s0.st1_idx
8250  s0.st2
8251  s0.st2_idx
8252  st1_idx
8253  st1_exp
8254  s0.sft0
8255  s0.smv0
8256  s1.st0
8257 (16 rows)
8258
8259 SELECT starelid, attname, stainherit FROM columns_locked_v c;
8260  starelid | attname | stainherit 
8261 ----------+---------+------------
8262  st0      | id      | f
8263  st0      | name    | f
8264  st1      | val     | f
8265  st1      | str     | f
8266  s0.st0   | id      | f
8267  s0.st0   | id      | t
8268  s0.st0   | num     | f
8269  s0.st0   | num     | t
8270  s0.st1   | id      | f
8271  s0.st1   | num     | f
8272  s0.st2   | id      | f
8273  s0.st2   | txt     | f
8274  st1_exp  | lower   | f
8275  s0.sft0  | id      | f
8276  s0.smv0  | id      | f
8277  s0.smv0  | num     | f
8278  s0.smv0  | txt     | f
8279  s1.st0   | id      | f
8280  s1.st0   | num     | f
8281 (19 rows)
8282
8283 SELECT dbms_stats.unlock_column_stats('st0', 'id');
8284  unlock_column_stats 
8285 ---------------------
8286  st0
8287 (1 row)
8288
8289 SELECT starelid, attname, stainherit FROM columns_locked_v c;
8290  starelid | attname | stainherit 
8291 ----------+---------+------------
8292  st0      | name    | f
8293  st1      | val     | f
8294  st1      | str     | f
8295  s0.st0   | id      | f
8296  s0.st0   | id      | t
8297  s0.st0   | num     | f
8298  s0.st0   | num     | t
8299  s0.st1   | id      | f
8300  s0.st1   | num     | f
8301  s0.st2   | id      | f
8302  s0.st2   | txt     | f
8303  st1_exp  | lower   | f
8304  s0.sft0  | id      | f
8305  s0.smv0  | id      | f
8306  s0.smv0  | num     | f
8307  s0.smv0  | txt     | f
8308  s1.st0   | id      | f
8309  s1.st0   | num     | f
8310 (18 rows)
8311
8312 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
8313  GROUP BY relid
8314  ORDER BY relid;
8315    relid    
8316 ------------
8317  pt0
8318  pt0_idx
8319  st0
8320  st0_idx
8321  st1
8322  s0.st0
8323  s0.st0_idx
8324  s0.st1
8325  s0.st1_idx
8326  s0.st2
8327  s0.st2_idx
8328  st1_idx
8329  st1_exp
8330  s0.sft0
8331  s0.smv0
8332  s1.st0
8333 (16 rows)
8334
8335 -- No.14-5-5
8336 DELETE FROM dbms_stats.relation_stats_locked;
8337 SELECT dbms_stats.lock_database_stats();
8338  lock_database_stats 
8339 ---------------------
8340  pt0
8341  pt0_idx
8342  st0
8343  st0_idx
8344  st1
8345  s0.st0
8346  s0.st0_idx
8347  s0.st1
8348  s0.st1_idx
8349  s0.st2
8350  s0.st2_idx
8351  st1_idx
8352  st1_exp
8353  s0.sft0
8354  s0.smv0
8355  s1.st0
8356 (16 rows)
8357
8358 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
8359  GROUP BY relid
8360  ORDER BY relid;
8361    relid    
8362 ------------
8363  pt0
8364  pt0_idx
8365  st0
8366  st0_idx
8367  st1
8368  s0.st0
8369  s0.st0_idx
8370  s0.st1
8371  s0.st1_idx
8372  s0.st2
8373  s0.st2_idx
8374  st1_idx
8375  st1_exp
8376  s0.sft0
8377  s0.smv0
8378  s1.st0
8379 (16 rows)
8380
8381 SELECT starelid, attname, stainherit FROM columns_locked_v c;
8382  starelid | attname | stainherit 
8383 ----------+---------+------------
8384  st0      | id      | f
8385  st0      | name    | f
8386  st1      | val     | f
8387  st1      | str     | f
8388  s0.st0   | id      | f
8389  s0.st0   | id      | t
8390  s0.st0   | num     | f
8391  s0.st0   | num     | t
8392  s0.st1   | id      | f
8393  s0.st1   | num     | f
8394  s0.st2   | id      | f
8395  s0.st2   | txt     | f
8396  st1_exp  | lower   | f
8397  s0.sft0  | id      | f
8398  s0.smv0  | id      | f
8399  s0.smv0  | num     | f
8400  s0.smv0  | txt     | f
8401  s1.st0   | id      | f
8402  s1.st0   | num     | f
8403 (19 rows)
8404
8405 SELECT dbms_stats.unlock_column_stats('s0.st0', 'dummy');
8406 ERROR:  column "dummy" not found in relation "s0.st0"
8407 CONTEXT:  PL/pgSQL function dbms_stats.unlock_column_stats(regclass,text) line 8 at RAISE
8408 SELECT starelid, attname, stainherit FROM columns_locked_v c;
8409  starelid | attname | stainherit 
8410 ----------+---------+------------
8411  st0      | id      | f
8412  st0      | name    | f
8413  st1      | val     | f
8414  st1      | str     | f
8415  s0.st0   | id      | f
8416  s0.st0   | id      | t
8417  s0.st0   | num     | f
8418  s0.st0   | num     | t
8419  s0.st1   | id      | f
8420  s0.st1   | num     | f
8421  s0.st2   | id      | f
8422  s0.st2   | txt     | f
8423  st1_exp  | lower   | f
8424  s0.sft0  | id      | f
8425  s0.smv0  | id      | f
8426  s0.smv0  | num     | f
8427  s0.smv0  | txt     | f
8428  s1.st0   | id      | f
8429  s1.st0   | num     | f
8430 (19 rows)
8431
8432 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
8433  GROUP BY relid
8434  ORDER BY relid;
8435    relid    
8436 ------------
8437  pt0
8438  pt0_idx
8439  st0
8440  st0_idx
8441  st1
8442  s0.st0
8443  s0.st0_idx
8444  s0.st1
8445  s0.st1_idx
8446  s0.st2
8447  s0.st2_idx
8448  st1_idx
8449  st1_exp
8450  s0.sft0
8451  s0.smv0
8452  s1.st0
8453 (16 rows)
8454
8455 -- No.14-5-6
8456 DELETE FROM dbms_stats.relation_stats_locked;
8457 SELECT dbms_stats.lock_database_stats();
8458  lock_database_stats 
8459 ---------------------
8460  pt0
8461  pt0_idx
8462  st0
8463  st0_idx
8464  st1
8465  s0.st0
8466  s0.st0_idx
8467  s0.st1
8468  s0.st1_idx
8469  s0.st2
8470  s0.st2_idx
8471  st1_idx
8472  st1_exp
8473  s0.sft0
8474  s0.smv0
8475  s1.st0
8476 (16 rows)
8477
8478 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
8479  GROUP BY relid
8480  ORDER BY relid;
8481    relid    
8482 ------------
8483  pt0
8484  pt0_idx
8485  st0
8486  st0_idx
8487  st1
8488  s0.st0
8489  s0.st0_idx
8490  s0.st1
8491  s0.st1_idx
8492  s0.st2
8493  s0.st2_idx
8494  st1_idx
8495  st1_exp
8496  s0.sft0
8497  s0.smv0
8498  s1.st0
8499 (16 rows)
8500
8501 SELECT starelid, attname, stainherit FROM columns_locked_v c;
8502  starelid | attname | stainherit 
8503 ----------+---------+------------
8504  st0      | id      | f
8505  st0      | name    | f
8506  st1      | val     | f
8507  st1      | str     | f
8508  s0.st0   | id      | f
8509  s0.st0   | id      | t
8510  s0.st0   | num     | f
8511  s0.st0   | num     | t
8512  s0.st1   | id      | f
8513  s0.st1   | num     | f
8514  s0.st2   | id      | f
8515  s0.st2   | txt     | f
8516  st1_exp  | lower   | f
8517  s0.sft0  | id      | f
8518  s0.smv0  | id      | f
8519  s0.smv0  | num     | f
8520  s0.smv0  | txt     | f
8521  s1.st0   | id      | f
8522  s1.st0   | num     | f
8523 (19 rows)
8524
8525 SELECT dbms_stats.unlock_column_stats('s00.s0', 'id');
8526 ERROR:  schema "s00" does not exist
8527 LINE 1: SELECT dbms_stats.unlock_column_stats('s00.s0', 'id');
8528                                               ^
8529 SELECT starelid, attname, stainherit FROM columns_locked_v c;
8530  starelid | attname | stainherit 
8531 ----------+---------+------------
8532  st0      | id      | f
8533  st0      | name    | f
8534  st1      | val     | f
8535  st1      | str     | f
8536  s0.st0   | id      | f
8537  s0.st0   | id      | t
8538  s0.st0   | num     | f
8539  s0.st0   | num     | t
8540  s0.st1   | id      | f
8541  s0.st1   | num     | f
8542  s0.st2   | id      | f
8543  s0.st2   | txt     | f
8544  st1_exp  | lower   | f
8545  s0.sft0  | id      | f
8546  s0.smv0  | id      | f
8547  s0.smv0  | num     | f
8548  s0.smv0  | txt     | f
8549  s1.st0   | id      | f
8550  s1.st0   | num     | f
8551 (19 rows)
8552
8553 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
8554  GROUP BY relid
8555  ORDER BY relid;
8556    relid    
8557 ------------
8558  pt0
8559  pt0_idx
8560  st0
8561  st0_idx
8562  st1
8563  s0.st0
8564  s0.st0_idx
8565  s0.st1
8566  s0.st1_idx
8567  s0.st2
8568  s0.st2_idx
8569  st1_idx
8570  st1_exp
8571  s0.sft0
8572  s0.smv0
8573  s1.st0
8574 (16 rows)
8575
8576 -- No.14-5-7
8577 DELETE FROM dbms_stats.relation_stats_locked;
8578 SELECT dbms_stats.lock_database_stats();
8579  lock_database_stats 
8580 ---------------------
8581  pt0
8582  pt0_idx
8583  st0
8584  st0_idx
8585  st1
8586  s0.st0
8587  s0.st0_idx
8588  s0.st1
8589  s0.st1_idx
8590  s0.st2
8591  s0.st2_idx
8592  st1_idx
8593  st1_exp
8594  s0.sft0
8595  s0.smv0
8596  s1.st0
8597 (16 rows)
8598
8599 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
8600  GROUP BY relid
8601  ORDER BY relid;
8602    relid    
8603 ------------
8604  pt0
8605  pt0_idx
8606  st0
8607  st0_idx
8608  st1
8609  s0.st0
8610  s0.st0_idx
8611  s0.st1
8612  s0.st1_idx
8613  s0.st2
8614  s0.st2_idx
8615  st1_idx
8616  st1_exp
8617  s0.sft0
8618  s0.smv0
8619  s1.st0
8620 (16 rows)
8621
8622 SELECT starelid, attname, stainherit FROM columns_locked_v c;
8623  starelid | attname | stainherit 
8624 ----------+---------+------------
8625  st0      | id      | f
8626  st0      | name    | f
8627  st1      | val     | f
8628  st1      | str     | f
8629  s0.st0   | id      | f
8630  s0.st0   | id      | t
8631  s0.st0   | num     | f
8632  s0.st0   | num     | t
8633  s0.st1   | id      | f
8634  s0.st1   | num     | f
8635  s0.st2   | id      | f
8636  s0.st2   | txt     | f
8637  st1_exp  | lower   | f
8638  s0.sft0  | id      | f
8639  s0.smv0  | id      | f
8640  s0.smv0  | num     | f
8641  s0.smv0  | txt     | f
8642  s1.st0   | id      | f
8643  s1.st0   | num     | f
8644 (19 rows)
8645
8646 SELECT dbms_stats.unlock_column_stats(NULL, 'id');
8647  unlock_column_stats 
8648 ---------------------
8649 (0 rows)
8650
8651 SELECT starelid, attname, stainherit FROM columns_locked_v c;
8652  starelid | attname | stainherit 
8653 ----------+---------+------------
8654  st0      | id      | f
8655  st0      | name    | f
8656  st1      | val     | f
8657  st1      | str     | f
8658  s0.st0   | id      | f
8659  s0.st0   | id      | t
8660  s0.st0   | num     | f
8661  s0.st0   | num     | t
8662  s0.st1   | id      | f
8663  s0.st1   | num     | f
8664  s0.st2   | id      | f
8665  s0.st2   | txt     | f
8666  st1_exp  | lower   | f
8667  s0.sft0  | id      | f
8668  s0.smv0  | id      | f
8669  s0.smv0  | num     | f
8670  s0.smv0  | txt     | f
8671  s1.st0   | id      | f
8672  s1.st0   | num     | f
8673 (19 rows)
8674
8675 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
8676  GROUP BY relid
8677  ORDER BY relid;
8678    relid    
8679 ------------
8680  pt0
8681  pt0_idx
8682  st0
8683  st0_idx
8684  st1
8685  s0.st0
8686  s0.st0_idx
8687  s0.st1
8688  s0.st1_idx
8689  s0.st2
8690  s0.st2_idx
8691  st1_idx
8692  st1_exp
8693  s0.sft0
8694  s0.smv0
8695  s1.st0
8696 (16 rows)
8697
8698 -- No.14-5-8
8699 DELETE FROM dbms_stats.relation_stats_locked;
8700 SELECT dbms_stats.lock_database_stats();
8701  lock_database_stats 
8702 ---------------------
8703  pt0
8704  pt0_idx
8705  st0
8706  st0_idx
8707  st1
8708  s0.st0
8709  s0.st0_idx
8710  s0.st1
8711  s0.st1_idx
8712  s0.st2
8713  s0.st2_idx
8714  st1_idx
8715  st1_exp
8716  s0.sft0
8717  s0.smv0
8718  s1.st0
8719 (16 rows)
8720
8721 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
8722  GROUP BY relid
8723  ORDER BY relid;
8724    relid    
8725 ------------
8726  pt0
8727  pt0_idx
8728  st0
8729  st0_idx
8730  st1
8731  s0.st0
8732  s0.st0_idx
8733  s0.st1
8734  s0.st1_idx
8735  s0.st2
8736  s0.st2_idx
8737  st1_idx
8738  st1_exp
8739  s0.sft0
8740  s0.smv0
8741  s1.st0
8742 (16 rows)
8743
8744 SELECT starelid, attname, stainherit FROM columns_locked_v c;
8745  starelid | attname | stainherit 
8746 ----------+---------+------------
8747  st0      | id      | f
8748  st0      | name    | f
8749  st1      | val     | f
8750  st1      | str     | f
8751  s0.st0   | id      | f
8752  s0.st0   | id      | t
8753  s0.st0   | num     | f
8754  s0.st0   | num     | t
8755  s0.st1   | id      | f
8756  s0.st1   | num     | f
8757  s0.st2   | id      | f
8758  s0.st2   | txt     | f
8759  st1_exp  | lower   | f
8760  s0.sft0  | id      | f
8761  s0.smv0  | id      | f
8762  s0.smv0  | num     | f
8763  s0.smv0  | txt     | f
8764  s1.st0   | id      | f
8765  s1.st0   | num     | f
8766 (19 rows)
8767
8768 SELECT dbms_stats.unlock_column_stats('s0.st0', NULL);
8769  unlock_column_stats 
8770 ---------------------
8771 (0 rows)
8772
8773 SELECT starelid, attname, stainherit FROM columns_locked_v c;
8774  starelid | attname | stainherit 
8775 ----------+---------+------------
8776  st0      | id      | f
8777  st0      | name    | f
8778  st1      | val     | f
8779  st1      | str     | f
8780  s0.st0   | id      | f
8781  s0.st0   | id      | t
8782  s0.st0   | num     | f
8783  s0.st0   | num     | t
8784  s0.st1   | id      | f
8785  s0.st1   | num     | f
8786  s0.st2   | id      | f
8787  s0.st2   | txt     | f
8788  st1_exp  | lower   | f
8789  s0.sft0  | id      | f
8790  s0.smv0  | id      | f
8791  s0.smv0  | num     | f
8792  s0.smv0  | txt     | f
8793  s1.st0   | id      | f
8794  s1.st0   | num     | f
8795 (19 rows)
8796
8797 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
8798  GROUP BY relid
8799  ORDER BY relid;
8800    relid    
8801 ------------
8802  pt0
8803  pt0_idx
8804  st0
8805  st0_idx
8806  st1
8807  s0.st0
8808  s0.st0_idx
8809  s0.st1
8810  s0.st1_idx
8811  s0.st2
8812  s0.st2_idx
8813  st1_idx
8814  st1_exp
8815  s0.sft0
8816  s0.smv0
8817  s1.st0
8818 (16 rows)
8819
8820 -- No.14-5-9
8821 DELETE FROM dbms_stats.relation_stats_locked;
8822 VACUUM dbms_stats.relation_stats_locked;  -- in order to avoid auto vacuum
8823 SELECT dbms_stats.lock_database_stats();
8824  lock_database_stats 
8825 ---------------------
8826  pt0
8827  pt0_idx
8828  st0
8829  st0_idx
8830  st1
8831  s0.st0
8832  s0.st0_idx
8833  s0.st1
8834  s0.st1_idx
8835  s0.st2
8836  s0.st2_idx
8837  st1_idx
8838  st1_exp
8839  s0.sft0
8840  s0.smv0
8841  s1.st0
8842 (16 rows)
8843
8844 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
8845  GROUP BY relid
8846  ORDER BY relid;
8847    relid    
8848 ------------
8849  pt0
8850  pt0_idx
8851  st0
8852  st0_idx
8853  st1
8854  s0.st0
8855  s0.st0_idx
8856  s0.st1
8857  s0.st1_idx
8858  s0.st2
8859  s0.st2_idx
8860  st1_idx
8861  st1_exp
8862  s0.sft0
8863  s0.smv0
8864  s1.st0
8865 (16 rows)
8866
8867 SELECT starelid, attname, stainherit FROM columns_locked_v c;
8868  starelid | attname | stainherit 
8869 ----------+---------+------------
8870  st0      | id      | f
8871  st0      | name    | f
8872  st1      | val     | f
8873  st1      | str     | f
8874  s0.st0   | id      | f
8875  s0.st0   | id      | t
8876  s0.st0   | num     | f
8877  s0.st0   | num     | t
8878  s0.st1   | id      | f
8879  s0.st1   | num     | f
8880  s0.st2   | id      | f
8881  s0.st2   | txt     | f
8882  st1_exp  | lower   | f
8883  s0.sft0  | id      | f
8884  s0.smv0  | id      | f
8885  s0.smv0  | num     | f
8886  s0.smv0  | txt     | f
8887  s1.st0   | id      | f
8888  s1.st0   | num     | f
8889 (19 rows)
8890
8891 BEGIN;
8892 SELECT * FROM internal_locks;
8893  relation | mode 
8894 ----------+------
8895 (0 rows)
8896
8897 SELECT dbms_stats.unlock_column_stats('s0.st0', 'id');
8898  unlock_column_stats 
8899 ---------------------
8900  s0.st0
8901 (1 row)
8902
8903 SELECT * FROM internal_locks;
8904              relation             |       mode       
8905 ----------------------------------+------------------
8906  dbms_stats.column_stats_locked   | RowExclusiveLock
8907  dbms_stats.relation_stats_locked | RowShareLock
8908 (2 rows)
8909
8910 COMMIT;
8911 SELECT starelid, attname, stainherit FROM columns_locked_v c;
8912  starelid | attname | stainherit 
8913 ----------+---------+------------
8914  st0      | id      | f
8915  st0      | name    | f
8916  st1      | val     | f
8917  st1      | str     | f
8918  s0.st0   | num     | f
8919  s0.st0   | num     | t
8920  s0.st1   | id      | f
8921  s0.st1   | num     | f
8922  s0.st2   | id      | f
8923  s0.st2   | txt     | f
8924  st1_exp  | lower   | f
8925  s0.sft0  | id      | f
8926  s0.smv0  | id      | f
8927  s0.smv0  | num     | f
8928  s0.smv0  | txt     | f
8929  s1.st0   | id      | f
8930  s1.st0   | num     | f
8931 (17 rows)
8932
8933 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
8934  GROUP BY relid
8935  ORDER BY relid;
8936    relid    
8937 ------------
8938  pt0
8939  pt0_idx
8940  st0
8941  st0_idx
8942  st1
8943  s0.st0
8944  s0.st0_idx
8945  s0.st1
8946  s0.st1_idx
8947  s0.st2
8948  s0.st2_idx
8949  st1_idx
8950  st1_exp
8951  s0.sft0
8952  s0.smv0
8953  s1.st0
8954 (16 rows)
8955
8956 /*
8957  * No.14-6 dbms_stats.unlock_column_stats(schemaname, tablename, attname)
8958  */
8959 -- No.14-6-1
8960 DELETE FROM dbms_stats.relation_stats_locked;
8961 SELECT dbms_stats.lock_database_stats();
8962  lock_database_stats 
8963 ---------------------
8964  pt0
8965  pt0_idx
8966  st0
8967  st0_idx
8968  st1
8969  s0.st0
8970  s0.st0_idx
8971  s0.st1
8972  s0.st1_idx
8973  s0.st2
8974  s0.st2_idx
8975  st1_idx
8976  st1_exp
8977  s0.sft0
8978  s0.smv0
8979  s1.st0
8980 (16 rows)
8981
8982 SELECT * FROM dbms_stats.backup_history
8983  ORDER BY id;
8984  id |                time                 | unit | comment 
8985 ----+-------------------------------------+------+---------
8986   1 | Wed Feb 29 23:59:56.999999 2012 PST | d    | (null)
8987   2 | Wed Feb 29 23:59:57 2012 PST        | d    | (null)
8988   3 | Wed Feb 29 23:59:57.000001 2012 PST | t    | (null)
8989   4 | Wed Feb 29 23:59:58 2012 PST        | d    | (null)
8990   5 | Thu Mar 01 00:00:00 2012 PST        | c    | (null)
8991   6 | Thu Mar 01 00:00:02 2012 PST        | t    | (null)
8992   7 | Thu Mar 01 00:00:04 2012 PST        | t    | (null)
8993   8 | Thu Mar 01 00:00:06 2012 PST        | s    | (null)
8994 (8 rows)
8995
8996 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
8997  GROUP BY relid
8998  ORDER BY relid;
8999    relid    
9000 ------------
9001  pt0
9002  pt0_idx
9003  st0
9004  st0_idx
9005  st1
9006  s0.st0
9007  s0.st0_idx
9008  s0.st1
9009  s0.st1_idx
9010  s0.st2
9011  s0.st2_idx
9012  st1_idx
9013  st1_exp
9014  s0.sft0
9015  s0.smv0
9016  s1.st0
9017 (16 rows)
9018
9019 SELECT starelid, attname, stainherit FROM columns_locked_v c;
9020  starelid | attname | stainherit 
9021 ----------+---------+------------
9022  st0      | id      | f
9023  st0      | name    | f
9024  st1      | val     | f
9025  st1      | str     | f
9026  s0.st0   | id      | f
9027  s0.st0   | id      | t
9028  s0.st0   | num     | f
9029  s0.st0   | num     | t
9030  s0.st1   | id      | f
9031  s0.st1   | num     | f
9032  s0.st2   | id      | f
9033  s0.st2   | txt     | f
9034  st1_exp  | lower   | f
9035  s0.sft0  | id      | f
9036  s0.smv0  | id      | f
9037  s0.smv0  | num     | f
9038  s0.smv0  | txt     | f
9039  s1.st0   | id      | f
9040  s1.st0   | num     | f
9041 (19 rows)
9042
9043 SELECT dbms_stats.unlock_column_stats('s0', 'st0', 'id');
9044  unlock_column_stats 
9045 ---------------------
9046  s0.st0
9047 (1 row)
9048
9049 SELECT starelid, attname, stainherit FROM columns_locked_v c;
9050  starelid | attname | stainherit 
9051 ----------+---------+------------
9052  st0      | id      | f
9053  st0      | name    | f
9054  st1      | val     | f
9055  st1      | str     | f
9056  s0.st0   | num     | f
9057  s0.st0   | num     | t
9058  s0.st1   | id      | f
9059  s0.st1   | num     | f
9060  s0.st2   | id      | f
9061  s0.st2   | txt     | f
9062  st1_exp  | lower   | f
9063  s0.sft0  | id      | f
9064  s0.smv0  | id      | f
9065  s0.smv0  | num     | f
9066  s0.smv0  | txt     | f
9067  s1.st0   | id      | f
9068  s1.st0   | num     | f
9069 (17 rows)
9070
9071 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
9072  GROUP BY relid
9073  ORDER BY relid;
9074    relid    
9075 ------------
9076  pt0
9077  pt0_idx
9078  st0
9079  st0_idx
9080  st1
9081  s0.st0
9082  s0.st0_idx
9083  s0.st1
9084  s0.st1_idx
9085  s0.st2
9086  s0.st2_idx
9087  st1_idx
9088  st1_exp
9089  s0.sft0
9090  s0.smv0
9091  s1.st0
9092 (16 rows)
9093
9094 SELECT * FROM dbms_stats.backup_history
9095  ORDER BY id;
9096  id |                time                 | unit | comment 
9097 ----+-------------------------------------+------+---------
9098   1 | Wed Feb 29 23:59:56.999999 2012 PST | d    | (null)
9099   2 | Wed Feb 29 23:59:57 2012 PST        | d    | (null)
9100   3 | Wed Feb 29 23:59:57.000001 2012 PST | t    | (null)
9101   4 | Wed Feb 29 23:59:58 2012 PST        | d    | (null)
9102   5 | Thu Mar 01 00:00:00 2012 PST        | c    | (null)
9103   6 | Thu Mar 01 00:00:02 2012 PST        | t    | (null)
9104   7 | Thu Mar 01 00:00:04 2012 PST        | t    | (null)
9105   8 | Thu Mar 01 00:00:06 2012 PST        | s    | (null)
9106 (8 rows)
9107
9108 SELECT count(*) FROM dbms_stats.relation_stats_backup;
9109  count 
9110 -------
9111     26
9112 (1 row)
9113
9114 SELECT count(*) FROM dbms_stats.column_stats_backup;
9115  count 
9116 -------
9117     39
9118 (1 row)
9119
9120 -- No.14-6-2
9121 DELETE FROM dbms_stats.relation_stats_locked;
9122 SELECT dbms_stats.lock_database_stats();
9123  lock_database_stats 
9124 ---------------------
9125  pt0
9126  pt0_idx
9127  st0
9128  st0_idx
9129  st1
9130  s0.st0
9131  s0.st0_idx
9132  s0.st1
9133  s0.st1_idx
9134  s0.st2
9135  s0.st2_idx
9136  st1_idx
9137  st1_exp
9138  s0.sft0
9139  s0.smv0
9140  s1.st0
9141 (16 rows)
9142
9143 DELETE FROM dbms_stats.column_stats_locked;
9144 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
9145  GROUP BY relid
9146  ORDER BY relid;
9147    relid    
9148 ------------
9149  pt0
9150  pt0_idx
9151  st0
9152  st0_idx
9153  st1
9154  s0.st0
9155  s0.st0_idx
9156  s0.st1
9157  s0.st1_idx
9158  s0.st2
9159  s0.st2_idx
9160  st1_idx
9161  st1_exp
9162  s0.sft0
9163  s0.smv0
9164  s1.st0
9165 (16 rows)
9166
9167 SELECT dbms_stats.unlock_column_stats('s0', 'st0', 'id');
9168  unlock_column_stats 
9169 ---------------------
9170  s0.st0
9171 (1 row)
9172
9173 SELECT starelid, attname, stainherit FROM columns_locked_v c;
9174  starelid | attname | stainherit 
9175 ----------+---------+------------
9176 (0 rows)
9177
9178 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
9179  GROUP BY relid
9180  ORDER BY relid;
9181    relid    
9182 ------------
9183  pt0
9184  pt0_idx
9185  st0
9186  st0_idx
9187  st1
9188  s0.st0
9189  s0.st0_idx
9190  s0.st1
9191  s0.st1_idx
9192  s0.st2
9193  s0.st2_idx
9194  st1_idx
9195  st1_exp
9196  s0.sft0
9197  s0.smv0
9198  s1.st0
9199 (16 rows)
9200
9201 -- No.14-6-3
9202 DELETE FROM dbms_stats.relation_stats_locked;
9203 SELECT dbms_stats.lock_database_stats();
9204  lock_database_stats 
9205 ---------------------
9206  pt0
9207  pt0_idx
9208  st0
9209  st0_idx
9210  st1
9211  s0.st0
9212  s0.st0_idx
9213  s0.st1
9214  s0.st1_idx
9215  s0.st2
9216  s0.st2_idx
9217  st1_idx
9218  st1_exp
9219  s0.sft0
9220  s0.smv0
9221  s1.st0
9222 (16 rows)
9223
9224 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
9225  GROUP BY relid
9226  ORDER BY relid;
9227    relid    
9228 ------------
9229  pt0
9230  pt0_idx
9231  st0
9232  st0_idx
9233  st1
9234  s0.st0
9235  s0.st0_idx
9236  s0.st1
9237  s0.st1_idx
9238  s0.st2
9239  s0.st2_idx
9240  st1_idx
9241  st1_exp
9242  s0.sft0
9243  s0.smv0
9244  s1.st0
9245 (16 rows)
9246
9247 SELECT starelid, attname, stainherit FROM columns_locked_v c;
9248  starelid | attname | stainherit 
9249 ----------+---------+------------
9250  st0      | id      | f
9251  st0      | name    | f
9252  st1      | val     | f
9253  st1      | str     | f
9254  s0.st0   | id      | f
9255  s0.st0   | id      | t
9256  s0.st0   | num     | f
9257  s0.st0   | num     | t
9258  s0.st1   | id      | f
9259  s0.st1   | num     | f
9260  s0.st2   | id      | f
9261  s0.st2   | txt     | f
9262  st1_exp  | lower   | f
9263  s0.sft0  | id      | f
9264  s0.smv0  | id      | f
9265  s0.smv0  | num     | f
9266  s0.smv0  | txt     | f
9267  s1.st0   | id      | f
9268  s1.st0   | num     | f
9269 (19 rows)
9270
9271 SELECT dbms_stats.unlock_column_stats('s0', 'st0', 'id');
9272  unlock_column_stats 
9273 ---------------------
9274  s0.st0
9275 (1 row)
9276
9277 SELECT starelid, attname, stainherit FROM columns_locked_v c;
9278  starelid | attname | stainherit 
9279 ----------+---------+------------
9280  st0      | id      | f
9281  st0      | name    | f
9282  st1      | val     | f
9283  st1      | str     | f
9284  s0.st0   | num     | f
9285  s0.st0   | num     | t
9286  s0.st1   | id      | f
9287  s0.st1   | num     | f
9288  s0.st2   | id      | f
9289  s0.st2   | txt     | f
9290  st1_exp  | lower   | f
9291  s0.sft0  | id      | f
9292  s0.smv0  | id      | f
9293  s0.smv0  | num     | f
9294  s0.smv0  | txt     | f
9295  s1.st0   | id      | f
9296  s1.st0   | num     | f
9297 (17 rows)
9298
9299 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
9300  GROUP BY relid
9301  ORDER BY relid;
9302    relid    
9303 ------------
9304  pt0
9305  pt0_idx
9306  st0
9307  st0_idx
9308  st1
9309  s0.st0
9310  s0.st0_idx
9311  s0.st1
9312  s0.st1_idx
9313  s0.st2
9314  s0.st2_idx
9315  st1_idx
9316  st1_exp
9317  s0.sft0
9318  s0.smv0
9319  s1.st0
9320 (16 rows)
9321
9322 -- No.14-6-4
9323 DELETE FROM dbms_stats.relation_stats_locked;
9324 SELECT dbms_stats.lock_database_stats();
9325  lock_database_stats 
9326 ---------------------
9327  pt0
9328  pt0_idx
9329  st0
9330  st0_idx
9331  st1
9332  s0.st0
9333  s0.st0_idx
9334  s0.st1
9335  s0.st1_idx
9336  s0.st2
9337  s0.st2_idx
9338  st1_idx
9339  st1_exp
9340  s0.sft0
9341  s0.smv0
9342  s1.st0
9343 (16 rows)
9344
9345 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
9346  GROUP BY relid
9347  ORDER BY relid;
9348    relid    
9349 ------------
9350  pt0
9351  pt0_idx
9352  st0
9353  st0_idx
9354  st1
9355  s0.st0
9356  s0.st0_idx
9357  s0.st1
9358  s0.st1_idx
9359  s0.st2
9360  s0.st2_idx
9361  st1_idx
9362  st1_exp
9363  s0.sft0
9364  s0.smv0
9365  s1.st0
9366 (16 rows)
9367
9368 SELECT starelid, attname, stainherit FROM columns_locked_v c;
9369  starelid | attname | stainherit 
9370 ----------+---------+------------
9371  st0      | id      | f
9372  st0      | name    | f
9373  st1      | val     | f
9374  st1      | str     | f
9375  s0.st0   | id      | f
9376  s0.st0   | id      | t
9377  s0.st0   | num     | f
9378  s0.st0   | num     | t
9379  s0.st1   | id      | f
9380  s0.st1   | num     | f
9381  s0.st2   | id      | f
9382  s0.st2   | txt     | f
9383  st1_exp  | lower   | f
9384  s0.sft0  | id      | f
9385  s0.smv0  | id      | f
9386  s0.smv0  | num     | f
9387  s0.smv0  | txt     | f
9388  s1.st0   | id      | f
9389  s1.st0   | num     | f
9390 (19 rows)
9391
9392 SELECT dbms_stats.unlock_column_stats('s0', 'st0', 'dummy');
9393 ERROR:  column "dummy" not found in relation "s0.st0"
9394 CONTEXT:  PL/pgSQL function dbms_stats.unlock_column_stats(text,text,text) line 9 at RAISE
9395 SELECT starelid, attname, stainherit FROM columns_locked_v c;
9396  starelid | attname | stainherit 
9397 ----------+---------+------------
9398  st0      | id      | f
9399  st0      | name    | f
9400  st1      | val     | f
9401  st1      | str     | f
9402  s0.st0   | id      | f
9403  s0.st0   | id      | t
9404  s0.st0   | num     | f
9405  s0.st0   | num     | t
9406  s0.st1   | id      | f
9407  s0.st1   | num     | f
9408  s0.st2   | id      | f
9409  s0.st2   | txt     | f
9410  st1_exp  | lower   | f
9411  s0.sft0  | id      | f
9412  s0.smv0  | id      | f
9413  s0.smv0  | num     | f
9414  s0.smv0  | txt     | f
9415  s1.st0   | id      | f
9416  s1.st0   | num     | f
9417 (19 rows)
9418
9419 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
9420  GROUP BY relid
9421  ORDER BY relid;
9422    relid    
9423 ------------
9424  pt0
9425  pt0_idx
9426  st0
9427  st0_idx
9428  st1
9429  s0.st0
9430  s0.st0_idx
9431  s0.st1
9432  s0.st1_idx
9433  s0.st2
9434  s0.st2_idx
9435  st1_idx
9436  st1_exp
9437  s0.sft0
9438  s0.smv0
9439  s1.st0
9440 (16 rows)
9441
9442 -- No.14-6-5
9443 DELETE FROM dbms_stats.relation_stats_locked;
9444 SELECT dbms_stats.lock_database_stats();
9445  lock_database_stats 
9446 ---------------------
9447  pt0
9448  pt0_idx
9449  st0
9450  st0_idx
9451  st1
9452  s0.st0
9453  s0.st0_idx
9454  s0.st1
9455  s0.st1_idx
9456  s0.st2
9457  s0.st2_idx
9458  st1_idx
9459  st1_exp
9460  s0.sft0
9461  s0.smv0
9462  s1.st0
9463 (16 rows)
9464
9465 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
9466  GROUP BY relid
9467  ORDER BY relid;
9468    relid    
9469 ------------
9470  pt0
9471  pt0_idx
9472  st0
9473  st0_idx
9474  st1
9475  s0.st0
9476  s0.st0_idx
9477  s0.st1
9478  s0.st1_idx
9479  s0.st2
9480  s0.st2_idx
9481  st1_idx
9482  st1_exp
9483  s0.sft0
9484  s0.smv0
9485  s1.st0
9486 (16 rows)
9487
9488 SELECT starelid, attname, stainherit FROM columns_locked_v c;
9489  starelid | attname | stainherit 
9490 ----------+---------+------------
9491  st0      | id      | f
9492  st0      | name    | f
9493  st1      | val     | f
9494  st1      | str     | f
9495  s0.st0   | id      | f
9496  s0.st0   | id      | t
9497  s0.st0   | num     | f
9498  s0.st0   | num     | t
9499  s0.st1   | id      | f
9500  s0.st1   | num     | f
9501  s0.st2   | id      | f
9502  s0.st2   | txt     | f
9503  st1_exp  | lower   | f
9504  s0.sft0  | id      | f
9505  s0.smv0  | id      | f
9506  s0.smv0  | num     | f
9507  s0.smv0  | txt     | f
9508  s1.st0   | id      | f
9509  s1.st0   | num     | f
9510 (19 rows)
9511
9512 SELECT dbms_stats.unlock_column_stats(NULL, 'st0', 'id');
9513  unlock_column_stats 
9514 ---------------------
9515 (0 rows)
9516
9517 SELECT starelid, attname, stainherit FROM columns_locked_v c;
9518  starelid | attname | stainherit 
9519 ----------+---------+------------
9520  st0      | id      | f
9521  st0      | name    | f
9522  st1      | val     | f
9523  st1      | str     | f
9524  s0.st0   | id      | f
9525  s0.st0   | id      | t
9526  s0.st0   | num     | f
9527  s0.st0   | num     | t
9528  s0.st1   | id      | f
9529  s0.st1   | num     | f
9530  s0.st2   | id      | f
9531  s0.st2   | txt     | f
9532  st1_exp  | lower   | f
9533  s0.sft0  | id      | f
9534  s0.smv0  | id      | f
9535  s0.smv0  | num     | f
9536  s0.smv0  | txt     | f
9537  s1.st0   | id      | f
9538  s1.st0   | num     | f
9539 (19 rows)
9540
9541 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
9542  GROUP BY relid
9543  ORDER BY relid;
9544    relid    
9545 ------------
9546  pt0
9547  pt0_idx
9548  st0
9549  st0_idx
9550  st1
9551  s0.st0
9552  s0.st0_idx
9553  s0.st1
9554  s0.st1_idx
9555  s0.st2
9556  s0.st2_idx
9557  st1_idx
9558  st1_exp
9559  s0.sft0
9560  s0.smv0
9561  s1.st0
9562 (16 rows)
9563
9564 -- No.14-6-6
9565 DELETE FROM dbms_stats.relation_stats_locked;
9566 SELECT dbms_stats.lock_database_stats();
9567  lock_database_stats 
9568 ---------------------
9569  pt0
9570  pt0_idx
9571  st0
9572  st0_idx
9573  st1
9574  s0.st0
9575  s0.st0_idx
9576  s0.st1
9577  s0.st1_idx
9578  s0.st2
9579  s0.st2_idx
9580  st1_idx
9581  st1_exp
9582  s0.sft0
9583  s0.smv0
9584  s1.st0
9585 (16 rows)
9586
9587 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
9588  GROUP BY relid
9589  ORDER BY relid;
9590    relid    
9591 ------------
9592  pt0
9593  pt0_idx
9594  st0
9595  st0_idx
9596  st1
9597  s0.st0
9598  s0.st0_idx
9599  s0.st1
9600  s0.st1_idx
9601  s0.st2
9602  s0.st2_idx
9603  st1_idx
9604  st1_exp
9605  s0.sft0
9606  s0.smv0
9607  s1.st0
9608 (16 rows)
9609
9610 SELECT starelid, attname, stainherit FROM columns_locked_v c;
9611  starelid | attname | stainherit 
9612 ----------+---------+------------
9613  st0      | id      | f
9614  st0      | name    | f
9615  st1      | val     | f
9616  st1      | str     | f
9617  s0.st0   | id      | f
9618  s0.st0   | id      | t
9619  s0.st0   | num     | f
9620  s0.st0   | num     | t
9621  s0.st1   | id      | f
9622  s0.st1   | num     | f
9623  s0.st2   | id      | f
9624  s0.st2   | txt     | f
9625  st1_exp  | lower   | f
9626  s0.sft0  | id      | f
9627  s0.smv0  | id      | f
9628  s0.smv0  | num     | f
9629  s0.smv0  | txt     | f
9630  s1.st0   | id      | f
9631  s1.st0   | num     | f
9632 (19 rows)
9633
9634 SELECT dbms_stats.unlock_column_stats('s0', NULL, 'id');
9635  unlock_column_stats 
9636 ---------------------
9637 (0 rows)
9638
9639 SELECT starelid, attname, stainherit FROM columns_locked_v c;
9640  starelid | attname | stainherit 
9641 ----------+---------+------------
9642  st0      | id      | f
9643  st0      | name    | f
9644  st1      | val     | f
9645  st1      | str     | f
9646  s0.st0   | id      | f
9647  s0.st0   | id      | t
9648  s0.st0   | num     | f
9649  s0.st0   | num     | t
9650  s0.st1   | id      | f
9651  s0.st1   | num     | f
9652  s0.st2   | id      | f
9653  s0.st2   | txt     | f
9654  st1_exp  | lower   | f
9655  s0.sft0  | id      | f
9656  s0.smv0  | id      | f
9657  s0.smv0  | num     | f
9658  s0.smv0  | txt     | f
9659  s1.st0   | id      | f
9660  s1.st0   | num     | f
9661 (19 rows)
9662
9663 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
9664  GROUP BY relid
9665  ORDER BY relid;
9666    relid    
9667 ------------
9668  pt0
9669  pt0_idx
9670  st0
9671  st0_idx
9672  st1
9673  s0.st0
9674  s0.st0_idx
9675  s0.st1
9676  s0.st1_idx
9677  s0.st2
9678  s0.st2_idx
9679  st1_idx
9680  st1_exp
9681  s0.sft0
9682  s0.smv0
9683  s1.st0
9684 (16 rows)
9685
9686 -- No.14-6-7
9687 DELETE FROM dbms_stats.relation_stats_locked;
9688 SELECT dbms_stats.lock_database_stats();
9689  lock_database_stats 
9690 ---------------------
9691  pt0
9692  pt0_idx
9693  st0
9694  st0_idx
9695  st1
9696  s0.st0
9697  s0.st0_idx
9698  s0.st1
9699  s0.st1_idx
9700  s0.st2
9701  s0.st2_idx
9702  st1_idx
9703  st1_exp
9704  s0.sft0
9705  s0.smv0
9706  s1.st0
9707 (16 rows)
9708
9709 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
9710  GROUP BY relid
9711  ORDER BY relid;
9712    relid    
9713 ------------
9714  pt0
9715  pt0_idx
9716  st0
9717  st0_idx
9718  st1
9719  s0.st0
9720  s0.st0_idx
9721  s0.st1
9722  s0.st1_idx
9723  s0.st2
9724  s0.st2_idx
9725  st1_idx
9726  st1_exp
9727  s0.sft0
9728  s0.smv0
9729  s1.st0
9730 (16 rows)
9731
9732 SELECT starelid, attname, stainherit FROM columns_locked_v c;
9733  starelid | attname | stainherit 
9734 ----------+---------+------------
9735  st0      | id      | f
9736  st0      | name    | f
9737  st1      | val     | f
9738  st1      | str     | f
9739  s0.st0   | id      | f
9740  s0.st0   | id      | t
9741  s0.st0   | num     | f
9742  s0.st0   | num     | t
9743  s0.st1   | id      | f
9744  s0.st1   | num     | f
9745  s0.st2   | id      | f
9746  s0.st2   | txt     | f
9747  st1_exp  | lower   | f
9748  s0.sft0  | id      | f
9749  s0.smv0  | id      | f
9750  s0.smv0  | num     | f
9751  s0.smv0  | txt     | f
9752  s1.st0   | id      | f
9753  s1.st0   | num     | f
9754 (19 rows)
9755
9756 SELECT dbms_stats.unlock_column_stats('s0', 'st0', NULL);
9757  unlock_column_stats 
9758 ---------------------
9759 (0 rows)
9760
9761 SELECT starelid, attname, stainherit FROM columns_locked_v c;
9762  starelid | attname | stainherit 
9763 ----------+---------+------------
9764  st0      | id      | f
9765  st0      | name    | f
9766  st1      | val     | f
9767  st1      | str     | f
9768  s0.st0   | id      | f
9769  s0.st0   | id      | t
9770  s0.st0   | num     | f
9771  s0.st0   | num     | t
9772  s0.st1   | id      | f
9773  s0.st1   | num     | f
9774  s0.st2   | id      | f
9775  s0.st2   | txt     | f
9776  st1_exp  | lower   | f
9777  s0.sft0  | id      | f
9778  s0.smv0  | id      | f
9779  s0.smv0  | num     | f
9780  s0.smv0  | txt     | f
9781  s1.st0   | id      | f
9782  s1.st0   | num     | f
9783 (19 rows)
9784
9785 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
9786  GROUP BY relid
9787  ORDER BY relid;
9788    relid    
9789 ------------
9790  pt0
9791  pt0_idx
9792  st0
9793  st0_idx
9794  st1
9795  s0.st0
9796  s0.st0_idx
9797  s0.st1
9798  s0.st1_idx
9799  s0.st2
9800  s0.st2_idx
9801  st1_idx
9802  st1_exp
9803  s0.sft0
9804  s0.smv0
9805  s1.st0
9806 (16 rows)
9807
9808 -- No.14-6-8
9809 DELETE FROM dbms_stats.relation_stats_locked;
9810 VACUUM dbms_stats.relation_stats_locked;  -- in order to avoid auto vacuum
9811 SELECT dbms_stats.lock_database_stats();
9812  lock_database_stats 
9813 ---------------------
9814  pt0
9815  pt0_idx
9816  st0
9817  st0_idx
9818  st1
9819  s0.st0
9820  s0.st0_idx
9821  s0.st1
9822  s0.st1_idx
9823  s0.st2
9824  s0.st2_idx
9825  st1_idx
9826  st1_exp
9827  s0.sft0
9828  s0.smv0
9829  s1.st0
9830 (16 rows)
9831
9832 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
9833  GROUP BY relid
9834  ORDER BY relid;
9835    relid    
9836 ------------
9837  pt0
9838  pt0_idx
9839  st0
9840  st0_idx
9841  st1
9842  s0.st0
9843  s0.st0_idx
9844  s0.st1
9845  s0.st1_idx
9846  s0.st2
9847  s0.st2_idx
9848  st1_idx
9849  st1_exp
9850  s0.sft0
9851  s0.smv0
9852  s1.st0
9853 (16 rows)
9854
9855 SELECT starelid, attname, stainherit FROM columns_locked_v c;
9856  starelid | attname | stainherit 
9857 ----------+---------+------------
9858  st0      | id      | f
9859  st0      | name    | f
9860  st1      | val     | f
9861  st1      | str     | f
9862  s0.st0   | id      | f
9863  s0.st0   | id      | t
9864  s0.st0   | num     | f
9865  s0.st0   | num     | t
9866  s0.st1   | id      | f
9867  s0.st1   | num     | f
9868  s0.st2   | id      | f
9869  s0.st2   | txt     | f
9870  st1_exp  | lower   | f
9871  s0.sft0  | id      | f
9872  s0.smv0  | id      | f
9873  s0.smv0  | num     | f
9874  s0.smv0  | txt     | f
9875  s1.st0   | id      | f
9876  s1.st0   | num     | f
9877 (19 rows)
9878
9879 BEGIN;
9880 SELECT * FROM internal_locks;
9881  relation | mode 
9882 ----------+------
9883 (0 rows)
9884
9885 SELECT dbms_stats.unlock_column_stats('s0', 'st0', 'id');
9886  unlock_column_stats 
9887 ---------------------
9888  s0.st0
9889 (1 row)
9890
9891 SELECT * FROM internal_locks;
9892              relation             |       mode       
9893 ----------------------------------+------------------
9894  dbms_stats.column_stats_locked   | RowExclusiveLock
9895  dbms_stats.relation_stats_locked | RowShareLock
9896 (2 rows)
9897
9898 COMMIT;
9899 SELECT starelid, attname, stainherit FROM columns_locked_v c;
9900  starelid | attname | stainherit 
9901 ----------+---------+------------
9902  st0      | id      | f
9903  st0      | name    | f
9904  st1      | val     | f
9905  st1      | str     | f
9906  s0.st0   | num     | f
9907  s0.st0   | num     | t
9908  s0.st1   | id      | f
9909  s0.st1   | num     | f
9910  s0.st2   | id      | f
9911  s0.st2   | txt     | f
9912  st1_exp  | lower   | f
9913  s0.sft0  | id      | f
9914  s0.smv0  | id      | f
9915  s0.smv0  | num     | f
9916  s0.smv0  | txt     | f
9917  s1.st0   | id      | f
9918  s1.st0   | num     | f
9919 (17 rows)
9920
9921 SELECT relid::regclass FROM dbms_stats.relation_stats_locked
9922  GROUP BY relid
9923  ORDER BY relid;
9924    relid    
9925 ------------
9926  pt0
9927  pt0_idx
9928  st0
9929  st0_idx
9930  st1
9931  s0.st0
9932  s0.st0_idx
9933  s0.st1
9934  s0.st1_idx
9935  s0.st2
9936  s0.st2_idx
9937  st1_idx
9938  st1_exp
9939  s0.sft0
9940  s0.smv0
9941  s1.st0
9942 (16 rows)
9943
9944 -- No.15 Make sure that the stats given by pg_dbms_stats doesn't
9945 -- ignored by ACL check
9946 CREATE FUNCTION testfunc() RETURNS TEXT AS $$
9947 DECLARE
9948   ret text;
9949   v text;
9950 BEGIN
9951   ret = '';
9952   FOR v IN EXPLAIN SELECT * FROM s0.st4 WHERE a < '000' LOOP
9953     -- mask unnecessary values
9954     v = regexp_replace(v, '(cost|width)=[0-9.]+', E'\\1=xxx', 'g');
9955     ret = ret || v || E'\n';
9956   END LOOP;    
9957   RETURN ret;
9958 END;
9959 $$ LANGUAGE plpgsql;
9960 SET pg_dbms_stats.use_locked_stats TO on;
9961 CREATE TABLE s0.st4 (a text);
9962 INSERT INTO s0.st4 SELECT '1' || md5(g::text) FROM generate_series(1, 10000) as g;
9963 VACUUM ANALYZE s0.st4;
9964 -- should estimate that rows = 1, not 5000
9965 SELECT testfunc();
9966                    testfunc                   
9967 ----------------------------------------------
9968  Seq Scan on st4  (cost=xxx rows=1 width=xxx)+
9969    Filter: (a < '000'::text)                 +
9970  
9971 (1 row)
9972
9973 SET pg_dbms_stats.use_locked_stats TO off;
9974 SELECT dbms_stats.lock_table_stats('s0.st4');
9975  lock_table_stats 
9976 ------------------
9977  s0.st4
9978 (1 row)
9979
9980 SET pg_dbms_stats.use_locked_stats TO on;
9981 -- should estimate that rows = 1, not 5000
9982 SELECT testfunc();
9983                    testfunc                   
9984 ----------------------------------------------
9985  Seq Scan on st4  (cost=xxx rows=1 width=xxx)+
9986    Filter: (a < '000'::text)                 +
9987  
9988 (1 row)
9989
9990 DROP TABLE s0.st4;
9991 SELECT dbms_stats.clean_up_stats();
9992  clean_up_stats 
9993 ----------------
9994  s0.st4, 1
9995  s0.st4,
9996 (2 rows)
9997
9998 /*
9999  * No.15-2 Ditto for index stats
10000  */
10001 CREATE TABLE s0.st4 (a double precision);
10002 CREATE INDEX on s0.st4 (floor(log(a)));
10003 SELECT dbms_stats.lock_table_stats('s0.st4');
10004  lock_table_stats 
10005 ------------------
10006  s0.st4
10007 (1 row)
10008
10009 INSERT INTO s0.st4 (SELECT a from GENERATE_SERIES(1, 99999) a);
10010 ANALYZE t1;
10011 ERROR:  relation "t1" does not exist
10012 SET pg_dbms_stats.use_locked_stats TO off;
10013 SELECT testfunc();
10014                      testfunc                     
10015 --------------------------------------------------
10016  Seq Scan on st4  (cost=xxx rows=33373 width=xxx)+
10017    Filter: (a < '0'::double precision)           +
10018  
10019 (1 row)
10020
10021 SET pg_dbms_stats.use_locked_stats TO on;
10022 SELECT testfunc();
10023                     testfunc                    
10024 ------------------------------------------------
10025  Seq Scan on st4  (cost=xxx rows=713 width=xxx)+
10026    Filter: (a < '0'::double precision)         +
10027  
10028 (1 row)
10029
10030 DROP TABLE s0.st4;
10031 DROP FUNCTION testfunc();
10032 SELECT dbms_stats.clean_up_stats();
10033  clean_up_stats 
10034 ----------------
10035  s0.st4,
10036 (1 row)
10037
10038 -- No.16 error description. -- abnormal case.
10039 RESET SESSION AUTHORIZATION;
10040 CREATE TABLE s0.st4 (a int, b text);
10041 CREATE VIEW s0.vst4 AS select * FROM s0.st4;
10042 GRANT SELECT ON s0.vst4 TO regular_user;
10043 ALTER TABLE dbms_stats.relation_stats_locked OWNER TO regular_user;
10044 /* reconnection needed to flush cache */
10045 \c - regular_user
10046 EXPLAIN (COSTS OFF) SELECT * FROM s0.vst4 WHERE a = 1;
10047 ERROR:  permission denied for schema dbms_stats
10048 LINE 1: SELECT *   FROM dbms_stats.column_stats_locked WHERE stareli...
10049                         ^
10050 DETAIL:  dbms_stats could not access the object as the role "regular_user".
10051 HINT:  Check your settings of pg_dbms_stats.
10052 QUERY:  SELECT *   FROM dbms_stats.column_stats_locked WHERE starelid = $1    AND staattnum = $2    AND stainherit = $3
10053 \c - super_user
10054 ALTER TABLE dbms_stats.relation_stats_locked OWNER TO super_user;
10055 DROP TABLE s0.st4 CASCADE;
10056 NOTICE:  drop cascades to view s0.vst4
10057 /*
10058  * No.20-1 confirm change at 1.3.5. Moved from ut-common.sql at 1.3.11
10059  */
10060 SELECT CURRENT_USER;
10061  current_user 
10062 --------------
10063  super_user
10064 (1 row)
10065
10066 CREATE TABLE s0.st4 (a int, b text);
10067 CREATE INDEX i_st4_a on s0.st4 (a);
10068 CREATE VIEW s0.vst4 AS select * FROM s0.st4;
10069 GRANT SELECT ON s0.vst4 TO regular_user;
10070 INSERT INTO s0.st4 (SELECT a, a::text FROM generate_series(0, 999) a);
10071 ANALYZE s0.st4;
10072 SELECT dbms_stats.lock('s0.st4');
10073   lock  
10074 --------
10075  s0.st4
10076 (1 row)
10077
10078 DELETE FROM s0.st4;
10079 INSERT INTO s0.st4 (SELECT 1, a::text FROM generate_series(0, 999) a);
10080 ANALYZE s0.st4;
10081 EXPLAIN (COSTS OFF) SELECT * FROM s0.vst4 WHERE a = 1;
10082            QUERY PLAN            
10083 ---------------------------------
10084  Index Scan using i_st4_a on st4
10085    Index Cond: (a = 1)
10086 (2 rows)
10087
10088 EXPLAIN (COSTS OFF) SELECT * FROM s0.st4  WHERE a = 1;
10089            QUERY PLAN            
10090 ---------------------------------
10091  Index Scan using i_st4_a on st4
10092    Index Cond: (a = 1)
10093 (2 rows)
10094
10095 SET SESSION AUTHORIZATION regular_user;
10096 EXPLAIN (COSTS OFF) SELECT * FROM s0.st4  WHERE a = 1;
10097 ERROR:  permission denied for table st4
10098 EXPLAIN (COSTS OFF) SELECT * FROM s0.vst4 WHERE a = 1;
10099            QUERY PLAN            
10100 ---------------------------------
10101  Index Scan using i_st4_a on st4
10102    Index Cond: (a = 1)
10103 (2 rows)
10104
10105 SET pg_dbms_stats.use_locked_stats TO off;
10106 EXPLAIN (COSTS OFF) SELECT * FROM s0.vst4 WHERE a = 1;
10107     QUERY PLAN     
10108 -------------------
10109  Seq Scan on st4
10110    Filter: (a = 1)
10111 (2 rows)
10112
10113 \c - super_user
10114 ALTER TABLE dbms_stats.relation_stats_locked OWNER TO super_user;
10115 SELECT dbms_stats.unlock('s0.st4');
10116  unlock 
10117 --------
10118  s0.st4
10119 (1 row)
10120
10121 DROP TABLE s0.st4 CASCADE;
10122 NOTICE:  drop cascades to view s0.vst4