OSDN Git Service

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