From: naoki_kishi_b1
Date: Thu, 14 Feb 2013 04:21:19 +0000 (+0900)
Subject: 1.3.0
X-Git-Tag: REL1_3_1~1
X-Git-Url: http://git.osdn.net/view?p=pgdbmsstats%2Fpg_dbms_stats.git;a=commitdiff_plain;h=eeb3c94b0559729b721f5e95db612ebc6e95e0d7
1.3.0
---
eeb3c94b0559729b721f5e95db612ebc6e95e0d7
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..4d91977
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,19 @@
+# Generated by make_ctags for development
+tags
+
+# Global excludes across all subdirectories
+*.o
+*.so
+
+# Generated by test suite
+export_stats.dmp
+
+# Generated by build
+/pg_dbms_stats--1.0.sql
+/export_effective_stats.sql.sample
+/export_original_stats.sql.sample
+
+# Generated subdirectories
+/log/
+/results/
+/tmp_check/
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..a44b879
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,33 @@
+# pg_dbms_stats/Makefile
+
+MODULE_big = pg_dbms_stats
+OBJS = pg_dbms_stats.o dump.o import.o
+
+ifdef UNIT_TEST
+PG_CPPFLAGS = -DUNIT_TEST
+endif
+
+EXTENSION = pg_dbms_stats
+DATA = pg_dbms_stats--1.0.sql
+
+REGRESS = init-common init-$(MAJORVERSION) ut-common ut-$(MAJORVERSION) \
+ ut_imp_exp-$(MAJORVERSION)
+
+REGRESS_OPTS = --encoding=UTF8
+
+DOCS = export_effective_stats-$(MAJORVERSION).sql.sample \
+ export_plain_stats-$(MAJORVERSION).sql.sample
+
+EXTRA_CLEAN = sql/ut_anyarray-*.sql expected/ut_anyarray-*.out \
+ sql/ut_imp_exp-*.sql expected/ut_imp_exp-*.out \
+ export_stats.dmp $(DATA)
+
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
+include $(PGXS)
+
+all: $(DATA) $(DOCS)
+
+$(DATA): %.sql: %-$(MAJORVERSION).sql
+ cp $< $@
+
diff --git a/SPECS/pg_dbms_stats91.spec b/SPECS/pg_dbms_stats91.spec
new file mode 100644
index 0000000..c02d1cd
--- /dev/null
+++ b/SPECS/pg_dbms_stats91.spec
@@ -0,0 +1,74 @@
+# SPEC file for pg_dbms_stats
+# Copyright(C) 2012 NIPPON TELEGRAPH AND TELEPHONE CORPORATION
+
+%define _pgdir /usr/pgsql-9.1
+%define _bindir %{_pgdir}/bin
+%define _libdir %{_pgdir}/lib
+%define _datadir %{_pgdir}/share
+%define _docdir /usr/share/doc/pgsql
+
+## Set general information for pg_dbms_stats.
+Summary: Plan Stabilizer for PostgreSQL 9.1
+Name: pg_dbms_stats91
+Version: 1.3.0
+Release: 1%{?dist}
+License: BSD
+Group: Applications/Databases
+Source0: %{name}-%{version}.tar.gz
+#URL: http://example.com/pg_dbms_stats/
+BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-%(%{__id_u} -n)
+Vendor: NIPPON TELEGRAPH AND TELEPHONE CORPORATION
+
+## We use postgresql-devel package
+BuildRequires: postgresql91-devel
+Requires: postgresql91-libs
+
+## Description for "pg_dbms_stats"
+%description
+pg_dbms_stats provides capability to replace planner's statistics with snapshot
+taken at arbitrary timing, so that planner generates stable plans even if
+ANALYZE is invoked after changes of data.
+
+pg_dbms_stats also provides following features:
+ - backup multiple generations of planner statistics to reuse plans after
+ - import planner statistics from another system for tuning an testing
+
+Note that this package is available for only PostgreSQL 9.1.
+
+## pre work for build pg_dbms_stats
+%prep
+%setup -q
+
+## Set variables for build environment
+%build
+make %{?_smp_mflags}
+
+## Set variables for install
+%install
+rm -rf %{buildroot}
+install -d %{buildroot}%{_libdir}
+install -m 755 pg_dbms_stats.so %{buildroot}%{_libdir}/pg_dbms_stats.so
+install -d %{buildroot}%{_datadir}/extension
+install -m 644 pg_dbms_stats--1.0.sql %{buildroot}%{_datadir}/extension/pg_dbms_stats--1.0.sql
+install -m 644 pg_dbms_stats.control %{buildroot}%{_datadir}/extension/pg_dbms_stats.control
+install -d %{buildroot}%{_docdir}/extension
+install -m 644 export_effective_stats-9.1.sql.sample %{buildroot}%{_docdir}/extension/export_effective_stats-9.1.sql.sample
+install -m 644 export_plain_stats-9.1.sql.sample %{buildroot}%{_docdir}/extension/export_plain_stats-9.1.sql.sample
+
+%clean
+rm -rf %{buildroot}
+
+%files
+%defattr(0755,root,root)
+%{_libdir}/pg_dbms_stats.so
+%defattr(0644,root,root)
+%{_datadir}/extension/pg_dbms_stats--1.0.sql
+%{_datadir}/extension/pg_dbms_stats.control
+%{_docdir}/extension/export_effective_stats-9.1.sql.sample
+%{_docdir}/extension/export_plain_stats-9.1.sql.sample
+
+# History of pg_dbms_stats.
+%changelog
+* Wed Sep 05 2012 Shigeru Hanada
+- Initial cut for 1.0.0
+
diff --git a/SPECS/pg_dbms_stats92.spec b/SPECS/pg_dbms_stats92.spec
new file mode 100644
index 0000000..2583fcd
--- /dev/null
+++ b/SPECS/pg_dbms_stats92.spec
@@ -0,0 +1,74 @@
+# SPEC file for pg_dbms_stats
+# Copyright(C) 2012 NIPPON TELEGRAPH AND TELEPHONE CORPORATION
+
+%define _pgdir /usr/pgsql-9.2
+%define _bindir %{_pgdir}/bin
+%define _libdir %{_pgdir}/lib
+%define _datadir %{_pgdir}/share
+%define _docdir /usr/share/doc/pgsql
+
+## Set general information for pg_dbms_stats.
+Summary: Plan Stabilizer for PostgreSQL 9.2
+Name: pg_dbms_stats92
+Version: 1.3.0
+Release: 1%{?dist}
+License: BSD
+Group: Applications/Databases
+Source0: %{name}-%{version}.tar.gz
+#URL: http://example.com/pg_dbms_stats/
+BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-%(%{__id_u} -n)
+Vendor: NIPPON TELEGRAPH AND TELEPHONE CORPORATION
+
+## We use postgresql-devel package
+BuildRequires: postgresql92-devel
+Requires: postgresql92-libs
+
+## Description for "pg_dbms_stats"
+%description
+pg_dbms_stats provides capability to replace planner's statistics with snapshot
+taken at arbitrary timing, so that planner generates stable plans even if
+ANALYZE is invoked after changes of data.
+
+pg_dbms_stats also provides following features:
+ - backup multiple generations of planner statistics to reuse plans after
+ - import planner statistics from another system for tuning an testing
+
+Note that this package is available for only PostgreSQL 9.2.
+
+## pre work for build pg_dbms_stats
+%prep
+%setup -q
+
+## Set variables for build environment
+%build
+make %{?_smp_mflags}
+
+## Set variables for install
+%install
+rm -rf %{buildroot}
+install -d %{buildroot}%{_libdir}
+install -m 755 pg_dbms_stats.so %{buildroot}%{_libdir}/pg_dbms_stats.so
+install -d %{buildroot}%{_datadir}/extension
+install -m 644 pg_dbms_stats--1.0.sql %{buildroot}%{_datadir}/extension/pg_dbms_stats--1.0.sql
+install -m 644 pg_dbms_stats.control %{buildroot}%{_datadir}/extension/pg_dbms_stats.control
+install -d %{buildroot}%{_docdir}/extension
+install -m 644 export_effective_stats-9.2.sql.sample %{buildroot}%{_docdir}/extension/export_effective_stats-9.2.sql.sample
+install -m 644 export_plain_stats-9.2.sql.sample %{buildroot}%{_docdir}/extension/export_plain_stats-9.2.sql.sample
+
+%clean
+rm -rf %{buildroot}
+
+%files
+%defattr(0755,root,root)
+%{_libdir}/pg_dbms_stats.so
+%defattr(0644,root,root)
+%{_datadir}/extension/pg_dbms_stats--1.0.sql
+%{_datadir}/extension/pg_dbms_stats.control
+%{_docdir}/extension/export_effective_stats-9.2.sql.sample
+%{_docdir}/extension/export_plain_stats-9.2.sql.sample
+
+# History of pg_dbms_stats.
+%changelog
+* Wed Sep 05 2012 Shigeru Hanada
+- Initial cut for 1.0.0
+
diff --git a/doc/objects-ja.html b/doc/objects-ja.html
new file mode 100644
index 0000000..29300d5
--- /dev/null
+++ b/doc/objects-ja.html
@@ -0,0 +1,246 @@
+
+
+
+pg_dbms_stats
+
+
+
+
+
+
+pg_dbms_stats
+
+
+
+
+é¢æ°
+
+pg_dbms_stats ã¯ä¸è¨ã®é¢æ°ãå«ã¿ã¾ãã
+
+
åé¢æ°ã®æå³ã¯ä»¥ä¸ã®éãã§ãã
+
+
+
+ æ©è½ é¢æ° å¼æ° ãªãã¸ã§ã¯ãåä½ æ»ãå¤
+
+
+
+ããã¯ã¢ãã
+ dbms_stats.backup_database_stats
+ comment
+ ãã¼ã¿ãã¼ã¹
+ int8
+dbms_stats.backup_schema_stats
+ schemanameãcomment
+ ã¹ãã¼ã
+dbms_stats.backup_table_stats
+ relnameãcomment
+ ãã¼ãã«
+schemanameãtablenameãcomment
+dbms_stats.backup_column_stats
+ relnameãattnameãcomment
+ ã«ã©ã
+schemanameãtablenameãattnameãcomment
+ãªã¹ãã¢
+ dbms_stats.restore_database_stats
+ timestamp
+ ãã¼ã¿ãã¼ã¹
+ regclass
+dbms_stats.restore_schema_stats
+ schemanameãtimestamp
+ ã¹ãã¼ã
+dbms_stats.restore_table_stats
+ relnameãtimestamp
+ ãã¼ãã«
+schemanameãtablenameãtimestamp
+dbms_stats.restore_column_stats
+ relnameãattnameãtimestamp
+ ã«ã©ã
+schemanameãtablenameãattnameãtimestamp
+dbms_stats.restore_stats
+ backup_id
+ ããã¯ã¢ãã
+ããã¯
+ dbms_stats.lock_database_stats
+ (ãªã)
+ ãã¼ã¿ãã¼ã¹
+ regclass
+dbms_stats.lock_schema_stats
+ schemaname
+ ã¹ãã¼ã
+dbms_stats.lock_table_stats
+ relname
+ ãã¼ãã«
+schemanameãtablename
+dbms_stats.lock_column_stats
+ relnameãattname
+ ã«ã©ã
+schemanameãtablenameãattname
+ããã¯è§£é¤
+ dbms_stats.unlock_database_stats
+ (ãªã)
+ ãã¼ã¿ãã¼ã¹
+ regclass
+dbms_stats.unlock_schema_stats
+ schemaname
+ ã¹ãã¼ã
+dbms_stats.unlock_table_stats
+ relname
+ ãã¼ãã«
+schemanameãtablename
+dbms_stats.unlock_column_stats
+ relnameãattname
+ ã«ã©ã
+schemanameãtablenameãattname
+ã¤ã³ãã¼ã
+ dbms_stats.import_database_stats
+ src
+ ãã¼ã¿ãã¼ã¹
+ void
+dbms_stats.import_schema_stats
+ schemanameãsrc
+ ã¹ãã¼ã
+dbms_stats.import_table_stats
+ relnameãsrc
+ ãã¼ãã«
+schemanameãtablenameãsrc
+dbms_stats.import_column_stats
+ relnameãattnameãsrc
+ ã«ã©ã
+schemanameãtablenameãattnameãsrc
+ãã¼ã¸
+ dbms_stats.purge_stats
+ backup_idãforce
+ ããã¯ã¢ãã
+ dbms_stats.backup_history
+
+
+
+åé¢æ°ã§ç¨ãããã¦ããå¼æ°ã®æå³ã¯ä»¥ä¸ã®éãã§ãã
+
+
+
+ å¼æ° ãã¼ã¿å æå³
+
+
+
+schemaname
+ text
+ å¦ç対象ã®ã¹ãã¼ãåã§ãã
+relname
+ regclass
+ å¦ç対象ã®ãã¼ãã«åã§ãããã ãã(ã¹ãã¼ãå).(ãã¼ãã«å) ã¨ããå½¢ã«ãªãã¾ãã
+tablename
+ text
+ å¦ç対象ã®ãã¼ãã«åã§ãã
+attname
+ text
+ å¦ç対象ã®ã«ã©ã åã§ãã
+comment
+ text
+ ããã¯ã¢ãããèå¥ããããã®ã³ã¡ã³ãã§ãã
+as_of_timestamp
+ timestamptz
+ ãªã¹ãã¢ãããã¿ã¤ãã³ã°ã®åºæºã«ãªãã¿ã¤ã ã¹ã¿ã³ãã§ãããã®ã¿ã¤ã ã¹ã¿ã³ã以åã§ææ°ã®ããã¯ã¢ãããã¼ã¿ããªã¹ãã¢ãã¾ãã該å½ããããã¯ã¢ãããåå¨ããªãå ´åãçµ±è¨æ
å ±ã¯ç¾å¨ãã©ã³ããè¦ã¦ããå¤ããå¤æ´ããã¾ããã
+src
+ text
+ ã¤ã³ãã¼ã対象ã®ãã¡ã¤ã«ã®çµ¶å¯¾ãã¹ã§ãã
+backup_id
+ bigint
+ ãªã¹ãã¢ããã¼ã¸ã®å¯¾è±¡ã¨ãªãããã¯ã¢ããIDã§ãã
+ãªã¹ãã¢ã®å ´åãä¸è´ããããã¯ã¢ããIDã®ããã¯ã¢ãããã¼ã¿ããªã¹ãã¢ãã¾ãã
+ãã¼ã¸ã®å ´åãä¸è´ããããã¯ã¢ããID以åã®ããã¯ã¢ãããåé¤ãã¾ãã
+
+force
+ bool
+ ãã¼ã¸ããã¨ããããã¯ã¢ãããå¼·å¶çã«åé¤ãããã決ããå¤æ°ã§ãã
+trueã®å ´åã対象ç¯å²ã®ããã¯ã¢ãããå
¨ã¦åé¤ãã¾ãã
+falseã®å ´åã対象ç¯å²å¤ã«ãã¼ã¿ãã¼ã¹åä½ã®ããã¯ã¢ãããã¼ã¿ãåå¨ããªããã°ãè¦åã¡ãã»ã¼ã¸ãåºåãã¦å¦çãä¸æãã¾ãã
+ããã©ã«ãã¯falseã§ãã
+
+
+
+ã¾ããçµ±è¨æ
å ±ã®ã¨ã¯ã¹ãã¼ãæ©è½ã¯ãSQLãã¡ã¤ã«ã§å®è£
ãã¦ãã¾ãã
+
+åSQLãã¡ã¤ã«ã®æå³ã¯ä»¥ä¸ã®éãã§ãããªããåºåãã¡ã¤ã«åã®ããã©ã«ãã¯export_stats.dmpã§ãã
+
+
+
+ ãã¡ã¤ã«å 対象統è¨æ
å ± åè
+
+
+
+export_effective_stats.sql.sample
+ ãã©ã³ããè¦ã¦ããçµ±è¨æ
å ±
+ -
+
+ export_plain_stats.sql.sample
+ çã®çµ±è¨æ
å ±ã®ã¿
+ pg_dbms_statsæªã¤ã³ã¹ãã¼ã«ã§ã使ç¨å¯è½ã§ãã
+
+
+
+ãã¼ãã«
+pg_dbms_statsã¯ä»¥ä¸ã®ãã¼ãã«ãå«ã¿ã¾ãã
+åãã¼ãã«ã®æå³ã¯ä»¥ä¸ã®éãã§ãã
+
+
+
+ ãã¼ãã«å åå ãã¼ã¿å æå³
+
+
+
+dbms_stats.backup_history
+ id
+ int8
+ ããã¯ã¢ããæã«ä»ä¸ãããããã¯ã¢ããIDã§ãã
+time
+ timestamptz
+ ããã¯ã¢ããæã®ã¿ã¤ã ã¹ã¿ã³ãã§ãã
+unit
+ char(1)
+ ããã¯ã¢ããæã®ãªãã¸ã§ã¯ãåä½ã§ãã
+d:ãã¼ã¿ãã¼ã¹ãs:ã¹ãã¼ããt:ãã¼ãã«ãc:å
+comment
+ text
+ ããã¯ã¢ããæã«æå®ããã³ã¡ã³ãã§ãã
+
+
+
+ãã¥ã¼
+pg_dbms_stats ã¯ä¸è¨ã®ãã¥ã¼ãå«ã¿ã¾ãã
+åãã¥ã¼ã®æå³ã¯ä»¥ä¸ã®éãã§ãã
+
+
+
+ ãã¥ã¼å æå³
+
+
+
+dbms_stats.relation_stats_effective
+ ãã©ã³ãã«è¦ãããã¼ãã«ãã¨ã®çµ±è¨æ
å ±ã表示ãã¾ããPostgreSQLã®pg_classã«ã¿ãã°ã«å¯¾å¿ãã¾ãã
+dbms_stats.column_stats_effective
+ ãã©ã³ãã«è¦ããã«ã©ã ãã¨ã®çµ±è¨æ
å ±ã表示ãã¾ããPostgreSQLã®pg_statisticã«ã¿ãã°ã«å¯¾å¿ãã¾ãã
+dbms_stats.status
+ ãã©ã³ãã«è¦ããã«ã©ã ãã¨ã®çµ±è¨æ
å ±ã®ãã¡ãã¦ã¼ã¶ãèªã¿åãå¯è½ãªãã®ã表示ãã¾ããPostgreSQLã®pg_statsãã¥ã¼ã«å¯¾å¿ãã¾ãã
+
+
+
+é¢é£é
ç®
+psql ,
+vacuumdb
+
+
+
+
+
+
diff --git a/doc/pg_dbms_stats-ja.html b/doc/pg_dbms_stats-ja.html
new file mode 100644
index 0000000..d243d82
--- /dev/null
+++ b/doc/pg_dbms_stats-ja.html
@@ -0,0 +1,426 @@
+
+
+
+pg_dbms_stats
+
+
+
+
+
+
+pg_dbms_stats 1.2.0
+
+
+
+
+
+åå
+pg_dbms_stats -- çµ±è¨æ
å ±ã®ç®¡çãè¡ããéæ¥çã«å®è¡è¨ç»ãå¶å¾¡ãã¾ãã
+
+æ¦è¦
+PostgreSQL 㯠ANALYZE ã³ãã³ãã«ãããã¼ãã«ãã¤ã³ããã¯ã¹ãããµã³ããªã³ã°ããå¤ãéè¨ãã¦çµ±è¨æ
å ±ã¨ãã¦ä¿æãã¦ãã¾ãã
+ã¯ã¨ãªã»ãªããã£ãã¤ã¶ã¯ããã®çµ±è¨æ
å ±ãå©ç¨ãã¦ã¯ã¨ãªã®ã³ã¹ããè¨ç®ããæãã³ã¹ãã®ä½ãå®è¡è¨ç»ãé¸æãã¾ãããã®ããããã¼ã¿ã®éãç¹æ§ãå¤åããããçµ±è¨æ
å ±ã®ç²¾åº¦ãä¸ååã§ãã£ããããå ´åã«ã¯ãé¸æãããå®è¡è¨ç»ãå¤åããå ´åãããã¾ãã
+pg_dbms_stats ããã±ã¼ã¸ã¯ãã®ãããªäºæãã¬å®è¡è¨ç»ã®å¤åãé²ãããã®æ©è½æ¡å¼µã§ãããã©ã³ãã®å¦çã«å²ãè¾¼ãã§ããã©ã³ããåç
§ããçµ±è¨æ
å ±ãäºåã«ä½æããããã¼çµ±è¨æ
å ±ã«å·®ãæ¿ãããã¨ã§ãé¸æãããçµ±è¨æ
å ±ãåºå®ãã¾ãããå®è¡è¨ç»ãéç¨ä¸ã«æ¥ã«å¤åããã·ã¹ãã ã®æ§è½ãä½ä¸ãããã¨ãããªã¹ã¯ãæãããå ´åã«æå¹ã§ãã
+
+æ©è½èª¬æ
+pg_dbms_statsã«ã¯ããã©ã³ãã使ç¨ããçµ±è¨æ
å ±ãæä½ããæ©è½ã¨ãã¦ä»¥ä¸ã®7ã¤ãããã¾ãããªããã¨ã¯ã¹ãã¼ããé¤ãåæ©è½ã¯ãSQLé¢æ°çµç±ã§å©ç¨ãã¾ããåé¢æ°ã®è©³ç´°ã¯ãªãã¸ã§ã¯ãä¸è¦§ ãåç
§ãã¦ãã ããã
+
+ããã¯ã¢ãã
+
+æ¦è¦
+ç¾å¨é¸æããã¦ããå®è¡è¨ç»ãå°æ¥çã«åç¾ããããã«ãç¾å¨ãã©ã³ããè¦ã¦ããçµ±è¨æ
å ±ãããã¯ã¢ããã¨ãã¦ä¿åãã¾ãã
+å©ç¨æ¹æ³
+backup_<ãªãã¸ã§ã¯ãåä½>_stats()ã¨ããSQLé¢æ°ãå®è¡
+詳細
+
+
+ããã¯ã¢ããã«å«ããçµ±è¨æ
å ±ã®ç¯å²ã¯ããã¼ã¿ãã¼ã¹(ç¾å¨æ¥ç¶ä¸ã®ãã®)ã»ã¹ãã¼ãã»ãã¼ãã«ã»åã®ããããã®åä½ã§æå®ã§ãã¾ãã
+ä¾ãã°ããã¹ãã¼ãã«å«ã¾ãã¦ããå
¨ã¦ã®è¡¨ã¨ãããã®å
¨ã¦ã®åã®çµ±è¨æ
å ±ãä¿åãã¦ããããå ´åã¯ãã¹ãã¼ãåä½ã§ããã¯ã¢ãããã¾ããåºæ¬çã«ã¯ãã¼ã¿ãã¼ã¹åä½ã¾ãã¯ã¹ãã¼ãåä½ãªã©ã®å¤§ãç®ã®åä½ã§ããã¯ã¢ãããã¦ãããã¨ããå§ããã¾ãã
+ç¾å¨ä¿åããã¦ããããã¯ã¢ããã«é¢ããæ
å ±ã¯ãdbms_stats.backup_historyãã¼ãã«ã§åç
§ã§ãã¾ããdbms_stats.backup_historyãã¼ãã«ã®è©³ç´°ã«ã¤ãã¦ã¯ãã¼ãã« ãåç
§ãã¦ãã ããã
+
+
+
+ãªã¹ãã¢
+
+æ¦è¦
+ããã¯ã¢ããæç¹ã§é¸æããã¦ããå®è¡è¨ç»ãåã³é¸æãããããã«ãããã¯ã¢ããããçµ±è¨æ
å ±ã復å
ãã¦åºå®ãã¾ãã
+å©ç¨æ¹æ³
+restore_stats()ãã¾ãã¯restore_<ãªãã¸ã§ã¯ãåä½>_stats()ã¨ããSQLé¢æ°ãå®è¡
+詳細
+
+
+ãªã¹ãã¢æã«æå®ãããªãã¸ã§ã¯ã以å¤ã®çµ±è¨æ
å ±ä»¥å¤ã¯å¤æ´ãããå
ã®ã¾ã¾æ®ãã¾ãããªã¹ãã¢ããããã¯ã¢ããçµ±è¨æ
å ±ã®æå®æ¹æ³ã¯ã以ä¸ã®äºç¨®é¡ãããã¾ãã
+
+ããã¯ã¢ããID
+restore_stats()ã¨ããé¢æ°ã«ããã¯ã¢ããIDãæå®ãã¦å®è¡ãããã¨ã§ããã®IDãæã¤ããã¯ã¢ããã«å«ã¾ããçµ±è¨æ
å ±ãå
¨ã¦ãªã¹ãã¢ãã¾ãããã¼ã¿ãã¼ã¹ãã¹ãã¼ãåä½ã§ããã¯ã¢ãããå®æçã«åå¾ããéç¨ã®å ´åã¯ããã®æå®æ¹æ³ãåç´ã§ããã§ãããããªããããã¯ã¢ããIDã¯ãã¼ã¿ãã¼ã¹ãã¨ã«ä¸æã«ãªã£ã¦ãã¾ãã®ã§ãè¤æ°ãã¼ã¿ãã¼ã¹ã§pg_dbms_statsãå©ç¨ãã¦ããå ´åã¯ãä»ã®ãã¼ã¿ãã¼ã¹ã®ããã¯ã¢ããIDã¨æ··åããªãããã«æ³¨æãã¦ãã ããã
+ãªãã¸ã§ã¯ãï¼ã¿ã¤ã ã¹ã¿ã³ã
+restore_<ãªãã¸ã§ã¯ãåä½>_stats()ãªãã¸ã§ã¯ã(ãã¼ã¿ãã¼ã¹ãã¹ãã¼ãããã¼ãã«ãåã®ãããã)ãæå®ãã¦å®è¡ãããã¨ã§ãããã«å«ã¾ããå
¨ã¦ã®åã¨è¡¨ã®çµ±è¨æ
å ±ããæå®ããã¿ã¤ã ã¹ã¿ã³ãæç¹ã®ç¶æ
ã«ãªã¹ãã¢ãã¾ãããã ããæå®ããã¿ã¤ã ã¹ã¿ã³ãããåã«ãªã¹ãã¢ãããããåºãç¯å²ã®ããã¯ã¢ãããåå¾ãã¦ãããã¨ãåæã§ãã
+ããæç¹ã¾ã§ã¯é©åãªå®è¡è¨ç»ãé¸æããã¦ãããã¨ãåãã£ã¦ããããããã¯ã¢ãããç´°ããåä½ã§åå¾ãã¦ãã¦ã©ãããªã¹ãã¢ããã°ãããåãããªããã¨ããå ´åã¯ãã®æå®æ¹æ³ã便å©ã§ãã
+
+
+ãªã¹ãã¢ããæç¹ã§çµ±è¨æ
å ±ã¯ããã¯ã¢ããããæç¹ã®ãã®ã§åºå®ããã¦ãã¾ãã®ã§ããªã¹ãã¢å¾ã«æ示çã«ããã¯ããå¿
è¦ã¯ããã¾ããã
+
+
+
+
+ãã¼ã¸
+
+æ¦è¦
+ä¸è¦ã«ãªã£ãçµ±è¨æ
å ±ããã¯ã¢ãããä¸æ¬åé¤ããæ©è½ã§ãæå®ããããã¯ã¢ããID以åã®ããã¯ã¢ãããåé¤ãã¾ãã
+å©ç¨æ¹æ³
+purge_stats()ã¨ããSQLé¢æ°ãå®è¡
+詳細
+
+åºæ¬çã«ã¯ä»»æä¸ä»£ä»¥åã®ããã¯ã¢ãããåé¤ã§ãã¾ãããä¸ç¨æã«ããã¯ã¢ãããåé¤ãã¦ãã¾ããã¨ãé²ãããã«ããã¼ã¸å¾ã«ãã¼ã¿ãã¼ã¹åä½ã®ããã¯ã¢ãããã²ã¨ã¤ãæ®ããªãç¶æ³ã§ã®ä¸æ¬åé¤ã¯ã§ãã¾ããããã®å¶éã¯ãã¦ã¼ã¶ãå¼·å¶åé¤ãæå®ãããã¨ã§åé¿å¯è½ã§ãã
+
+
+
+ããã¯
+
+æ¦è¦
+ANALYZEãå®è¡ãã¦çµ±è¨æ
å ±ãå¤åãã¦ãç¾å¨é¸æããã¦ããå®è¡è¨ç»ãé¸æããç¶ããããã«ããã©ã³ããåç
§ããçµ±è¨æ
å ±ãåºå®ãã¾ãã
+å©ç¨æ¹æ³
+lock_<ãªãã¸ã§ã¯ãåä½>_stats()ã¨ããSQLé¢æ°ãå®è¡
+詳細
+
+çµ±è¨æ
å ±ãããã¯ããç¯å²ã¯ããã¼ã¿ãã¼ã¹(ç¾å¨æ¥ç¶ä¸ã®ãã®)ã»ã¹ãã¼ãã»ãã¼ãã«ã»åã®ããããã®åä½ã§æå®ã§ãã¾ãã
+
+
+
+ããã¯è§£é¤
+
+æ¦è¦
+PostgreSQLæ¬æ¥ã®å®è¡è¨ç»é¸æåºæºã«æ»ãããã«ãçµ±è¨æ
å ±ã®åºå®ç¶æ
ã解é¤ãã¾ãã
+å©ç¨æ¹æ³
+unlock_<ãªãã¸ã§ã¯ãåä½>_stats()ã¨ããSQLé¢æ°ãå®è¡
+詳細
+
+ããã¯ã解é¤ããã¨ããã©ã³ããpg_classãpg_statisticãåç
§ããããã«ãªãã¾ããçµ±è¨æ
å ±ã®ããã¯ã解é¤ããç¯å²ã¯ããã¼ã¿ãã¼ã¹(ç¾å¨æ¥ç¶ä¸ã®ãã®)ã»ã¹ãã¼ãã»ãã¼ãã«ã»åã®ããããã®åä½ã§æå®ã§ãã¾ãããªããããã¯ã¨ç°ãªãåä½ãæå®ãã¦ããã¯è§£é¤ãããã¨ãå¯è½ã§ãã
+
+
+
+
+ã¨ã¯ã¹ãã¼ã
+
+æ¦è¦
+ç¾å¨ã®çµ±è¨æ
å ±ãå¤é¨ãã¡ã¤ã«ã«åºåãã¾ãã
+å©ç¨æ¹æ³
+ã¨ã¯ã¹ãã¼ã対象å¥ã®ãµã³ãã«SQLãã¡ã¤ã«(export_<種å¥>_stats-.sql.sample)ãåèã«COPYæãä½æããpsqlã³ãã³ããªã©ã§å®è¡
+詳細
+
+ç¨éã«å¿ãã¦ã以ä¸ã®äºç¨®é¡ã®çµ±è¨æ
å ±ãã¨ã¯ã¹ãã¼ãã§ãã¾ãããªããã¨ã¯ã¹ãã¼ãã«ã¯COPYã³ãã³ãã使ç¨ããã®ã§ãã¨ã¯ã¹ãã¼ããã¡ã¤ã«åºåå
ãã£ã¬ã¯ããªã«ã¯PostgreSQLå®è¡ã¦ã¼ã¶ã§ãã¡ã¤ã«ãä½æã§ãããã£ã¬ã¯ããªãæå®ãã¦ãã ããã
+
+PostgreSQLæ¬æ¥ã®çµ±è¨æ
å ±
+pg_classãpg_statisticã¨ãã£ãPostgreSQLãå
ã
æã£ã¦ããçµ±è¨æ
å ±ã§ãpg_dbms_statsãã¤ã³ã¹ãã¼ã«ããã¦ããªãæ¬çªéç¨ç°å¢ããæ¤è¨¼ç°å¢ãªã©ã®å¥ç°å¢ã«çµ±è¨æ
å ±ãã³ãã¼ãã¦ã解æããã¥ã¼ãã³ã°ãå®è¡ããå ´åã«åãã¦ãã¾ãã
+ç¾å¨æå¹ãªçµ±è¨æ
å ±
+ããã¯ããªã¹ãã¢ãã¤ã³ãã¼ããªã©ã«ãã£ã¦ä½æããããpg_dbms_statsãç¾å¨ãã©ã³ãã«è¦ãã¦ããçµ±è¨æ
å ±ã§ããpg_dbms_statsãæå¹ãªç°å¢ã§çµ±è¨æ
å ±ãç·¨éãã¦ãã¥ã¼ãã³ã°ããå¾ã«ãã®çµ±è¨æ
å ±ãæ¬çªç°å¢ã«æ»ãå ´åããçµ±è¨æ
å ±ã®ããã¯ã¢ãããOSãã¡ã¤ã«ã§ä¿åãã¦ããããå ´åãªã©ã«åãã¦ãã¾ãã
+
+
+ãµã³ãã«ãã¡ã¤ã«ã¯ããpg_config --docdirãã§è¡¨ç¤ºããããã£ã¬ã¯ããªã«ããextensionãµããã£ã¬ã¯ããªã«ã¤ã³ã¹ãã¼ã«ããã¦ãã¾ãã
+
+
+
+ã¤ã³ãã¼ã
+
+æ¦è¦
+ã¨ã¯ã¹ãã¼ãæ©è½ã§ä½æããå¤é¨ãã¡ã¤ã«ããçµ±è¨æ
å ±ãèªã¿è¾¼ã¿ããã©ã³ããåç
§ããçµ±è¨æ
å ±ã¨ãã¦åºå®ãã¾ãã
+å©ç¨æ¹æ³
+import_<ãªãã¸ã§ã¯ãåä½>_stats()ã¨ããSQLé¢æ°ãå®è¡
+詳細
+
+ã¤ã³ãã¼ãããçµ±è¨æ
å ±ã®ç¯å²ã¯ããã¼ã¿ãã¼ã¹(ç¾å¨æ¥ç¶ä¸ã®ãã®)ã»ã¹ãã¼ãã»ãã¼ãã«ã»åã®ããããã®åä½ã§æå®ã§ãã¾ããã¤ã³ãã¼ããããã¡ã¤ã«ã¯ãPostgreSQLå®è¡ã¦ã¼ã¶ãèªã¿åãããã£ã¬ã¯ããªã«é
ç½®ãã¦ãã ããã
+
+
+
+ã¤ã³ã¹ãã¼ã«
+pg_dbms_stats ã®ã¤ã³ã¹ãã¼ã«æ¹æ³ã¯ãæ¨æºã®æ¡å¼µ(EXTENSION)ã¨åæ§ã§ãã
+
+ãã«ã
+make ã使ã£ã¦ãã«ãã§ãã¾ããPostgreSQLãã¤ã³ã¹ãã¼ã«ããOSã¦ã¼ã¶ã§ã¤ã³ã¹ãã¼ã«ãã¦ãã ããã
+ãã®ã¨ããpg_config ã§ãã«ãã«å¿
è¦ãªæ
å ±ãåéãã¾ãã®ã§ãè¤æ°ãã¼ã¸ã§ã³ãã¤ã³ã¹ãã¼ã«ãããç°å¢ã§ã¯ PATH ç°å¢å¤æ°ã«æ³¨æãã¦ä¸ããã
+$ cd pg_dbms_stats
+$ make
+$ su
+# make install
+
+ãã¼ã¿ãã¼ã¹ã¸ã®ç»é²
+pg_dbms_stats 㯠PostgreSQL ã®æ¡å¼µ(EXTENSION)ã§ãã®ã§ããã®æ©è½ãå©ç¨ãããã¼ã¿ãã¼ã¹ã«ã¹ã¼ãã¼ã¦ã¼ã¶ã§æ¥ç¶ã㦠CREATE EXTENSION ã³ãã³ã ãå®è¡ãã¦ãã ããã
+ã³ãã³ãã®ä¾ã以ä¸ã«ç¤ºãã¾ãã
+dbname ã¯å¯¾è±¡ã¨ãªããã¼ã¿ãã¼ã¹åãæå³ãã¾ãã
+$ psql -d dbname -c "CREATE EXTENSION pg_dbms_stats"
+ç»é²è§£é¤ã¯ DROP EXTENSION ã³ãã³ãã§å¯è½ã§ããç»é²ã解é¤ãã¦ã dbms_stats ã¹ãã¼ãã¯ãã®ã¾ã¾æ®ãã¾ãã®ã§ãå¿
è¦ã«å¿ãã¦åé¤ãã¦ä¸ããã
+
+pg_dbms_statsã®ãã¼ã
+pg_dbms_statsãæå¹ã«ããã«ã¯ã以ä¸ã®ä¾ã®ããã«pg_dbms_statsã®å
±æã©ã¤ãã©ãªããã¼ããã¦ãã ããã
+å
¨ã¦ã®ã»ãã·ã§ã³ã§pg_dbms_statsãæå¹ã«ããã«ã¯ãpostgresql.confã®shared_preload_libraries GUCãã©ã¡ã¼ã¿ã«'pg_dbms_stats'ã追å ãã¦ãããµã¼ããåèµ·åãã¦ä¸ããã
+
postgres=# LOAD 'pg_dbms_stats';
+LOAD
+postgres=#
+
+
+注æ :
+pg_dbms_stats ããã¼ã¿ãã¼ã¹ã«ç»é² ããã«ããã¼ãå¾ã«SQLæãå®è¡ããã¨ä»¥ä¸ã«ç¤ºãä¾ã®ãããªã¨ã©ã¼ã¨ãªãã¾ãã
+pg_dbms_stats ã使ãã¨ãã¯ããã¼ã¿ãã¼ã¹ã¸ã®ç»é²ãå¿ããªãããã«æ³¨æãã¦ãã ããã
+
test=# SELECT * FROM test;
+ERROR: schema "dbms_stats" does not exist
+LINE 1: SELECT relpages, reltuples, curpages FROM dbms_stats.relati...
+ ^
+QUERY: SELECT relpages, reltuples, curpages FROM dbms_stats.relation_stats_locked WHERE relid = $1
+test=#
+
+
+pg_dbms_statsã®ç¡å¹å
+pg_dbms_statsããã¼ãããããã§ç¡å¹ã«ãããå ´åã¯ã以ä¸ã®ä¾ã®ããã«pg_dbms_stats.use_locked_statsãoffã«è¨å®ãã¦ãã ããã
+
test=# SET pg_dbms_stats.use_locked_stats TO off;
+SET
+test=# SELECT * FROM test; -- é常ã®åºæºã§ãã©ã³ãä½æ
+...
+test=# SET pg_dbms_stats.use_locked_stats TO on;
+SET
+test=# SELECT * FROM test; -- ããã¼çµ±è¨æ
å ±ã§ãã©ã³ãä½æ
+...
+
+
+
+å
¨ã¦ã®ã»ãã·ã§ã³ã§pg_dbms_statsãç¡å¹ã«ããã«ã¯ãpostgresql.confã§pg_dbms_stats.use_locked_statsãoffã«è¨å®ãã¦ãããµã¼ããåèµ·åãã¦ä¸ããã
+PostgreSQL 9.1ã®ç°å¢ã§pg_dbms_stats.use_locked_statsãpostgresql.confãã¡ã¤ã«ã§è¨å®ããããã«ã¯custom_variable_classes ã«pg_dbms_statsãå ããå¿
è¦ãããã¾ãã
+
# postgresql.conf
+shared_preload_libraries = 'pg_dbms_stats'
+custom_variable_classes = 'pg_dbms_stats' # 9.2以éã¯å»æ¢ãããããè¨è¿°ä¸è¦
+pg_dbms_stats.use_locked_stats = off
+PostgreSQL 9.2以éã§ã¯custom_variable_classesã¯å»æ¢ããã¦ãããããpg_dbms_stats.use_locked_statsãæ¨æºã®GUCãã©ã¡ã¼ã¿ã¨åæ§ã«è¨è¿°ãããã¨ãã§ãã¾ãã
+
+
+ã¢ã³ã¤ã³ã¹ãã¼ã«
+
+pg_dbms_stats ãã¢ã³ã¤ã³ã¹ãã¼ã«ããã¨ãã¯ã以ä¸ã®æé ãå®è¡ãã¦ãã ããã
+dbname ã¯å¯¾è±¡ã¨ãªããã¼ã¿ãã¼ã¹åãæå³ãã¾ãã
+
+pg_dbms_statsãã¤ã³ã¹ãã¼ã«ããOSã¦ã¼ã¶ã§make uninstallãå®è¡ãã¦ãã ããã
+$ cd pg_dbms_stats
+$ su
+# make uninstall
+pg_dbms_statsãç»é²ãããã¼ã¿ãã¼ã¹ã«ã¹ã¼ãã¼ã¦ã¼ã¶ã§æ¥ç¶ã㦠DROP EXTENSION ã³ãã³ããå®è¡ãã¦ãã ããã
+$ psql -d dbname -c "DROP EXTENSION pg_dbms_stats"
+pg_dbms_stats ç¬èªã®çµ±è¨æ
å ±(ããã¯æ©è½ãããã¯ã¢ããæ©è½ã§ä¿åãããã®)ãå¿
è¦ãªãå ´åã¯ãdbms_statsã¹ãã¼ããåé¤ãã¦ãã ããã
+$ psql -d dbname -c "DROP SCHEMA dbms_stats"
+
+
+
+使ç¨ä¾
+大ããåãã¦ãããã¯ã¢ãã主ä½ããããã¯ä¸»ä½ããã¨ã¯ã¹ãã¼ã主ä½ãã®3ã¤ã®éç¨æ¹æ³ãããã¾ãã
+ã©ã®éç¨æ¹æ³ãé©ãã¦ãããå¤æã§ããªãå ´åã«ã¯ãã¾ããããã¯ã¢ãã主ä½ãã§éç¨ãããã¨ãã奨ããã¾ãã
+
+
+çµ±è¨æ
å ±ãããã¯ã¢ããããéç¨
+ãµã¼ãã¹éç¨ä¸ã«çµ±è¨æ
å ±ãæ¥ã
ããã¯ã¢ããããåé¡ãçããããªã¹ãã¢ããå ´åã«ã¯ backup_xxx() 㨠restore_xxx() é¢æ°ã使ç¨ãã¾ãã
+ç¹ã«åé¡ããªãéãããã¼ã¿ãã¼ã¹åä½ã§ããã¯ã¢ãããã¦ãã ããã
+çµ±è¨æ
å ±ããªã¹ãã¢ããæ¹æ³ã¯ãããã¯ã¢ããä¸ä»£ã表ãããã¯ã¢ããIDãæå®ããæ¹æ³ã¨ãã©ã®æç¹ã®çµ±è¨æ
å ±ã«å¾©å
ãããã表ãã¿ã¤ã ã¹ã¿ã³ããæå®ããæ¹æ³ã®2種é¡ã§ãã
+ããã¯ã¢ããIDãæå®ãã¦ãªã¹ãã¢ããå ´åã ããã¯ã¢ããIDãä¸è´ãããã¼ã¿ã使ã£ã¦ãªã¹ãã¢ãã¾ãã ãªã¹ãã¢ãããããã¯ã¢ããä¸ä»£ã®IDãæå®ãã¦ãªã¹ãã¢ãã¦ãã ããã
+ã¿ã¤ã ã¹ã¿ã³ããæå®ãã¦ãªã¹ãã¢ããå ´åã ãªãã¸ã§ã¯ããã¨ã«ãæå®ããæ¥æ以åã®ããã¯ã¢ãããã¼ã¿ã使ã£ã¦ãªã¹ãã¢ãã¾ãã ãªã¹ãã¢ãããæ¥æãæå®ãã¦ãã¼ã¿ãã¼ã¹åä½ã§ãªã¹ãã¢ãã¦ãã ããã
+ç¹ã«åé¡ããªãéããããã¯ã¢ããIDãæå®ããæ¹æ³ã§ãªã¹ãã¢ãã¦ãã ããã
+
+-- æ¥ã
ããã¯ã¢ãããåãããã®å¾ ANALYZE ããã
+test=# SELECT dbms_stats.backup_database_stats('comment');
+ backup_database_stats
+-----------------------
+ 1
+(1 row)
+
+test=# ANALYZE;
+ANALYZE
+test=#
+
+-- 1æ¥åã®ããã¯ã¢ãããæ¸ãæ»ãããã®å¤ã§ããã¯ããã
+test=# SELECT dbms_stats.restore_database_stats(now() - '1 day');
+注æ :
+ã¿ã¤ã ã¹ã¿ã³ããæå®ãã¦ãªã¹ãã¢ããå ´åããªã¹ãã¢å¯¾è±¡ã®ãªãã¸ã§ã¯ãã«å«ã¾ãããªã¬ã¼ã·ã§ã³ãã«ã©ã ããããã«ã¤ãã¦ãæå®ããã¿ã¤ã ã¹ã¿ã³ã以åã§ææ°ã®çµ±è¨æ
å ±ããªã¹ãã¢ãã¾ãã
+ãã®ãããåä½ã®å°ããªãªãã¸ã§ã¯ãã§ããã¯ã¢ãããã¦ããã¨ããæå®ããã¿ã¤ã ã¹ã¿ã³ã以åã«ããã¯ã¢ãããã¦ããªããªã¬ã¼ã·ã§ã³ãåã®çµ±è¨æ
å ±ã¯ãªã¹ãã¢ããããçµ±è¨æ
å ±ãã¦ã¼ã¶ã®æ³å®éãã«ãªããªãå ´åãããã¾ãã®ã§æ³¨æãã¦ãã ããã
+
+çµ±è¨æ
å ±ããã¯ã¢ãããã¼ã¿ããªã¹ãã¢ããã¨ãã®ä¾ã以ä¸ã«ç¤ºãã¾ãã
+ãªããtimeåã¯åãªã¬ã¼ã·ã§ã³ã®çµ±è¨æ
å ±ãããã¯ã¢ããããæã®ã¿ã¤ã ã¹ã¿ã³ããæå³ãã¾ãã
+
+test=# SELECT b.id, b.time, r.relname
+ FROM dbms_stats.relation_stats_backup r
+ JOIN dbms_stats.backup_history b ON (r.id=b.id)
+ ORDER BY id;
+ id | time | relname
+----+------------------------+-----------------
+ 4 | 2012-01-01 00:00:00+09 | public.droptest
+ 5 | 2012-01-02 12:00:00+09 | public.test
+(5 rows)
+
+test=# SELECT dbms_stats.restore_database_stats('2012-01-03 00:00:00+09');
+ restore_database_stats
+------------------------
+ test
+ droptest
+(2 rows)
+
+test=#
+
+çµ±è¨æ
å ±ãããã¯ããéç¨
+ãµã¼ãã¹éå§æã«çµ±è¨æ
å ±ãããã¯ãã¦ããã®ã¾ã¾éç¨ããå ´åã«ã¯ãlock_xxx() é¢æ°ã使ç¨ãã¾ãã
+test=# SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ droptest
+ test
+(2 rows)
+
+test=#
+
+
+çµ±è¨æ
å ±ãã¨ã¯ã¹ãã¼ãããéç¨
+ãµã¼ãã¹éç¨ä¸ã®çµ±è¨æ
å ±ãã¨ã¯ã¹ãã¼ãããä»ã®ãã¼ã¿ãã¼ã¹ã«ã¤ã³ãã¼ããããã¨ã§å®è¡è¨ç»ãåç¾ãããå ´åã«ã¯ãexport_xxx_stats.sql_sampleãã¡ã¤ã«ã¨import_xxx()é¢æ°ã使ç¨ãã¾ãã
+$ cd pg_dbms_stats
+$ psql -d test -f export_effective_stats.sql_sample
+BEGIN
+COMMIT
+$ psql -d test2 -c "SELECT dbms_stats.import_database_stats('$PWD/export_stats.dmp')"
+ import_database_stats
+-----------------------
+
+(1 row)
+
+$
+
+注æ :
+çµ±è¨æ
å ±ãã¨ã¯ã¹ãã¼ãããã¨ããç¾å¨ã®ãã¹ã«export_stats.dmpãã¡ã¤ã«ãä½æãã¾ãã
+ãã®ã¨ããååã®ãã¡ã¤ã«ãæ¢ã«åå¨ããå ´åãæ°ããã¨ã¯ã¹ãã¼ãçµæã§ä¸æ¸ããã¾ãã
+ä¸æ¸ããé¿ãããå ´åã¯ãæ¢åã®ãã¡ã¤ã«åãå¤æ´ãããªã©ãã¦å¯¾å¿ãã¦ãã ããã
+
+ã¾ããçµ±è¨æ
å ±ãã¤ã³ãã¼ãããã¨ãã«æå®ããæ
å ±ã¯ã対象ã¨ãªããã¡ã¤ã«ã®çµ¶å¯¾ãã¹ã§ãã
+ç¸å¯¾ãã¹ãæå®ããã¨ä»¥ä¸ã«ç¤ºãä¾ã®ãããªã¨ã©ã¼ã¨ãªãã¾ãã®ã§æ³¨æãã¦ãã ããã
+
+test=# select dbms_stats.import_database_stats('export_stats.dmp');
+ERROR: relative path not allowed for dbms_stats_export to file
+test=#
+ã¾ããã¨ã¯ã¹ãã¼ããã¡ã¤ã«ã«ã¯COPYã®ãã¤ããªãã©ã¼ããããå©ç¨ãã¦ãããããã¨ã¯ã¹ãã¼ãå
ã¨ã¤ã³ãã¼ãå
ã§ã¢ã¼ããã¯ãã£ãPostgreSQLãã¼ã¸ã§ã³ã«å·®ãããå ´åã¯æ£å¸¸ã«åä½ããªãå ´åãããã¾ãã詳ããã¯ãCOPYã³ãã³ãã®ããã¥ã¡ã³ã ãåç
§ãã¦ä¸ããã
+
+使ç¨ä¸ã®æ³¨æã¨å¶ç´
+pg_dbms_stats ã使ç¨ããéã«ã¯ã以ä¸ã®ä½¿ç¨ä¸ã®æ³¨æã¨å¶ç´ãããã¾ãã
+
+
+å©ç¨åã«å¿
è¦ãªä½æ¥
+pg_dbms_statsã®ããã¯æ©è½ãããã¯ã¢ããæ©è½ã使ç¨ããåã«ãå¿
ãä¸åã¯ANALYZEã³ãã³ãã§çµ±è¨æ
å ±ãåå¾ãã¦ãã ãããçµ±è¨æ
å ±ãåå¨ããªãç¶æ
ã§ããã¯ãããã¯ã¢ãããå®è¡ããå ´åãã¨ã©ã¼ã¯çºçãã¾ãããå®è¡è¨ç»ã¯å¶å¾¡ã§ãã¾ããã
+
+çµ±è¨æ
å ±ã®ããã¯ã¢ããå¥æ©
+ANALYZEã³ãã³ããçµ±è¨æ
å ±ã®æ¸ãæããããªã¬ã¨ãã¦çµ±è¨æ
å ±ãããã¯ã¢ãããããã¨ã¯ã§ãã¾ããã
+ã¸ã§ã管çãã¼ã«ããå®æçã«çµ±è¨æ
å ±ãããã¯ã¢ããããããautovacuum ã® ANALYZE ãç¡å¹åããçµ±è¨æ
å ±ã®ããã¯ã¢ããã¨åå¾ãã»ããã®ã¸ã§ãã¨ãã¦å®è¡ãã¦ãã ããã
+ãã¼ã«ã®ç¨é
+ãã®ã¢ã¸ã¥ã¼ã«ã¯éå»ã®çµ±è¨æ
å ±ãåç¾ãããã®ã§ãããæ°ããå®è¡è¨ç»ã試ããã¥ã¼ãã³ã°ã«ã¯å©ç¨ã§ãã¾ããã
+GUCãã©ã¡ã¼ã¿ã®å½±é¿
+ãã®ãã¼ã«ã¯ãå®è¡è¨ç»ã«å½±é¿ããè¦ç´ ã®ãã¡çµ±è¨æ
å ±ã®ã¿ãä¿åãããããå®è¡è¨ç»ã®çæã«é¢ããGUCãã©ã¡ã¼ã¿ ãå¤æ´ãããå ´åã¯ãçµ±è¨æ
å ±ãåºå®ãã¦ãã¦ãå®è¡è¨ç»ãå¤åããå ´åãããã¾ãã
+ããã¯é¢æ°ã使ããã¼ã«ã¨ã®ç«¶å
+pg_dbms_statsã§ã¯ã以ä¸ã®ããã¯é¢æ°ã使ç¨ãã¦ãã¾ãã
+
+get_relation_info_hook: æ¢åã®ããã¯é¢æ°ãå¼ã³åºããå¾ã«ç¬èªå¦ç
+get_attavgwidth_hook: æ¢åã®ããã¯é¢æ°ãå¼ã³åºããã«ç¬èªå¦ç
+get_relation_stats_hook: æ¢åã®ããã¯é¢æ°ãå¼ã³åºããã«ç¬èªå¦ç
+get_index_stats_hook: æ¢åã®ããã¯é¢æ°ãå¼ã³åºããã«ç¬èªå¦ç
+
+get_relation_info_hookã使ç¨ãããã¼ã«ã«ã¤ãã¦ã¯ãpg_dbms_statsãå¾ãããã¼ããããã¨ã§ä½µç¨å¯è½ã§ãããæ®ãã®ä¸ã¤ã®ããã¯é¢æ°ã使ç¨ãã¦ããå¤é¨ãã¼ã«ã¯ä½µç¨ããªãã§ãã ããã
+ãªããããã¯é¢æ°ã¨ã¯ãã©ã³ããã¨ã°ã¼ãã¥ã¼ã¿çã®PostgreSQLæ¬ä½ã®å¦çã«å¤é¨ãã¼ã«ãå²ãè¾¼ãããã«ä½¿ç¨ããé¢æ°ã§ãã
+
+ãã³ãã»ãªã¹ãã¢æã®æ³¨æç¹
+
+pg_dbms_statsã¯ãååä½ã®çµ±è¨æ
å ±ãã¦ã¼ã¶å®ç¾©ãã¼ãã«ã§ä¿æããåã«ç¬èªã«å®ç¾©ããanyarrayåã使ç¨ãã¦ãã¾ãããã®åã®å¤ãããã¹ãå½¢å¼ã§ãã³ãããã¨ãã¼ã¿åã®æ
å ±ã失ãããããããªã¹ãã¢æã«ã¨ã©ã¼ãçºçãã¾ãããªã¹ãã¢æã«ã¨ã©ã¼ãçºçãã¾ããpg_dbms_statsã®ãªãã¸ã§ã¯ããå«ããã³ã/ãªã¹ãã¢ã¯ã以ä¸ã®æé ã§å®æ½ãã¦ãã ããã
+
+ãCOPY <dbms_statsã¹ãã¼ããæã¤ãã¼ãã«å> TO '<ãã¡ã¤ã«å>' FORMAT binary;ã ã§pg_dbms_stats ã管çãã¦ããçµ±è¨æ
å ±ã <ãã¡ã¤ã«å>ã«ãã¤ããªå½¢å¼ã§ä¿åãã¾ãã
+ãpgdump --exclude-schema 'dbms_stats' <æ§ãã¼ã¿ãã¼ã¹å> > <ãã³ããã¡ã¤ã«å>ã 㧠dbms_stats ã¹ãã¼ããé¤ãã¦ãã³ããã¾ãã
+ãpg_restore -d <æ°ãã¼ã¿ãã¼ã¹å> <ãã³ããã¡ã¤ã«å>ãã§ãã³ããããã¡ã¤ã«ããªã¹ãã¢ãã¾ãã
+pg_dbms_statsãã¤ã³ã¹ãã¼ã«ãã¾ãã
+ãCOPY <dbms_statsã¹ãã¼ããæã¤ãã¼ãã«å> FROM '<ãã¡ã¤ã«å>' FORMAT binary;ã ã§<ãã¡ã¤ã«å>ã«ä¿åããã¦ããçµ±è¨æ
å ±ãdbms_statsã¹ãã¼ããæã¤ãã¼ãã«ã«ä¿åãã¾ãã
+
+
+ãªãã¸ã§ã¯ãåé¤æã®æ³¨æç¹
+ãªãã¸ã§ã¯ããåé¤ããå ´åã¯ãããã¯è§£é¤æ©è½ããã¼ã¸æ©è½ã使ã£ã¦pg_dbms_statsç¬èªã®çµ±è¨æ
å ±ãå
ã«åé¤ãã¦ãã ããããªããããã¯ä»¥å¤ã«ãããªã¹ãã¢ãã¤ã³ãã¼ããå®è¡ããå ´åãpg_dbms_statsç¬èªã®çµ±è¨æ
å ±ãä½æããã¾ãã
+
+
+詳細
+å
¨ä½æ§æ
+pg_dbms_statsã¯ãANALYZEã§ä½æãããçµ±è¨æ
å ±ã®ä»£ããã« pg_dbms_stats ãä¿æããç¬èªã®çµ±è¨æ
å ±ã PostgreSQL ã«ä½¿ããããã¨ã§å®è¡è¨ç»ãå¶å¾¡ãã¾ãã使ç¨ããçµ±è¨æ
å ±ã¯ã以ä¸ã®ããããã®æ¹æ³ã§é¸æã§ãã¾ãã
+
+ç¾å¨ã®çµ±è¨æ
å ±ã§ããã¯ãã
+ããã¯ã¢ãããã復å
ãã
+ã¨ã¯ã¹ãã¼ããã¡ã¤ã«ãåãè¾¼ã
+
+
+pg_dbms_stats ã§ã¯ãç¬èªã®çµ±è¨æ
å ±ãããã¤ãã®ãã¼ãã«/ãã¡ã¤ã«ç¾¤ã§ç®¡çãã¾ãã
+
+ç¾å¨æå¹ãªçµ±è¨æ
å ±
+ãã©ã³ããå®éã«ä½¿ç¨ããçµ±è¨æ
å ±ã§ãããã¯æ©è½ãããã¯ã¢ããæ©è½ãã¤ã³ãã¼ãæ©è½ã§ä½æããã¾ã
+ããã¯ã¢ããçµ±è¨æ
å ±
+ããã¯ã¢ããæ©è½ã«ãã£ã¦ä¿åãããä»»æã®æç¹ã®çµ±è¨æ
å ±ã»ããã§ãè¤æ°ä¸ä»£ä¿æå¯è½ã§ããããã¯ã¢ããå±¥æ´ã¯å±¥æ´ãã¼ãã«ã§ç®¡çããã¾ãããªã¹ãã¢æ©è½ã§ç¾å¨æå¹ãªçµ±è¨æ
å ±ãç½®ãæãããã¾ãã
+ã¨ã¯ã¹ãã¼ããããçµ±è¨æ
å ±
+ã¨ã¯ã¹ãã¼ãæ©è½ã«ãã£ã¦ä½æãããä»»æã®ç°å¢ã®çµ±è¨æ
å ±ã»ããã§ãOSãã¡ã¤ã«ã§ä¿åããã¾ãããã¡ã¤ã«åãå¤ãããã¨ã§è¤æ°ã»ãããä¿æå¯è½ã§ããã¤ã³ãã¼ãæ©è½ã§ç¾å¨æå¹ãªçµ±è¨æ
å ±ãç½®ãæãããã¾ãã
+
+
+ãªããpg_dbms_stats ãæä¾ãããããã®æ©è½ããPostgreSQL ãå
ã
使ç¨ãã¦ãçµ±è¨æ
å ± (pg_catalog.pg_classãpg_catalog.pg_statistic) ãå¤æ´ãã¾ããã
+
+
+pg_dbms_statsã®ã¦ã¼ã¶ã¤ã³ã¿ã¼ãã§ã¼ã¹
+pg_dbms_statsã®åæ©è½ã¯ãåç¯ã§èª¬æããç¬èªã®çµ±è¨æ
å ±ãã¼ãã«ã®å
容ãSQLæã§æ´æ°ãããã¨ã§å®ç¾ããã¦ãã¾ãããã ããã¦ã¼ã¶ãç´æ¥SQLæãå®è¡ããã¨æä½ãã¹ã«ããåé¤ããã¼ã¿ä¸æ´åãªã©ãèµ·ãããããããã¦ã¼ã¶ã¤ã³ã¿ã¼ãã§ã¼ã¹ã¨ãã¦åæ©è½ã«å¯¾å¿ããSQLé¢æ°ãæä¾ãã¦ããããããã使ã£ã¦ã®æä½ãå¼·ãæ¨å¥¨ããã¦ãã¾ãã
+
+autovacuum ã«ãã ANALYZE ã®ç¡å¹åã«ã¤ãã¦
+pg_dbms_stats 㯠ANALYZE ãç¡å¹åãç¦æ¢ããã¾ããã
+ANALYZE 㯠pg_statistic ã·ã¹ãã ã«ã¿ãã°ãå¤æ´ãã¾ãããæçµçã« pg_dbms_stats ã®ç¬èªçµ±è¨æ
å ±ã§å¤ãé ããã¾ãã
+å¹æã®ç¡ã ANALYZE ãç¹°ãè¿ãã®ã¯è³æºã®ç¡é§ã¨èããã®ã§ããã°ãautovacuum ã«ãã ANALYZE ãç¡å¹åãã¦ãã ããã
+ç¡å¹åã¯ãä¸è¨ã®ããã« ANALYZE ã®å¿
è¦æ§å¤å®ã®é¾å¤ãä¸ãããã¨ã§è¡ãã¾ãã
+ãã ããç¡å¹åããªãã¦ãç°å¸¸ãªåä½ããããã¨ã¯ããã¾ããã
+
+å
¨ä½è¨å®ã®å ´å
+# postgresql.conf
+autovacuum_analyze_threshold = 100000
+autovacuum_analyze_scale_factor = 100
+
+
+åå¥è¨å®ã®å ´å
+test=# ALTER TABLE tbl SET (
+ autovacuum_analyze_threshold = 100000,
+ autovacuum_analyze_scale_factor = 100);
+
+ããã¯ããçµ±è¨æ
å ±ã«ã¤ãã¦
+å®è¡è¨ç»ãä½æããéãã¯ã¨ãªã»ãªããã£ãã¤ã¶ã¯ä»¥ä¸ã®çµ±è¨æ
å ±ã¾ãã¯å®éã®ãã¼ã¿ã®ç¶æ
ã«åºã¥ãã¦ã³ã¹ããè¨ç®ãã¾ããpg_dbms_stats ã¯ããããå
¨ã¦ã®æ
å ±ãããã¯ãããã¨ãã§ãã¾ããå®éã®ãã¡ã¤ã«ãµã¤ãºãå¤åãã¦ããããã¯ããã¨ãã®ãã¡ã¤ã«ãµã¤ãºãç¶ç¶ãã¦åç
§ãã¾ãã
+
+ANALYZE ã§ãµã³ããªã³ã°ããè¡ã®å¤ (pg_catalog.pg_statistic)
+ANALYZE æã®æ¨å®è¡æ° (pg_catalog.pg_class.reltuples)
+ANALYZE æã®ãã¡ã¤ã«ãµã¤ãº (pg_catalog.pg_class.relpages)
+å®è¡è¨ç»ä½ææã®ãã¡ã¤ã«ãµã¤ãº
+
+
+åä½ç°å¢
+
+PostgreSQLãã¼ã¸ã§ã³
+PostgreSQL 9.1, 9.2
+OS
+RHEL 6.1
+
+
+é¢é£é
ç®
+psql ,
+vacuumdb
+COPY
+
+
+
+
+
+
diff --git a/doc/pg_dbms_stats-ja.png b/doc/pg_dbms_stats-ja.png
new file mode 100644
index 0000000..0592726
Binary files /dev/null and b/doc/pg_dbms_stats-ja.png differ
diff --git a/doc/style.css b/doc/style.css
new file mode 100644
index 0000000..4a87054
--- /dev/null
+++ b/doc/style.css
@@ -0,0 +1,81 @@
+body {
+ font-family:
+ Lucida Grande, Verdana, Arial, Helvetica,
+ 'ã¡ã¤ãªãª',
+ 'Meiryo',
+ 'ãã©ã®ãè§ã´ Pro W3',
+ 'Hiragino Kaku Gothic Pro',
+ 'Osaka',
+ 'ï¼ï¼³ ï¼°ã´ã·ãã¯',
+ sans-serif;
+ color: #202020;
+}
+
+/* give the rule a bit of extra space (above and below), since its being used to divide
+ sections on some pages (project summary) */
+HR { margin: 5px 0px 5px 0px }
+
+
+h2, h3, h4, h5, h6 {
+ color: Black;
+ background: none;
+ padding-top: 0.5em;
+ padding-bottom: 0.17em;
+ border-bottom: 1px solid #aaaaaa;
+}
+H1 { font-size: x-large; font-family: Lucida Grande,verdana,arial,helvetica,sans-serif; }
+H2 { font-size: large; font-family: Lucida Grande,verdana,arial,helvetica,sans-serif; }
+H3 { padding-left: 1em; font-size: medium; font-family: Lucida Grande,verdana,arial,helvetica,sans-serif; }
+H4 { padding-left: 2em; font-size: small; font-family: Lucida Grande,verdana,arial,helvetica,sans-serif; }
+H5 { padding-left: 3em; font-size: x-small; font-family: Lucida Grande,verdana,arial,helvetica,sans-serif; }
+H6 { padding-left: 4em; font-size: xx-small; font-family: Lucida Grande,verdana,arial,helvetica,sans-serif; }
+
+pre {
+ font-family: courier,sans-serif;
+ background-color: #FBFBFD;
+ border: 1px dashed #7E7ECB;
+ color: black;
+ line-height: 1.1em; padding: 0.5em;
+ overflow: auto;
+}
+
+li {
+ line-height: 1.4em;
+}
+
+table {
+ background: #f9f9f9;
+ border: 1px solid #aaa;
+ border-collapse: collapse;
+}
+
+th, td {
+ border: 1px solid #aaa;
+ padding: 0.2em;
+}
+
+thead th {
+ background: #f2f2f2;
+ text-align: center;
+}
+
+tbody th {
+ background: #f2f2f2;
+ text-align: left;
+}
+
+div.index {
+ float:right;
+ border:thin solid black;
+ background-color: white;
+ padding-top: 0.2em;
+ padding-bottom: 0.2em;
+ padding-left: 1em;
+ padding-right: 1em;
+ margin-left: 0.5em;
+}
+
+p.footer {
+ text-align: right;
+ font-size: small;
+}
diff --git a/dump.c b/dump.c
new file mode 100644
index 0000000..9bd0a1b
--- /dev/null
+++ b/dump.c
@@ -0,0 +1,375 @@
+/*
+ * dump.c
+ *
+ * Copyright (c) 2009-2012, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
+ * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ */
+#include "postgres.h"
+
+#include "libpq/pqformat.h"
+#include "utils/array.h"
+#include "utils/builtins.h"
+#include "utils/lsyscache.h"
+#include "utils/memutils.h"
+
+PG_FUNCTION_INFO_V1(dbms_stats_array_recv);
+
+extern Datum dbms_stats_array_recv(PG_FUNCTION_ARGS);
+
+static void ReadArrayBinary(StringInfo buf, int nitems,
+ FmgrInfo *receiveproc, Oid typioparam, int32 typmod,
+ int typlen, bool typbyval, char typalign,
+ Datum *values, bool *nulls,
+ bool *hasnulls, int32 *nbytes);
+static void CopyArrayEls(ArrayType *array,
+ Datum *values, bool *nulls, int nitems,
+ int typlen, bool typbyval, char typalign,
+ bool freedata);
+static int ArrayCastAndSet(Datum src,
+ int typlen, bool typbyval, char typalign,
+ char *dest);
+
+/*
+ * recv function for use-defined type dbms_stats.anyarray. Receive string
+ * representation of anyarray object, and convert it into binary data.
+ */
+Datum
+dbms_stats_array_recv(PG_FUNCTION_ARGS)
+{
+ StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
+ Oid element_type;
+ int typlen;
+ bool typbyval;
+ char typalign;
+ Oid typioparam;
+ int i,
+ nitems;
+ Datum *dataPtr;
+ bool *nullsPtr;
+ bool hasnulls;
+ int32 nbytes;
+ int32 dataoffset;
+ ArrayType *retval;
+ int ndim,
+ flags,
+ dim[MAXDIM],
+ lBound[MAXDIM];
+ ArrayMetaState *my_extra;
+
+ /* Get the array header information */
+ ndim = pq_getmsgint(buf, 4);
+ if (ndim < 0) /* we do allow zero-dimension arrays */
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
+ errmsg("invalid number of dimensions: %d", ndim)));
+ if (ndim > MAXDIM)
+ ereport(ERROR,
+ (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
+ errmsg("number of array dimensions (%d) exceeds the maximum allowed (%d)",
+ ndim, MAXDIM)));
+
+ flags = pq_getmsgint(buf, 4);
+ if (flags != 0 && flags != 1)
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
+ errmsg("invalid array flags")));
+
+ element_type = pq_getmsgint(buf, sizeof(Oid));
+
+ for (i = 0; i < ndim; i++)
+ {
+ int ub;
+
+ dim[i] = pq_getmsgint(buf, 4);
+ lBound[i] = pq_getmsgint(buf, 4);
+
+ ub = lBound[i] + dim[i] - 1;
+ /* overflow? */
+ if (lBound[i] > ub)
+ ereport(ERROR,
+ (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
+ errmsg("integer out of range")));
+ }
+
+ /* This checks for overflow of array dimensions */
+ nitems = ArrayGetNItems(ndim, dim);
+
+ /*
+ * We arrange to look up info about element type, including its receive
+ * conversion proc, only once per series of calls, assuming the element
+ * type doesn't change underneath us.
+ */
+ my_extra = (ArrayMetaState *) fcinfo->flinfo->fn_extra;
+ if (my_extra == NULL)
+ {
+ fcinfo->flinfo->fn_extra = MemoryContextAlloc(fcinfo->flinfo->fn_mcxt,
+ sizeof(ArrayMetaState));
+ my_extra = (ArrayMetaState *) fcinfo->flinfo->fn_extra;
+ my_extra->element_type = ~element_type;
+ }
+
+ if (my_extra->element_type != element_type)
+ {
+ /* Get info about element type, including its receive proc */
+ get_type_io_data(element_type, IOFunc_receive,
+ &my_extra->typlen, &my_extra->typbyval,
+ &my_extra->typalign, &my_extra->typdelim,
+ &my_extra->typioparam, &my_extra->typiofunc);
+ if (!OidIsValid(my_extra->typiofunc))
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_FUNCTION),
+ errmsg("no binary input function available for type \"%s\"",
+ format_type_be(element_type))));
+ fmgr_info_cxt(my_extra->typiofunc, &my_extra->proc,
+ fcinfo->flinfo->fn_mcxt);
+ my_extra->element_type = element_type;
+ }
+
+ if (nitems == 0)
+ {
+ /* Return empty array ... but not till we've validated element_type */
+ PG_RETURN_ARRAYTYPE_P(construct_empty_array(element_type));
+ }
+
+ typlen = my_extra->typlen;
+ typbyval = my_extra->typbyval;
+ typalign = my_extra->typalign;
+ typioparam = my_extra->typioparam;
+
+ dataPtr = (Datum *) palloc(nitems * sizeof(Datum));
+ nullsPtr = (bool *) palloc(nitems * sizeof(bool));
+ ReadArrayBinary(buf, nitems,
+ &my_extra->proc, typioparam, 0,
+ typlen, typbyval, typalign,
+ dataPtr, nullsPtr,
+ &hasnulls, &nbytes);
+ if (hasnulls)
+ {
+ dataoffset = ARR_OVERHEAD_WITHNULLS(ndim, nitems);
+ nbytes += dataoffset;
+ }
+ else
+ {
+ dataoffset = 0; /* marker for no null bitmap */
+ nbytes += ARR_OVERHEAD_NONULLS(ndim);
+ }
+ retval = (ArrayType *) palloc(nbytes);
+ SET_VARSIZE(retval, nbytes);
+ retval->ndim = ndim;
+ retval->dataoffset = dataoffset;
+ retval->elemtype = element_type;
+ memcpy(ARR_DIMS(retval), dim, ndim * sizeof(int));
+ memcpy(ARR_LBOUND(retval), lBound, ndim * sizeof(int));
+
+ CopyArrayEls(retval,
+ dataPtr, nullsPtr, nitems,
+ typlen, typbyval, typalign,
+ true);
+
+ pfree(dataPtr);
+ pfree(nullsPtr);
+
+ PG_RETURN_ARRAYTYPE_P(retval);
+}
+
+static void
+ReadArrayBinary(StringInfo buf,
+ int nitems,
+ FmgrInfo *receiveproc,
+ Oid typioparam,
+ int32 typmod,
+ int typlen,
+ bool typbyval,
+ char typalign,
+ Datum *values,
+ bool *nulls,
+ bool *hasnulls,
+ int32 *nbytes)
+{
+ int i;
+ bool hasnull;
+ int32 totbytes;
+
+ for (i = 0; i < nitems; i++)
+ {
+ int itemlen;
+ StringInfoData elem_buf;
+ char csave;
+
+ /* Get and check the item length */
+ itemlen = pq_getmsgint(buf, 4);
+ if (itemlen < -1 || itemlen > (buf->len - buf->cursor))
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
+ errmsg("insufficient data left in message")));
+
+ if (itemlen == -1)
+ {
+ /* -1 length means NULL */
+ values[i] = ReceiveFunctionCall(receiveproc, NULL,
+ typioparam, typmod);
+ nulls[i] = true;
+ continue;
+ }
+
+ /*
+ * Rather than copying data around, we just set up a phony StringInfo
+ * pointing to the correct portion of the input buffer. We assume we
+ * can scribble on the input buffer so as to maintain the convention
+ * that StringInfos have a trailing null.
+ */
+ elem_buf.data = &buf->data[buf->cursor];
+ elem_buf.maxlen = itemlen + 1;
+ elem_buf.len = itemlen;
+ elem_buf.cursor = 0;
+
+ buf->cursor += itemlen;
+
+ csave = buf->data[buf->cursor];
+ buf->data[buf->cursor] = '\0';
+
+ /* Now call the element's receiveproc */
+ values[i] = ReceiveFunctionCall(receiveproc, &elem_buf,
+ typioparam, typmod);
+ nulls[i] = false;
+
+ /* Trouble if it didn't eat the whole buffer */
+ if (elem_buf.cursor != itemlen)
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
+ errmsg("improper binary format in array element %d",
+ i + 1)));
+
+ buf->data[buf->cursor] = csave;
+ }
+
+ /*
+ * Check for nulls, compute total data space needed
+ */
+ hasnull = false;
+ totbytes = 0;
+ for (i = 0; i < nitems; i++)
+ {
+ if (nulls[i])
+ hasnull = true;
+ else
+ {
+ /* let's just make sure data is not toasted */
+ if (typlen == -1)
+ values[i] = PointerGetDatum(PG_DETOAST_DATUM(values[i]));
+ totbytes = att_addlength_datum(totbytes, typlen, values[i]);
+ totbytes = att_align_nominal(totbytes, typalign);
+ /* check for overflow of total request */
+ if (!AllocSizeIsValid(totbytes))
+ ereport(ERROR,
+ (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
+ errmsg("array size exceeds the maximum allowed (%d)",
+ (int) MaxAllocSize)));
+ }
+ }
+ *hasnulls = hasnull;
+ *nbytes = totbytes;
+}
+
+static void
+CopyArrayEls(ArrayType *array,
+ Datum *values,
+ bool *nulls,
+ int nitems,
+ int typlen,
+ bool typbyval,
+ char typalign,
+ bool freedata)
+{
+ char *p = ARR_DATA_PTR(array);
+ bits8 *bitmap = ARR_NULLBITMAP(array);
+ int bitval = 0;
+ int bitmask = 1;
+ int i;
+
+ if (typbyval)
+ freedata = false;
+
+ for (i = 0; i < nitems; i++)
+ {
+ if (nulls && nulls[i])
+ {
+ if (!bitmap) /* shouldn't happen */
+ elog(ERROR, "null array element where not supported");
+ /* bitmap bit stays 0 */
+ }
+ else
+ {
+ bitval |= bitmask;
+ p += ArrayCastAndSet(values[i], typlen, typbyval, typalign, p);
+ if (freedata)
+ pfree(DatumGetPointer(values[i]));
+ }
+ if (bitmap)
+ {
+ bitmask <<= 1;
+ if (bitmask == 0x100)
+ {
+ *bitmap++ = bitval;
+ bitval = 0;
+ bitmask = 1;
+ }
+ }
+ }
+
+ if (bitmap && bitmask != 1)
+ *bitmap = bitval;
+}
+
+static int
+ArrayCastAndSet(Datum src,
+ int typlen,
+ bool typbyval,
+ char typalign,
+ char *dest)
+{
+ int inc;
+
+ if (typlen > 0)
+ {
+ if (typbyval)
+ store_att_byval(dest, src, typlen);
+ else
+ memmove(dest, DatumGetPointer(src), typlen);
+ inc = att_align_nominal(typlen, typalign);
+ }
+ else
+ {
+ Assert(!typbyval);
+ inc = att_addlength_datum(0, typlen, src);
+ memmove(dest, DatumGetPointer(src), inc);
+ inc = att_align_nominal(inc, typalign);
+ }
+
+ return inc;
+}
+
+#ifdef UNIT_TEST
+void test_dump(int *passed, int *total);
+/*
+ * Unit test entry point for dump.c. This will be called by PG_init()
+ * function, after initialization for this extension is completed .
+ * This funciton should add the numbers of tests passed and the total number of
+ * tests to parameter passed and total respectively.
+ */
+void
+test_dump(int *passed, int *total)
+{
+ int local_passed = 0;
+ int local_total = 0;
+
+ elog(WARNING, "==========");
+
+ /* Do tests here */
+
+ elog(WARNING, "%s %d/%d passed", __FUNCTION__, local_passed, local_total);
+ *passed += local_passed;
+ *total += local_total;
+}
+#endif
diff --git a/expected/.gitignore b/expected/.gitignore
new file mode 100644
index 0000000..4b31aca
--- /dev/null
+++ b/expected/.gitignore
@@ -0,0 +1,2 @@
+/ut_anyarray-*.out
+/ut_imp_exp-*.out
diff --git a/expected/init-9.1.out b/expected/init-9.1.out
new file mode 100644
index 0000000..392ac8c
--- /dev/null
+++ b/expected/init-9.1.out
@@ -0,0 +1,97 @@
+CREATE VIEW plain_relations_statistic_v AS
+SELECT oid::regclass,
+ relpages,
+ reltuples,
+ pg_relation_size(oid) / 8192 curpages
+ FROM pg_class
+ ORDER BY oid::regclass::text;
+CREATE VIEW relations_locked_v AS
+SELECT relid::regclass,
+ relname,
+ relpages,
+ reltuples,
+ curpages
+ FROM dbms_stats._relation_stats_locked
+ ORDER BY relid;
+CREATE VIEW relations_backup_v AS
+SELECT id,
+ relid::regclass,
+ relname,
+ relpages,
+ reltuples,
+ curpages
+ FROM dbms_stats.relation_stats_backup
+ ORDER BY id, relid;
+CREATE VIEW plain_columns_statistic_v AS
+SELECT starelid::regclass, staattnum, stainherit,
+ stanullfrac, stawidth, stadistinct,
+ stakind1, stakind2, stakind3, stakind4,
+ staop1, staop2, staop3, staop4,
+ stanumbers1, stanumbers2, stanumbers3, stanumbers4,
+ stavalues1::text, stavalues2::text, stavalues3::text, stavalues4::text
+ FROM pg_statistic
+ ORDER BY starelid, staattnum, stainherit;
+CREATE VIEW columns_locked_v AS
+SELECT starelid::regclass, staattnum, attname, stainherit,
+ stanullfrac, stawidth, stadistinct,
+ stakind1, stakind2, stakind3, stakind4,
+ staop1, staop2, staop3, staop4,
+ stanumbers1, stanumbers2, stanumbers3, stanumbers4,
+ stavalues1, stavalues2, stavalues3, stavalues4
+ FROM dbms_stats._column_stats_locked c
+ JOIN pg_attribute a
+ ON (c.starelid = a.attrelid AND c.staattnum = a.attnum)
+ ORDER BY starelid, staattnum, stainherit;
+CREATE VIEW columns_backup_v AS
+SELECT id, statypid,
+ starelid::regclass, staattnum, stainherit,
+ stanullfrac, stawidth, stadistinct,
+ stakind1, stakind2, stakind3, stakind4,
+ staop1, staop2, staop3, staop4,
+ stanumbers1, stanumbers2, stanumbers3, stanumbers4,
+ stavalues1, stavalues2, stavalues3, stavalues4
+ FROM dbms_stats.column_stats_backup
+ ORDER BY id, starelid, staattnum, stainherit;
+CREATE TABLE dbms_stats.work (
+ nspname name NOT NULL,
+ relname name NOT NULL,
+ relpages int4 NOT NULL,
+ reltuples float4 NOT NULL,
+ curpages int4 NOT NULL,
+ last_analyze timestamp with time zone,
+ last_autoanalyze timestamp with time zone,
+ attname name,
+ nspname_of_typename name,
+ typname name,
+ atttypmod int4,
+ stainherit bool,
+ stanullfrac float4,
+ stawidth int4,
+ stadistinct float4,
+ stakind1 int2,
+ stakind2 int2,
+ stakind3 int2,
+ stakind4 int2,
+ staop1 oid,
+ staop2 oid,
+ staop3 oid,
+ staop4 oid,
+ stanumbers1 float4[],
+ stanumbers2 float4[],
+ stanumbers3 float4[],
+ stanumbers4 float4[],
+ stavalues1 dbms_stats.anyarray,
+ stavalues2 dbms_stats.anyarray,
+ stavalues3 dbms_stats.anyarray,
+ stavalues4 dbms_stats.anyarray
+);
+CREATE VIEW work_v AS
+SELECT nspname, relname, relpages, reltuples,
+ curpages, attname, nspname_of_typename, typname, atttypmod,
+ stainherit, stanullfrac, stawidth, stadistinct,
+ stakind1, stakind2, stakind3, stakind4,
+ staop1, staop2, staop3, staop4,
+ stanumbers1, stanumbers2, stanumbers3, stanumbers4,
+ stavalues1, stavalues2, stavalues3, stavalues4
+ FROM dbms_stats.work
+ ORDER BY nspname, relname, attname, stainherit;
diff --git a/expected/init-9.2.out b/expected/init-9.2.out
new file mode 100644
index 0000000..93c3e91
--- /dev/null
+++ b/expected/init-9.2.out
@@ -0,0 +1,105 @@
+CREATE VIEW plain_relations_statistic_v AS
+SELECT oid::regclass,
+ relpages,
+ reltuples,
+ relallvisible,
+ pg_relation_size(oid) / 8192 curpages
+ FROM pg_class
+ ORDER BY oid::regclass::text;
+CREATE VIEW relations_locked_v AS
+SELECT relid::regclass,
+ relname,
+ relpages,
+ reltuples,
+ relallvisible,
+ curpages
+ FROM dbms_stats._relation_stats_locked
+ ORDER BY relid;
+CREATE VIEW relations_backup_v AS
+SELECT id,
+ relid::regclass,
+ relname,
+ relpages,
+ reltuples,
+ relallvisible,
+ curpages
+ FROM dbms_stats.relation_stats_backup
+ ORDER BY id, relid;
+CREATE VIEW plain_columns_statistic_v AS
+SELECT starelid::regclass, staattnum, stainherit,
+ stanullfrac, stawidth, stadistinct,
+ stakind1, stakind2, stakind3, stakind4, stakind5,
+ staop1, staop2, staop3, staop4, staop5,
+ stanumbers1, stanumbers2, stanumbers3, stanumbers4, stanumbers5,
+ stavalues1::text, stavalues2::text, stavalues3::text, stavalues4::text, stavalues5::text
+ FROM pg_statistic
+ ORDER BY starelid, staattnum, stainherit;
+CREATE VIEW columns_locked_v AS
+SELECT starelid::regclass, 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
+ FROM dbms_stats._column_stats_locked c
+ JOIN pg_attribute a
+ ON (c.starelid = a.attrelid AND c.staattnum = a.attnum)
+ ORDER BY starelid, staattnum, stainherit;
+CREATE VIEW columns_backup_v AS
+SELECT id, statypid,
+ starelid::regclass, 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
+ FROM dbms_stats.column_stats_backup
+ ORDER BY id, starelid, staattnum, stainherit;
+CREATE TABLE dbms_stats.work (
+ nspname name NOT NULL,
+ relname name NOT NULL,
+ relpages int4 NOT NULL,
+ reltuples float4 NOT NULL,
+ relallvisible int4 NOT NULL,
+ curpages int4 NOT NULL,
+ last_analyze timestamp with time zone,
+ last_autoanalyze timestamp with time zone,
+ attname name,
+ nspname_of_typename name,
+ typname name,
+ atttypmod int4,
+ stainherit bool,
+ stanullfrac float4,
+ stawidth int4,
+ stadistinct float4,
+ stakind1 int2,
+ stakind2 int2,
+ stakind3 int2,
+ stakind4 int2,
+ stakind5 int2,
+ staop1 oid,
+ staop2 oid,
+ staop3 oid,
+ staop4 oid,
+ staop5 oid,
+ stanumbers1 float4[],
+ stanumbers2 float4[],
+ stanumbers3 float4[],
+ stanumbers4 float4[],
+ stanumbers5 float4[],
+ stavalues1 dbms_stats.anyarray,
+ stavalues2 dbms_stats.anyarray,
+ stavalues3 dbms_stats.anyarray,
+ stavalues4 dbms_stats.anyarray
+ ,stavalues5 dbms_stats.anyarray
+);
+CREATE VIEW work_v AS
+SELECT nspname, relname, relpages, reltuples, relallvisible,
+ curpages, attname, nspname_of_typename, typname, atttypmod,
+ stainherit, stanullfrac, stawidth, stadistinct,
+ stakind1, stakind2, stakind3, stakind4, stakind5,
+ staop1, staop2, staop3, staop4, staop5,
+ stanumbers1, stanumbers2, stanumbers3, stanumbers4, stanumbers5,
+ stavalues1, stavalues2, stavalues3, stavalues4, stavalues5
+ FROM dbms_stats.work
+ ORDER BY nspname, relname, attname, stainherit;
diff --git a/expected/init-common.out b/expected/init-common.out
new file mode 100644
index 0000000..316aad8
--- /dev/null
+++ b/expected/init-common.out
@@ -0,0 +1,83 @@
+/*
+ * No.1-1 CREATE EXTENSION
+ */
+-- No.1-1-1
+CREATE EXTENSION pg_dbms_stats;
+-- No.1-1-2
+DROP EXTENSION pg_dbms_stats;
+CREATE EXTENSION pg_dbms_stats;
+-- create no superuser and superuser
+SET client_min_messages = warning;
+DROP ROLE IF EXISTS regular_user;
+CREATE ROLE regular_user LOGIN;
+SET client_min_messages = fatal;
+CREATE ROLE postgres SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN;
+-- create object
+CREATE TABLE pt0(id integer, day date);
+CREATE INDEX pt0_idx ON pt0(id);
+CREATE TABLE st0(id integer, name char(5));
+CREATE INDEX st0_idx ON st0(id);
+CREATE TABLE st1(val integer, str text);
+CREATE SCHEMA s0;
+CREATE TABLE s0.st0(id integer, num integer);
+CREATE INDEX st0_idx ON s0.st0(id);
+CREATE TABLE s0.st1() INHERITS(s0.st0);
+CREATE INDEX st1_idx ON s0.st1(id);
+CREATE TABLE s0.st2(id integer, txt text);
+CREATE INDEX st2_idx ON s0.st2(id);
+CREATE VIEW sv0 AS
+ SELECT st0.id, st0.num, st2.txt
+ FROM s0.st0 st0, s0.st2 st2
+ WHERE st0.id = st2.id;
+CREATE TYPE s0.sc0 AS (num integer, txt text);
+CREATE FOREIGN DATA WRAPPER test_wrapper;
+CREATE SERVER test_server
+ FOREIGN DATA WRAPPER test_wrapper;
+CREATE FOREIGN TABLE s0.sft0(id integer)
+ SERVER test_server;
+CREATE SEQUENCE s0.ss0 START 1;
+CREATE SCHEMA s1;
+CREATE TABLE s1.st0(id integer, num integer);
+CREATE SCHEMA s2;
+GRANT USAGE ON SCHEMA s0 TO regular_user;
+GRANT SELECT ON TABLE s0.st2 TO regular_user;
+CREATE TYPE complex AS (
+ r double precision,
+ i double precision
+);
+CREATE FUNCTION inform(VARIADIC arr text[]) RETURNS int AS $$
+DECLARE
+ str text := 'arguments are ';
+ count int;
+BEGIN
+ FOR count IN SELECT i FROM generate_subscripts($1, 1) g(i) LOOP
+ IF count != 1 THEN
+ str := str || ', ';
+ END IF;
+ IF $1[count] IS NULL THEN
+ str := str || '';
+ ELSE
+ str := str || $1[count];
+ END IF;
+ END LOOP;
+ RAISE NOTICE '%', str;
+ RETURN 1;
+END;
+$$LANGUAGE plpgsql;
+CREATE VIEW lockd_io AS
+ SELECT relname, heap_blks_read hbr, heap_blks_hit hbh,
+ idx_blks_read ibr, idx_blks_hit ibh
+ FROM pg_statio_user_tables
+ WHERE schemaname = 'dbms_stats'
+ AND relname LIKE '%stats_locked'
+ ORDER BY relid;
+-- load data
+INSERT INTO st0 VALUES (1, 'test'), (2, 'test');
+INSERT INTO st1 SELECT i % 3, i % 3 FROM generate_series(1, 10000) t(i);
+INSERT INTO s0.st0 VALUES (1, 10), (2, 20);
+INSERT INTO s0.st1 VALUES (4, 40), (5, 50), (6, 60);
+INSERT INTO s0.st2 VALUES (1, '1'), (2, 'test'), (3, 'comment');
+INSERT INTO s1.st0 VALUES (1, 15), (2, 25), (3, 35), (4, 45);
+CREATE INDEX st1_idx ON st1 (val);
+CREATE INDEX st1_exp ON st1 (lower(str));
+VACUUM ANALYZE;
diff --git a/expected/ut-9.1.out b/expected/ut-9.1.out
new file mode 100644
index 0000000..558f2c3
--- /dev/null
+++ b/expected/ut-9.1.out
@@ -0,0 +1,9099 @@
+\pset null '(null)'
+/*
+ * No.2-1 table definitions.
+ */
+-- No.2-1-1
+\d dbms_stats.backup_history
+ Table "dbms_stats.backup_history"
+ Column | Type | Modifiers
+---------+--------------------------+------------------------------------------------------------------------
+ id | bigint | not null default nextval('dbms_stats.backup_history_id_seq'::regclass)
+ time | timestamp with time zone | not null
+ unit | character(1) | not null
+ comment | text |
+Indexes:
+ "backup_history_pkey" PRIMARY KEY, btree (id)
+Referenced by:
+ TABLE "dbms_stats.column_stats_backup" CONSTRAINT "column_stats_backup_id_fkey" FOREIGN KEY (id) REFERENCES dbms_stats.backup_history(id) ON DELETE CASCADE
+ TABLE "dbms_stats.relation_stats_backup" CONSTRAINT "relation_stats_backup_id_fkey" FOREIGN KEY (id) REFERENCES dbms_stats.backup_history(id) ON DELETE CASCADE
+
+-- No.2-1-2
+\d dbms_stats.column_stats_backup
+ Table "dbms_stats.column_stats_backup"
+ Column | Type | Modifiers
+-------------+---------------------+-----------
+ id | bigint | not null
+ statypid | oid | not null
+ starelid | oid | not null
+ staattnum | smallint | not null
+ stainherit | boolean | not null
+ stanullfrac | real | not null
+ stawidth | integer | not null
+ stadistinct | real | not null
+ stakind1 | smallint | not null
+ stakind2 | smallint | not null
+ stakind3 | smallint | not null
+ stakind4 | smallint | not null
+ staop1 | oid | not null
+ staop2 | oid | not null
+ staop3 | oid | not null
+ staop4 | oid | not null
+ stanumbers1 | real[] |
+ stanumbers2 | real[] |
+ stanumbers3 | real[] |
+ stanumbers4 | real[] |
+ stavalues1 | dbms_stats.anyarray |
+ stavalues2 | dbms_stats.anyarray |
+ stavalues3 | dbms_stats.anyarray |
+ stavalues4 | dbms_stats.anyarray |
+Indexes:
+ "column_stats_backup_pkey" PRIMARY KEY, btree (id, starelid, staattnum, stainherit)
+Foreign-key constraints:
+ "column_stats_backup_id_fkey" FOREIGN KEY (id) REFERENCES dbms_stats.backup_history(id) ON DELETE CASCADE
+ "column_stats_backup_id_fkey1" FOREIGN KEY (id, starelid) REFERENCES dbms_stats.relation_stats_backup(id, relid) ON DELETE CASCADE
+
+-- No.2-1-3
+\d dbms_stats._column_stats_locked
+ Table "dbms_stats._column_stats_locked"
+ Column | Type | Modifiers
+-------------+---------------------+-----------
+ starelid | oid | not null
+ staattnum | smallint | not null
+ stainherit | boolean | not null
+ stanullfrac | real |
+ stawidth | integer |
+ stadistinct | real |
+ stakind1 | smallint |
+ stakind2 | smallint |
+ stakind3 | smallint |
+ stakind4 | smallint |
+ staop1 | oid |
+ staop2 | oid |
+ staop3 | oid |
+ staop4 | oid |
+ stanumbers1 | real[] |
+ stanumbers2 | real[] |
+ stanumbers3 | real[] |
+ stanumbers4 | real[] |
+ stavalues1 | dbms_stats.anyarray |
+ stavalues2 | dbms_stats.anyarray |
+ stavalues3 | dbms_stats.anyarray |
+ stavalues4 | dbms_stats.anyarray |
+Indexes:
+ "_column_stats_locked_pkey" PRIMARY KEY, btree (starelid, staattnum, stainherit)
+Foreign-key constraints:
+ "_column_stats_locked_starelid_fkey" FOREIGN KEY (starelid) REFERENCES dbms_stats._relation_stats_locked(relid) ON DELETE CASCADE
+Triggers:
+ 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()
+
+-- No.2-1-4
+\d dbms_stats.relation_stats_backup
+ Table "dbms_stats.relation_stats_backup"
+ Column | Type | Modifiers
+------------------+--------------------------+-----------
+ id | bigint | not null
+ relid | oid | not null
+ relname | text | not null
+ relpages | integer | not null
+ reltuples | real | not null
+ curpages | integer | not null
+ last_analyze | timestamp with time zone |
+ last_autoanalyze | timestamp with time zone |
+Indexes:
+ "relation_stats_backup_pkey" PRIMARY KEY, btree (id, relid)
+Foreign-key constraints:
+ "relation_stats_backup_id_fkey" FOREIGN KEY (id) REFERENCES dbms_stats.backup_history(id) ON DELETE CASCADE
+Referenced by:
+ 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
+
+-- No.2-1-5
+\d dbms_stats._relation_stats_locked
+ Table "dbms_stats._relation_stats_locked"
+ Column | Type | Modifiers
+------------------+--------------------------+-----------
+ relid | oid | not null
+ relname | text | not null
+ relpages | integer |
+ reltuples | real |
+ curpages | integer |
+ last_analyze | timestamp with time zone |
+ last_autoanalyze | timestamp with time zone |
+Indexes:
+ "_relation_stats_locked_pkey" PRIMARY KEY, btree (relid)
+Referenced by:
+ 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
+Triggers:
+ 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()
+
+/*
+ * No.2-2 view definitions.
+ */
+-- No.2-2-1
+\dS+ dbms_stats.column_stats_effective
+ View "dbms_stats.column_stats_effective"
+ Column | Type | Modifiers | Storage | Description
+-------------+---------------------+-----------+----------+-------------
+ starelid | oid | | plain |
+ staattnum | smallint | | plain |
+ stainherit | boolean | | plain |
+ stanullfrac | real | | plain |
+ stawidth | integer | | plain |
+ stadistinct | real | | plain |
+ stakind1 | smallint | | plain |
+ stakind2 | smallint | | plain |
+ stakind3 | smallint | | plain |
+ stakind4 | smallint | | plain |
+ staop1 | oid | | plain |
+ staop2 | oid | | plain |
+ staop3 | oid | | plain |
+ staop4 | oid | | plain |
+ stanumbers1 | real[] | | extended |
+ stanumbers2 | real[] | | extended |
+ stanumbers3 | real[] | | extended |
+ stanumbers4 | real[] | | extended |
+ stavalues1 | dbms_stats.anyarray | | extended |
+ stavalues2 | dbms_stats.anyarray | | extended |
+ stavalues3 | dbms_stats.anyarray | | extended |
+ stavalues4 | dbms_stats.anyarray | | extended |
+View definition:
+ SELECT m.starelid, m.staattnum, m.stainherit, m.stanullfrac, m.stawidth, m.stadistinct, m.stakind1, m.stakind2, m.stakind3, m.stakind4, m.staop1, m.staop2, m.staop3, m.staop4, m.stanumbers1, m.stanumbers2, m.stanumbers3, m.stanumbers4, m.stavalues1, m.stavalues2, m.stavalues3, m.stavalues4
+ FROM ( SELECT (dbms_stats.merge(v.*, s.*)).starelid AS starelid, (dbms_stats.merge(v.*, s.*)).staattnum AS staattnum, (dbms_stats.merge(v.*, s.*)).stainherit AS stainherit, (dbms_stats.merge(v.*, s.*)).stanullfrac AS stanullfrac, (dbms_stats.merge(v.*, s.*)).stawidth AS stawidth, (dbms_stats.merge(v.*, s.*)).stadistinct AS stadistinct, (dbms_stats.merge(v.*, s.*)).stakind1 AS stakind1, (dbms_stats.merge(v.*, s.*)).stakind2 AS stakind2, (dbms_stats.merge(v.*, s.*)).stakind3 AS stakind3, (dbms_stats.merge(v.*, s.*)).stakind4 AS stakind4, (dbms_stats.merge(v.*, s.*)).staop1 AS staop1, (dbms_stats.merge(v.*, s.*)).staop2 AS staop2, (dbms_stats.merge(v.*, s.*)).staop3 AS staop3, (dbms_stats.merge(v.*, s.*)).staop4 AS staop4, (dbms_stats.merge(v.*, s.*)).stanumbers1 AS stanumbers1, (dbms_stats.merge(v.*, s.*)).stanumbers2 AS stanumbers2, (dbms_stats.merge(v.*, s.*)).stanumbers3 AS stanumbers3, (dbms_stats.merge(v.*, s.*)).stanumbers4 AS stanumbers4, (dbms_stats.merge(v.*, s.*)).stavalues1 AS stavalues1, (dbms_stats.merge(v.*, s.*)).stavalues2 AS stavalues2, (dbms_stats.merge(v.*, s.*)).stavalues3 AS stavalues3, (dbms_stats.merge(v.*, s.*)).stavalues4 AS stavalues4
+ FROM pg_statistic s
+ FULL JOIN dbms_stats._column_stats_locked v USING (starelid, staattnum, stainherit)
+ WHERE NOT dbms_stats.is_system_catalog(starelid::regclass)) m
+ WHERE m.starelid IS NOT NULL;
+
+-- No.2-2-2
+\dS+ dbms_stats.relation_stats_effective
+ View "dbms_stats.relation_stats_effective"
+ Column | Type | Modifiers | Storage | Description
+------------------+--------------------------+-----------+----------+-------------
+ relid | oid | | plain |
+ relname | text | | extended |
+ relpages | integer | | plain |
+ reltuples | real | | plain |
+ curpages | integer | | plain |
+ last_analyze | timestamp with time zone | | plain |
+ last_autoanalyze | timestamp with time zone | | plain |
+View definition:
+ SELECT c.oid AS relid, dbms_stats.relname(n.nspname::text, c.relname::text) AS relname, COALESCE(v.relpages, c.relpages) AS relpages, COALESCE(v.reltuples, c.reltuples) AS reltuples, COALESCE(v.curpages, (pg_relation_size(c.oid::regclass) / current_setting('block_size'::text)::integer)::integer) AS curpages, COALESCE(v.last_analyze, pg_stat_get_last_analyze_time(c.oid)) AS last_analyze, COALESCE(v.last_autoanalyze, pg_stat_get_last_autoanalyze_time(c.oid)) AS last_autoanalyze
+ FROM pg_class c
+ JOIN pg_namespace n ON c.relnamespace = n.oid
+ LEFT JOIN dbms_stats._relation_stats_locked v ON v.relid = c.oid
+ WHERE dbms_stats.is_target_relkind(c.relkind) AND NOT dbms_stats.is_system_schema(n.nspname::text);
+
+-- No.2-2-3
+\dS+ dbms_stats.stats
+ View "dbms_stats.stats"
+ Column | Type | Modifiers | Storage | Description
+-------------------+---------------------+-----------+----------+-------------
+ schemaname | name | | plain |
+ tablename | name | | plain |
+ attname | name | | plain |
+ inherited | boolean | | plain |
+ null_frac | real | | plain |
+ avg_width | integer | | plain |
+ n_distinct | real | | plain |
+ most_common_vals | dbms_stats.anyarray | | extended |
+ most_common_freqs | real[] | | extended |
+ histogram_bounds | dbms_stats.anyarray | | extended |
+ correlation | real | | plain |
+View definition:
+ SELECT n.nspname AS schemaname, c.relname AS tablename, a.attname, s.stainherit AS inherited, s.stanullfrac AS null_frac, s.stawidth AS avg_width, s.stadistinct AS n_distinct,
+ CASE
+ WHEN s.stakind1 = ANY (ARRAY[1, 4]) THEN s.stavalues1
+ WHEN s.stakind2 = ANY (ARRAY[1, 4]) THEN s.stavalues2
+ WHEN s.stakind3 = ANY (ARRAY[1, 4]) THEN s.stavalues3
+ WHEN s.stakind4 = ANY (ARRAY[1, 4]) THEN s.stavalues4
+ ELSE NULL::dbms_stats.anyarray
+ END AS most_common_vals,
+ CASE
+ WHEN s.stakind1 = ANY (ARRAY[1, 4]) THEN s.stanumbers1
+ WHEN s.stakind2 = ANY (ARRAY[1, 4]) THEN s.stanumbers2
+ WHEN s.stakind3 = ANY (ARRAY[1, 4]) THEN s.stanumbers3
+ WHEN s.stakind4 = ANY (ARRAY[1, 4]) THEN s.stanumbers4
+ ELSE NULL::real[]
+ END AS most_common_freqs,
+ CASE
+ WHEN s.stakind1 = 2 THEN s.stavalues1
+ WHEN s.stakind2 = 2 THEN s.stavalues2
+ WHEN s.stakind3 = 2 THEN s.stavalues3
+ WHEN s.stakind4 = 2 THEN s.stavalues4
+ ELSE NULL::dbms_stats.anyarray
+ END AS histogram_bounds,
+ CASE
+ WHEN s.stakind1 = 3 THEN s.stanumbers1[1]
+ WHEN s.stakind2 = 3 THEN s.stanumbers2[1]
+ WHEN s.stakind3 = 3 THEN s.stanumbers3[1]
+ WHEN s.stakind4 = 3 THEN s.stanumbers4[1]
+ ELSE NULL::real
+ END AS correlation
+ FROM dbms_stats.column_stats_effective s
+ JOIN pg_class c ON c.oid = s.starelid
+ JOIN pg_attribute a ON c.oid = a.attrelid AND a.attnum = s.staattnum
+ LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
+ WHERE NOT a.attisdropped AND has_column_privilege(c.oid, a.attnum, 'select'::text);
+
+-- No.2-2-4
+\dS+ dbms_stats.column_stats_locked
+ View "dbms_stats.column_stats_locked"
+ Column | Type | Modifiers | Storage | Description
+-------------+---------------------+-----------+----------+-------------
+ starelid | oid | | plain |
+ staattnum | smallint | | plain |
+ stainherit | boolean | | plain |
+ stanullfrac | real | | plain |
+ stawidth | integer | | plain |
+ stadistinct | real | | plain |
+ stakind1 | smallint | | plain |
+ stakind2 | smallint | | plain |
+ stakind3 | smallint | | plain |
+ stakind4 | smallint | | plain |
+ staop1 | oid | | plain |
+ staop2 | oid | | plain |
+ staop3 | oid | | plain |
+ staop4 | oid | | plain |
+ stanumbers1 | real[] | | extended |
+ stanumbers2 | real[] | | extended |
+ stanumbers3 | real[] | | extended |
+ stanumbers4 | real[] | | extended |
+ stavalues1 | dbms_stats.anyarray | | extended |
+ stavalues2 | dbms_stats.anyarray | | extended |
+ stavalues3 | dbms_stats.anyarray | | extended |
+ stavalues4 | dbms_stats.anyarray | | extended |
+View definition:
+ SELECT _column_stats_locked.starelid, _column_stats_locked.staattnum, _column_stats_locked.stainherit, _column_stats_locked.stanullfrac, _column_stats_locked.stawidth, _column_stats_locked.stadistinct, _column_stats_locked.stakind1, _column_stats_locked.stakind2, _column_stats_locked.stakind3, _column_stats_locked.stakind4, _column_stats_locked.staop1, _column_stats_locked.staop2, _column_stats_locked.staop3, _column_stats_locked.staop4, _column_stats_locked.stanumbers1, _column_stats_locked.stanumbers2, _column_stats_locked.stanumbers3, _column_stats_locked.stanumbers4, _column_stats_locked.stavalues1, _column_stats_locked.stavalues2, _column_stats_locked.stavalues3, _column_stats_locked.stavalues4
+ FROM dbms_stats._column_stats_locked
+ WHERE has_column_privilege(_column_stats_locked.starelid, _column_stats_locked.staattnum, 'SELECT'::text);
+
+-- No.2-2-5
+\dS+ dbms_stats.relation_stats_locked
+ View "dbms_stats.relation_stats_locked"
+ Column | Type | Modifiers | Storage | Description
+------------------+--------------------------+-----------+----------+-------------
+ relid | oid | | plain |
+ relname | text | | extended |
+ relpages | integer | | plain |
+ reltuples | real | | plain |
+ curpages | integer | | plain |
+ last_analyze | timestamp with time zone | | plain |
+ last_autoanalyze | timestamp with time zone | | plain |
+View definition:
+ SELECT _relation_stats_locked.relid, _relation_stats_locked.relname, _relation_stats_locked.relpages, _relation_stats_locked.reltuples, _relation_stats_locked.curpages, _relation_stats_locked.last_analyze, _relation_stats_locked.last_autoanalyze
+ FROM dbms_stats._relation_stats_locked;
+
+/*
+ * No.5-1 dbms_stats.merge
+ */
+UPDATE pg_statistic SET
+ stanullfrac = staattnum,
+ stawidth = staattnum,
+ stadistinct = staattnum,
+ stakind1 = 4,
+ stakind2 = 1,
+ stakind3 = 2,
+ stakind4 = 3,
+ staop1 = 14,
+ staop2 = 11,
+ staop3 = 12,
+ staop4 = 13,
+ stanumbers1 = ARRAY[staattnum,4],
+ stanumbers2 = ARRAY[staattnum,1],
+ stanumbers3 = ARRAY[staattnum,2],
+ stanumbers4 = ARRAY[staattnum,3],
+ stavalues2 = array_cat(stavalues1,stavalues1),
+ stavalues3 = array_cat(array_cat(stavalues1,stavalues1),stavalues1),
+ stavalues4 = array_cat(array_cat(array_cat(stavalues1,stavalues1),stavalues1),stavalues1)
+ WHERE starelid = 'st0'::regclass;
+SELECT dbms_stats.lock_table_stats('st0');
+ lock_table_stats
+------------------
+ st0
+(1 row)
+
+UPDATE dbms_stats._column_stats_locked SET
+ stainherit = 't',
+ stanullfrac = -staattnum,
+ stawidth = -staattnum,
+ stadistinct = -staattnum,
+ stakind1 = 2,
+ stakind2 = 3,
+ stakind3 = 4,
+ stakind4 = 1,
+ staop1 = 22,
+ staop2 = 23,
+ staop3 = 24,
+ staop4 = 21,
+ stanumbers1 = ARRAY[-staattnum,22],
+ stanumbers2 = ARRAY[-staattnum,23],
+ stanumbers3 = ARRAY[-staattnum,24],
+ stanumbers4 = ARRAY[-staattnum,21],
+ stavalues1 = stavalues3,
+ stavalues2 = stavalues2,
+ stavalues3 = stavalues1,
+ stavalues4 = stavalues4
+;
+/*
+ * Driver function dbms_stats.merge1
+ */
+CREATE FUNCTION dbms_stats.merge1(
+ lhs dbms_stats._column_stats_locked,
+ rhs pg_catalog.pg_statistic
+) RETURNS integer AS
+'$libdir/pg_dbms_stats', 'dbms_stats_merge'
+LANGUAGE C STABLE;
+SELECT * FROM columns_locked_v
+ WHERE starelid = 'st0'::regclass;
+ starelid | staattnum | attname | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+---------------------------+-------------------+------------+-----------------------------------
+ st0 | 1 | id | t | -1 | -1 | -1 | 2 | 3 | 4 | 1 | 22 | 23 | 24 | 21 | {-1,22} | {-1,23} | {-1,24} | {-1,21} | {1,2,1,2,1,2} | {1,2,1,2} | {1,2} | {1,2,1,2,1,2,1,2}
+ st0 | 2 | name | t | -2 | -2 | -2 | 2 | 3 | 4 | 1 | 22 | 23 | 24 | 21 | {-2,22} | {-2,23} | {-2,24} | {-2,21} | {"test ","test ","test "} | {"test ","test "} | {"test "} | {"test ","test ","test ","test "}
+(2 rows)
+
+SELECT * FROM plain_columns_statistic_v
+ WHERE starelid = 'st0'::regclass;
+ starelid | staattnum | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+----------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+------------+-------------------+---------------------------+-----------------------------------
+ st0 | 1 | f | 1 | 1 | 1 | 4 | 1 | 2 | 3 | 14 | 11 | 12 | 13 | {1,4} | {1,1} | {1,2} | {1,3} | {1,2} | {1,2,1,2} | {1,2,1,2,1,2} | {1,2,1,2,1,2,1,2}
+ st0 | 2 | f | 2 | 2 | 2 | 4 | 1 | 2 | 3 | 14 | 11 | 12 | 13 | {2,4} | {2,1} | {2,2} | {2,3} | {"test "} | {"test ","test "} | {"test ","test ","test "} | {"test ","test ","test ","test "}
+(2 rows)
+
+SET client_min_messages TO LOG;
+-- No.5-1-1
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ FROM (SELECT dbms_stats.merge(NULL, s)
+ FROM pg_statistic s
+ WHERE starelid = 'st0'::regclass
+ AND staattnum = '1'::int2) m;
+ starelid | staattnum | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+----------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+------------+------------+---------------+-------------------
+ st0 | 1 | f | 1 | 1 | 1 | 4 | 1 | 2 | 3 | 14 | 11 | 12 | 13 | {1,4} | {1,1} | {1,2} | {1,3} | {1,2} | {1,2,1,2} | {1,2,1,2,1,2} | {1,2,1,2,1,2,1,2}
+(1 row)
+
+-- No.5-1-2
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ FROM (SELECT dbms_stats.merge(v, NULL)
+ FROM dbms_stats._column_stats_locked v
+ WHERE starelid = 'st0'::regclass
+ AND staattnum = '2'::int2) m;
+ starelid | staattnum | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+----------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+---------------------------+-------------------+------------+-----------------------------------
+ st0 | 2 | t | -2 | -2 | -2 | 2 | 3 | 4 | 1 | 22 | 23 | 24 | 21 | {-2,22} | {-2,23} | {-2,24} | {-2,21} | {"test ","test ","test "} | {"test ","test "} | {"test "} | {"test ","test ","test ","test "}
+(1 row)
+
+-- No.5-1-3
+SELECT dbms_stats.merge(NULL, NULL);
+ merge
+--------
+ (null)
+(1 row)
+
+-- No.5-1-4
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ FROM (SELECT dbms_stats.merge(v, s)
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '2'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2) m;
+ starelid | staattnum | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+----------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+---------------------------+-------------------+------------+-----------------------------------
+ st0 | 2 | t | -2 | -2 | -2 | 2 | 3 | 4 | 1 | 22 | 23 | 24 | 21 | {-2,22} | {-2,23} | {-2,24} | {-2,21} | {"test ","test ","test "} | {"test ","test "} | {"test "} | {"test ","test ","test ","test "}
+(1 row)
+
+-- No.5-1-5
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ FROM (SELECT dbms_stats.merge(v, s)
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '2'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2) m;
+ starelid | staattnum | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+----------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+---------------------------+-------------------+------------+-----------------------------------
+ st0 | 2 | t | -2 | -2 | -2 | 2 | 3 | 4 | 1 | 22 | 23 | 24 | 21 | {-2,22} | {-2,23} | {-2,24} | {-2,21} | {"test ","test ","test "} | {"test ","test "} | {"test "} | {"test ","test ","test ","test "}
+(1 row)
+
+-- No.5-1-6
+SELECT dbms_stats.merge1(v, s)
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '2'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2;
+ERROR: return type must be a row type
+-- No.5-1-7
+SELECT dbms_stats.merge(NULL, (
+ s.starelid::regclass, s.staattnum, s.stainherit,
+ s.stanullfrac, s.stawidth, s.stadistinct,
+ s.stakind1, s.stakind2, s.stakind3, s.stakind4,
+ s.staop1, s.staop2, s.staop3,
+ NULL, s.stanumbers1, s.stanumbers2, s.stanumbers3, s.stanumbers4,
+ s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
+ ))
+ FROM pg_statistic s
+ WHERE s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2;
+ merge
+--------
+ (null)
+(1 row)
+
+-- No.5-1-8
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ FROM (SELECT dbms_stats.merge(NULL, (
+ s.starelid::regclass, s.staattnum, s.stainherit,
+ s.stanullfrac, s.stawidth, s.stadistinct,
+ s.stakind1, s.stakind2, s.stakind3, s.stakind4,
+ s.staop1, s.staop2, s.staop3, s.staop4,
+ NULL, s.stanumbers2, s.stanumbers3, s.stanumbers4,
+ s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
+ ))
+ FROM pg_statistic s
+ WHERE s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2) m;
+ starelid | staattnum | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+----------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+------------+------------+---------------+-------------------
+ st0 | 1 | f | 1 | 1 | 1 | 4 | 1 | 2 | 3 | 14 | 11 | 12 | 13 | (null) | {1,1} | {1,2} | {1,3} | {1,2} | {1,2,1,2} | {1,2,1,2,1,2} | {1,2,1,2,1,2,1,2}
+(1 row)
+
+-- No.5-1-9
+SELECT dbms_stats.merge((
+ v.starelid::regclass, v.staattnum, v.stainherit,
+ v.stanullfrac, v.stawidth, v.stadistinct,
+ v.stakind1, v.stakind2, v.stakind3, v.stakind4,
+ v.staop1, v.staop2, v.staop3,
+ NULL, v.stanumbers1, v.stanumbers2, v.stanumbers3, v.stanumbers4,
+ v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
+ ), NULL)
+ FROM dbms_stats._column_stats_locked v
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '2'::int2;
+ merge
+--------
+ (null)
+(1 row)
+
+-- No.5-1-10
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ FROM (SELECT dbms_stats.merge((
+ v.starelid::regclass, v.staattnum, v.stainherit,
+ v.stanullfrac, v.stawidth, v.stadistinct,
+ v.stakind1, v.stakind2, v.stakind3, v.stakind4,
+ v.staop1, v.staop2, v.staop3, v.staop4,
+ NULL, v.stanumbers2, v.stanumbers3, v.stanumbers4,
+ v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
+ ), NULL)
+ FROM dbms_stats._column_stats_locked v
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '2'::int2) m;
+ starelid | staattnum | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+----------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+---------------------------+-------------------+------------+-----------------------------------
+ st0 | 2 | t | -2 | -2 | -2 | 2 | 3 | 4 | 1 | 22 | 23 | 24 | 21 | (null) | {-2,23} | {-2,24} | {-2,21} | {"test ","test ","test "} | {"test ","test "} | {"test "} | {"test ","test ","test ","test "}
+(1 row)
+
+-- No.5-1-11
+SELECT dbms_stats.merge((
+ v.starelid::regclass, v.staattnum, v.stainherit,
+ v.stanullfrac, v.stawidth, v.stadistinct,
+ v.stakind1, v.stakind2, v.stakind3, v.stakind4,
+ v.staop1, v.staop2, v.staop3,
+ NULL, v.stanumbers1, v.stanumbers2, v.stanumbers3, v.stanumbers4,
+ v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
+ ), (
+ s.starelid::regclass, s.staattnum, s.stainherit,
+ s.stanullfrac, s.stawidth, s.stadistinct,
+ s.stakind1, s.stakind2, s.stakind3, s.stakind4,
+ s.staop1, s.staop2, s.staop3,
+ NULL, s.stanumbers1, s.stanumbers2, s.stanumbers3, s.stanumbers4,
+ s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
+ ))
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '2'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2;
+LOG: pg_dbms_stats: bad statistics
+DETAIL: column "staop4" should not be null
+ merge
+--------
+ (null)
+(1 row)
+
+-- No.5-1-12
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ FROM (SELECT dbms_stats.merge((
+ v.starelid::regclass, v.staattnum, v.stainherit,
+ v.stanullfrac, v.stawidth, v.stadistinct,
+ v.stakind1, v.stakind2, v.stakind3, v.stakind4,
+ v.staop1, v.staop2, v.staop3, v.staop4,
+ NULL, v.stanumbers2, v.stanumbers3, v.stanumbers4,
+ v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
+ ), (
+ s.starelid::regclass, s.staattnum, s.stainherit,
+ s.stanullfrac, s.stawidth, s.stadistinct,
+ s.stakind1, s.stakind2, s.stakind3, s.stakind4,
+ s.staop1, s.staop2, s.staop3, s.staop4,
+ NULL, s.stanumbers2, s.stanumbers3, s.stanumbers4,
+ s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
+ ))
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '2'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2) m;
+ starelid | staattnum | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+----------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+---------------------------+-------------------+------------+-----------------------------------
+ st0 | 2 | t | -2 | -2 | -2 | 2 | 3 | 4 | 1 | 22 | 23 | 24 | 21 | (null) | {-2,23} | {-2,24} | {-2,21} | {"test ","test ","test "} | {"test ","test "} | {"test "} | {"test ","test ","test ","test "}
+(1 row)
+
+-- No.5-1-13
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ FROM (SELECT dbms_stats.merge((
+ NULL, NULL, NULL,
+ NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL
+ ), s)
+ FROM pg_statistic s
+ WHERE s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2) m;
+ starelid | staattnum | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+----------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+------------+------------+---------------+-------------------
+ st0 | 1 | f | 1 | 1 | 1 | 4 | 1 | 2 | 3 | 14 | 11 | 12 | 13 | {1,4} | {1,1} | {1,2} | {1,3} | {1,2} | {1,2,1,2} | {1,2,1,2,1,2} | {1,2,1,2,1,2,1,2}
+(1 row)
+
+-- No.5-1-14
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ FROM (SELECT dbms_stats.merge(v, (
+ NULL, NULL, NULL,
+ NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL))
+ FROM dbms_stats._column_stats_locked v
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '2'::int2) m;
+ starelid | staattnum | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+----------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+---------------------------+-------------------+------------+-----------------------------------
+ st0 | 2 | t | -2 | -2 | -2 | 2 | 3 | 4 | 1 | 22 | 23 | 24 | 21 | {-2,22} | {-2,23} | {-2,24} | {-2,21} | {"test ","test ","test "} | {"test ","test "} | {"test "} | {"test ","test ","test ","test "}
+(1 row)
+
+-- No.5-1-15
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ FROM (SELECT dbms_stats.merge(v, s)
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '2'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2) m;
+ starelid | staattnum | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+----------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+---------------------------+-------------------+------------+-----------------------------------
+ st0 | 2 | t | -2 | -2 | -2 | 2 | 3 | 4 | 1 | 22 | 23 | 24 | 21 | {-2,22} | {-2,23} | {-2,24} | {-2,21} | {"test ","test ","test "} | {"test ","test "} | {"test "} | {"test ","test ","test ","test "}
+(1 row)
+
+-- No.5-1-16
+SELECT dbms_stats.merge((
+ v.starelid::regclass, v.staattnum, v.stainherit,
+ v.stanullfrac, v.stawidth, v.stadistinct,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL
+ ), (
+ s.starelid::regclass, s.staattnum, s.stainherit,
+ s.stanullfrac, s.stawidth, s.stadistinct,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL))
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '2'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2;
+LOG: pg_dbms_stats: bad statistics
+DETAIL: column "stakind1" should not be null
+ merge
+--------
+ (null)
+(1 row)
+
+-- No.5-1-17
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ FROM (SELECT dbms_stats.merge((
+ v.starelid::regclass, v.staattnum, v.stainherit,
+ v.stanullfrac, v.stawidth, v.stadistinct,
+ v.stakind1, v.stakind2, v.stakind3, v.stakind4,
+ v.staop1, v.staop2, v.staop3,
+ NULL, v.stanumbers1, v.stanumbers2, v.stanumbers3, v.stanumbers4,
+ v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
+ ), (
+ s.starelid::regclass, s.staattnum, s.stainherit,
+ s.stanullfrac, s.stawidth, s.stadistinct,
+ s.stakind1, s.stakind2, s.stakind3, s.stakind4,
+ s.staop1, s.staop2, s.staop3, s.staop4,
+ s.stanumbers1, s.stanumbers2, s.stanumbers3, s.stanumbers4,
+ s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
+ ))
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '1'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2) m;
+ starelid | staattnum | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+----------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+------------+------------+---------------+-------------------
+ st0 | 1 | t | -1 | -1 | -1 | 4 | 1 | 2 | 3 | 14 | 11 | 12 | 13 | {1,4} | {1,1} | {1,2} | {1,3} | {1,2} | {1,2,1,2} | {1,2,1,2,1,2} | {1,2,1,2,1,2,1,2}
+(1 row)
+
+-- No.5-1-18
+SELECT dbms_stats.merge((
+ v.starelid::regclass, v.staattnum, v.stainherit,
+ v.stanullfrac, v.stawidth, v.stadistinct,
+ v.stakind1, v.stakind2, v.stakind3, v.stakind4,
+ v.staop1, v.staop2, v.staop3,
+ NULL, v.stanumbers1, v.stanumbers2, v.stanumbers3, v.stanumbers4,
+ v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
+ ), (
+ s.starelid::regclass, s.staattnum, s.stainherit,
+ s.stanullfrac, s.stawidth, s.stadistinct,
+ s.stakind1, s.stakind2, s.stakind3, s.stakind4,
+ s.staop1, s.staop2, s.staop3,
+ NULL, s.stanumbers1, s.stanumbers2, s.stanumbers3, s.stanumbers4,
+ s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
+ ))
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '1'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2;
+LOG: pg_dbms_stats: bad statistics
+DETAIL: column "staop4" should not be null
+ merge
+--------
+ (null)
+(1 row)
+
+-- No.5-1-19
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ FROM (SELECT dbms_stats.merge((
+ v.starelid::regclass, v.staattnum, v.stainherit,
+ v.stanullfrac, v.stawidth, v.stadistinct,
+ '1', '1', '1', '1',
+ v.staop1, v.staop2, v.staop3, v.staop4,
+ v.stanumbers1, v.stanumbers2, v.stanumbers3, v.stanumbers4,
+ v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
+ ), (
+ s.starelid::regclass, s.staattnum, s.stainherit,
+ s.stanullfrac, s.stawidth, s.stadistinct,
+ '1', '1', '1', '1',
+ s.staop1, s.staop2, s.staop3, s.staop4,
+ s.stanumbers1, s.stanumbers2, s.stanumbers3, s.stanumbers4,
+ s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
+ ))
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '2'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2) m;
+ starelid | staattnum | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+----------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+---------------------------+-------------------+------------+-----------------------------------
+ st0 | 2 | t | -2 | -2 | -2 | 1 | 1 | 1 | 1 | 22 | 23 | 24 | 21 | {-2,22} | {-2,23} | {-2,24} | {-2,21} | {"test ","test ","test "} | {"test ","test "} | {"test "} | {"test ","test ","test ","test "}
+(1 row)
+
+-- No.5-1-20
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ FROM (SELECT dbms_stats.merge((v.starelid::regclass, v.staattnum, v.stainherit,
+ v.stanullfrac, v.stawidth, v.stadistinct,
+ '2', '2', '2', '2',
+ v.staop1, v.staop2, v.staop3, v.staop4,
+ v.stanumbers1, v.stanumbers2, v.stanumbers3, v.stanumbers4,
+ v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
+ ), (
+ s.starelid::regclass, s.staattnum, s.stainherit,
+ s.stanullfrac, s.stawidth, s.stadistinct,
+ '2', '2', '2', '2',
+ s.staop1, s.staop2, s.staop3, s.staop4,
+ s.stanumbers1, s.stanumbers2, s.stanumbers3, s.stanumbers4,
+ s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
+ ))
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '2'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2) m;
+ starelid | staattnum | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+----------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+---------------------------+-------------------+------------+-----------------------------------
+ st0 | 2 | t | -2 | -2 | -2 | 2 | 2 | 2 | 2 | 22 | 23 | 24 | 21 | {-2,22} | {-2,23} | {-2,24} | {-2,21} | {"test ","test ","test "} | {"test ","test "} | {"test "} | {"test ","test ","test ","test "}
+(1 row)
+
+-- No.5-1-21
+SELECT dbms_stats.merge((v.starelid::regclass, '2', v.stainherit,
+ v.stanullfrac, v.stawidth, v.stadistinct,
+ '1', '1', '1', '1',
+ v.staop1, v.staop2, v.staop3, v.staop4,
+ v.stanumbers1, v.stanumbers2, v.stanumbers3, v.stanumbers4,
+ v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
+ ), (
+ s.starelid::regclass, s.staattnum, s.stainherit,
+ s.stanullfrac, s.stawidth, s.stadistinct,
+ '1', '1', '1', '1',
+ s.staop1, s.staop2, s.staop3, s.staop4,
+ s.stanumbers1, s.stanumbers2, s.stanumbers3, s.stanumbers4,
+ s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
+ ))
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '1'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2;
+LOG: pg_dbms_stats: bad column type
+DETAIL: type of column "name" has been changed
+HINT: need to execute dbms_stats.unlock('st0', 'name')
+ merge
+--------
+ (null)
+(1 row)
+
+-- No.5-1-22
+SELECT dbms_stats.merge((v.starelid::regclass, '2', v.stainherit,
+ v.stanullfrac, v.stawidth, v.stadistinct,
+ '2', '2', '2', '2',
+ v.staop1, v.staop2, v.staop3, v.staop4,
+ v.stanumbers1, v.stanumbers2, v.stanumbers3, v.stanumbers4,
+ v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
+ ), (
+ s.starelid::regclass, s.staattnum, s.stainherit,
+ s.stanullfrac, s.stawidth, s.stadistinct,
+ '2', '2', '2', '2',
+ s.staop1, s.staop2, s.staop3, s.staop4,
+ s.stanumbers1, s.stanumbers2, s.stanumbers3, s.stanumbers4,
+ s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
+ ))
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '1'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2;
+LOG: pg_dbms_stats: bad column type
+DETAIL: type of column "name" has been changed
+HINT: need to execute dbms_stats.unlock('st0', 'name')
+ merge
+--------
+ (null)
+(1 row)
+
+RESET client_min_messages;
+SELECT dbms_stats.unlock_database_stats();
+ unlock_database_stats
+-----------------------
+ st0
+(1 row)
+
+/*
+ * No.6-4 dbms_stats.is_target_relkind
+ */
+-- No.6-4-10
+SELECT dbms_stats.is_target_relkind('f');
+ is_target_relkind
+-------------------
+ f
+(1 row)
+
+/*
+ * No.7-1 dbms_stats.backup
+ */
+DELETE FROM dbms_stats.backup_history;
+INSERT INTO dbms_stats.backup_history(id, time, unit) values(1, '2012-01-01', 'd');
+-- No.7-1-9
+SELECT dbms_stats.backup(1, 's0.sft0'::regclass, NULL);
+ backup
+--------
+ 1
+(1 row)
+
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+ count
+-------
+ 0
+(1 row)
+
+-- No.7-1-11
+DELETE FROM dbms_stats.relation_stats_backup;
+SELECT dbms_stats.backup(1, NULL, 1::int2);
+ backup
+--------
+ 1
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats.relation_stats_backup
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s1.st0
+ st1_idx
+ st1_exp
+(14 rows)
+
+SELECT starelid::regclass, staattnum FROM dbms_stats.column_stats_backup
+ GROUP BY starelid, staattnum
+ ORDER BY starelid, staattnum;
+ starelid | staattnum
+----------+-----------
+ st0 | 1
+ st1 | 1
+ s0.st0 | 1
+ s0.st1 | 1
+ s0.st2 | 1
+ s1.st0 | 1
+ st1_exp | 1
+(7 rows)
+
+-- No.7-1-13
+DELETE FROM dbms_stats.relation_stats_backup;
+SELECT dbms_stats.backup(1, NULL::regclass, NULL);
+ backup
+--------
+ 1
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats.relation_stats_backup
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s1.st0
+ st1_idx
+ st1_exp
+(14 rows)
+
+SELECT starelid::regclass, staattnum FROM dbms_stats.column_stats_backup
+ GROUP BY starelid, staattnum
+ ORDER BY starelid, staattnum;
+ starelid | staattnum
+----------+-----------
+ st0 | 1
+ st0 | 2
+ st1 | 1
+ st1 | 2
+ s0.st0 | 1
+ s0.st0 | 2
+ s0.st1 | 1
+ s0.st1 | 2
+ s0.st2 | 1
+ s0.st2 | 2
+ s1.st0 | 1
+ s1.st0 | 2
+ st1_exp | 1
+(13 rows)
+
+-- No.7-1-17
+DELETE FROM dbms_stats.relation_stats_backup;
+SELECT dbms_stats.backup(NULL, 's0.st0'::regclass, NULL);
+ERROR: null value in column "id" violates not-null constraint
+CONTEXT: SQL function "backup" statement 1
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+ count
+-------
+ 0
+(1 row)
+
+/*
+ * No.8-1 dbms_stats.backup
+ */
+SELECT setval('dbms_stats.backup_history_id_seq',1, false);
+ setval
+--------
+ 1
+(1 row)
+
+/*
+ * Stab function dbms_stats.backup
+ */
+ALTER FUNCTION dbms_stats.backup(
+ backup_id int8,
+ relid regclass,
+ attnum int2)
+ RENAME TO truth_func_backup;
+CREATE OR REPLACE FUNCTION dbms_stats.backup(
+ backup_id int8,
+ regclass,
+ attnum int2)
+RETURNS int8 AS
+$$
+BEGIN
+ RAISE NOTICE 'arguments are %, %, %', $1, $2, $3;
+ RETURN 1;
+END;
+$$
+LANGUAGE plpgsql;
+-- No.8-1-1
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup('s0.st0'::regclass, 'id', 'dummy comment');
+NOTICE: arguments are 1, s0.st0, 1
+CONTEXT: SQL statement "INSERT INTO dbms_stats.backup_history(time, unit, comment)
+ VALUES (current_timestamp, unit_type, $3)
+ RETURNING dbms_stats.backup(id, $1, set_attnum)"
+PL/pgSQL function "backup" line 42 at SQL statement
+ backup
+--------
+ 1
+(1 row)
+
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+ id | unit | comment
+----+------+---------------
+ 1 | c | dummy comment
+(1 row)
+
+-- No.8-1-2
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup('s0.st0'::regclass, NULL, 'dummy comment');
+NOTICE: arguments are 2, s0.st0,
+CONTEXT: SQL statement "INSERT INTO dbms_stats.backup_history(time, unit, comment)
+ VALUES (current_timestamp, unit_type, $3)
+ RETURNING dbms_stats.backup(id, $1, set_attnum)"
+PL/pgSQL function "backup" line 42 at SQL statement
+ backup
+--------
+ 1
+(1 row)
+
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+ id | unit | comment
+----+------+---------------
+ 2 | t | dummy comment
+(1 row)
+
+-- No.8-1-3
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup(NULL::regclass, 'id', 'dummy comment');
+ERROR: relation is required
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+ id | unit | comment
+----+------+---------
+(0 rows)
+
+-- No.8-1-4
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup(NULL::regclass, NULL, 'dummy comment');
+NOTICE: arguments are 3, ,
+CONTEXT: SQL statement "INSERT INTO dbms_stats.backup_history(time, unit, comment)
+ VALUES (current_timestamp, unit_type, $3)
+ RETURNING dbms_stats.backup(id, $1, set_attnum)"
+PL/pgSQL function "backup" line 42 at SQL statement
+ backup
+--------
+ 1
+(1 row)
+
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+ id | unit | comment
+----+------+---------------
+ 3 | d | dummy comment
+(1 row)
+
+-- No.8-1-5
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup(0, NULL, 'dummy comment');
+ERROR: relation "-" does not exist
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+ id | unit | comment
+----+------+---------
+(0 rows)
+
+-- No.8-1-6
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup('s0.st0'::regclass, NULL, 'dummy comment');
+NOTICE: arguments are 4, s0.st0,
+CONTEXT: SQL statement "INSERT INTO dbms_stats.backup_history(time, unit, comment)
+ VALUES (current_timestamp, unit_type, $3)
+ RETURNING dbms_stats.backup(id, $1, set_attnum)"
+PL/pgSQL function "backup" line 42 at SQL statement
+ backup
+--------
+ 1
+(1 row)
+
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+ id | unit | comment
+----+------+---------------
+ 4 | t | dummy comment
+(1 row)
+
+-- No.8-1-7
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup(
+ 'pg_toast.pg_toast_2618'::regclass,
+ NULL,
+ 'dummy comment');
+ERROR: can not backup statistics of "pg_toast.pg_toast_2618" with relkind "t"
+HINT: only tables and indexes are supported
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+ id | unit | comment
+----+------+---------
+(0 rows)
+
+-- No.8-1-8
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup('s0.st0_idx'::regclass, NULL, 'dummy comment');
+NOTICE: arguments are 5, s0.st0_idx,
+CONTEXT: SQL statement "INSERT INTO dbms_stats.backup_history(time, unit, comment)
+ VALUES (current_timestamp, unit_type, $3)
+ RETURNING dbms_stats.backup(id, $1, set_attnum)"
+PL/pgSQL function "backup" line 42 at SQL statement
+ backup
+--------
+ 1
+(1 row)
+
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+ id | unit | comment
+----+------+---------------
+ 5 | t | dummy comment
+(1 row)
+
+-- No.8-1-9
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup('s0.ss0'::regclass, NULL, 'dummy comment');
+ERROR: can not backup statistics of "s0.ss0" with relkind "S"
+HINT: only tables and indexes are supported
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+ id | unit | comment
+----+------+---------
+(0 rows)
+
+-- No.8-1-10
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup('s0.sc0'::regclass, NULL, 'dummy comment');
+ERROR: can not backup statistics of "s0.sc0" with relkind "c"
+HINT: only tables and indexes are supported
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+ id | unit | comment
+----+------+---------
+(0 rows)
+
+-- No.8-1-11
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup('s0.sft0'::regclass, NULL, 'dummy comment');
+ERROR: can not backup statistics of "s0.sft0" with relkind "f"
+HINT: only tables and indexes are supported
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+ id | unit | comment
+----+------+---------
+(0 rows)
+
+-- No.8-1-12
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup('pg_catalog.pg_class'::regclass, NULL, 'dummy comment');
+ERROR: can not backup statistics of system catalog "pg_class"
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+ id | unit | comment
+----+------+---------
+(0 rows)
+
+-- No.8-1-13
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup('s0.st0'::regclass, 'dummy', 'dummy comment');
+ERROR: column "dummy" of "s0.st0" does not exist
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+ id | unit | comment
+----+------+---------
+(0 rows)
+
+-- No.8-1-14
+DELETE FROM dbms_stats.backup_history;
+DELETE FROM pg_statistic
+ WHERE starelid = 's0.st0'::regclass
+ AND staattnum = 1::int2;
+SELECT count(*) FROM dbms_stats.column_stats_effective
+ WHERE starelid = 's0.st0'::regclass
+ AND staattnum = 1::int2;
+ count
+-------
+ 0
+(1 row)
+
+SELECT dbms_stats.backup('s0.st0'::regclass, 'id', 'dummy comment');
+ERROR: statistic for column "id" of "s0.st0" does not exist
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+ id | unit | comment
+----+------+---------
+(0 rows)
+
+/*
+ * Stab function dbms_stats.backup
+ */
+ALTER FUNCTION dbms_stats.backup(
+ relid regclass,
+ attname text,
+ comment text)
+ RENAME TO truth_func_backup;
+CREATE OR REPLACE FUNCTION dbms_stats.backup(
+ relid regclass DEFAULT NULL,
+ attname text DEFAULT NULL,
+ comment text DEFAULT NULL)
+RETURNS int8 AS
+$$
+BEGIN
+ IF $3 = '' THEN
+ RAISE NOTICE 'third argument is not NULL but string ""';
+ END IF;
+ RAISE NOTICE 'arguments are %, %, %', $1, $2, $3;
+ RETURN 1;
+END;
+$$
+LANGUAGE plpgsql;
+/*
+ * No.8-3 dbms_stats.backup_schema_stats
+ */
+SELECT setval('dbms_stats.backup_history_id_seq',9, false);
+ setval
+--------
+ 9
+(1 row)
+
+-- No.8-3-1
+SELECT dbms_stats.backup_schema_stats('s0', 'comment');
+NOTICE: arguments are 9, s0.st0,
+CONTEXT: SQL statement "SELECT dbms_stats.backup(backup_id, cn.oid, NULL)
+ FROM (SELECT c.oid
+ FROM pg_catalog.pg_class c,
+ pg_catalog.pg_namespace n
+ WHERE n.nspname = schemaname
+ AND c.relnamespace = n.oid
+ AND dbms_stats.is_target_relkind(c.relkind)
+ ORDER BY c.oid
+ ) cn"
+PL/pgSQL function "backup_schema_stats" line 16 at PERFORM
+NOTICE: arguments are 9, s0.st0_idx,
+CONTEXT: SQL statement "SELECT dbms_stats.backup(backup_id, cn.oid, NULL)
+ FROM (SELECT c.oid
+ FROM pg_catalog.pg_class c,
+ pg_catalog.pg_namespace n
+ WHERE n.nspname = schemaname
+ AND c.relnamespace = n.oid
+ AND dbms_stats.is_target_relkind(c.relkind)
+ ORDER BY c.oid
+ ) cn"
+PL/pgSQL function "backup_schema_stats" line 16 at PERFORM
+NOTICE: arguments are 9, s0.st1,
+CONTEXT: SQL statement "SELECT dbms_stats.backup(backup_id, cn.oid, NULL)
+ FROM (SELECT c.oid
+ FROM pg_catalog.pg_class c,
+ pg_catalog.pg_namespace n
+ WHERE n.nspname = schemaname
+ AND c.relnamespace = n.oid
+ AND dbms_stats.is_target_relkind(c.relkind)
+ ORDER BY c.oid
+ ) cn"
+PL/pgSQL function "backup_schema_stats" line 16 at PERFORM
+NOTICE: arguments are 9, s0.st1_idx,
+CONTEXT: SQL statement "SELECT dbms_stats.backup(backup_id, cn.oid, NULL)
+ FROM (SELECT c.oid
+ FROM pg_catalog.pg_class c,
+ pg_catalog.pg_namespace n
+ WHERE n.nspname = schemaname
+ AND c.relnamespace = n.oid
+ AND dbms_stats.is_target_relkind(c.relkind)
+ ORDER BY c.oid
+ ) cn"
+PL/pgSQL function "backup_schema_stats" line 16 at PERFORM
+NOTICE: arguments are 9, s0.st2,
+CONTEXT: SQL statement "SELECT dbms_stats.backup(backup_id, cn.oid, NULL)
+ FROM (SELECT c.oid
+ FROM pg_catalog.pg_class c,
+ pg_catalog.pg_namespace n
+ WHERE n.nspname = schemaname
+ AND c.relnamespace = n.oid
+ AND dbms_stats.is_target_relkind(c.relkind)
+ ORDER BY c.oid
+ ) cn"
+PL/pgSQL function "backup_schema_stats" line 16 at PERFORM
+NOTICE: arguments are 9, s0.st2_idx,
+CONTEXT: SQL statement "SELECT dbms_stats.backup(backup_id, cn.oid, NULL)
+ FROM (SELECT c.oid
+ FROM pg_catalog.pg_class c,
+ pg_catalog.pg_namespace n
+ WHERE n.nspname = schemaname
+ AND c.relnamespace = n.oid
+ AND dbms_stats.is_target_relkind(c.relkind)
+ ORDER BY c.oid
+ ) cn"
+PL/pgSQL function "backup_schema_stats" line 16 at PERFORM
+ backup_schema_stats
+---------------------
+ 9
+(1 row)
+
+SELECT id, unit, comment FROM dbms_stats.backup_history
+ ORDER BY id DESC
+ LIMIT 1;
+ id | unit | comment
+----+------+---------
+ 9 | s | comment
+(1 row)
+
+-- No.8-3-2
+SELECT dbms_stats.backup_schema_stats('s00', 'comment');
+ERROR: schema "s00" does not exist
+SELECT id, unit, comment FROM dbms_stats.backup_history
+ ORDER BY id DESC
+ LIMIT 1;
+ id | unit | comment
+----+------+---------
+ 9 | s | comment
+(1 row)
+
+-- No.8-3-3
+SELECT dbms_stats.backup_schema_stats('pg_catalog', 'comment');
+ERROR: can not backup statistics of relation in system schema "pg_catalog"
+SELECT id, unit, comment FROM dbms_stats.backup_history
+ ORDER BY id DESC
+ LIMIT 1;
+ id | unit | comment
+----+------+---------
+ 9 | s | comment
+(1 row)
+
+/*
+ * Delete stab function dbms_stats.backup
+ */
+DROP FUNCTION dbms_stats.backup(
+ backup_id int8,
+ regclass,
+ attnum int2);
+ALTER FUNCTION dbms_stats.truth_func_backup(
+ backup_id int8,
+ regclass,
+ attnum int2)
+ RENAME TO backup;
+DROP FUNCTION dbms_stats.backup(
+ regclass,
+ attname text,
+ comment text);
+ALTER FUNCTION dbms_stats.truth_func_backup(
+ regclass,
+ attname text,
+ comment text)
+ RENAME TO backup;
+VACUUM ANALYZE;
+/*
+ * create backup statistics state A
+ */
+DELETE FROM dbms_stats.backup_history;
+INSERT INTO dbms_stats.backup_history(id, time, unit)
+ VALUES (1, '2012-02-29 23:59:56.999999', 'd');
+SELECT setval('dbms_stats.backup_history_id_seq',1);
+ setval
+--------
+ 1
+(1 row)
+
+SELECT dbms_stats.backup();
+ backup
+--------
+ 2
+(1 row)
+
+UPDATE dbms_stats.backup_history
+ SET time = '2012-02-29 23:59:57'
+ WHERE id = 2;
+SELECT dbms_stats.backup('s0.st0');
+ backup
+--------
+ 3
+(1 row)
+
+UPDATE dbms_stats.backup_history
+ SET time = '2012-02-29 23:59:57.000001'
+ WHERE id = 3;
+SELECT dbms_stats.backup();
+ backup
+--------
+ 4
+(1 row)
+
+UPDATE dbms_stats.backup_history
+ SET time = '2012-02-29 23:59:58'
+ WHERE id = 4;
+DELETE FROM dbms_stats.relation_stats_backup
+ WHERE id = 4;
+SELECT dbms_stats.backup('s0.st0', 'id');
+ backup
+--------
+ 5
+(1 row)
+
+UPDATE dbms_stats.backup_history
+ SET time = '2012-03-01 00:00:00'
+ WHERE id = 5;
+SELECT dbms_stats.backup('s0.st0');
+ backup
+--------
+ 6
+(1 row)
+
+UPDATE dbms_stats.backup_history
+ SET time = '2012-03-01 00:00:02'
+ WHERE id = 6;
+SELECT dbms_stats.backup('public.st0');
+ backup
+--------
+ 7
+(1 row)
+
+UPDATE dbms_stats.backup_history
+ SET time = '2012-03-01 00:00:04'
+ WHERE id = 7;
+INSERT INTO dbms_stats.backup_history(time, unit)
+ VALUES ('2012-03-01 00:00:06', 's');
+SELECT dbms_stats.backup(8, c.oid, NULL)
+ FROM pg_catalog.pg_class c,
+ pg_catalog.pg_namespace n
+ WHERE n.nspname = 's0'
+ AND c.relnamespace = n.oid
+ AND c.relkind IN ('r', 'i');
+ backup
+--------
+ 8
+ 8
+ 8
+ 8
+ 8
+ 8
+(6 rows)
+
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+ id | time | unit | comment
+----+-------------------------------------+------+---------
+ 1 | Wed Feb 29 23:59:56.999999 2012 PST | d | (null)
+ 2 | Wed Feb 29 23:59:57 2012 PST | d | (null)
+ 3 | Wed Feb 29 23:59:57.000001 2012 PST | t | (null)
+ 4 | Wed Feb 29 23:59:58 2012 PST | d | (null)
+ 5 | Thu Mar 01 00:00:00 2012 PST | c | (null)
+ 6 | Thu Mar 01 00:00:02 2012 PST | t | (null)
+ 7 | Thu Mar 01 00:00:04 2012 PST | t | (null)
+ 8 | Thu Mar 01 00:00:06 2012 PST | s | (null)
+(8 rows)
+
+SELECT * FROM relations_backup_v;
+ id | relid | relname | relpages | reltuples | curpages
+----+------------+----------------+----------+-----------+----------
+ 2 | pt0 | public.pt0 | 0 | 0 | 0
+ 2 | pt0_idx | public.pt0_idx | 2 | 0 | 2
+ 2 | st0 | public.st0 | 1 | 2 | 1
+ 2 | st0_idx | public.st0_idx | 2 | 2 | 2
+ 2 | st1 | public.st1 | 45 | 10000 | 45
+ 2 | s0.st0 | s0.st0 | 1 | 2 | 1
+ 2 | s0.st0_idx | s0.st0_idx | 2 | 2 | 2
+ 2 | s0.st1 | s0.st1 | 1 | 3 | 1
+ 2 | s0.st1_idx | s0.st1_idx | 2 | 3 | 2
+ 2 | s0.st2 | s0.st2 | 1 | 3 | 1
+ 2 | s0.st2_idx | s0.st2_idx | 2 | 3 | 2
+ 2 | s1.st0 | s1.st0 | 1 | 4 | 1
+ 2 | st1_idx | public.st1_idx | 30 | 10000 | 30
+ 2 | st1_exp | public.st1_exp | 30 | 10000 | 30
+ 3 | s0.st0 | s0.st0 | 1 | 2 | 1
+ 5 | s0.st0 | s0.st0 | 1 | 2 | 1
+ 6 | s0.st0 | s0.st0 | 1 | 2 | 1
+ 7 | st0 | public.st0 | 1 | 2 | 1
+ 8 | s0.st0 | s0.st0 | 1 | 2 | 1
+ 8 | s0.st0_idx | s0.st0_idx | 2 | 2 | 2
+ 8 | s0.st1 | s0.st1 | 1 | 3 | 1
+ 8 | s0.st1_idx | s0.st1_idx | 2 | 3 | 2
+ 8 | s0.st2 | s0.st2 | 1 | 3 | 1
+ 8 | s0.st2_idx | s0.st2_idx | 2 | 3 | 2
+(24 rows)
+
+SELECT * FROM columns_backup_v;
+ id | statypid | starelid | staattnum | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+----+----------+----------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+------------------------+-------------+-------------+-------------+------------------+------------+------------+------------
+ 2 | 23 | st0 | 1 | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2} | (null) | (null) | (null)
+ 2 | 1042 | st0 | 2 | f | 0 | 6 | -0.5 | 1 | 3 | 0 | 0 | 1054 | 1058 | 0 | 0 | {1} | {1} | (null) | (null) | {"test "} | (null) | (null) | (null)
+ 2 | 23 | st1 | 1 | f | 0 | 4 | 3 | 1 | 3 | 0 | 0 | 96 | 97 | 0 | 0 | {0.3334,0.3333,0.3333} | {0.3332} | (null) | (null) | {1,0,2} | (null) | (null) | (null)
+ 2 | 25 | st1 | 2 | f | 0 | 2 | 3 | 1 | 3 | 0 | 0 | 98 | 664 | 0 | 0 | {0.3334,0.3333,0.3333} | {0.3332} | (null) | (null) | {1,0,2} | (null) | (null) | (null)
+ 2 | 23 | s0.st0 | 1 | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2} | (null) | (null) | (null)
+ 2 | 23 | s0.st0 | 1 | t | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2,4,5,6} | (null) | (null) | (null)
+ 2 | 23 | s0.st0 | 2 | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {10,20} | (null) | (null) | (null)
+ 2 | 23 | s0.st0 | 2 | t | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {10,20,40,50,60} | (null) | (null) | (null)
+ 2 | 23 | s0.st1 | 1 | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {4,5,6} | (null) | (null) | (null)
+ 2 | 23 | s0.st1 | 2 | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {40,50,60} | (null) | (null) | (null)
+ 2 | 23 | s0.st2 | 1 | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2,3} | (null) | (null) | (null)
+ 2 | 25 | s0.st2 | 2 | f | 0 | 5 | -1 | 2 | 3 | 0 | 0 | 664 | 664 | 0 | 0 | (null) | {0.5} | (null) | (null) | {1,comment,test} | (null) | (null) | (null)
+ 2 | 23 | s1.st0 | 1 | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2,3,4} | (null) | (null) | (null)
+ 2 | 23 | s1.st0 | 2 | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {15,25,35,45} | (null) | (null) | (null)
+ 2 | 25 | st1_exp | 1 | f | 0 | 5 | 3 | 1 | 3 | 0 | 0 | 98 | 664 | 0 | 0 | {0.3334,0.3333,0.3333} | {0.3332} | (null) | (null) | {1,0,2} | (null) | (null) | (null)
+ 3 | 23 | s0.st0 | 1 | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2} | (null) | (null) | (null)
+ 3 | 23 | s0.st0 | 1 | t | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2,4,5,6} | (null) | (null) | (null)
+ 3 | 23 | s0.st0 | 2 | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {10,20} | (null) | (null) | (null)
+ 3 | 23 | s0.st0 | 2 | t | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {10,20,40,50,60} | (null) | (null) | (null)
+ 5 | 23 | s0.st0 | 1 | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2} | (null) | (null) | (null)
+ 5 | 23 | s0.st0 | 1 | t | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2,4,5,6} | (null) | (null) | (null)
+ 6 | 23 | s0.st0 | 1 | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2} | (null) | (null) | (null)
+ 6 | 23 | s0.st0 | 1 | t | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2,4,5,6} | (null) | (null) | (null)
+ 6 | 23 | s0.st0 | 2 | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {10,20} | (null) | (null) | (null)
+ 6 | 23 | s0.st0 | 2 | t | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {10,20,40,50,60} | (null) | (null) | (null)
+ 7 | 23 | st0 | 1 | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2} | (null) | (null) | (null)
+ 7 | 1042 | st0 | 2 | f | 0 | 6 | -0.5 | 1 | 3 | 0 | 0 | 1054 | 1058 | 0 | 0 | {1} | {1} | (null) | (null) | {"test "} | (null) | (null) | (null)
+ 8 | 23 | s0.st0 | 1 | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2} | (null) | (null) | (null)
+ 8 | 23 | s0.st0 | 1 | t | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2,4,5,6} | (null) | (null) | (null)
+ 8 | 23 | s0.st0 | 2 | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {10,20} | (null) | (null) | (null)
+ 8 | 23 | s0.st0 | 2 | t | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {10,20,40,50,60} | (null) | (null) | (null)
+ 8 | 23 | s0.st1 | 1 | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {4,5,6} | (null) | (null) | (null)
+ 8 | 23 | s0.st1 | 2 | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {40,50,60} | (null) | (null) | (null)
+ 8 | 23 | s0.st2 | 1 | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2,3} | (null) | (null) | (null)
+ 8 | 25 | s0.st2 | 2 | f | 0 | 5 | -1 | 2 | 3 | 0 | 0 | 664 | 664 | 0 | 0 | (null) | {0.5} | (null) | (null) | {1,comment,test} | (null) | (null) | (null)
+(35 rows)
+
+VACUUM ANALYZE;
+/*
+ * No.9-1 dbms_stats.restore
+ */
+-- No.9-1-1
+DELETE FROM dbms_stats._relation_stats_locked;
+BEGIN;
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+ relation | mode
+----------+---------------
+ (null) | ExclusiveLock
+(1 row)
+
+SELECT dbms_stats.restore(2, 's0.st0', NULL);
+ restore
+---------
+ s0.st0
+(1 row)
+
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+ relation | mode
+----------------------------------------+--------------------------
+ dbms_stats._column_stats_locked | RowExclusiveLock
+ dbms_stats._column_stats_locked | ShareUpdateExclusiveLock
+ dbms_stats._column_stats_locked_pkey | RowExclusiveLock
+ dbms_stats._relation_stats_locked | RowExclusiveLock
+ dbms_stats._relation_stats_locked | ShareUpdateExclusiveLock
+ dbms_stats._relation_stats_locked_pkey | RowExclusiveLock
+ (null) | ExclusiveLock
+ (null) | ExclusiveLock
+(8 rows)
+
+COMMIT;
+SELECT relid::regclass FROM dbms_stats.relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+--------
+ s0.st0
+(1 row)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+(4 rows)
+
+-- No.9-1-2
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(2, 'st0', NULL);
+ restore
+---------
+ st0
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats.relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+-------
+ st0
+(1 row)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+(2 rows)
+
+-- No.9-1-3
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(2, 's00.s0', NULL);
+ERROR: schema "s00" does not exist
+LINE 1: SELECT dbms_stats.restore(2, 's00.s0', NULL);
+ ^
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+-- No.9-1-4
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(NULL, 's0.st0', NULL);
+ERROR: backup id is required
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+-- No.9-1-5
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(2, 's0.st0', 'id');
+ restore
+---------
+ s0.st0
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats.relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+--------
+ s0.st0
+(1 row)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ s0.st0 | id | f
+ s0.st0 | id | t
+(2 rows)
+
+-- No.9-1-6
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(2, NULL, 'id');
+ERROR: relation is required
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+-- No.9-1-7
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(2, 's0.st0', NULL);
+ restore
+---------
+ s0.st0
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats.relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+--------
+ s0.st0
+(1 row)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+(4 rows)
+
+-- No.9-1-8
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(2, NULL, NULL);
+ restore
+------------
+ pt0
+ pt0_idx
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s1.st0
+ st0
+ st0_idx
+ st1
+ st1_exp
+ st1_idx
+(14 rows)
+
+SELECT relid::regclass FROM dbms_stats.relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s1.st0
+ st1_idx
+ st1_exp
+(14 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+ st1_exp | lower | f
+(15 rows)
+
+-- No.9-1-9
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(0, 's0.st0', NULL);
+ERROR: backup id 0 does not exist
+SELECT relid::regclass FROM dbms_stats.relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+-------
+(0 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+(0 rows)
+
+-- No.9-1-10
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(2, 0, 'id');
+ERROR: relation "-" does not exist
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+-- No.9-1-11
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(1, 's0.st0', NULL);
+ERROR: relation "s0.st0" does not exist in previous backup
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+-- No.9-1-12
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(2, 's0.st0', 'dummy');
+ERROR: column "dummy" of "s0.st0" does not exist
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+-- No.9-1-13
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(1, 's0.st0', 'id');
+ERROR: relation "s0.st0" does not exist in previous backup
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+-- No.9-1-15
+DELETE FROM dbms_stats._relation_stats_locked;
+ALTER TABLE s1.st0 DROP COLUMN id;
+SELECT dbms_stats.restore(2, 's1.st0', 'id');
+ERROR: column "id" of "s1.st0" does not exist
+SELECT relid::regclass FROM dbms_stats.relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+-------
+(0 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+(0 rows)
+
+-- No.9-1-14
+DELETE FROM dbms_stats._relation_stats_locked;
+\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';"`
+DROP TABLE s1.st0;
+SET client_min_messages TO FATAL;
+SELECT dbms_stats.restore(2, :s1_st0_oid, NULL);
+RESET client_min_messages;
+\! tail ${PGDATA}/pg_log/postgresql.log > results/ut_no3_1_14.out
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+CREATE TABLE s1.st0(id integer, num integer);
+INSERT INTO s1.st0 VALUES (1, 15), (2, 25), (3, 35), (4, 45);
+VACUUM ANALYZE;
+-- No.9-1-16
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(2, 's0.st0', NULL);
+ restore
+---------
+ s0.st0
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats.relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+--------
+ s0.st0
+(1 row)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+(4 rows)
+
+-- No.9-1-17
+DELETE FROM dbms_stats._relation_stats_locked;
+INSERT INTO dbms_stats.relation_stats_backup(
+ id, relid, relname, relpages, reltuples,
+ curpages)
+ VALUES (2,
+ 'pg_toast.pg_toast_2618'::regclass,
+ 'pg_toast.pg_toast_2618', 1, 1,
+ 1);
+SELECT * FROM relations_backup_v
+ WHERE id = 2
+ AND relname = 'pg_toast.pg_toast_2618';
+ id | relid | relname | relpages | reltuples | curpages
+----+------------------------+------------------------+----------+-----------+----------
+ 2 | pg_toast.pg_toast_2618 | pg_toast.pg_toast_2618 | 1 | 1 | 1
+(1 row)
+
+SELECT dbms_stats.restore(2, 'pg_toast.pg_toast_2618', NULL);
+ restore
+---------
+(0 rows)
+
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+DELETE FROM dbms_stats.relation_stats_backup
+ WHERE id = 2
+ AND relname = 'pg_toast.pg_toast_2618';
+-- No.9-1-18
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(2, 's0.st0_idx', NULL);
+ restore
+------------
+ s0.st0_idx
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats.relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ s0.st0_idx
+(1 row)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+(0 rows)
+
+-- No.9-1-19
+DELETE FROM dbms_stats._relation_stats_locked;
+INSERT INTO dbms_stats.relation_stats_backup(
+ id, relid, relname, relpages, reltuples,
+ curpages)
+ VALUES (2, 's0.ss0'::regclass, 's0.ss0', 1, 1,
+ 1);
+SELECT * FROM relations_backup_v
+ WHERE id = 2
+ AND relname = 's0.ss0';
+ id | relid | relname | relpages | reltuples | curpages
+----+--------+---------+----------+-----------+----------
+ 2 | s0.ss0 | s0.ss0 | 1 | 1 | 1
+(1 row)
+
+SELECT dbms_stats.restore(2, 's0.ss0', NULL);
+ restore
+---------
+(0 rows)
+
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+DELETE FROM dbms_stats.relation_stats_backup
+ WHERE id = 2
+ AND relname = 's0.ss0';
+-- No.9-1-20
+DELETE FROM dbms_stats._relation_stats_locked;
+INSERT INTO dbms_stats.relation_stats_backup(
+ id, relid, relname, relpages, reltuples,
+ curpages)
+ VALUES (2, 's0.sc0'::regclass, 's0.sc0', 1, 1,
+ 1);
+SELECT * FROM relations_backup_v
+ WHERE id = 2
+ AND relname = 's0.sc0';
+ id | relid | relname | relpages | reltuples | curpages
+----+--------+---------+----------+-----------+----------
+ 2 | s0.sc0 | s0.sc0 | 1 | 1 | 1
+(1 row)
+
+SELECT dbms_stats.restore(2, 's0.sc0', NULL);
+ restore
+---------
+(0 rows)
+
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+DELETE FROM dbms_stats.relation_stats_backup
+ WHERE id = 2
+ AND relname = 's0.sc0';
+-- No.9-1-21
+DELETE FROM dbms_stats._relation_stats_locked;
+INSERT INTO dbms_stats.relation_stats_backup(
+ id, relid, relname, relpages, reltuples,
+ curpages)
+ VALUES (2, 's0.sft0'::regclass, 's0.sft0', 1, 1,
+ 1);
+SELECT * FROM relations_backup_v
+ WHERE id = 2
+ AND relname = 's0.sft0';
+ id | relid | relname | relpages | reltuples | curpages
+----+---------+---------+----------+-----------+----------
+ 2 | s0.sft0 | s0.sft0 | 1 | 1 | 1
+(1 row)
+
+SELECT dbms_stats.restore(2, 's0.sft0', NULL);
+ restore
+---------
+(0 rows)
+
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+DELETE FROM dbms_stats.relation_stats_backup
+ WHERE id = 2
+ AND relname = 's0.sft0';
+-- No.9-1-22
+DELETE FROM dbms_stats._relation_stats_locked;
+INSERT INTO dbms_stats.relation_stats_backup(
+ id, relid, relname, relpages, reltuples,
+ curpages)
+ VALUES (2, 'pg_catalog.pg_class'::regclass, 'pg_catalog.pg_class', 1, 1,
+ 1);
+SELECT * FROM relations_backup_v
+ WHERE id = 2
+ AND relname = 'pg_catalog.pg_class';
+ id | relid | relname | relpages | reltuples | curpages
+----+----------+---------------------+----------+-----------+----------
+ 2 | pg_class | pg_catalog.pg_class | 1 | 1 | 1
+(1 row)
+
+SELECT dbms_stats.restore(2, 'pg_catalog.pg_class', NULL);
+ restore
+---------
+(0 rows)
+
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+DELETE FROM dbms_stats.relation_stats_backup
+ WHERE id = 2
+ AND relname = 'pg_catalog.pg_class';
+-- No.9-1-23
+DELETE FROM dbms_stats._relation_stats_locked;
+INSERT INTO dbms_stats._relation_stats_locked(relid, relname)
+ VALUES ('s0.st0'::regclass, 's0.st0');
+INSERT INTO dbms_stats._column_stats_locked(starelid, staattnum, stainherit)
+ SELECT starelid::regclass, staattnum, stainherit
+ FROM dbms_stats.column_stats_effective
+ WHERE starelid = 's0.st0'::regclass;
+SELECT id, unit, comment FROM dbms_stats.backup_history
+ WHERE id = 2;
+ id | unit | comment
+----+------+---------
+ 2 | d | (null)
+(1 row)
+
+SELECT * FROM columns_locked_v;
+ starelid | staattnum | attname | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+------------+------------+------------+------------
+ s0.st0 | 1 | id | f | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0.st0 | 1 | id | t | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0.st0 | 2 | num | f | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0.st0 | 2 | num | t | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+(4 rows)
+
+SELECT * FROM relations_locked_v;
+ relid | relname | relpages | reltuples | curpages
+--------+---------+----------+-----------+----------
+ s0.st0 | s0.st0 | (null) | (null) | (null)
+(1 row)
+
+SELECT dbms_stats.restore(2, 's0.st0', NULL);
+ restore
+---------
+ s0.st0
+(1 row)
+
+SELECT * FROM relations_locked_v;
+ relid | relname | relpages | reltuples | curpages
+--------+---------+----------+-----------+----------
+ s0.st0 | s0.st0 | 1 | 2 | 1
+(1 row)
+
+SELECT * FROM columns_locked_v;
+ starelid | staattnum | attname | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+------------------+------------+------------+------------
+ s0.st0 | 1 | id | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2} | (null) | (null) | (null)
+ s0.st0 | 1 | id | t | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2,4,5,6} | (null) | (null) | (null)
+ s0.st0 | 2 | num | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {10,20} | (null) | (null) | (null)
+ s0.st0 | 2 | num | t | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {10,20,40,50,60} | (null) | (null) | (null)
+(4 rows)
+
+-- No.9-1-24
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT id, unit, comment FROM dbms_stats.backup_history
+ WHERE id = 2;
+ id | unit | comment
+----+------+---------
+ 2 | d | (null)
+(1 row)
+
+SELECT dbms_stats.restore(2, 's0.st0', NULL);
+ restore
+---------
+ s0.st0
+(1 row)
+
+SELECT * FROM relations_locked_v;
+ relid | relname | relpages | reltuples | curpages
+--------+---------+----------+-----------+----------
+ s0.st0 | s0.st0 | 1 | 2 | 1
+(1 row)
+
+SELECT * FROM columns_locked_v;
+ starelid | staattnum | attname | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+------------------+------------+------------+------------
+ s0.st0 | 1 | id | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2} | (null) | (null) | (null)
+ s0.st0 | 1 | id | t | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2,4,5,6} | (null) | (null) | (null)
+ s0.st0 | 2 | num | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {10,20} | (null) | (null) | (null)
+ s0.st0 | 2 | num | t | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {10,20,40,50,60} | (null) | (null) | (null)
+(4 rows)
+
+/*
+ * Stab function dbms_stats.restore
+ */
+CREATE OR REPLACE FUNCTION dbms_stats.restore(
+ backup_id int8,
+ relid regclass DEFAULT NULL,
+ attname text DEFAULT NULL)
+RETURNS SETOF regclass AS
+$$
+BEGIN
+ RAISE NOTICE 'arguments are "%, %, %"', $1, $2, $3;
+ RETURN QUERY
+ SELECT c.oid::regclass
+ FROM pg_class c, dbms_stats.relation_stats_backup b
+ WHERE (c.oid = $2 OR $2 IS NULL)
+ AND c.oid = b.relid
+ AND c.relkind IN ('r', 'i')
+ AND (b.id <= $1 OR $1 IS NOT NULL)
+ GROUP BY c.oid
+ ORDER BY c.oid::regclass::text;
+END;
+$$
+LANGUAGE plpgsql;
+/*
+ * No.10-1 dbms_stats.restore_database_stats
+ */
+-- No.10-1-1
+SELECT dbms_stats.restore_database_stats('2012-02-29 23:59:57');
+NOTICE: arguments are "2, pt0, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, pt0_idx, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, st0, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, st0_idx, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, st1, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, s0.st0, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, s0.st0_idx, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, s0.st1, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, s0.st1_idx, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, s0.st2, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, s0.st2_idx, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, st1_idx, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, st1_exp, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+ restore_database_stats
+------------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+(13 rows)
+
+-- No.10-1-2
+SELECT dbms_stats.restore_database_stats('2012-02-29 23:59:57.000002');
+NOTICE: arguments are "2, pt0, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, pt0_idx, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, st0, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, st0_idx, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, st1, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "3, s0.st0, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, s0.st0_idx, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, s0.st1, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, s0.st1_idx, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, s0.st2, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, s0.st2_idx, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, st1_idx, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, st1_exp, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+ restore_database_stats
+------------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+(13 rows)
+
+-- No.10-1-3
+SELECT dbms_stats.restore_database_stats('2012-01-01 00:00:00');
+ restore_database_stats
+------------------------
+(0 rows)
+
+--#No.10-1-4 is skipped after lock tests
+--#No.10-1-5 is skipped after lock tests
+-- No.10-1-6
+SELECT dbms_stats.restore_database_stats('2012-02-29 23:59:57');
+NOTICE: arguments are "2, pt0, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, pt0_idx, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, st0, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, st0_idx, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, st1, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, s0.st0, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, s0.st0_idx, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, s0.st1, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, s0.st1_idx, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, s0.st2, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, s0.st2_idx, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, st1_idx, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, st1_exp, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+ restore_database_stats
+------------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+(13 rows)
+
+/*
+ * No.10-2 dbms_stats.restore_schema_stats
+ */
+-- No.10-2-1
+SELECT dbms_stats.restore_schema_stats('s0', '2012-02-29 23:59:57');
+NOTICE: arguments are "2, s0.st0, "
+CONTEXT: PL/pgSQL function "restore_schema_stats" line 10 at RETURN QUERY
+NOTICE: arguments are "2, s0.st0_idx, "
+CONTEXT: PL/pgSQL function "restore_schema_stats" line 10 at RETURN QUERY
+NOTICE: arguments are "2, s0.st1, "
+CONTEXT: PL/pgSQL function "restore_schema_stats" line 10 at RETURN QUERY
+NOTICE: arguments are "2, s0.st1_idx, "
+CONTEXT: PL/pgSQL function "restore_schema_stats" line 10 at RETURN QUERY
+NOTICE: arguments are "2, s0.st2, "
+CONTEXT: PL/pgSQL function "restore_schema_stats" line 10 at RETURN QUERY
+NOTICE: arguments are "2, s0.st2_idx, "
+CONTEXT: PL/pgSQL function "restore_schema_stats" line 10 at RETURN QUERY
+ restore_schema_stats
+----------------------
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+(6 rows)
+
+-- No.10-2-2
+SELECT dbms_stats.restore_schema_stats('s0', '2012-02-29 23:59:57.000002');
+NOTICE: arguments are "3, s0.st0, "
+CONTEXT: PL/pgSQL function "restore_schema_stats" line 10 at RETURN QUERY
+NOTICE: arguments are "2, s0.st0_idx, "
+CONTEXT: PL/pgSQL function "restore_schema_stats" line 10 at RETURN QUERY
+NOTICE: arguments are "2, s0.st1, "
+CONTEXT: PL/pgSQL function "restore_schema_stats" line 10 at RETURN QUERY
+NOTICE: arguments are "2, s0.st1_idx, "
+CONTEXT: PL/pgSQL function "restore_schema_stats" line 10 at RETURN QUERY
+NOTICE: arguments are "2, s0.st2, "
+CONTEXT: PL/pgSQL function "restore_schema_stats" line 10 at RETURN QUERY
+NOTICE: arguments are "2, s0.st2_idx, "
+CONTEXT: PL/pgSQL function "restore_schema_stats" line 10 at RETURN QUERY
+ restore_schema_stats
+----------------------
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+(6 rows)
+
+-- No.10-2-3
+SELECT dbms_stats.restore_schema_stats('s0', '2012-01-01 00:00:00');
+ restore_schema_stats
+----------------------
+(0 rows)
+
+--#No.10-2-4 is skipped after lock tests
+--#No.10-2-5 is skipped after lock tests
+-- No.10-2-6
+SELECT dbms_stats.restore_schema_stats('s0', '2012-02-29 23:59:57');
+NOTICE: arguments are "2, s0.st0, "
+CONTEXT: PL/pgSQL function "restore_schema_stats" line 10 at RETURN QUERY
+NOTICE: arguments are "2, s0.st0_idx, "
+CONTEXT: PL/pgSQL function "restore_schema_stats" line 10 at RETURN QUERY
+NOTICE: arguments are "2, s0.st1, "
+CONTEXT: PL/pgSQL function "restore_schema_stats" line 10 at RETURN QUERY
+NOTICE: arguments are "2, s0.st1_idx, "
+CONTEXT: PL/pgSQL function "restore_schema_stats" line 10 at RETURN QUERY
+NOTICE: arguments are "2, s0.st2, "
+CONTEXT: PL/pgSQL function "restore_schema_stats" line 10 at RETURN QUERY
+NOTICE: arguments are "2, s0.st2_idx, "
+CONTEXT: PL/pgSQL function "restore_schema_stats" line 10 at RETURN QUERY
+ restore_schema_stats
+----------------------
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+(6 rows)
+
+-- No.10-2-7
+SELECT dbms_stats.restore_schema_stats('s0', '2012-02-29 23:59:57');
+NOTICE: arguments are "2, s0.st0, "
+CONTEXT: PL/pgSQL function "restore_schema_stats" line 10 at RETURN QUERY
+NOTICE: arguments are "2, s0.st0_idx, "
+CONTEXT: PL/pgSQL function "restore_schema_stats" line 10 at RETURN QUERY
+NOTICE: arguments are "2, s0.st1, "
+CONTEXT: PL/pgSQL function "restore_schema_stats" line 10 at RETURN QUERY
+NOTICE: arguments are "2, s0.st1_idx, "
+CONTEXT: PL/pgSQL function "restore_schema_stats" line 10 at RETURN QUERY
+NOTICE: arguments are "2, s0.st2, "
+CONTEXT: PL/pgSQL function "restore_schema_stats" line 10 at RETURN QUERY
+NOTICE: arguments are "2, s0.st2_idx, "
+CONTEXT: PL/pgSQL function "restore_schema_stats" line 10 at RETURN QUERY
+ restore_schema_stats
+----------------------
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+(6 rows)
+
+--#No.10-2-8 is skipped after lock tests
+-- No.10-2-9
+SELECT dbms_stats.restore_schema_stats('s00', '2012-02-29 23:59:57');
+ERROR: schema "s00" does not exist
+-- No.10-2-10
+SELECT dbms_stats.restore_schema_stats('pg_catalog', '2012-02-29 23:59:57');
+ERROR: can not restore statistics of relation in system schema "pg_catalog"
+/*
+ * No.10-7 dbms_stats.restore_stats
+ */
+-- No.10-7-1
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore_stats(NULL);
+ restore_stats
+---------------
+(0 rows)
+
+-- No.10-7-2
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore_stats(0);
+ERROR: backup id 0 does not exist
+-- No.10-7-3
+DELETE FROM dbms_stats._relation_stats_locked;
+BEGIN;
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+ relation | mode
+----------+---------------
+ (null) | ExclusiveLock
+(1 row)
+
+SELECT dbms_stats.restore_stats(2);
+ restore_stats
+---------------
+ pt0
+ pt0_idx
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st0
+ st0_idx
+ st1
+ st1_exp
+ st1_idx
+(13 rows)
+
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+ relation | mode
+----------------------------------------+--------------------------
+ dbms_stats._column_stats_locked | RowExclusiveLock
+ dbms_stats._column_stats_locked | ShareUpdateExclusiveLock
+ dbms_stats._column_stats_locked_pkey | RowExclusiveLock
+ dbms_stats._relation_stats_locked | RowExclusiveLock
+ dbms_stats._relation_stats_locked | ShareUpdateExclusiveLock
+ dbms_stats._relation_stats_locked_pkey | RowExclusiveLock
+ (null) | ExclusiveLock
+ (null) | ExclusiveLock
+(8 rows)
+
+COMMIT;
+SELECT relid::regclass FROM dbms_stats.relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+(13 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+(13 rows)
+
+-- No.10-7-4
+DELETE FROM dbms_stats._relation_stats_locked;
+INSERT INTO dbms_stats._relation_stats_locked(relid, relname)
+ SELECT relid::regclass, relname
+ FROM dbms_stats.relation_stats_effective;
+INSERT INTO dbms_stats._column_stats_locked(starelid, staattnum, stainherit)
+ SELECT starelid::regclass, staattnum, stainherit
+ FROM dbms_stats.column_stats_effective;
+SELECT id, unit, comment FROM dbms_stats.backup_history
+ WHERE id = 8;
+ id | unit | comment
+----+------+---------
+ 8 | s | (null)
+(1 row)
+
+SELECT * FROM columns_locked_v;
+ starelid | staattnum | attname | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+------------+------------+------------+------------
+ st0 | 1 | id | f | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ st0 | 2 | name | f | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ st1 | 1 | val | f | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ st1 | 2 | str | f | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0.st0 | 1 | id | f | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0.st0 | 1 | id | t | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0.st0 | 2 | num | f | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0.st0 | 2 | num | t | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0.st1 | 1 | id | f | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0.st1 | 2 | num | f | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0.st2 | 1 | id | f | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0.st2 | 2 | txt | f | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ st1_exp | 1 | lower | f | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s1.st0 | 1 | id | f | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s1.st0 | 2 | num | f | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+(15 rows)
+
+SELECT * FROM relations_locked_v;
+ relid | relname | relpages | reltuples | curpages
+------------+----------------+----------+-----------+----------
+ pt0 | public.pt0 | (null) | (null) | (null)
+ pt0_idx | public.pt0_idx | (null) | (null) | (null)
+ st0 | public.st0 | (null) | (null) | (null)
+ st0_idx | public.st0_idx | (null) | (null) | (null)
+ st1 | public.st1 | (null) | (null) | (null)
+ s0.st0 | s0.st0 | (null) | (null) | (null)
+ s0.st0_idx | s0.st0_idx | (null) | (null) | (null)
+ s0.st1 | s0.st1 | (null) | (null) | (null)
+ s0.st1_idx | s0.st1_idx | (null) | (null) | (null)
+ s0.st2 | s0.st2 | (null) | (null) | (null)
+ s0.st2_idx | s0.st2_idx | (null) | (null) | (null)
+ st1_idx | public.st1_idx | (null) | (null) | (null)
+ st1_exp | public.st1_exp | (null) | (null) | (null)
+ s1.st0 | s1.st0 | (null) | (null) | (null)
+(14 rows)
+
+SELECT dbms_stats.restore_stats(8);
+ restore_stats
+---------------
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+(6 rows)
+
+SELECT * FROM relations_locked_v;
+ relid | relname | relpages | reltuples | curpages
+------------+----------------+----------+-----------+----------
+ pt0 | public.pt0 | (null) | (null) | (null)
+ pt0_idx | public.pt0_idx | (null) | (null) | (null)
+ st0 | public.st0 | (null) | (null) | (null)
+ st0_idx | public.st0_idx | (null) | (null) | (null)
+ st1 | public.st1 | (null) | (null) | (null)
+ s0.st0 | s0.st0 | 1 | 2 | 1
+ s0.st0_idx | s0.st0_idx | 2 | 2 | 2
+ s0.st1 | s0.st1 | 1 | 3 | 1
+ s0.st1_idx | s0.st1_idx | 2 | 3 | 2
+ s0.st2 | s0.st2 | 1 | 3 | 1
+ s0.st2_idx | s0.st2_idx | 2 | 3 | 2
+ st1_idx | public.st1_idx | (null) | (null) | (null)
+ st1_exp | public.st1_exp | (null) | (null) | (null)
+ s1.st0 | s1.st0 | (null) | (null) | (null)
+(14 rows)
+
+SELECT * FROM columns_locked_v;
+ starelid | staattnum | attname | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+------------------+------------+------------+------------
+ st0 | 1 | id | f | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ st0 | 2 | name | f | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ st1 | 1 | val | f | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ st1 | 2 | str | f | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0.st0 | 1 | id | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2} | (null) | (null) | (null)
+ s0.st0 | 1 | id | t | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2,4,5,6} | (null) | (null) | (null)
+ s0.st0 | 2 | num | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {10,20} | (null) | (null) | (null)
+ s0.st0 | 2 | num | t | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {10,20,40,50,60} | (null) | (null) | (null)
+ s0.st1 | 1 | id | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {4,5,6} | (null) | (null) | (null)
+ s0.st1 | 2 | num | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {40,50,60} | (null) | (null) | (null)
+ s0.st2 | 1 | id | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2,3} | (null) | (null) | (null)
+ s0.st2 | 2 | txt | f | 0 | 5 | -1 | 2 | 3 | 0 | 0 | 664 | 664 | 0 | 0 | (null) | {0.5} | (null) | (null) | {1,comment,test} | (null) | (null) | (null)
+ st1_exp | 1 | lower | f | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s1.st0 | 1 | id | f | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s1.st0 | 2 | num | f | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+(15 rows)
+
+-- No.10-7-5
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT id, unit, comment FROM dbms_stats.backup_history
+ WHERE id = 8;
+ id | unit | comment
+----+------+---------
+ 8 | s | (null)
+(1 row)
+
+SELECT dbms_stats.restore_stats(8);
+ restore_stats
+---------------
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+(6 rows)
+
+SELECT * FROM relations_locked_v;
+ relid | relname | relpages | reltuples | curpages
+------------+------------+----------+-----------+----------
+ s0.st0 | s0.st0 | 1 | 2 | 1
+ s0.st0_idx | s0.st0_idx | 2 | 2 | 2
+ s0.st1 | s0.st1 | 1 | 3 | 1
+ s0.st1_idx | s0.st1_idx | 2 | 3 | 2
+ s0.st2 | s0.st2 | 1 | 3 | 1
+ s0.st2_idx | s0.st2_idx | 2 | 3 | 2
+(6 rows)
+
+SELECT * FROM columns_locked_v;
+ starelid | staattnum | attname | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+------------------+------------+------------+------------
+ s0.st0 | 1 | id | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2} | (null) | (null) | (null)
+ s0.st0 | 1 | id | t | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2,4,5,6} | (null) | (null) | (null)
+ s0.st0 | 2 | num | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {10,20} | (null) | (null) | (null)
+ s0.st0 | 2 | num | t | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {10,20,40,50,60} | (null) | (null) | (null)
+ s0.st1 | 1 | id | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {4,5,6} | (null) | (null) | (null)
+ s0.st1 | 2 | num | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {40,50,60} | (null) | (null) | (null)
+ s0.st2 | 1 | id | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2,3} | (null) | (null) | (null)
+ s0.st2 | 2 | txt | f | 0 | 5 | -1 | 2 | 3 | 0 | 0 | 664 | 664 | 0 | 0 | (null) | {0.5} | (null) | (null) | {1,comment,test} | (null) | (null) | (null)
+(8 rows)
+
+/*
+ * No.11-1 dbms_stats.lock(relid, attname)
+ */
+-- No.11-1-1
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock(NULL, NULL);
+ERROR: relation is required
+-- No.11-1-2
+ALTER FUNCTION dbms_stats.lock(relid regclass)
+ RENAME TO truth_lock;
+CREATE FUNCTION dbms_stats.lock(relid regclass)
+RETURNS regclass AS
+$$
+BEGIN
+ RAISE NOTICE 'arguments are %', $1;
+ RETURN $1;
+END
+$$
+LANGUAGE plpgsql;
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.st0', NULL);
+NOTICE: arguments are s0.st0
+CONTEXT: PL/pgSQL function "lock" line 11 at RETURN
+ lock
+--------
+ s0.st0
+(1 row)
+
+DROP FUNCTION dbms_stats.lock(relid regclass);
+ALTER FUNCTION dbms_stats.truth_lock(relid regclass)
+ RENAME TO lock;
+-- No.11-1-3
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock(NULL, 'id');
+ERROR: relation is required
+-- No.11-1-4
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.st0', 'id');
+ lock
+--------
+ s0.st0
+(1 row)
+
+SELECT * FROM relations_locked_v;
+ relid | relname | relpages | reltuples | curpages
+--------+---------+----------+-----------+----------
+ s0.st0 | s0.st0 | (null) | (null) | (null)
+(1 row)
+
+SELECT * FROM columns_locked_v c;
+ starelid | staattnum | attname | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------+------------+------------
+ s0.st0 | 1 | id | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2} | (null) | (null) | (null)
+ s0.st0 | 1 | id | t | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2,4,5,6} | (null) | (null) | (null)
+(2 rows)
+
+-- No.11-1-5
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock(0, 'id');
+ERROR: relation "-" does not exist
+-- No.11-1-6
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.st0', 'id');
+ lock
+--------
+ s0.st0
+(1 row)
+
+SELECT * FROM relations_locked_v;
+ relid | relname | relpages | reltuples | curpages
+--------+---------+----------+-----------+----------
+ s0.st0 | s0.st0 | (null) | (null) | (null)
+(1 row)
+
+SELECT * FROM columns_locked_v c;
+ starelid | staattnum | attname | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------+------------+------------
+ s0.st0 | 1 | id | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2} | (null) | (null) | (null)
+ s0.st0 | 1 | id | t | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2,4,5,6} | (null) | (null) | (null)
+(2 rows)
+
+-- No.11-1-7
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('pg_toast.pg_toast_2618', 'id');
+ERROR: "pg_toast.pg_toast_2618" is not a table nor an index
+-- No.11-1-8
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.st0_idx', 'id');
+ERROR: "s0.st0_idx" is not an indexes on expressions
+-- No.11-1-9
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('st1_exp', 'lower');
+ lock
+---------
+ st1_exp
+(1 row)
+
+SELECT * FROM relations_locked_v;
+ relid | relname | relpages | reltuples | curpages
+---------+----------------+----------+-----------+----------
+ st1_exp | public.st1_exp | (null) | (null) | (null)
+(1 row)
+
+SELECT * FROM columns_locked_v c;
+ starelid | staattnum | attname | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+------------------------+-------------+-------------+-------------+------------+------------+------------+------------
+ st1_exp | 1 | lower | f | 0 | 5 | 3 | 1 | 3 | 0 | 0 | 98 | 664 | 0 | 0 | {0.3334,0.3333,0.3333} | {0.3332} | (null) | (null) | {1,0,2} | (null) | (null) | (null)
+(1 row)
+
+DELETE FROM dbms_stats._relation_stats_locked;
+-- No.11-1-10
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.ss0', 'id');
+ERROR: "s0.ss0" is not a table nor an index
+-- No.11-1-11
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.sc0', 'id');
+ERROR: "s0.sc0" is not a table nor an index
+-- No.11-1-12
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.sft0', 'id');
+ERROR: "s0.sft0" is not a table nor an index
+-- No.11-1-13
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('pg_catalog.pg_class', 'id');
+ERROR: can not lock statistics of system catalog "pg_class"
+-- No.11-1-14
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.st0', 'dummy');
+ERROR: column "dummy" of "s0.st0" does not exist
+-- No.11-1-15
+DELETE FROM dbms_stats._relation_stats_locked;
+DELETE FROM pg_statistic
+ WHERE starelid = 's0.st0'::regclass;
+SELECT dbms_stats.lock('s0.st0', 'id');
+ERROR: statistic for column "id" of "s0.st0" does not exist
+VACUUM ANALYZE;
+-- No.11-1-16
+DELETE FROM dbms_stats._relation_stats_locked;
+INSERT INTO dbms_stats._relation_stats_locked(
+ relid, relname, relpages, reltuples,
+ curpages)
+ VALUES('s0.st0'::regclass, 's0.st0', 1, 1640,
+ 1);
+SELECT dbms_stats.lock_column_stats('s0.st0','id');
+ lock_column_stats
+-------------------
+ s0.st0
+(1 row)
+
+UPDATE dbms_stats._column_stats_locked
+ SET (stanullfrac, stawidth, stadistinct,
+ stakind1, stakind2, stakind3, stakind4,
+ staop1, staop2, staop3, staop4,
+ stanumbers1, stanumbers2, stanumbers3, stanumbers4,
+ stavalues1, stavalues2, stavalues3, stavalues4
+ ) = (
+ NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL)
+ WHERE starelid = 's0.st0'::regclass;
+SELECT dbms_stats.lock('s0.st0', 'id');
+ lock
+--------
+ s0.st0
+(1 row)
+
+SELECT * FROM relations_locked_v;
+ relid | relname | relpages | reltuples | curpages
+--------+---------+----------+-----------+----------
+ s0.st0 | s0.st0 | 1 | 1640 | 1
+(1 row)
+
+SELECT * FROM columns_locked_v c;
+ starelid | staattnum | attname | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------+------------+------------
+ s0.st0 | 1 | id | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2} | (null) | (null) | (null)
+ s0.st0 | 1 | id | t | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2,4,5,6} | (null) | (null) | (null)
+(2 rows)
+
+-- No.11-1-17
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.st0', 'id');
+ lock
+--------
+ s0.st0
+(1 row)
+
+SELECT * FROM relations_locked_v
+ WHERE relid = 's0.st0'::regclass;
+ relid | relname | relpages | reltuples | curpages
+--------+---------+----------+-----------+----------
+ s0.st0 | s0.st0 | (null) | (null) | (null)
+(1 row)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ s0.st0 | id | f
+ s0.st0 | id | t
+(2 rows)
+
+/*
+ * No.11-2 dbms_stats.lock(relid)
+ */
+-- No.11-2-1
+DELETE FROM dbms_stats._relation_stats_locked;
+BEGIN;
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+ relation | mode
+----------+---------------
+ (null) | ExclusiveLock
+(1 row)
+
+SELECT dbms_stats.lock('s0.st0');
+ lock
+--------
+ s0.st0
+(1 row)
+
+SELECT * FROM relations_locked_v;
+ relid | relname | relpages | reltuples | curpages
+--------+---------+----------+-----------+----------
+ s0.st0 | s0.st0 | 1 | 2 | 1
+(1 row)
+
+SELECT * FROM columns_locked_v c;
+ starelid | staattnum | attname | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+------------------+------------+------------+------------
+ s0.st0 | 1 | id | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2} | (null) | (null) | (null)
+ s0.st0 | 1 | id | t | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2,4,5,6} | (null) | (null) | (null)
+ s0.st0 | 2 | num | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {10,20} | (null) | (null) | (null)
+ s0.st0 | 2 | num | t | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {10,20,40,50,60} | (null) | (null) | (null)
+(4 rows)
+
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+ relation | mode
+----------------------------------------+--------------------------
+ dbms_stats._column_stats_locked | RowExclusiveLock
+ dbms_stats._column_stats_locked | ShareUpdateExclusiveLock
+ dbms_stats._column_stats_locked_pkey | RowExclusiveLock
+ dbms_stats._relation_stats_locked | RowExclusiveLock
+ dbms_stats._relation_stats_locked | ShareUpdateExclusiveLock
+ dbms_stats._relation_stats_locked_pkey | RowExclusiveLock
+ (null) | ExclusiveLock
+ (null) | ExclusiveLock
+(8 rows)
+
+COMMIT;
+-- No.11-2-2
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock(NULL);
+ERROR: relation is required
+-- No.11-2-3
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('0');
+ERROR: relation "-" does not exist
+-- No.11-2-4
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.st0');
+ lock
+--------
+ s0.st0
+(1 row)
+
+SELECT * FROM relations_locked_v;
+ relid | relname | relpages | reltuples | curpages
+--------+---------+----------+-----------+----------
+ s0.st0 | s0.st0 | 1 | 2 | 1
+(1 row)
+
+SELECT * FROM columns_locked_v c;
+ starelid | staattnum | attname | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+------------------+------------+------------+------------
+ s0.st0 | 1 | id | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2} | (null) | (null) | (null)
+ s0.st0 | 1 | id | t | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2,4,5,6} | (null) | (null) | (null)
+ s0.st0 | 2 | num | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {10,20} | (null) | (null) | (null)
+ s0.st0 | 2 | num | t | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {10,20,40,50,60} | (null) | (null) | (null)
+(4 rows)
+
+-- No.11-2-5
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('pg_toast.pg_toast_2618');
+ERROR: can not lock statistics of "pg_toast.pg_toast_2618" with relkind "t"
+HINT: only tables and indexes are supported
+-- No.11-2-6
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.st0_idx');
+ lock
+------------
+ s0.st0_idx
+(1 row)
+
+SELECT * FROM relations_locked_v;
+ relid | relname | relpages | reltuples | curpages
+------------+------------+----------+-----------+----------
+ s0.st0_idx | s0.st0_idx | 2 | 2 | 2
+(1 row)
+
+SELECT * FROM columns_locked_v c;
+ starelid | staattnum | attname | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+------------+------------+------------+------------
+(0 rows)
+
+-- No.11-2-7
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.ss0');
+ERROR: can not lock statistics of "s0.ss0" with relkind "S"
+HINT: only tables and indexes are supported
+-- No.11-2-8
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.sc0');
+ERROR: can not lock statistics of "s0.sc0" with relkind "c"
+HINT: only tables and indexes are supported
+-- No.11-2-9
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.sft0');
+ERROR: can not lock statistics of "s0.sft0" with relkind "f"
+HINT: only tables and indexes are supported
+-- No.11-2-10
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('pg_catalog.pg_class');
+ERROR: can not lock statistics of system catalog "pg_class"
+-- No.11-2-11
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_table_stats('s0.st0');
+ lock_table_stats
+------------------
+ s0.st0
+(1 row)
+
+UPDATE dbms_stats._relation_stats_locked
+ SET (relpages, reltuples,
+ curpages)
+ = (NULL, NULL, NULL
+ )
+ WHERE relid = 's0.st0'::regclass;
+SELECT dbms_stats.lock('s0.st0');
+ lock
+--------
+ s0.st0
+(1 row)
+
+SELECT * FROM relations_locked_v;
+ relid | relname | relpages | reltuples | curpages
+--------+---------+----------+-----------+----------
+ s0.st0 | s0.st0 | 1 | 2 | 1
+(1 row)
+
+SELECT * FROM columns_locked_v c;
+ starelid | staattnum | attname | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+------------------+------------+------------+------------
+ s0.st0 | 1 | id | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2} | (null) | (null) | (null)
+ s0.st0 | 1 | id | t | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2,4,5,6} | (null) | (null) | (null)
+ s0.st0 | 2 | num | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {10,20} | (null) | (null) | (null)
+ s0.st0 | 2 | num | t | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {10,20,40,50,60} | (null) | (null) | (null)
+(4 rows)
+
+-- No.11-2-12
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.st0');
+ lock
+--------
+ s0.st0
+(1 row)
+
+SELECT * FROM relations_locked_v;
+ relid | relname | relpages | reltuples | curpages
+--------+---------+----------+-----------+----------
+ s0.st0 | s0.st0 | 1 | 2 | 1
+(1 row)
+
+SELECT * FROM columns_locked_v c;
+ starelid | staattnum | attname | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+------------------+------------+------------+------------
+ s0.st0 | 1 | id | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2} | (null) | (null) | (null)
+ s0.st0 | 1 | id | t | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2,4,5,6} | (null) | (null) | (null)
+ s0.st0 | 2 | num | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {10,20} | (null) | (null) | (null)
+ s0.st0 | 2 | num | t | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {10,20,40,50,60} | (null) | (null) | (null)
+(4 rows)
+
+/*
+ * Stab function dbms_stats.lock
+ */
+ALTER FUNCTION dbms_stats.lock(relid regclass)
+ RENAME TO truth_lock;
+CREATE FUNCTION dbms_stats.lock(relid regclass)
+RETURNS regclass AS
+$$
+BEGIN
+ RAISE NOTICE 'arguments are %', $1;
+ RETURN $1;
+END
+$$
+LANGUAGE plpgsql;
+ALTER FUNCTION dbms_stats.lock(relid regclass, attname text)
+ RENAME TO truth_lock;
+CREATE FUNCTION dbms_stats.lock(
+ relid regclass,
+ attname text)
+RETURNS regclass AS
+$$
+BEGIN
+ RAISE NOTICE 'arguments are %, %', $1, $2;
+ RETURN $1;
+END
+$$
+LANGUAGE plpgsql;
+/*
+ * No.12-1 dbms_stats.lock_database_stats
+ */
+-- No.12-1-1
+SELECT dbms_stats.lock_database_stats();
+NOTICE: arguments are pt0
+CONTEXT: SQL function "lock_database_stats" statement 1
+NOTICE: arguments are pt0_idx
+CONTEXT: SQL function "lock_database_stats" statement 1
+NOTICE: arguments are st0
+CONTEXT: SQL function "lock_database_stats" statement 1
+NOTICE: arguments are st0_idx
+CONTEXT: SQL function "lock_database_stats" statement 1
+NOTICE: arguments are st1
+CONTEXT: SQL function "lock_database_stats" statement 1
+NOTICE: arguments are s0.st0
+CONTEXT: SQL function "lock_database_stats" statement 1
+NOTICE: arguments are s0.st0_idx
+CONTEXT: SQL function "lock_database_stats" statement 1
+NOTICE: arguments are s0.st1
+CONTEXT: SQL function "lock_database_stats" statement 1
+NOTICE: arguments are s0.st1_idx
+CONTEXT: SQL function "lock_database_stats" statement 1
+NOTICE: arguments are s0.st2
+CONTEXT: SQL function "lock_database_stats" statement 1
+NOTICE: arguments are s0.st2_idx
+CONTEXT: SQL function "lock_database_stats" statement 1
+NOTICE: arguments are st1_idx
+CONTEXT: SQL function "lock_database_stats" statement 1
+NOTICE: arguments are st1_exp
+CONTEXT: SQL function "lock_database_stats" statement 1
+NOTICE: arguments are s1.st0
+CONTEXT: SQL function "lock_database_stats" statement 1
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+/*
+ * No.12-2 dbms_stats.lock_schema_stats
+ */
+-- No.12-2-1
+SELECT dbms_stats.lock_schema_stats('s0');
+NOTICE: arguments are s0.st0
+CONTEXT: PL/pgSQL function "lock_schema_stats" line 10 at RETURN QUERY
+NOTICE: arguments are s0.st0_idx
+CONTEXT: PL/pgSQL function "lock_schema_stats" line 10 at RETURN QUERY
+NOTICE: arguments are s0.st1
+CONTEXT: PL/pgSQL function "lock_schema_stats" line 10 at RETURN QUERY
+NOTICE: arguments are s0.st1_idx
+CONTEXT: PL/pgSQL function "lock_schema_stats" line 10 at RETURN QUERY
+NOTICE: arguments are s0.st2
+CONTEXT: PL/pgSQL function "lock_schema_stats" line 10 at RETURN QUERY
+NOTICE: arguments are s0.st2_idx
+CONTEXT: PL/pgSQL function "lock_schema_stats" line 10 at RETURN QUERY
+ lock_schema_stats
+-------------------
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+(6 rows)
+
+-- No.12-2-2
+SELECT dbms_stats.lock_schema_stats('s00');
+ERROR: schema "s00" does not exist
+-- No.12-2-3
+SELECT dbms_stats.lock_schema_stats('pg_catalog');
+ERROR: can not lock statistics of relation in system schema "pg_catalog"
+/*
+ * No.12-3 dbms_stats.lock_table_stats(regclass)
+ */
+-- No.12-3-1
+SELECT dbms_stats.lock_table_stats('s0.st0');
+NOTICE: arguments are s0.st0
+CONTEXT: SQL function "lock_table_stats" statement 1
+ lock_table_stats
+------------------
+ s0.st0
+(1 row)
+
+-- No.12-3-2
+SELECT dbms_stats.lock_table_stats('st0');
+NOTICE: arguments are st0
+CONTEXT: SQL function "lock_table_stats" statement 1
+ lock_table_stats
+------------------
+ st0
+(1 row)
+
+-- No.12-3-3
+SELECT dbms_stats.lock_table_stats('s00.s0');
+ERROR: schema "s00" does not exist
+LINE 1: SELECT dbms_stats.lock_table_stats('s00.s0');
+ ^
+/*
+ * No.12-4 dbms_stats.lock_table_stats(schemaname, tablename)
+ */
+-- No.12-4-1
+SELECT dbms_stats.lock_table_stats('s0', 'st0');
+NOTICE: arguments are s0.st0
+CONTEXT: SQL function "lock_table_stats" statement 1
+ lock_table_stats
+------------------
+ s0.st0
+(1 row)
+
+/*
+ * No.12-5 dbms_stats.lock_column_stats(regclass, attname)
+ */
+-- No.12-5-1
+SELECT dbms_stats.lock_column_stats('s0.st0', 'id');
+NOTICE: arguments are s0.st0, id
+CONTEXT: SQL function "lock_column_stats" statement 1
+ lock_column_stats
+-------------------
+ s0.st0
+(1 row)
+
+-- No.12-5-2
+SELECT dbms_stats.lock_column_stats('st0', 'id');
+NOTICE: arguments are st0, id
+CONTEXT: SQL function "lock_column_stats" statement 1
+ lock_column_stats
+-------------------
+ st0
+(1 row)
+
+-- No.12-5-3
+SELECT dbms_stats.lock_column_stats('s00.s0', 'id');
+ERROR: schema "s00" does not exist
+LINE 1: SELECT dbms_stats.lock_column_stats('s00.s0', 'id');
+ ^
+/*
+ * No.12-6 dbms_stats.lock_column_stats(schemaname, tablename, int2)
+ */
+-- No.12-6-1
+SELECT dbms_stats.lock_column_stats('s0', 'st0', 'id');
+NOTICE: arguments are s0.st0, id
+CONTEXT: SQL function "lock_column_stats" statement 1
+ lock_column_stats
+-------------------
+ s0.st0
+(1 row)
+
+/*
+ * Delete Stab function lock
+ */
+DROP FUNCTION dbms_stats.lock(relid regclass);
+ALTER FUNCTION dbms_stats.truth_lock(relid regclass)
+ RENAME TO lock;
+DROP FUNCTION dbms_stats.lock(relid regclass, attname text);
+ALTER FUNCTION dbms_stats.truth_lock(relid regclass, attname text)
+ RENAME TO lock;
+/*
+ * No.13-1 dbms_stats.unlock
+ */
+-- No.13-1-1
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+ id | time | unit | comment
+----+-------------------------------------+------+---------
+ 1 | Wed Feb 29 23:59:56.999999 2012 PST | d | (null)
+ 2 | Wed Feb 29 23:59:57 2012 PST | d | (null)
+ 3 | Wed Feb 29 23:59:57.000001 2012 PST | t | (null)
+ 4 | Wed Feb 29 23:59:58 2012 PST | d | (null)
+ 5 | Thu Mar 01 00:00:00 2012 PST | c | (null)
+ 6 | Thu Mar 01 00:00:02 2012 PST | t | (null)
+ 7 | Thu Mar 01 00:00:04 2012 PST | t | (null)
+ 8 | Thu Mar 01 00:00:06 2012 PST | s | (null)
+(8 rows)
+
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+ count
+-------
+ 24
+(1 row)
+
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+ count
+-------
+ 35
+(1 row)
+
+SELECT dbms_stats.unlock();
+ unlock
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+ id | time | unit | comment
+----+-------------------------------------+------+---------
+ 1 | Wed Feb 29 23:59:56.999999 2012 PST | d | (null)
+ 2 | Wed Feb 29 23:59:57 2012 PST | d | (null)
+ 3 | Wed Feb 29 23:59:57.000001 2012 PST | t | (null)
+ 4 | Wed Feb 29 23:59:58 2012 PST | d | (null)
+ 5 | Thu Mar 01 00:00:00 2012 PST | c | (null)
+ 6 | Thu Mar 01 00:00:02 2012 PST | t | (null)
+ 7 | Thu Mar 01 00:00:04 2012 PST | t | (null)
+ 8 | Thu Mar 01 00:00:06 2012 PST | s | (null)
+(8 rows)
+
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+ count
+-------
+ 24
+(1 row)
+
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+ count
+-------
+ 35
+(1 row)
+
+-- No.13-1-2
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT dbms_stats.unlock();
+ unlock
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+-- No.13-1-3
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+DELETE FROM dbms_stats._column_stats_locked;
+SELECT dbms_stats.unlock();
+ unlock
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+-- No.13-1-4
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.unlock();
+ unlock
+--------
+(0 rows)
+
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+-- No.13-1-5
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+SELECT dbms_stats.unlock('s0.st0');
+ unlock
+--------
+ s0.st0
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(13 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(6 rows)
+
+-- No.13-1-6
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+SELECT dbms_stats.unlock('st0');
+ unlock
+--------
+ st0
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(13 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(6 rows)
+
+-- No.13-1-7
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+ count
+-------
+ 14
+(1 row)
+
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+ count
+-------
+ 15
+(1 row)
+
+SELECT dbms_stats.unlock('s00.s0');
+ERROR: schema "s00" does not exist
+LINE 1: SELECT dbms_stats.unlock('s00.s0');
+ ^
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+ count
+-------
+ 14
+(1 row)
+
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+ count
+-------
+ 15
+(1 row)
+
+-- No.13-1-8
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+SELECT dbms_stats.unlock('s0.st0', 'id');
+ unlock
+--------
+ s0.st0
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(13 rows)
+
+-- No.13-1-9
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+SELECT dbms_stats.unlock('s0.st0', 'dummy');
+ERROR: column "dummy" of "s0.st0" does not exist
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+-- No.13-1-10
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+DELETE FROM dbms_stats._column_stats_locked;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT dbms_stats.unlock('s0.st0', 'id');
+ unlock
+--------
+ s0.st0
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid::regclass, staattnum FROM dbms_stats._column_stats_locked
+ GROUP BY starelid, staattnum
+ ORDER BY starelid;
+ starelid | staattnum
+----------+-----------
+(0 rows)
+
+-- No.13-1-11
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid::regclass, staattnum FROM dbms_stats._column_stats_locked
+ GROUP BY starelid, staattnum
+ ORDER BY starelid;
+ starelid | staattnum
+----------+-----------
+ st0 | 1
+ st0 | 2
+ st1 | 1
+ st1 | 2
+ s0.st0 | 1
+ s0.st0 | 2
+ s0.st1 | 1
+ s0.st1 | 2
+ s0.st2 | 1
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 1
+ s1.st0 | 2
+(13 rows)
+
+SELECT dbms_stats.unlock(NULL, 'id');
+ERROR: relation is required
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid::regclass, staattnum FROM dbms_stats._column_stats_locked
+ GROUP BY starelid, staattnum
+ ORDER BY starelid;
+ starelid | staattnum
+----------+-----------
+ st0 | 1
+ st0 | 2
+ st1 | 1
+ st1 | 2
+ s0.st0 | 1
+ s0.st0 | 2
+ s0.st1 | 1
+ s0.st1 | 2
+ s0.st2 | 1
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 1
+ s1.st0 | 2
+(13 rows)
+
+-- No.13-1-12
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid::regclass, staattnum FROM dbms_stats._column_stats_locked
+ GROUP BY starelid, staattnum
+ ORDER BY starelid;
+ starelid | staattnum
+----------+-----------
+ st0 | 1
+ st0 | 2
+ st1 | 1
+ st1 | 2
+ s0.st0 | 1
+ s0.st0 | 2
+ s0.st1 | 1
+ s0.st1 | 2
+ s0.st2 | 1
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 1
+ s1.st0 | 2
+(13 rows)
+
+SELECT dbms_stats.unlock('s0.st0', NULL);
+ unlock
+--------
+ s0.st0
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(13 rows)
+
+SELECT starelid::regclass, staattnum FROM dbms_stats._column_stats_locked
+ GROUP BY starelid, staattnum
+ ORDER BY starelid;
+ starelid | staattnum
+----------+-----------
+ st0 | 1
+ st0 | 2
+ st1 | 1
+ st1 | 2
+ s0.st1 | 1
+ s0.st1 | 2
+ s0.st2 | 1
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 1
+ s1.st0 | 2
+(11 rows)
+
+-- No.13-1-13
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+ count
+-------
+ 14
+(1 row)
+
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+ count
+-------
+ 15
+(1 row)
+
+BEGIN;
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+ relation | mode
+----------+---------------
+ (null) | ExclusiveLock
+(1 row)
+
+SELECT dbms_stats.unlock();
+ unlock
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+ relation | mode
+-----------------------------------+--------------------------
+ dbms_stats._column_stats_locked | RowExclusiveLock
+ dbms_stats._column_stats_locked | ShareUpdateExclusiveLock
+ dbms_stats._relation_stats_locked | RowExclusiveLock
+ dbms_stats._relation_stats_locked | ShareUpdateExclusiveLock
+ (null) | ExclusiveLock
+ (null) | ExclusiveLock
+(6 rows)
+
+COMMIT;
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+/*
+ * No.14-1 dbms_stats.unlock_database_stats
+ */
+-- No.14-1-1
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+ id | time | unit | comment
+----+-------------------------------------+------+---------
+ 1 | Wed Feb 29 23:59:56.999999 2012 PST | d | (null)
+ 2 | Wed Feb 29 23:59:57 2012 PST | d | (null)
+ 3 | Wed Feb 29 23:59:57.000001 2012 PST | t | (null)
+ 4 | Wed Feb 29 23:59:58 2012 PST | d | (null)
+ 5 | Thu Mar 01 00:00:00 2012 PST | c | (null)
+ 6 | Thu Mar 01 00:00:02 2012 PST | t | (null)
+ 7 | Thu Mar 01 00:00:04 2012 PST | t | (null)
+ 8 | Thu Mar 01 00:00:06 2012 PST | s | (null)
+(8 rows)
+
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+ count
+-------
+ 24
+(1 row)
+
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+ count
+-------
+ 35
+(1 row)
+
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+ count
+-------
+ 14
+(1 row)
+
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+ count
+-------
+ 15
+(1 row)
+
+SELECT dbms_stats.unlock_database_stats();
+ unlock_database_stats
+-----------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+ id | time | unit | comment
+----+-------------------------------------+------+---------
+ 1 | Wed Feb 29 23:59:56.999999 2012 PST | d | (null)
+ 2 | Wed Feb 29 23:59:57 2012 PST | d | (null)
+ 3 | Wed Feb 29 23:59:57.000001 2012 PST | t | (null)
+ 4 | Wed Feb 29 23:59:58 2012 PST | d | (null)
+ 5 | Thu Mar 01 00:00:00 2012 PST | c | (null)
+ 6 | Thu Mar 01 00:00:02 2012 PST | t | (null)
+ 7 | Thu Mar 01 00:00:04 2012 PST | t | (null)
+ 8 | Thu Mar 01 00:00:06 2012 PST | s | (null)
+(8 rows)
+
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+ count
+-------
+ 24
+(1 row)
+
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+ count
+-------
+ 35
+(1 row)
+
+-- No.14-1-2
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+DELETE FROM dbms_stats._column_stats_locked;
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+ count
+-------
+ 14
+(1 row)
+
+SELECT dbms_stats.unlock_database_stats();
+ unlock_database_stats
+-----------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+-- No.14-1-3
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.unlock_database_stats();
+ unlock_database_stats
+-----------------------
+(0 rows)
+
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+-- No.14-1-4
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+ count
+-------
+ 14
+(1 row)
+
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+ count
+-------
+ 15
+(1 row)
+
+BEGIN;
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+ relation | mode
+----------+---------------
+ (null) | ExclusiveLock
+(1 row)
+
+SELECT dbms_stats.unlock_database_stats();
+ unlock_database_stats
+-----------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+ relation | mode
+-----------------------------------+--------------------------
+ dbms_stats._column_stats_locked | RowExclusiveLock
+ dbms_stats._column_stats_locked | ShareUpdateExclusiveLock
+ dbms_stats._relation_stats_locked | RowExclusiveLock
+ dbms_stats._relation_stats_locked | ShareUpdateExclusiveLock
+ (null) | ExclusiveLock
+ (null) | ExclusiveLock
+(6 rows)
+
+COMMIT;
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+/*
+ * No.14-2 dbms_stats.unlock_schema_stats
+ */
+-- No.14-2-1
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+ id | time | unit | comment
+----+-------------------------------------+------+---------
+ 1 | Wed Feb 29 23:59:56.999999 2012 PST | d | (null)
+ 2 | Wed Feb 29 23:59:57 2012 PST | d | (null)
+ 3 | Wed Feb 29 23:59:57.000001 2012 PST | t | (null)
+ 4 | Wed Feb 29 23:59:58 2012 PST | d | (null)
+ 5 | Thu Mar 01 00:00:00 2012 PST | c | (null)
+ 6 | Thu Mar 01 00:00:02 2012 PST | t | (null)
+ 7 | Thu Mar 01 00:00:04 2012 PST | t | (null)
+ 8 | Thu Mar 01 00:00:06 2012 PST | s | (null)
+(8 rows)
+
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+ count
+-------
+ 24
+(1 row)
+
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+ count
+-------
+ 35
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+SELECT dbms_stats.unlock_schema_stats('s0');
+ unlock_schema_stats
+---------------------
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+(6 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+---------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ st1_idx
+ st1_exp
+ s1.st0
+(8 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(4 rows)
+
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+ id | time | unit | comment
+----+-------------------------------------+------+---------
+ 1 | Wed Feb 29 23:59:56.999999 2012 PST | d | (null)
+ 2 | Wed Feb 29 23:59:57 2012 PST | d | (null)
+ 3 | Wed Feb 29 23:59:57.000001 2012 PST | t | (null)
+ 4 | Wed Feb 29 23:59:58 2012 PST | d | (null)
+ 5 | Thu Mar 01 00:00:00 2012 PST | c | (null)
+ 6 | Thu Mar 01 00:00:02 2012 PST | t | (null)
+ 7 | Thu Mar 01 00:00:04 2012 PST | t | (null)
+ 8 | Thu Mar 01 00:00:06 2012 PST | s | (null)
+(8 rows)
+
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+ count
+-------
+ 24
+(1 row)
+
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+ count
+-------
+ 35
+(1 row)
+
+-- No.14-2-2
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+DELETE FROM dbms_stats._column_stats_locked;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+(0 rows)
+
+SELECT dbms_stats.unlock_schema_stats('s0');
+ unlock_schema_stats
+---------------------
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+(6 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+---------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ st1_idx
+ st1_exp
+ s1.st0
+(8 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+(0 rows)
+
+-- No.14-2-3
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+-------
+(0 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+(0 rows)
+
+SELECT dbms_stats.unlock_schema_stats('s0');
+ unlock_schema_stats
+---------------------
+(0 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+-------
+(0 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+(0 rows)
+
+-- No.14-2-4
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+SELECT dbms_stats.unlock_schema_stats('s0');
+ unlock_schema_stats
+---------------------
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+(6 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+---------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ st1_idx
+ st1_exp
+ s1.st0
+(8 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(4 rows)
+
+-- No.14-2-5
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+SELECT dbms_stats.unlock_schema_stats('s00');
+ERROR: schema "s00" does not exist
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+-- No.14-2-6
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+SELECT dbms_stats.unlock_schema_stats('pg_catalog');
+ERROR: can not unlock statistics of relation in system schema "pg_catalog"
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+-- No.14-2-7
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+SELECT dbms_stats.unlock_schema_stats(NULL);
+ unlock_schema_stats
+---------------------
+(0 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+-- No.14-2-8
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+BEGIN;
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+ relation | mode
+----------+---------------
+ (null) | ExclusiveLock
+(1 row)
+
+SELECT dbms_stats.unlock_schema_stats('s0');
+ unlock_schema_stats
+---------------------
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+(6 rows)
+
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+ relation | mode
+-----------------------------------+--------------------------
+ dbms_stats._column_stats_locked | RowExclusiveLock
+ dbms_stats._column_stats_locked | ShareUpdateExclusiveLock
+ dbms_stats._relation_stats_locked | RowExclusiveLock
+ dbms_stats._relation_stats_locked | ShareUpdateExclusiveLock
+ (null) | ExclusiveLock
+ (null) | ExclusiveLock
+(6 rows)
+
+COMMIT;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+---------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ st1_idx
+ st1_exp
+ s1.st0
+(8 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(4 rows)
+
+/*
+ * No.14-3 dbms_stats.unlock_table_stats(regclass)
+ */
+-- No.14-3-1
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+ id | time | unit | comment
+----+-------------------------------------+------+---------
+ 1 | Wed Feb 29 23:59:56.999999 2012 PST | d | (null)
+ 2 | Wed Feb 29 23:59:57 2012 PST | d | (null)
+ 3 | Wed Feb 29 23:59:57.000001 2012 PST | t | (null)
+ 4 | Wed Feb 29 23:59:58 2012 PST | d | (null)
+ 5 | Thu Mar 01 00:00:00 2012 PST | c | (null)
+ 6 | Thu Mar 01 00:00:02 2012 PST | t | (null)
+ 7 | Thu Mar 01 00:00:04 2012 PST | t | (null)
+ 8 | Thu Mar 01 00:00:06 2012 PST | s | (null)
+(8 rows)
+
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+ count
+-------
+ 24
+(1 row)
+
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+ count
+-------
+ 35
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+SELECT dbms_stats.unlock_table_stats('s0.st0');
+ unlock_table_stats
+--------------------
+ s0.st0
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(13 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(6 rows)
+
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+ id | time | unit | comment
+----+-------------------------------------+------+---------
+ 1 | Wed Feb 29 23:59:56.999999 2012 PST | d | (null)
+ 2 | Wed Feb 29 23:59:57 2012 PST | d | (null)
+ 3 | Wed Feb 29 23:59:57.000001 2012 PST | t | (null)
+ 4 | Wed Feb 29 23:59:58 2012 PST | d | (null)
+ 5 | Thu Mar 01 00:00:00 2012 PST | c | (null)
+ 6 | Thu Mar 01 00:00:02 2012 PST | t | (null)
+ 7 | Thu Mar 01 00:00:04 2012 PST | t | (null)
+ 8 | Thu Mar 01 00:00:06 2012 PST | s | (null)
+(8 rows)
+
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+ count
+-------
+ 24
+(1 row)
+
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+ count
+-------
+ 35
+(1 row)
+
+-- No.14-3-2
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+DELETE FROM dbms_stats._column_stats_locked;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+(0 rows)
+
+SELECT dbms_stats.unlock_table_stats('s0.st0');
+ unlock_table_stats
+--------------------
+ s0.st0
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(13 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+(0 rows)
+
+-- No.14-3-3
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+-------
+(0 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+(0 rows)
+
+SELECT dbms_stats.unlock_table_stats('s0.st0');
+ unlock_table_stats
+--------------------
+(0 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+-------
+(0 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+(0 rows)
+
+-- No.14-3-4
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+SELECT dbms_stats.unlock_table_stats('s0.st0');
+ unlock_table_stats
+--------------------
+ s0.st0
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(13 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(6 rows)
+
+-- No.14-3-5
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+SELECT dbms_stats.unlock_table_stats('st0');
+ unlock_table_stats
+--------------------
+ st0
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(13 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(6 rows)
+
+-- No.14-3-6
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+SELECT dbms_stats.unlock_table_stats('s00.s0');
+ERROR: schema "s00" does not exist
+LINE 1: SELECT dbms_stats.unlock_table_stats('s00.s0');
+ ^
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+-- No.14-3-7
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+SELECT dbms_stats.unlock_table_stats(NULL);
+ unlock_table_stats
+--------------------
+(0 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+-- No.14-3-8
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+BEGIN;
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+ relation | mode
+----------+---------------
+ (null) | ExclusiveLock
+(1 row)
+
+SELECT dbms_stats.unlock_table_stats('s0.st0');
+ unlock_table_stats
+--------------------
+ s0.st0
+(1 row)
+
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+ relation | mode
+----------------------------------------+--------------------------
+ dbms_stats._column_stats_locked | RowExclusiveLock
+ dbms_stats._column_stats_locked | ShareUpdateExclusiveLock
+ dbms_stats._relation_stats_locked | RowExclusiveLock
+ dbms_stats._relation_stats_locked | ShareUpdateExclusiveLock
+ dbms_stats._relation_stats_locked_pkey | RowExclusiveLock
+ (null) | ExclusiveLock
+ (null) | ExclusiveLock
+(7 rows)
+
+COMMIT;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(13 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(6 rows)
+
+/*
+ * No.14-4 dbms_stats.unlock_table_stats(schemaname, tablename)
+ */
+-- No.14-4-1
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+ id | time | unit | comment
+----+-------------------------------------+------+---------
+ 1 | Wed Feb 29 23:59:56.999999 2012 PST | d | (null)
+ 2 | Wed Feb 29 23:59:57 2012 PST | d | (null)
+ 3 | Wed Feb 29 23:59:57.000001 2012 PST | t | (null)
+ 4 | Wed Feb 29 23:59:58 2012 PST | d | (null)
+ 5 | Thu Mar 01 00:00:00 2012 PST | c | (null)
+ 6 | Thu Mar 01 00:00:02 2012 PST | t | (null)
+ 7 | Thu Mar 01 00:00:04 2012 PST | t | (null)
+ 8 | Thu Mar 01 00:00:06 2012 PST | s | (null)
+(8 rows)
+
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+ count
+-------
+ 24
+(1 row)
+
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+ count
+-------
+ 35
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+SELECT dbms_stats.unlock_table_stats('s0','st0');
+ unlock_table_stats
+--------------------
+ s0.st0
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(13 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(6 rows)
+
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+ id | time | unit | comment
+----+-------------------------------------+------+---------
+ 1 | Wed Feb 29 23:59:56.999999 2012 PST | d | (null)
+ 2 | Wed Feb 29 23:59:57 2012 PST | d | (null)
+ 3 | Wed Feb 29 23:59:57.000001 2012 PST | t | (null)
+ 4 | Wed Feb 29 23:59:58 2012 PST | d | (null)
+ 5 | Thu Mar 01 00:00:00 2012 PST | c | (null)
+ 6 | Thu Mar 01 00:00:02 2012 PST | t | (null)
+ 7 | Thu Mar 01 00:00:04 2012 PST | t | (null)
+ 8 | Thu Mar 01 00:00:06 2012 PST | s | (null)
+(8 rows)
+
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+ count
+-------
+ 24
+(1 row)
+
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+ count
+-------
+ 35
+(1 row)
+
+-- No.14-4-2
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+DELETE FROM dbms_stats._column_stats_locked;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+(0 rows)
+
+SELECT dbms_stats.unlock_table_stats('s0', 'st0');
+ unlock_table_stats
+--------------------
+ s0.st0
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(13 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+(0 rows)
+
+-- No.14-4-3
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+-------
+(0 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+(0 rows)
+
+SELECT dbms_stats.unlock_table_stats('s0', 'st0');
+ unlock_table_stats
+--------------------
+(0 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+-------
+(0 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+(0 rows)
+
+-- No.14-4-4
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+SELECT dbms_stats.unlock_table_stats('s0', 'st0');
+ unlock_table_stats
+--------------------
+ s0.st0
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(13 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(6 rows)
+
+-- No.14-4-5
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+SELECT dbms_stats.unlock_table_stats('s00', 's0');
+ERROR: schema "s00" does not exist
+CONTEXT: SQL function "unlock_table_stats" statement 3
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+-- No.14-4-6
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+SELECT dbms_stats.unlock_table_stats(NULL, 'st0');
+ unlock_table_stats
+--------------------
+(0 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+-- No.14-4-7
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+SELECT dbms_stats.unlock_table_stats('s0', NULL);
+ unlock_table_stats
+--------------------
+(0 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+-- No.14-4-8
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+BEGIN;
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+ relation | mode
+----------+---------------
+ (null) | ExclusiveLock
+(1 row)
+
+SELECT dbms_stats.unlock_table_stats('s0', 'st0');
+ unlock_table_stats
+--------------------
+ s0.st0
+(1 row)
+
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+ relation | mode
+----------------------------------------+--------------------------
+ dbms_stats._column_stats_locked | RowExclusiveLock
+ dbms_stats._column_stats_locked | ShareUpdateExclusiveLock
+ dbms_stats._relation_stats_locked | RowExclusiveLock
+ dbms_stats._relation_stats_locked | ShareUpdateExclusiveLock
+ dbms_stats._relation_stats_locked_pkey | RowExclusiveLock
+ (null) | ExclusiveLock
+ (null) | ExclusiveLock
+(7 rows)
+
+COMMIT;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(13 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(6 rows)
+
+/*
+ * No.14-5 dbms_stats.unlock_column_stats(regclass, attname)
+ */
+-- No.14-5-1
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+ id | time | unit | comment
+----+-------------------------------------+------+---------
+ 1 | Wed Feb 29 23:59:56.999999 2012 PST | d | (null)
+ 2 | Wed Feb 29 23:59:57 2012 PST | d | (null)
+ 3 | Wed Feb 29 23:59:57.000001 2012 PST | t | (null)
+ 4 | Wed Feb 29 23:59:58 2012 PST | d | (null)
+ 5 | Thu Mar 01 00:00:00 2012 PST | c | (null)
+ 6 | Thu Mar 01 00:00:02 2012 PST | t | (null)
+ 7 | Thu Mar 01 00:00:04 2012 PST | t | (null)
+ 8 | Thu Mar 01 00:00:06 2012 PST | s | (null)
+(8 rows)
+
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+ count
+-------
+ 24
+(1 row)
+
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+ count
+-------
+ 35
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+SELECT dbms_stats.unlock_column_stats('s0.st0', 'id');
+ unlock_column_stats
+---------------------
+ s0.st0
+(1 row)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(13 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+ id | time | unit | comment
+----+-------------------------------------+------+---------
+ 1 | Wed Feb 29 23:59:56.999999 2012 PST | d | (null)
+ 2 | Wed Feb 29 23:59:57 2012 PST | d | (null)
+ 3 | Wed Feb 29 23:59:57.000001 2012 PST | t | (null)
+ 4 | Wed Feb 29 23:59:58 2012 PST | d | (null)
+ 5 | Thu Mar 01 00:00:00 2012 PST | c | (null)
+ 6 | Thu Mar 01 00:00:02 2012 PST | t | (null)
+ 7 | Thu Mar 01 00:00:04 2012 PST | t | (null)
+ 8 | Thu Mar 01 00:00:06 2012 PST | s | (null)
+(8 rows)
+
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+ count
+-------
+ 24
+(1 row)
+
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+ count
+-------
+ 35
+(1 row)
+
+-- No.14-5-2
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+DELETE FROM dbms_stats._column_stats_locked;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT dbms_stats.unlock_column_stats('s0.st0', 'id');
+ unlock_column_stats
+---------------------
+ s0.st0
+(1 row)
+
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+-- No.14-5-3
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+SELECT dbms_stats.unlock_column_stats('s0.st0', 'id');
+ unlock_column_stats
+---------------------
+ s0.st0
+(1 row)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(13 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+-- No.14-5-4
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+SELECT dbms_stats.unlock_column_stats('st0', 'id');
+ unlock_column_stats
+---------------------
+ st0
+(1 row)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(14 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+-- No.14-5-5
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+SELECT dbms_stats.unlock_column_stats('s0.st0', 'dummy');
+ERROR: column "dummy" of "s0.st0" does not exist
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+-- No.14-5-6
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+SELECT dbms_stats.unlock_column_stats('s00.s0', 'id');
+ERROR: schema "s00" does not exist
+LINE 1: SELECT dbms_stats.unlock_column_stats('s00.s0', 'id');
+ ^
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+-- No.14-5-7
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+SELECT dbms_stats.unlock_column_stats(NULL, 'id');
+ unlock_column_stats
+---------------------
+(0 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+-- No.14-5-8
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+SELECT dbms_stats.unlock_column_stats('s0.st0', NULL);
+ unlock_column_stats
+---------------------
+(0 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+-- No.14-5-9
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+BEGIN;
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+ relation | mode
+----------+---------------
+ (null) | ExclusiveLock
+(1 row)
+
+SELECT dbms_stats.unlock_column_stats('s0.st0', 'id');
+ unlock_column_stats
+---------------------
+ s0.st0
+(1 row)
+
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+ relation | mode
+-----------------------------------+--------------------------
+ dbms_stats._column_stats_locked | RowExclusiveLock
+ dbms_stats._column_stats_locked | ShareUpdateExclusiveLock
+ dbms_stats._relation_stats_locked | ShareUpdateExclusiveLock
+ (null) | ExclusiveLock
+ (null) | ExclusiveLock
+(5 rows)
+
+COMMIT;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(13 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+/*
+ * No.14-6 dbms_stats.unlock_column_stats(schemaname, tablename, attname)
+ */
+-- No.14-6-1
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+ id | time | unit | comment
+----+-------------------------------------+------+---------
+ 1 | Wed Feb 29 23:59:56.999999 2012 PST | d | (null)
+ 2 | Wed Feb 29 23:59:57 2012 PST | d | (null)
+ 3 | Wed Feb 29 23:59:57.000001 2012 PST | t | (null)
+ 4 | Wed Feb 29 23:59:58 2012 PST | d | (null)
+ 5 | Thu Mar 01 00:00:00 2012 PST | c | (null)
+ 6 | Thu Mar 01 00:00:02 2012 PST | t | (null)
+ 7 | Thu Mar 01 00:00:04 2012 PST | t | (null)
+ 8 | Thu Mar 01 00:00:06 2012 PST | s | (null)
+(8 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+SELECT dbms_stats.unlock_column_stats('s0', 'st0', 'id');
+ unlock_column_stats
+---------------------
+ s0.st0
+(1 row)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(13 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+ id | time | unit | comment
+----+-------------------------------------+------+---------
+ 1 | Wed Feb 29 23:59:56.999999 2012 PST | d | (null)
+ 2 | Wed Feb 29 23:59:57 2012 PST | d | (null)
+ 3 | Wed Feb 29 23:59:57.000001 2012 PST | t | (null)
+ 4 | Wed Feb 29 23:59:58 2012 PST | d | (null)
+ 5 | Thu Mar 01 00:00:00 2012 PST | c | (null)
+ 6 | Thu Mar 01 00:00:02 2012 PST | t | (null)
+ 7 | Thu Mar 01 00:00:04 2012 PST | t | (null)
+ 8 | Thu Mar 01 00:00:06 2012 PST | s | (null)
+(8 rows)
+
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+ count
+-------
+ 24
+(1 row)
+
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+ count
+-------
+ 35
+(1 row)
+
+-- No.14-6-2
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+DELETE FROM dbms_stats._column_stats_locked;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT dbms_stats.unlock_column_stats('s0', 'st0', 'id');
+ unlock_column_stats
+---------------------
+ s0.st0
+(1 row)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+(0 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+-- No.14-6-3
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+SELECT dbms_stats.unlock_column_stats('s0', 'st0', 'id');
+ unlock_column_stats
+---------------------
+ s0.st0
+(1 row)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(13 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+-- No.14-6-4
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+SELECT dbms_stats.unlock_column_stats('s0', 'st0', 'dummy');
+ERROR: column "dummy" of "s0.st0" does not exist
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+-- No.14-6-5
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+SELECT dbms_stats.unlock_column_stats(NULL, 'st0', 'id');
+ unlock_column_stats
+---------------------
+(0 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+-- No.14-6-6
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+SELECT dbms_stats.unlock_column_stats('s0', NULL, 'id');
+ unlock_column_stats
+---------------------
+(0 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+-- No.14-6-7
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+SELECT dbms_stats.unlock_column_stats('s0', 'st0', NULL);
+ unlock_column_stats
+---------------------
+(0 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+-- No.14-6-8
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+BEGIN;
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+ relation | mode
+----------+---------------
+ (null) | ExclusiveLock
+(1 row)
+
+SELECT dbms_stats.unlock_column_stats('s0', 'st0', 'id');
+ unlock_column_stats
+---------------------
+ s0.st0
+(1 row)
+
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+ relation | mode
+-----------------------------------+--------------------------
+ dbms_stats._column_stats_locked | RowExclusiveLock
+ dbms_stats._column_stats_locked | ShareUpdateExclusiveLock
+ dbms_stats._relation_stats_locked | ShareUpdateExclusiveLock
+ (null) | ExclusiveLock
+ (null) | ExclusiveLock
+(5 rows)
+
+COMMIT;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(13 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
diff --git a/expected/ut-9.2.out b/expected/ut-9.2.out
new file mode 100644
index 0000000..5d5d3f7
--- /dev/null
+++ b/expected/ut-9.2.out
@@ -0,0 +1,9571 @@
+\pset null '(null)'
+/*
+ * No.2-1 table definitions.
+ */
+-- No.2-1-1
+\d dbms_stats.backup_history
+ Table "dbms_stats.backup_history"
+ Column | Type | Modifiers
+---------+--------------------------+------------------------------------------------------------------------
+ id | bigint | not null default nextval('dbms_stats.backup_history_id_seq'::regclass)
+ time | timestamp with time zone | not null
+ unit | character(1) | not null
+ comment | text |
+Indexes:
+ "backup_history_pkey" PRIMARY KEY, btree (id)
+Referenced by:
+ TABLE "dbms_stats.column_stats_backup" CONSTRAINT "column_stats_backup_id_fkey" FOREIGN KEY (id) REFERENCES dbms_stats.backup_history(id) ON DELETE CASCADE
+ TABLE "dbms_stats.relation_stats_backup" CONSTRAINT "relation_stats_backup_id_fkey" FOREIGN KEY (id) REFERENCES dbms_stats.backup_history(id) ON DELETE CASCADE
+
+-- No.2-1-2
+\d dbms_stats.column_stats_backup
+ Table "dbms_stats.column_stats_backup"
+ Column | Type | Modifiers
+-------------+---------------------+-----------
+ id | bigint | not null
+ statypid | oid | not null
+ starelid | oid | not null
+ staattnum | smallint | not null
+ stainherit | boolean | not null
+ stanullfrac | real | not null
+ stawidth | integer | not null
+ stadistinct | real | not null
+ stakind1 | smallint | not null
+ stakind2 | smallint | not null
+ stakind3 | smallint | not null
+ stakind4 | smallint | not null
+ stakind5 | smallint | not null
+ staop1 | oid | not null
+ staop2 | oid | not null
+ staop3 | oid | not null
+ staop4 | oid | not null
+ staop5 | oid | not null
+ stanumbers1 | real[] |
+ stanumbers2 | real[] |
+ stanumbers3 | real[] |
+ stanumbers4 | real[] |
+ stanumbers5 | real[] |
+ stavalues1 | dbms_stats.anyarray |
+ stavalues2 | dbms_stats.anyarray |
+ stavalues3 | dbms_stats.anyarray |
+ stavalues4 | dbms_stats.anyarray |
+ stavalues5 | dbms_stats.anyarray |
+Indexes:
+ "column_stats_backup_pkey" PRIMARY KEY, btree (id, starelid, staattnum, stainherit)
+Foreign-key constraints:
+ "column_stats_backup_id_fkey" FOREIGN KEY (id) REFERENCES dbms_stats.backup_history(id) ON DELETE CASCADE
+ "column_stats_backup_id_fkey1" FOREIGN KEY (id, starelid) REFERENCES dbms_stats.relation_stats_backup(id, relid) ON DELETE CASCADE
+
+-- No.2-1-3
+\d dbms_stats._column_stats_locked
+ Table "dbms_stats._column_stats_locked"
+ Column | Type | Modifiers
+-------------+---------------------+-----------
+ starelid | oid | not null
+ staattnum | smallint | not null
+ stainherit | boolean | not null
+ stanullfrac | real |
+ stawidth | integer |
+ stadistinct | real |
+ stakind1 | smallint |
+ stakind2 | smallint |
+ stakind3 | smallint |
+ stakind4 | smallint |
+ stakind5 | smallint |
+ staop1 | oid |
+ staop2 | oid |
+ staop3 | oid |
+ staop4 | oid |
+ staop5 | oid |
+ stanumbers1 | real[] |
+ stanumbers2 | real[] |
+ stanumbers3 | real[] |
+ stanumbers4 | real[] |
+ stanumbers5 | real[] |
+ stavalues1 | dbms_stats.anyarray |
+ stavalues2 | dbms_stats.anyarray |
+ stavalues3 | dbms_stats.anyarray |
+ stavalues4 | dbms_stats.anyarray |
+ stavalues5 | dbms_stats.anyarray |
+Indexes:
+ "_column_stats_locked_pkey" PRIMARY KEY, btree (starelid, staattnum, stainherit)
+Foreign-key constraints:
+ "_column_stats_locked_starelid_fkey" FOREIGN KEY (starelid) REFERENCES dbms_stats._relation_stats_locked(relid) ON DELETE CASCADE
+Triggers:
+ 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()
+
+-- No.2-1-4
+\d dbms_stats.relation_stats_backup
+ Table "dbms_stats.relation_stats_backup"
+ Column | Type | Modifiers
+------------------+--------------------------+-----------
+ id | bigint | not null
+ relid | oid | not null
+ relname | text | not null
+ relpages | integer | not null
+ reltuples | real | not null
+ relallvisible | integer | not null
+ curpages | integer | not null
+ last_analyze | timestamp with time zone |
+ last_autoanalyze | timestamp with time zone |
+Indexes:
+ "relation_stats_backup_pkey" PRIMARY KEY, btree (id, relid)
+Foreign-key constraints:
+ "relation_stats_backup_id_fkey" FOREIGN KEY (id) REFERENCES dbms_stats.backup_history(id) ON DELETE CASCADE
+Referenced by:
+ 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
+
+-- No.2-1-5
+\d dbms_stats._relation_stats_locked
+ Table "dbms_stats._relation_stats_locked"
+ Column | Type | Modifiers
+------------------+--------------------------+-----------
+ relid | oid | not null
+ relname | text | not null
+ relpages | integer |
+ reltuples | real |
+ relallvisible | integer |
+ curpages | integer |
+ last_analyze | timestamp with time zone |
+ last_autoanalyze | timestamp with time zone |
+Indexes:
+ "_relation_stats_locked_pkey" PRIMARY KEY, btree (relid)
+Referenced by:
+ 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
+Triggers:
+ 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()
+
+/*
+ * No.2-2 view definitions.
+ */
+-- No.2-2-1
+\dS+ dbms_stats.column_stats_effective
+ View "dbms_stats.column_stats_effective"
+ Column | Type | Modifiers | Storage | Description
+-------------+---------------------+-----------+----------+-------------
+ starelid | oid | | plain |
+ staattnum | smallint | | plain |
+ stainherit | boolean | | plain |
+ stanullfrac | real | | plain |
+ stawidth | integer | | plain |
+ stadistinct | real | | plain |
+ stakind1 | smallint | | plain |
+ stakind2 | smallint | | plain |
+ stakind3 | smallint | | plain |
+ stakind4 | smallint | | plain |
+ stakind5 | smallint | | plain |
+ staop1 | oid | | plain |
+ staop2 | oid | | plain |
+ staop3 | oid | | plain |
+ staop4 | oid | | plain |
+ staop5 | oid | | plain |
+ stanumbers1 | real[] | | extended |
+ stanumbers2 | real[] | | extended |
+ stanumbers3 | real[] | | extended |
+ stanumbers4 | real[] | | extended |
+ stanumbers5 | real[] | | extended |
+ stavalues1 | dbms_stats.anyarray | | extended |
+ stavalues2 | dbms_stats.anyarray | | extended |
+ stavalues3 | dbms_stats.anyarray | | extended |
+ stavalues4 | dbms_stats.anyarray | | extended |
+ stavalues5 | dbms_stats.anyarray | | extended |
+View definition:
+ SELECT m.starelid, m.staattnum, m.stainherit, m.stanullfrac, m.stawidth,
+ m.stadistinct, m.stakind1, m.stakind2, m.stakind3, m.stakind4, m.stakind5,
+ m.staop1, m.staop2, m.staop3, m.staop4, m.staop5, m.stanumbers1,
+ m.stanumbers2, m.stanumbers3, m.stanumbers4, m.stanumbers5, m.stavalues1,
+ m.stavalues2, m.stavalues3, m.stavalues4, m.stavalues5
+ FROM ( SELECT (dbms_stats.merge(v.*, s.*)).starelid AS starelid,
+ (dbms_stats.merge(v.*, s.*)).staattnum AS staattnum,
+ (dbms_stats.merge(v.*, s.*)).stainherit AS stainherit,
+ (dbms_stats.merge(v.*, s.*)).stanullfrac AS stanullfrac,
+ (dbms_stats.merge(v.*, s.*)).stawidth AS stawidth,
+ (dbms_stats.merge(v.*, s.*)).stadistinct AS stadistinct,
+ (dbms_stats.merge(v.*, s.*)).stakind1 AS stakind1,
+ (dbms_stats.merge(v.*, s.*)).stakind2 AS stakind2,
+ (dbms_stats.merge(v.*, s.*)).stakind3 AS stakind3,
+ (dbms_stats.merge(v.*, s.*)).stakind4 AS stakind4,
+ (dbms_stats.merge(v.*, s.*)).stakind5 AS stakind5,
+ (dbms_stats.merge(v.*, s.*)).staop1 AS staop1,
+ (dbms_stats.merge(v.*, s.*)).staop2 AS staop2,
+ (dbms_stats.merge(v.*, s.*)).staop3 AS staop3,
+ (dbms_stats.merge(v.*, s.*)).staop4 AS staop4,
+ (dbms_stats.merge(v.*, s.*)).staop5 AS staop5,
+ (dbms_stats.merge(v.*, s.*)).stanumbers1 AS stanumbers1,
+ (dbms_stats.merge(v.*, s.*)).stanumbers2 AS stanumbers2,
+ (dbms_stats.merge(v.*, s.*)).stanumbers3 AS stanumbers3,
+ (dbms_stats.merge(v.*, s.*)).stanumbers4 AS stanumbers4,
+ (dbms_stats.merge(v.*, s.*)).stanumbers5 AS stanumbers5,
+ (dbms_stats.merge(v.*, s.*)).stavalues1 AS stavalues1,
+ (dbms_stats.merge(v.*, s.*)).stavalues2 AS stavalues2,
+ (dbms_stats.merge(v.*, s.*)).stavalues3 AS stavalues3,
+ (dbms_stats.merge(v.*, s.*)).stavalues4 AS stavalues4,
+ (dbms_stats.merge(v.*, s.*)).stavalues5 AS stavalues5
+ FROM pg_statistic s
+ FULL JOIN dbms_stats._column_stats_locked v USING (starelid, staattnum, stainherit)
+ WHERE NOT dbms_stats.is_system_catalog(starelid::regclass)) m
+ WHERE m.starelid IS NOT NULL;
+
+-- No.2-2-2
+\dS+ dbms_stats.relation_stats_effective
+ View "dbms_stats.relation_stats_effective"
+ Column | Type | Modifiers | Storage | Description
+------------------+--------------------------+-----------+----------+-------------
+ relid | oid | | plain |
+ relname | text | | extended |
+ relpages | integer | | plain |
+ reltuples | real | | plain |
+ relallvisible | integer | | plain |
+ curpages | integer | | plain |
+ last_analyze | timestamp with time zone | | plain |
+ last_autoanalyze | timestamp with time zone | | plain |
+View definition:
+ SELECT c.oid AS relid,
+ dbms_stats.relname(n.nspname::text, c.relname::text) AS relname,
+ COALESCE(v.relpages, c.relpages) AS relpages,
+ COALESCE(v.reltuples, c.reltuples) AS reltuples,
+ COALESCE(v.relallvisible, c.relallvisible) AS relallvisible,
+ COALESCE(v.curpages, (pg_relation_size(c.oid::regclass) / current_setting('block_size'::text)::integer)::integer) AS curpages,
+ COALESCE(v.last_analyze, pg_stat_get_last_analyze_time(c.oid)) AS last_analyze,
+ COALESCE(v.last_autoanalyze, pg_stat_get_last_autoanalyze_time(c.oid)) AS last_autoanalyze
+ FROM pg_class c
+ JOIN pg_namespace n ON c.relnamespace = n.oid
+ LEFT JOIN dbms_stats._relation_stats_locked v ON v.relid = c.oid
+ WHERE dbms_stats.is_target_relkind(c.relkind) AND NOT dbms_stats.is_system_schema(n.nspname::text);
+
+-- No.2-2-3
+\dS+ dbms_stats.stats
+ View "dbms_stats.stats"
+ Column | Type | Modifiers | Storage | Description
+------------------------+---------------------+-----------+----------+-------------
+ schemaname | name | | plain |
+ tablename | name | | plain |
+ attname | name | | plain |
+ inherited | boolean | | plain |
+ null_frac | real | | plain |
+ avg_width | integer | | plain |
+ n_distinct | real | | plain |
+ most_common_vals | dbms_stats.anyarray | | extended |
+ most_common_freqs | real[] | | extended |
+ histogram_bounds | dbms_stats.anyarray | | extended |
+ correlation | real | | plain |
+ most_common_elems | dbms_stats.anyarray | | extended |
+ most_common_elem_freqs | real[] | | extended |
+ elem_count_histogram | real[] | | extended |
+View definition:
+ SELECT n.nspname AS schemaname, c.relname AS tablename, a.attname,
+ s.stainherit AS inherited, s.stanullfrac AS null_frac,
+ s.stawidth AS avg_width, s.stadistinct AS n_distinct,
+ CASE
+ WHEN s.stakind1 = 1 THEN s.stavalues1
+ WHEN s.stakind2 = 1 THEN s.stavalues2
+ WHEN s.stakind3 = 1 THEN s.stavalues3
+ WHEN s.stakind4 = 1 THEN s.stavalues4
+ WHEN s.stakind5 = 1 THEN s.stavalues5
+ ELSE NULL::dbms_stats.anyarray
+ END AS most_common_vals,
+ CASE
+ WHEN s.stakind1 = 1 THEN s.stanumbers1
+ WHEN s.stakind2 = 1 THEN s.stanumbers2
+ WHEN s.stakind3 = 1 THEN s.stanumbers3
+ WHEN s.stakind4 = 1 THEN s.stanumbers4
+ WHEN s.stakind5 = 1 THEN s.stanumbers5
+ ELSE NULL::real[]
+ END AS most_common_freqs,
+ CASE
+ WHEN s.stakind1 = 2 THEN s.stavalues1
+ WHEN s.stakind2 = 2 THEN s.stavalues2
+ WHEN s.stakind3 = 2 THEN s.stavalues3
+ WHEN s.stakind4 = 2 THEN s.stavalues4
+ WHEN s.stakind5 = 2 THEN s.stavalues5
+ ELSE NULL::dbms_stats.anyarray
+ END AS histogram_bounds,
+ CASE
+ WHEN s.stakind1 = 3 THEN s.stanumbers1[1]
+ WHEN s.stakind2 = 3 THEN s.stanumbers2[1]
+ WHEN s.stakind3 = 3 THEN s.stanumbers3[1]
+ WHEN s.stakind4 = 3 THEN s.stanumbers4[1]
+ WHEN s.stakind5 = 3 THEN s.stanumbers5[1]
+ ELSE NULL::real
+ END AS correlation,
+ CASE
+ WHEN s.stakind1 = 4 THEN s.stavalues1
+ WHEN s.stakind2 = 4 THEN s.stavalues2
+ WHEN s.stakind3 = 4 THEN s.stavalues3
+ WHEN s.stakind4 = 4 THEN s.stavalues4
+ WHEN s.stakind5 = 4 THEN s.stavalues5
+ ELSE NULL::dbms_stats.anyarray
+ END AS most_common_elems,
+ CASE
+ WHEN s.stakind1 = 4 THEN s.stanumbers1
+ WHEN s.stakind2 = 4 THEN s.stanumbers2
+ WHEN s.stakind3 = 4 THEN s.stanumbers3
+ WHEN s.stakind4 = 4 THEN s.stanumbers4
+ WHEN s.stakind5 = 4 THEN s.stanumbers5
+ ELSE NULL::real[]
+ END AS most_common_elem_freqs,
+ CASE
+ WHEN s.stakind1 = 5 THEN s.stanumbers1
+ WHEN s.stakind2 = 5 THEN s.stanumbers2
+ WHEN s.stakind3 = 5 THEN s.stanumbers3
+ WHEN s.stakind4 = 5 THEN s.stanumbers4
+ WHEN s.stakind5 = 5 THEN s.stanumbers5
+ ELSE NULL::real[]
+ END AS elem_count_histogram
+ FROM dbms_stats.column_stats_effective s
+ JOIN pg_class c ON c.oid = s.starelid
+ JOIN pg_attribute a ON c.oid = a.attrelid AND a.attnum = s.staattnum
+ LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
+ WHERE NOT a.attisdropped AND has_column_privilege(c.oid, a.attnum, 'select'::text);
+
+-- No.2-2-4
+\dS+ dbms_stats.column_stats_locked
+ View "dbms_stats.column_stats_locked"
+ Column | Type | Modifiers | Storage | Description
+-------------+---------------------+-----------+----------+-------------
+ starelid | oid | | plain |
+ staattnum | smallint | | plain |
+ stainherit | boolean | | plain |
+ stanullfrac | real | | plain |
+ stawidth | integer | | plain |
+ stadistinct | real | | plain |
+ stakind1 | smallint | | plain |
+ stakind2 | smallint | | plain |
+ stakind3 | smallint | | plain |
+ stakind4 | smallint | | plain |
+ stakind5 | smallint | | plain |
+ staop1 | oid | | plain |
+ staop2 | oid | | plain |
+ staop3 | oid | | plain |
+ staop4 | oid | | plain |
+ staop5 | oid | | plain |
+ stanumbers1 | real[] | | extended |
+ stanumbers2 | real[] | | extended |
+ stanumbers3 | real[] | | extended |
+ stanumbers4 | real[] | | extended |
+ stanumbers5 | real[] | | extended |
+ stavalues1 | dbms_stats.anyarray | | extended |
+ stavalues2 | dbms_stats.anyarray | | extended |
+ stavalues3 | dbms_stats.anyarray | | extended |
+ stavalues4 | dbms_stats.anyarray | | extended |
+ stavalues5 | dbms_stats.anyarray | | extended |
+View definition:
+ SELECT _column_stats_locked.starelid, _column_stats_locked.staattnum,
+ _column_stats_locked.stainherit, _column_stats_locked.stanullfrac,
+ _column_stats_locked.stawidth, _column_stats_locked.stadistinct,
+ _column_stats_locked.stakind1, _column_stats_locked.stakind2,
+ _column_stats_locked.stakind3, _column_stats_locked.stakind4,
+ _column_stats_locked.stakind5, _column_stats_locked.staop1,
+ _column_stats_locked.staop2, _column_stats_locked.staop3,
+ _column_stats_locked.staop4, _column_stats_locked.staop5,
+ _column_stats_locked.stanumbers1, _column_stats_locked.stanumbers2,
+ _column_stats_locked.stanumbers3, _column_stats_locked.stanumbers4,
+ _column_stats_locked.stanumbers5, _column_stats_locked.stavalues1,
+ _column_stats_locked.stavalues2, _column_stats_locked.stavalues3,
+ _column_stats_locked.stavalues4, _column_stats_locked.stavalues5
+ FROM dbms_stats._column_stats_locked
+ WHERE has_column_privilege(_column_stats_locked.starelid, _column_stats_locked.staattnum, 'SELECT'::text);
+
+-- No.2-2-5
+\dS+ dbms_stats.relation_stats_locked
+ View "dbms_stats.relation_stats_locked"
+ Column | Type | Modifiers | Storage | Description
+------------------+--------------------------+-----------+----------+-------------
+ relid | oid | | plain |
+ relname | text | | extended |
+ relpages | integer | | plain |
+ reltuples | real | | plain |
+ relallvisible | integer | | plain |
+ curpages | integer | | plain |
+ last_analyze | timestamp with time zone | | plain |
+ last_autoanalyze | timestamp with time zone | | plain |
+View definition:
+ SELECT _relation_stats_locked.relid, _relation_stats_locked.relname,
+ _relation_stats_locked.relpages, _relation_stats_locked.reltuples,
+ _relation_stats_locked.relallvisible, _relation_stats_locked.curpages,
+ _relation_stats_locked.last_analyze,
+ _relation_stats_locked.last_autoanalyze
+ FROM dbms_stats._relation_stats_locked;
+
+/*
+ * No.5-1 dbms_stats.merge
+ */
+UPDATE pg_statistic SET
+ stanullfrac = staattnum,
+ stawidth = staattnum,
+ stadistinct = staattnum,
+ stakind1 = 4,
+ stakind2 = 1,
+ stakind3 = 2,
+ stakind4 = 3,
+ stakind5 = 5,
+ staop1 = 14,
+ staop2 = 11,
+ staop3 = 12,
+ staop4 = 13,
+ staop5 = 15,
+ stanumbers1 = ARRAY[staattnum,4],
+ stanumbers2 = ARRAY[staattnum,1],
+ stanumbers3 = ARRAY[staattnum,2],
+ stanumbers4 = ARRAY[staattnum,3],
+ stanumbers5 = ARRAY[staattnum,5],
+ stavalues2 = array_cat(stavalues1,stavalues1),
+ stavalues3 = array_cat(array_cat(stavalues1,stavalues1),stavalues1),
+ stavalues4 = array_cat(array_cat(array_cat(stavalues1,stavalues1),stavalues1),stavalues1)
+ ,stavalues5 = array_cat(array_cat(array_cat(array_cat(stavalues1,stavalues1),stavalues1),stavalues1),stavalues1)
+ WHERE starelid = 'st0'::regclass;
+SELECT dbms_stats.lock_table_stats('st0');
+ lock_table_stats
+------------------
+ st0
+(1 row)
+
+UPDATE dbms_stats._column_stats_locked SET
+ stainherit = 't',
+ stanullfrac = -staattnum,
+ stawidth = -staattnum,
+ stadistinct = -staattnum,
+ stakind1 = 2,
+ stakind2 = 3,
+ stakind3 = 4,
+ stakind4 = 1,
+ stakind5 = 5,
+ staop1 = 22,
+ staop2 = 23,
+ staop3 = 24,
+ staop4 = 21,
+ staop5 = 25,
+ stanumbers1 = ARRAY[-staattnum,22],
+ stanumbers2 = ARRAY[-staattnum,23],
+ stanumbers3 = ARRAY[-staattnum,24],
+ stanumbers4 = ARRAY[-staattnum,21],
+ stanumbers5 = ARRAY[-staattnum,25],
+ stavalues1 = stavalues3,
+ stavalues2 = stavalues2,
+ stavalues3 = stavalues1,
+ stavalues4 = stavalues4
+ ,stavalues5 = stavalues5
+;
+/*
+ * Driver function dbms_stats.merge1
+ */
+CREATE FUNCTION dbms_stats.merge1(
+ lhs dbms_stats._column_stats_locked,
+ rhs pg_catalog.pg_statistic
+) RETURNS integer AS
+'$libdir/pg_dbms_stats', 'dbms_stats_merge'
+LANGUAGE C STABLE;
+SELECT * FROM columns_locked_v
+ WHERE starelid = 'st0'::regclass;
+ 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
+----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+---------------------------+-------------------+------------+-----------------------------------+-------------------------------------------
+ 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}
+ 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 "}
+(2 rows)
+
+SELECT * FROM plain_columns_statistic_v
+ WHERE starelid = 'st0'::regclass;
+ 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
+----------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------+-------------------+---------------------------+-----------------------------------+-------------------------------------------
+ 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}
+ 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 "}
+(2 rows)
+
+SET client_min_messages TO LOG;
+-- No.5-1-1
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).stakind5,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).staop5,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stanumbers5,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ ,(m.merge).stavalues5
+ FROM (SELECT dbms_stats.merge(NULL, s)
+ FROM pg_statistic s
+ WHERE starelid = 'st0'::regclass
+ AND staattnum = '1'::int2) m;
+ 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
+----------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------+------------+---------------+-------------------+-----------------------
+ 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}
+(1 row)
+
+-- No.5-1-2
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).stakind5,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).staop5,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stanumbers5,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ ,(m.merge).stavalues5
+ FROM (SELECT dbms_stats.merge(v, NULL)
+ FROM dbms_stats._column_stats_locked v
+ WHERE starelid = 'st0'::regclass
+ AND staattnum = '2'::int2) m;
+ 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
+----------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+---------------------------+-------------------+------------+-----------------------------------+-------------------------------------------
+ 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 "}
+(1 row)
+
+-- No.5-1-3
+SELECT dbms_stats.merge(NULL, NULL);
+ merge
+--------
+ (null)
+(1 row)
+
+-- No.5-1-4
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).stakind5,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).staop5,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stanumbers5,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ ,(m.merge).stavalues5
+ FROM (SELECT dbms_stats.merge(v, s)
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '2'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2) m;
+ 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
+----------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+---------------------------+-------------------+------------+-----------------------------------+-------------------------------------------
+ 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 "}
+(1 row)
+
+-- No.5-1-5
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).stakind5,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).staop5,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stanumbers5,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ ,(m.merge).stavalues5
+ FROM (SELECT dbms_stats.merge(v, s)
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '2'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2) m;
+ 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
+----------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+---------------------------+-------------------+------------+-----------------------------------+-------------------------------------------
+ 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 "}
+(1 row)
+
+-- No.5-1-6
+SELECT dbms_stats.merge1(v, s)
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '2'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2;
+ERROR: return type must be a row type
+-- No.5-1-7
+SELECT dbms_stats.merge(NULL, (
+ s.starelid::regclass, s.staattnum, s.stainherit,
+ s.stanullfrac, s.stawidth, s.stadistinct,
+ s.stakind1, s.stakind2, s.stakind3, s.stakind4,
+ s.stakind5,
+ s.staop1, s.staop2, s.staop3,
+ s.staop4,
+ NULL, s.stanumbers1, s.stanumbers2, s.stanumbers3, s.stanumbers4,
+ s.stanumbers5,
+ s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
+ ,s.stavalues5
+ ))
+ FROM pg_statistic s
+ WHERE s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2;
+ merge
+--------
+ (null)
+(1 row)
+
+-- No.5-1-8
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).stakind5,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).staop5,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stanumbers5,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ ,(m.merge).stavalues5
+ FROM (SELECT dbms_stats.merge(NULL, (
+ s.starelid::regclass, s.staattnum, s.stainherit,
+ s.stanullfrac, s.stawidth, s.stadistinct,
+ s.stakind1, s.stakind2, s.stakind3, s.stakind4,
+ s.stakind5,
+ s.staop1, s.staop2, s.staop3, s.staop4,
+ s.staop5,
+ NULL, s.stanumbers2, s.stanumbers3, s.stanumbers4,
+ s.stanumbers5,
+ s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
+ ,s.stavalues5
+ ))
+ FROM pg_statistic s
+ WHERE s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2) m;
+ 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
+----------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------+------------+---------------+-------------------+-----------------------
+ 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}
+(1 row)
+
+-- No.5-1-9
+SELECT dbms_stats.merge((
+ v.starelid::regclass, v.staattnum, v.stainherit,
+ v.stanullfrac, v.stawidth, v.stadistinct,
+ v.stakind1, v.stakind2, v.stakind3, v.stakind4,
+ v.stakind5,
+ v.staop1, v.staop2, v.staop3,
+ v.staop4,
+ NULL, v.stanumbers1, v.stanumbers2, v.stanumbers3, v.stanumbers4,
+ v.stanumbers5,
+ v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
+ ,v.stavalues5
+ ), NULL)
+ FROM dbms_stats._column_stats_locked v
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '2'::int2;
+ merge
+--------
+ (null)
+(1 row)
+
+-- No.5-1-10
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).stakind5,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).staop5,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stanumbers5,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ ,(m.merge).stavalues5
+ FROM (SELECT dbms_stats.merge((
+ v.starelid::regclass, v.staattnum, v.stainherit,
+ v.stanullfrac, v.stawidth, v.stadistinct,
+ v.stakind1, v.stakind2, v.stakind3, v.stakind4,
+ v.stakind5,
+ v.staop1, v.staop2, v.staop3, v.staop4,
+ v.staop5,
+ NULL, v.stanumbers2, v.stanumbers3, v.stanumbers4,
+ v.stanumbers5,
+ v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
+ ,v.stavalues5
+ ), NULL)
+ FROM dbms_stats._column_stats_locked v
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '2'::int2) m;
+ 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
+----------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+---------------------------+-------------------+------------+-----------------------------------+-------------------------------------------
+ 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 "}
+(1 row)
+
+-- No.5-1-11
+SELECT dbms_stats.merge((
+ v.starelid::regclass, v.staattnum, v.stainherit,
+ v.stanullfrac, v.stawidth, v.stadistinct,
+ v.stakind1, v.stakind2, v.stakind3, v.stakind4,
+ v.stakind5,
+ v.staop1, v.staop2, v.staop3,
+ v.staop4,
+ NULL, v.stanumbers1, v.stanumbers2, v.stanumbers3, v.stanumbers4,
+ v.stanumbers5,
+ v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
+ ,v.stavalues5
+ ), (
+ s.starelid::regclass, s.staattnum, s.stainherit,
+ s.stanullfrac, s.stawidth, s.stadistinct,
+ s.stakind1, s.stakind2, s.stakind3, s.stakind4,
+ s.stakind5,
+ s.staop1, s.staop2, s.staop3,
+ s.staop4,
+ NULL, s.stanumbers1, s.stanumbers2, s.stanumbers3, s.stanumbers4,
+ s.stanumbers5,
+ s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
+ ,s.stavalues5
+ ))
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '2'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2;
+LOG: pg_dbms_stats: bad statistics
+DETAIL: column "staop5" should not be null
+ merge
+--------
+ (null)
+(1 row)
+
+-- No.5-1-12
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).stakind5,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).staop5,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stanumbers5,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ ,(m.merge).stavalues5
+ FROM (SELECT dbms_stats.merge((
+ v.starelid::regclass, v.staattnum, v.stainherit,
+ v.stanullfrac, v.stawidth, v.stadistinct,
+ v.stakind1, v.stakind2, v.stakind3, v.stakind4,
+ v.stakind5,
+ v.staop1, v.staop2, v.staop3, v.staop4,
+ v.staop5,
+ NULL, v.stanumbers2, v.stanumbers3, v.stanumbers4,
+ v.stanumbers5,
+ v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
+ ,v.stavalues5
+ ), (
+ s.starelid::regclass, s.staattnum, s.stainherit,
+ s.stanullfrac, s.stawidth, s.stadistinct,
+ s.stakind1, s.stakind2, s.stakind3, s.stakind4,
+ s.stakind5,
+ s.staop1, s.staop2, s.staop3, s.staop4,
+ s.staop5,
+ NULL, s.stanumbers2, s.stanumbers3, s.stanumbers4,
+ s.stanumbers5,
+ s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
+ ,s.stavalues5
+ ))
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '2'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2) m;
+ 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
+----------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+---------------------------+-------------------+------------+-----------------------------------+-------------------------------------------
+ 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 "}
+(1 row)
+
+-- No.5-1-13
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).stakind5,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).staop5,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stanumbers5,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ ,(m.merge).stavalues5
+ FROM (SELECT dbms_stats.merge((
+ NULL, NULL, NULL,
+ NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL
+ ,NULL, NULL, NULL, NULL
+ ), s)
+ FROM pg_statistic s
+ WHERE s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2) m;
+ 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
+----------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------+------------+---------------+-------------------+-----------------------
+ 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}
+(1 row)
+
+-- No.5-1-14
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).stakind5,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).staop5,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stanumbers5,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ ,(m.merge).stavalues5
+ FROM (SELECT dbms_stats.merge(v, (
+ NULL, NULL, NULL,
+ NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL))
+ FROM dbms_stats._column_stats_locked v
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '2'::int2) m;
+ 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
+----------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+---------------------------+-------------------+------------+-----------------------------------+-------------------------------------------
+ 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 "}
+(1 row)
+
+-- No.5-1-15
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).stakind5,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).staop5,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stanumbers5,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ ,(m.merge).stavalues5
+ FROM (SELECT dbms_stats.merge(v, s)
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '2'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2) m;
+ 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
+----------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+---------------------------+-------------------+------------+-----------------------------------+-------------------------------------------
+ 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 "}
+(1 row)
+
+-- No.5-1-16
+SELECT dbms_stats.merge((
+ v.starelid::regclass, v.staattnum, v.stainherit,
+ v.stanullfrac, v.stawidth, v.stadistinct,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL
+ ,NULL, NULL, NULL, NULL
+ ), (
+ s.starelid::regclass, s.staattnum, s.stainherit,
+ s.stanullfrac, s.stawidth, s.stadistinct,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL))
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '2'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2;
+LOG: pg_dbms_stats: bad statistics
+DETAIL: column "stakind1" should not be null
+ merge
+--------
+ (null)
+(1 row)
+
+-- No.5-1-17
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).stakind5,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).staop5,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stanumbers5,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ ,(m.merge).stavalues5
+ FROM (SELECT dbms_stats.merge((
+ v.starelid::regclass, v.staattnum, v.stainherit,
+ v.stanullfrac, v.stawidth, v.stadistinct,
+ v.stakind1, v.stakind2, v.stakind3, v.stakind4,
+ v.stakind5,
+ v.staop1, v.staop2, v.staop3,
+ v.staop4,
+ NULL, v.stanumbers1, v.stanumbers2, v.stanumbers3, v.stanumbers4,
+ v.stanumbers5,
+ v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
+ ,v.stavalues5
+ ), (
+ s.starelid::regclass, s.staattnum, s.stainherit,
+ s.stanullfrac, s.stawidth, s.stadistinct,
+ s.stakind1, s.stakind2, s.stakind3, s.stakind4,
+ s.stakind5,
+ s.staop1, s.staop2, s.staop3, s.staop4,
+ s.staop5,
+ s.stanumbers1, s.stanumbers2, s.stanumbers3, s.stanumbers4,
+ s.stanumbers5,
+ s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
+ ,s.stavalues5
+ ))
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '1'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2) m;
+ 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
+----------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------+------------+---------------+-------------------+-----------------------
+ 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}
+(1 row)
+
+-- No.5-1-18
+SELECT dbms_stats.merge((
+ v.starelid::regclass, v.staattnum, v.stainherit,
+ v.stanullfrac, v.stawidth, v.stadistinct,
+ v.stakind1, v.stakind2, v.stakind3, v.stakind4,
+ v.stakind5,
+ v.staop1, v.staop2, v.staop3,
+ v.staop4,
+ NULL, v.stanumbers1, v.stanumbers2, v.stanumbers3, v.stanumbers4,
+ v.stanumbers5,
+ v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
+ ,v.stavalues5
+ ), (
+ s.starelid::regclass, s.staattnum, s.stainherit,
+ s.stanullfrac, s.stawidth, s.stadistinct,
+ s.stakind1, s.stakind2, s.stakind3, s.stakind4,
+ s.stakind5,
+ s.staop1, s.staop2, s.staop3,
+ s.staop4,
+ NULL, s.stanumbers1, s.stanumbers2, s.stanumbers3, s.stanumbers4,
+ s.stanumbers5,
+ s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
+ ,s.stavalues5
+ ))
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '1'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2;
+LOG: pg_dbms_stats: bad statistics
+DETAIL: column "staop5" should not be null
+ merge
+--------
+ (null)
+(1 row)
+
+-- No.5-1-19
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).stakind5,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).staop5,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stanumbers5,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ ,(m.merge).stavalues5
+ FROM (SELECT dbms_stats.merge((
+ v.starelid::regclass, v.staattnum, v.stainherit,
+ v.stanullfrac, v.stawidth, v.stadistinct,
+ '1', '1', '1', '1',
+ '1',
+ v.staop1, v.staop2, v.staop3, v.staop4,
+ v.staop5,
+ v.stanumbers1, v.stanumbers2, v.stanumbers3, v.stanumbers4,
+ v.stanumbers5,
+ v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
+ ,v.stavalues5
+ ), (
+ s.starelid::regclass, s.staattnum, s.stainherit,
+ s.stanullfrac, s.stawidth, s.stadistinct,
+ '1', '1', '1', '1',
+ '1',
+ s.staop1, s.staop2, s.staop3, s.staop4,
+ s.staop5,
+ s.stanumbers1, s.stanumbers2, s.stanumbers3, s.stanumbers4,
+ s.stanumbers5,
+ s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
+ ,s.stavalues5
+ ))
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '2'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2) m;
+ 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
+----------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+---------------------------+-------------------+------------+-----------------------------------+-------------------------------------------
+ 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 "}
+(1 row)
+
+-- No.5-1-20
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).stakind5,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).staop5,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stanumbers5,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ ,(m.merge).stavalues5
+ FROM (SELECT dbms_stats.merge((v.starelid::regclass, v.staattnum, v.stainherit,
+ v.stanullfrac, v.stawidth, v.stadistinct,
+ '2', '2', '2', '2',
+ '2',
+ v.staop1, v.staop2, v.staop3, v.staop4,
+ v.staop5,
+ v.stanumbers1, v.stanumbers2, v.stanumbers3, v.stanumbers4,
+ v.stanumbers5,
+ v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
+ ,v.stavalues5
+ ), (
+ s.starelid::regclass, s.staattnum, s.stainherit,
+ s.stanullfrac, s.stawidth, s.stadistinct,
+ '2', '2', '2', '2',
+ '2',
+ s.staop1, s.staop2, s.staop3, s.staop4,
+ s.staop5,
+ s.stanumbers1, s.stanumbers2, s.stanumbers3, s.stanumbers4,
+ s.stanumbers5,
+ s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
+ ,s.stavalues5
+ ))
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '2'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2) m;
+ 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
+----------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+---------------------------+-------------------+------------+-----------------------------------+-------------------------------------------
+ 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 "}
+(1 row)
+
+-- No.5-1-21
+SELECT dbms_stats.merge((v.starelid::regclass, '2', v.stainherit,
+ v.stanullfrac, v.stawidth, v.stadistinct,
+ '1', '1', '1', '1',
+ '1',
+ v.staop1, v.staop2, v.staop3, v.staop4,
+ v.staop5,
+ v.stanumbers1, v.stanumbers2, v.stanumbers3, v.stanumbers4,
+ v.stanumbers5,
+ v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
+ ,v.stavalues5
+ ), (
+ s.starelid::regclass, s.staattnum, s.stainherit,
+ s.stanullfrac, s.stawidth, s.stadistinct,
+ '1', '1', '1', '1',
+ '1',
+ s.staop1, s.staop2, s.staop3, s.staop4,
+ s.staop5,
+ s.stanumbers1, s.stanumbers2, s.stanumbers3, s.stanumbers4,
+ s.stanumbers5,
+ s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
+ ,s.stavalues5
+ ))
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '1'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2;
+LOG: pg_dbms_stats: bad column type
+DETAIL: type of column "name" has been changed
+HINT: need to execute dbms_stats.unlock('st0', 'name')
+ merge
+--------
+ (null)
+(1 row)
+
+-- No.5-1-22
+SELECT dbms_stats.merge((v.starelid::regclass, '2', v.stainherit,
+ v.stanullfrac, v.stawidth, v.stadistinct,
+ '2', '2', '2', '2',
+ '2',
+ v.staop1, v.staop2, v.staop3, v.staop4,
+ v.staop5,
+ v.stanumbers1, v.stanumbers2, v.stanumbers3, v.stanumbers4,
+ v.stanumbers5,
+ v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
+ ,v.stavalues5
+ ), (
+ s.starelid::regclass, s.staattnum, s.stainherit,
+ s.stanullfrac, s.stawidth, s.stadistinct,
+ '2', '2', '2', '2',
+ '2',
+ s.staop1, s.staop2, s.staop3, s.staop4,
+ s.staop5,
+ s.stanumbers1, s.stanumbers2, s.stanumbers3, s.stanumbers4,
+ s.stanumbers5,
+ s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
+ ,s.stavalues5
+ ))
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '1'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2;
+LOG: pg_dbms_stats: bad column type
+DETAIL: type of column "name" has been changed
+HINT: need to execute dbms_stats.unlock('st0', 'name')
+ merge
+--------
+ (null)
+(1 row)
+
+RESET client_min_messages;
+SELECT dbms_stats.unlock_database_stats();
+ unlock_database_stats
+-----------------------
+ st0
+(1 row)
+
+/*
+ * No.6-4 dbms_stats.is_target_relkind
+ */
+-- No.6-4-10
+SELECT dbms_stats.is_target_relkind('f');
+ is_target_relkind
+-------------------
+ t
+(1 row)
+
+/*
+ * No.7-1 dbms_stats.backup
+ */
+DELETE FROM dbms_stats.backup_history;
+INSERT INTO dbms_stats.backup_history(id, time, unit) values(1, '2012-01-01', 'd');
+-- No.7-1-9
+SELECT dbms_stats.backup(1, 's0.sft0'::regclass, NULL);
+ backup
+--------
+ 1
+(1 row)
+
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+ count
+-------
+ 1
+(1 row)
+
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+ count
+-------
+ 0
+(1 row)
+
+-- No.7-1-11
+DELETE FROM dbms_stats.relation_stats_backup;
+SELECT dbms_stats.backup(1, NULL, 1::int2);
+ backup
+--------
+ 1
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats.relation_stats_backup
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ s1.st0
+ st1_idx
+ st1_exp
+(15 rows)
+
+SELECT starelid::regclass, staattnum FROM dbms_stats.column_stats_backup
+ GROUP BY starelid, staattnum
+ ORDER BY starelid, staattnum;
+ starelid | staattnum
+----------+-----------
+ st0 | 1
+ st1 | 1
+ s0.st0 | 1
+ s0.st1 | 1
+ s0.st2 | 1
+ s1.st0 | 1
+ st1_exp | 1
+(7 rows)
+
+-- No.7-1-13
+DELETE FROM dbms_stats.relation_stats_backup;
+SELECT dbms_stats.backup(1, NULL::regclass, NULL);
+ backup
+--------
+ 1
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats.relation_stats_backup
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ s1.st0
+ st1_idx
+ st1_exp
+(15 rows)
+
+SELECT starelid::regclass, staattnum FROM dbms_stats.column_stats_backup
+ GROUP BY starelid, staattnum
+ ORDER BY starelid, staattnum;
+ starelid | staattnum
+----------+-----------
+ st0 | 1
+ st0 | 2
+ st1 | 1
+ st1 | 2
+ s0.st0 | 1
+ s0.st0 | 2
+ s0.st1 | 1
+ s0.st1 | 2
+ s0.st2 | 1
+ s0.st2 | 2
+ s1.st0 | 1
+ s1.st0 | 2
+ st1_exp | 1
+(13 rows)
+
+-- No.7-1-17
+DELETE FROM dbms_stats.relation_stats_backup;
+\! psql contrib_regression -c "SELECT dbms_stats.backup(NULL, 's0.st0'::regclass, NULL)" > results/ut_no2_1_17.out 2>&1
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+ count
+-------
+ 0
+(1 row)
+
+/*
+ * No.8-1 dbms_stats.backup
+ */
+SELECT setval('dbms_stats.backup_history_id_seq',1, false);
+ setval
+--------
+ 1
+(1 row)
+
+/*
+ * Stab function dbms_stats.backup
+ */
+ALTER FUNCTION dbms_stats.backup(
+ backup_id int8,
+ relid regclass,
+ attnum int2)
+ RENAME TO truth_func_backup;
+CREATE OR REPLACE FUNCTION dbms_stats.backup(
+ backup_id int8,
+ regclass,
+ attnum int2)
+RETURNS int8 AS
+$$
+BEGIN
+ RAISE NOTICE 'arguments are %, %, %', $1, $2, $3;
+ RETURN 1;
+END;
+$$
+LANGUAGE plpgsql;
+-- No.8-1-1
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup('s0.st0'::regclass, 'id', 'dummy comment');
+NOTICE: arguments are 1, s0.st0, 1
+CONTEXT: SQL statement "INSERT INTO dbms_stats.backup_history(time, unit, comment)
+ VALUES (current_timestamp, unit_type, $3)
+ RETURNING dbms_stats.backup(id, $1, set_attnum)"
+PL/pgSQL function dbms_stats.backup(regclass,text,text) line 42 at SQL statement
+ backup
+--------
+ 1
+(1 row)
+
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+ id | unit | comment
+----+------+---------------
+ 1 | c | dummy comment
+(1 row)
+
+-- No.8-1-2
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup('s0.st0'::regclass, NULL, 'dummy comment');
+NOTICE: arguments are 2, s0.st0,
+CONTEXT: SQL statement "INSERT INTO dbms_stats.backup_history(time, unit, comment)
+ VALUES (current_timestamp, unit_type, $3)
+ RETURNING dbms_stats.backup(id, $1, set_attnum)"
+PL/pgSQL function dbms_stats.backup(regclass,text,text) line 42 at SQL statement
+ backup
+--------
+ 1
+(1 row)
+
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+ id | unit | comment
+----+------+---------------
+ 2 | t | dummy comment
+(1 row)
+
+-- No.8-1-3
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup(NULL::regclass, 'id', 'dummy comment');
+ERROR: relation is required
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+ id | unit | comment
+----+------+---------
+(0 rows)
+
+-- No.8-1-4
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup(NULL::regclass, NULL, 'dummy comment');
+NOTICE: arguments are 3, ,
+CONTEXT: SQL statement "INSERT INTO dbms_stats.backup_history(time, unit, comment)
+ VALUES (current_timestamp, unit_type, $3)
+ RETURNING dbms_stats.backup(id, $1, set_attnum)"
+PL/pgSQL function dbms_stats.backup(regclass,text,text) line 42 at SQL statement
+ backup
+--------
+ 1
+(1 row)
+
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+ id | unit | comment
+----+------+---------------
+ 3 | d | dummy comment
+(1 row)
+
+-- No.8-1-5
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup(0, NULL, 'dummy comment');
+ERROR: relation "-" does not exist
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+ id | unit | comment
+----+------+---------
+(0 rows)
+
+-- No.8-1-6
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup('s0.st0'::regclass, NULL, 'dummy comment');
+NOTICE: arguments are 4, s0.st0,
+CONTEXT: SQL statement "INSERT INTO dbms_stats.backup_history(time, unit, comment)
+ VALUES (current_timestamp, unit_type, $3)
+ RETURNING dbms_stats.backup(id, $1, set_attnum)"
+PL/pgSQL function dbms_stats.backup(regclass,text,text) line 42 at SQL statement
+ backup
+--------
+ 1
+(1 row)
+
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+ id | unit | comment
+----+------+---------------
+ 4 | t | dummy comment
+(1 row)
+
+-- No.8-1-7
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup(
+ 'pg_toast.pg_toast_2618'::regclass,
+ NULL,
+ 'dummy comment');
+ERROR: can not backup statistics of "pg_toast.pg_toast_2618" with relkind "t"
+HINT: only tables and indexes are supported
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+ id | unit | comment
+----+------+---------
+(0 rows)
+
+-- No.8-1-8
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup('s0.st0_idx'::regclass, NULL, 'dummy comment');
+NOTICE: arguments are 5, s0.st0_idx,
+CONTEXT: SQL statement "INSERT INTO dbms_stats.backup_history(time, unit, comment)
+ VALUES (current_timestamp, unit_type, $3)
+ RETURNING dbms_stats.backup(id, $1, set_attnum)"
+PL/pgSQL function dbms_stats.backup(regclass,text,text) line 42 at SQL statement
+ backup
+--------
+ 1
+(1 row)
+
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+ id | unit | comment
+----+------+---------------
+ 5 | t | dummy comment
+(1 row)
+
+-- No.8-1-9
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup('s0.ss0'::regclass, NULL, 'dummy comment');
+ERROR: can not backup statistics of "s0.ss0" with relkind "S"
+HINT: only tables and indexes are supported
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+ id | unit | comment
+----+------+---------
+(0 rows)
+
+-- No.8-1-10
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup('s0.sc0'::regclass, NULL, 'dummy comment');
+ERROR: can not backup statistics of "s0.sc0" with relkind "c"
+HINT: only tables and indexes are supported
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+ id | unit | comment
+----+------+---------
+(0 rows)
+
+-- No.8-1-11
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup('s0.sft0'::regclass, NULL, 'dummy comment');
+NOTICE: arguments are 6, s0.sft0,
+CONTEXT: SQL statement "INSERT INTO dbms_stats.backup_history(time, unit, comment)
+ VALUES (current_timestamp, unit_type, $3)
+ RETURNING dbms_stats.backup(id, $1, set_attnum)"
+PL/pgSQL function dbms_stats.backup(regclass,text,text) line 42 at SQL statement
+ backup
+--------
+ 1
+(1 row)
+
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+ id | unit | comment
+----+------+---------------
+ 6 | t | dummy comment
+(1 row)
+
+-- No.8-1-12
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup('pg_catalog.pg_class'::regclass, NULL, 'dummy comment');
+ERROR: can not backup statistics of system catalog "pg_class"
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+ id | unit | comment
+----+------+---------
+(0 rows)
+
+-- No.8-1-13
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup('s0.st0'::regclass, 'dummy', 'dummy comment');
+ERROR: column "dummy" of "s0.st0" does not exist
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+ id | unit | comment
+----+------+---------
+(0 rows)
+
+-- No.8-1-14
+DELETE FROM dbms_stats.backup_history;
+DELETE FROM pg_statistic
+ WHERE starelid = 's0.st0'::regclass
+ AND staattnum = 1::int2;
+SELECT count(*) FROM dbms_stats.column_stats_effective
+ WHERE starelid = 's0.st0'::regclass
+ AND staattnum = 1::int2;
+ count
+-------
+ 0
+(1 row)
+
+SELECT dbms_stats.backup('s0.st0'::regclass, 'id', 'dummy comment');
+ERROR: statistic for column "id" of "s0.st0" does not exist
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+ id | unit | comment
+----+------+---------
+(0 rows)
+
+/*
+ * Stab function dbms_stats.backup
+ */
+ALTER FUNCTION dbms_stats.backup(
+ relid regclass,
+ attname text,
+ comment text)
+ RENAME TO truth_func_backup;
+CREATE OR REPLACE FUNCTION dbms_stats.backup(
+ relid regclass DEFAULT NULL,
+ attname text DEFAULT NULL,
+ comment text DEFAULT NULL)
+RETURNS int8 AS
+$$
+BEGIN
+ IF $3 = '' THEN
+ RAISE NOTICE 'third argument is not NULL but string ""';
+ END IF;
+ RAISE NOTICE 'arguments are %, %, %', $1, $2, $3;
+ RETURN 1;
+END;
+$$
+LANGUAGE plpgsql;
+/*
+ * No.8-3 dbms_stats.backup_schema_stats
+ */
+SELECT setval('dbms_stats.backup_history_id_seq',9, false);
+ setval
+--------
+ 9
+(1 row)
+
+-- No.8-3-1
+SELECT dbms_stats.backup_schema_stats('s0', 'comment');
+NOTICE: arguments are 9, s0.st0,
+CONTEXT: SQL statement "SELECT dbms_stats.backup(backup_id, cn.oid, NULL)
+ FROM (SELECT c.oid
+ FROM pg_catalog.pg_class c,
+ pg_catalog.pg_namespace n
+ WHERE n.nspname = schemaname
+ AND c.relnamespace = n.oid
+ AND dbms_stats.is_target_relkind(c.relkind)
+ ORDER BY c.oid
+ ) cn"
+PL/pgSQL function dbms_stats.backup_schema_stats(text,text) line 16 at PERFORM
+NOTICE: arguments are 9, s0.st0_idx,
+CONTEXT: SQL statement "SELECT dbms_stats.backup(backup_id, cn.oid, NULL)
+ FROM (SELECT c.oid
+ FROM pg_catalog.pg_class c,
+ pg_catalog.pg_namespace n
+ WHERE n.nspname = schemaname
+ AND c.relnamespace = n.oid
+ AND dbms_stats.is_target_relkind(c.relkind)
+ ORDER BY c.oid
+ ) cn"
+PL/pgSQL function dbms_stats.backup_schema_stats(text,text) line 16 at PERFORM
+NOTICE: arguments are 9, s0.st1,
+CONTEXT: SQL statement "SELECT dbms_stats.backup(backup_id, cn.oid, NULL)
+ FROM (SELECT c.oid
+ FROM pg_catalog.pg_class c,
+ pg_catalog.pg_namespace n
+ WHERE n.nspname = schemaname
+ AND c.relnamespace = n.oid
+ AND dbms_stats.is_target_relkind(c.relkind)
+ ORDER BY c.oid
+ ) cn"
+PL/pgSQL function dbms_stats.backup_schema_stats(text,text) line 16 at PERFORM
+NOTICE: arguments are 9, s0.st1_idx,
+CONTEXT: SQL statement "SELECT dbms_stats.backup(backup_id, cn.oid, NULL)
+ FROM (SELECT c.oid
+ FROM pg_catalog.pg_class c,
+ pg_catalog.pg_namespace n
+ WHERE n.nspname = schemaname
+ AND c.relnamespace = n.oid
+ AND dbms_stats.is_target_relkind(c.relkind)
+ ORDER BY c.oid
+ ) cn"
+PL/pgSQL function dbms_stats.backup_schema_stats(text,text) line 16 at PERFORM
+NOTICE: arguments are 9, s0.st2,
+CONTEXT: SQL statement "SELECT dbms_stats.backup(backup_id, cn.oid, NULL)
+ FROM (SELECT c.oid
+ FROM pg_catalog.pg_class c,
+ pg_catalog.pg_namespace n
+ WHERE n.nspname = schemaname
+ AND c.relnamespace = n.oid
+ AND dbms_stats.is_target_relkind(c.relkind)
+ ORDER BY c.oid
+ ) cn"
+PL/pgSQL function dbms_stats.backup_schema_stats(text,text) line 16 at PERFORM
+NOTICE: arguments are 9, s0.st2_idx,
+CONTEXT: SQL statement "SELECT dbms_stats.backup(backup_id, cn.oid, NULL)
+ FROM (SELECT c.oid
+ FROM pg_catalog.pg_class c,
+ pg_catalog.pg_namespace n
+ WHERE n.nspname = schemaname
+ AND c.relnamespace = n.oid
+ AND dbms_stats.is_target_relkind(c.relkind)
+ ORDER BY c.oid
+ ) cn"
+PL/pgSQL function dbms_stats.backup_schema_stats(text,text) line 16 at PERFORM
+NOTICE: arguments are 9, s0.sft0,
+CONTEXT: SQL statement "SELECT dbms_stats.backup(backup_id, cn.oid, NULL)
+ FROM (SELECT c.oid
+ FROM pg_catalog.pg_class c,
+ pg_catalog.pg_namespace n
+ WHERE n.nspname = schemaname
+ AND c.relnamespace = n.oid
+ AND dbms_stats.is_target_relkind(c.relkind)
+ ORDER BY c.oid
+ ) cn"
+PL/pgSQL function dbms_stats.backup_schema_stats(text,text) line 16 at PERFORM
+ backup_schema_stats
+---------------------
+ 9
+(1 row)
+
+SELECT id, unit, comment FROM dbms_stats.backup_history
+ ORDER BY id DESC
+ LIMIT 1;
+ id | unit | comment
+----+------+---------
+ 9 | s | comment
+(1 row)
+
+-- No.8-3-2
+SELECT dbms_stats.backup_schema_stats('s00', 'comment');
+ERROR: schema "s00" does not exist
+SELECT id, unit, comment FROM dbms_stats.backup_history
+ ORDER BY id DESC
+ LIMIT 1;
+ id | unit | comment
+----+------+---------
+ 9 | s | comment
+(1 row)
+
+-- No.8-3-3
+SELECT dbms_stats.backup_schema_stats('pg_catalog', 'comment');
+ERROR: can not backup statistics of relation in system schema "pg_catalog"
+SELECT id, unit, comment FROM dbms_stats.backup_history
+ ORDER BY id DESC
+ LIMIT 1;
+ id | unit | comment
+----+------+---------
+ 9 | s | comment
+(1 row)
+
+/*
+ * Delete stab function dbms_stats.backup
+ */
+DROP FUNCTION dbms_stats.backup(
+ backup_id int8,
+ regclass,
+ attnum int2);
+ALTER FUNCTION dbms_stats.truth_func_backup(
+ backup_id int8,
+ regclass,
+ attnum int2)
+ RENAME TO backup;
+DROP FUNCTION dbms_stats.backup(
+ regclass,
+ attname text,
+ comment text);
+ALTER FUNCTION dbms_stats.truth_func_backup(
+ regclass,
+ attname text,
+ comment text)
+ RENAME TO backup;
+VACUUM ANALYZE;
+/*
+ * create backup statistics state A
+ */
+DELETE FROM dbms_stats.backup_history;
+INSERT INTO dbms_stats.backup_history(id, time, unit)
+ VALUES (1, '2012-02-29 23:59:56.999999', 'd');
+SELECT setval('dbms_stats.backup_history_id_seq',1);
+ setval
+--------
+ 1
+(1 row)
+
+SELECT dbms_stats.backup();
+ backup
+--------
+ 2
+(1 row)
+
+UPDATE dbms_stats.backup_history
+ SET time = '2012-02-29 23:59:57'
+ WHERE id = 2;
+SELECT dbms_stats.backup('s0.st0');
+ backup
+--------
+ 3
+(1 row)
+
+UPDATE dbms_stats.backup_history
+ SET time = '2012-02-29 23:59:57.000001'
+ WHERE id = 3;
+SELECT dbms_stats.backup();
+ backup
+--------
+ 4
+(1 row)
+
+UPDATE dbms_stats.backup_history
+ SET time = '2012-02-29 23:59:58'
+ WHERE id = 4;
+DELETE FROM dbms_stats.relation_stats_backup
+ WHERE id = 4;
+SELECT dbms_stats.backup('s0.st0', 'id');
+ backup
+--------
+ 5
+(1 row)
+
+UPDATE dbms_stats.backup_history
+ SET time = '2012-03-01 00:00:00'
+ WHERE id = 5;
+SELECT dbms_stats.backup('s0.st0');
+ backup
+--------
+ 6
+(1 row)
+
+UPDATE dbms_stats.backup_history
+ SET time = '2012-03-01 00:00:02'
+ WHERE id = 6;
+SELECT dbms_stats.backup('public.st0');
+ backup
+--------
+ 7
+(1 row)
+
+UPDATE dbms_stats.backup_history
+ SET time = '2012-03-01 00:00:04'
+ WHERE id = 7;
+INSERT INTO dbms_stats.backup_history(time, unit)
+ VALUES ('2012-03-01 00:00:06', 's');
+SELECT dbms_stats.backup(8, c.oid, NULL)
+ FROM pg_catalog.pg_class c,
+ pg_catalog.pg_namespace n
+ WHERE n.nspname = 's0'
+ AND c.relnamespace = n.oid
+ AND c.relkind IN ('r', 'i');
+ backup
+--------
+ 8
+ 8
+ 8
+ 8
+ 8
+ 8
+(6 rows)
+
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+ id | time | unit | comment
+----+-------------------------------------+------+---------
+ 1 | Wed Feb 29 23:59:56.999999 2012 PST | d | (null)
+ 2 | Wed Feb 29 23:59:57 2012 PST | d | (null)
+ 3 | Wed Feb 29 23:59:57.000001 2012 PST | t | (null)
+ 4 | Wed Feb 29 23:59:58 2012 PST | d | (null)
+ 5 | Thu Mar 01 00:00:00 2012 PST | c | (null)
+ 6 | Thu Mar 01 00:00:02 2012 PST | t | (null)
+ 7 | Thu Mar 01 00:00:04 2012 PST | t | (null)
+ 8 | Thu Mar 01 00:00:06 2012 PST | s | (null)
+(8 rows)
+
+SELECT * FROM relations_backup_v;
+ id | relid | relname | relpages | reltuples | relallvisible | curpages
+----+------------+----------------+----------+-----------+---------------+----------
+ 2 | pt0 | public.pt0 | 0 | 0 | 0 | 0
+ 2 | pt0_idx | public.pt0_idx | 2 | 0 | 0 | 2
+ 2 | st0 | public.st0 | 1 | 2 | 1 | 1
+ 2 | st0_idx | public.st0_idx | 2 | 2 | 0 | 2
+ 2 | st1 | public.st1 | 45 | 10000 | 45 | 45
+ 2 | s0.st0 | s0.st0 | 1 | 2 | 1 | 1
+ 2 | s0.st0_idx | s0.st0_idx | 2 | 2 | 0 | 2
+ 2 | s0.st1 | s0.st1 | 1 | 3 | 1 | 1
+ 2 | s0.st1_idx | s0.st1_idx | 2 | 3 | 0 | 2
+ 2 | s0.st2 | s0.st2 | 1 | 3 | 1 | 1
+ 2 | s0.st2_idx | s0.st2_idx | 2 | 3 | 0 | 2
+ 2 | s0.sft0 | s0.sft0 | 0 | 0 | 0 | 0
+ 2 | s1.st0 | s1.st0 | 1 | 4 | 1 | 1
+ 2 | st1_idx | public.st1_idx | 30 | 10000 | 0 | 30
+ 2 | st1_exp | public.st1_exp | 30 | 10000 | 0 | 30
+ 3 | s0.st0 | s0.st0 | 1 | 2 | 1 | 1
+ 5 | s0.st0 | s0.st0 | 1 | 2 | 1 | 1
+ 6 | s0.st0 | s0.st0 | 1 | 2 | 1 | 1
+ 7 | st0 | public.st0 | 1 | 2 | 1 | 1
+ 8 | s0.st0 | s0.st0 | 1 | 2 | 1 | 1
+ 8 | s0.st0_idx | s0.st0_idx | 2 | 2 | 0 | 2
+ 8 | s0.st1 | s0.st1 | 1 | 3 | 1 | 1
+ 8 | s0.st1_idx | s0.st1_idx | 2 | 3 | 0 | 2
+ 8 | s0.st2 | s0.st2 | 1 | 3 | 1 | 1
+ 8 | s0.st2_idx | s0.st2_idx | 2 | 3 | 0 | 2
+(25 rows)
+
+SELECT * FROM columns_backup_v;
+ 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
+----+----------+----------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+------------------------+-------------+-------------+-------------+-------------+------------------+------------+------------+------------+------------
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+(35 rows)
+
+VACUUM ANALYZE;
+/*
+ * No.9-1 dbms_stats.restore
+ */
+-- No.9-1-1
+DELETE FROM dbms_stats._relation_stats_locked;
+BEGIN;
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+ relation | mode
+----------+---------------
+ (null) | ExclusiveLock
+(1 row)
+
+SELECT dbms_stats.restore(2, 's0.st0', NULL);
+ restore
+---------
+ s0.st0
+(1 row)
+
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+ relation | mode
+----------------------------------------+--------------------------
+ dbms_stats._column_stats_locked | RowExclusiveLock
+ dbms_stats._column_stats_locked | ShareUpdateExclusiveLock
+ dbms_stats._column_stats_locked_pkey | RowExclusiveLock
+ dbms_stats._relation_stats_locked | RowExclusiveLock
+ dbms_stats._relation_stats_locked | ShareUpdateExclusiveLock
+ dbms_stats._relation_stats_locked_pkey | RowExclusiveLock
+ (null) | ExclusiveLock
+ (null) | ExclusiveLock
+(8 rows)
+
+COMMIT;
+SELECT relid::regclass FROM dbms_stats.relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+--------
+ s0.st0
+(1 row)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+(4 rows)
+
+-- No.9-1-2
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(2, 'st0', NULL);
+ restore
+---------
+ st0
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats.relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+-------
+ st0
+(1 row)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+(2 rows)
+
+-- No.9-1-3
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(2, 's00.s0', NULL);
+ERROR: schema "s00" does not exist
+LINE 1: SELECT dbms_stats.restore(2, 's00.s0', NULL);
+ ^
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+-- No.9-1-4
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(NULL, 's0.st0', NULL);
+ERROR: backup id is required
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+-- No.9-1-5
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(2, 's0.st0', 'id');
+ restore
+---------
+ s0.st0
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats.relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+--------
+ s0.st0
+(1 row)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ s0.st0 | id | f
+ s0.st0 | id | t
+(2 rows)
+
+-- No.9-1-6
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(2, NULL, 'id');
+ERROR: relation is required
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+-- No.9-1-7
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(2, 's0.st0', NULL);
+ restore
+---------
+ s0.st0
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats.relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+--------
+ s0.st0
+(1 row)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+(4 rows)
+
+-- No.9-1-8
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(2, NULL, NULL);
+ restore
+------------
+ pt0
+ pt0_idx
+ s0.sft0
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s1.st0
+ st0
+ st0_idx
+ st1
+ st1_exp
+ st1_idx
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats.relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ s1.st0
+ st1_idx
+ st1_exp
+(15 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+ st1_exp | lower | f
+(15 rows)
+
+-- No.9-1-9
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(0, 's0.st0', NULL);
+ERROR: backup id 0 does not exist
+SELECT relid::regclass FROM dbms_stats.relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+-------
+(0 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+(0 rows)
+
+-- No.9-1-10
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(2, 0, 'id');
+ERROR: relation "-" does not exist
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+-- No.9-1-11
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(1, 's0.st0', NULL);
+ERROR: relation "s0.st0" does not exist in previous backup
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+-- No.9-1-12
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(2, 's0.st0', 'dummy');
+ERROR: column "dummy" of "s0.st0" does not exist
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+-- No.9-1-13
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(1, 's0.st0', 'id');
+ERROR: relation "s0.st0" does not exist in previous backup
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+-- No.9-1-15
+DELETE FROM dbms_stats._relation_stats_locked;
+ALTER TABLE s1.st0 DROP COLUMN id;
+SELECT dbms_stats.restore(2, 's1.st0', 'id');
+ERROR: column "id" of "s1.st0" does not exist
+SELECT relid::regclass FROM dbms_stats.relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+-------
+(0 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+(0 rows)
+
+-- No.9-1-14
+DELETE FROM dbms_stats._relation_stats_locked;
+\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';"`
+DROP TABLE s1.st0;
+SET client_min_messages TO FATAL;
+SELECT dbms_stats.restore(2, :s1_st0_oid, NULL);
+RESET client_min_messages;
+\! tail ${PGDATA}/pg_log/postgresql.log > results/ut_no3_1_14.out
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+CREATE TABLE s1.st0(id integer, num integer);
+INSERT INTO s1.st0 VALUES (1, 15), (2, 25), (3, 35), (4, 45);
+VACUUM ANALYZE;
+-- No.9-1-16
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(2, 's0.st0', NULL);
+ restore
+---------
+ s0.st0
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats.relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+--------
+ s0.st0
+(1 row)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+(4 rows)
+
+-- No.9-1-17
+DELETE FROM dbms_stats._relation_stats_locked;
+INSERT INTO dbms_stats.relation_stats_backup(
+ id, relid, relname, relpages, reltuples,
+ relallvisible,
+ curpages)
+ VALUES (2,
+ 'pg_toast.pg_toast_2618'::regclass,
+ 'pg_toast.pg_toast_2618', 1, 1,
+ 1,
+ 1);
+SELECT * FROM relations_backup_v
+ WHERE id = 2
+ AND relname = 'pg_toast.pg_toast_2618';
+ id | relid | relname | relpages | reltuples | relallvisible | curpages
+----+------------------------+------------------------+----------+-----------+---------------+----------
+ 2 | pg_toast.pg_toast_2618 | pg_toast.pg_toast_2618 | 1 | 1 | 1 | 1
+(1 row)
+
+SELECT dbms_stats.restore(2, 'pg_toast.pg_toast_2618', NULL);
+ restore
+---------
+(0 rows)
+
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+DELETE FROM dbms_stats.relation_stats_backup
+ WHERE id = 2
+ AND relname = 'pg_toast.pg_toast_2618';
+-- No.9-1-18
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(2, 's0.st0_idx', NULL);
+ restore
+------------
+ s0.st0_idx
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats.relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ s0.st0_idx
+(1 row)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+(0 rows)
+
+-- No.9-1-19
+DELETE FROM dbms_stats._relation_stats_locked;
+INSERT INTO dbms_stats.relation_stats_backup(
+ id, relid, relname, relpages, reltuples,
+ relallvisible,
+ curpages)
+ VALUES (2, 's0.ss0'::regclass, 's0.ss0', 1, 1,
+ 1,
+ 1);
+SELECT * FROM relations_backup_v
+ WHERE id = 2
+ AND relname = 's0.ss0';
+ id | relid | relname | relpages | reltuples | relallvisible | curpages
+----+--------+---------+----------+-----------+---------------+----------
+ 2 | s0.ss0 | s0.ss0 | 1 | 1 | 1 | 1
+(1 row)
+
+SELECT dbms_stats.restore(2, 's0.ss0', NULL);
+ restore
+---------
+(0 rows)
+
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+DELETE FROM dbms_stats.relation_stats_backup
+ WHERE id = 2
+ AND relname = 's0.ss0';
+-- No.9-1-20
+DELETE FROM dbms_stats._relation_stats_locked;
+INSERT INTO dbms_stats.relation_stats_backup(
+ id, relid, relname, relpages, reltuples,
+ relallvisible,
+ curpages)
+ VALUES (2, 's0.sc0'::regclass, 's0.sc0', 1, 1,
+ 1,
+ 1);
+SELECT * FROM relations_backup_v
+ WHERE id = 2
+ AND relname = 's0.sc0';
+ id | relid | relname | relpages | reltuples | relallvisible | curpages
+----+--------+---------+----------+-----------+---------------+----------
+ 2 | s0.sc0 | s0.sc0 | 1 | 1 | 1 | 1
+(1 row)
+
+SELECT dbms_stats.restore(2, 's0.sc0', NULL);
+ restore
+---------
+(0 rows)
+
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+DELETE FROM dbms_stats.relation_stats_backup
+ WHERE id = 2
+ AND relname = 's0.sc0';
+-- No.9-1-21
+DELETE FROM dbms_stats._relation_stats_locked;
+INSERT INTO dbms_stats.relation_stats_backup(
+ id, relid, relname, relpages, reltuples,
+ relallvisible,
+ curpages)
+ VALUES (3, 's0.sft0'::regclass, 's0.sft0', 1, 1,
+ 1,
+ 1);
+SELECT * FROM relations_backup_v
+ WHERE id = 3
+ AND relname = 's0.sft0';
+ id | relid | relname | relpages | reltuples | relallvisible | curpages
+----+---------+---------+----------+-----------+---------------+----------
+ 3 | s0.sft0 | s0.sft0 | 1 | 1 | 1 | 1
+(1 row)
+
+SELECT dbms_stats.restore(2, 's0.sft0', NULL);
+ restore
+---------
+ s0.sft0
+(1 row)
+
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+ count
+-------
+ 1
+(1 row)
+
+DELETE FROM dbms_stats.relation_stats_backup
+ WHERE id = 3
+ AND relname = 's0.sft0';
+-- No.9-1-22
+DELETE FROM dbms_stats._relation_stats_locked;
+INSERT INTO dbms_stats.relation_stats_backup(
+ id, relid, relname, relpages, reltuples,
+ relallvisible,
+ curpages)
+ VALUES (2, 'pg_catalog.pg_class'::regclass, 'pg_catalog.pg_class', 1, 1,
+ 1,
+ 1);
+SELECT * FROM relations_backup_v
+ WHERE id = 2
+ AND relname = 'pg_catalog.pg_class';
+ id | relid | relname | relpages | reltuples | relallvisible | curpages
+----+----------+---------------------+----------+-----------+---------------+----------
+ 2 | pg_class | pg_catalog.pg_class | 1 | 1 | 1 | 1
+(1 row)
+
+SELECT dbms_stats.restore(2, 'pg_catalog.pg_class', NULL);
+ restore
+---------
+(0 rows)
+
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+DELETE FROM dbms_stats.relation_stats_backup
+ WHERE id = 2
+ AND relname = 'pg_catalog.pg_class';
+-- No.9-1-23
+DELETE FROM dbms_stats._relation_stats_locked;
+INSERT INTO dbms_stats._relation_stats_locked(relid, relname)
+ VALUES ('s0.st0'::regclass, 's0.st0');
+INSERT INTO dbms_stats._column_stats_locked(starelid, staattnum, stainherit)
+ SELECT starelid::regclass, staattnum, stainherit
+ FROM dbms_stats.column_stats_effective
+ WHERE starelid = 's0.st0'::regclass;
+SELECT id, unit, comment FROM dbms_stats.backup_history
+ WHERE id = 2;
+ id | unit | comment
+----+------+---------
+ 2 | d | (null)
+(1 row)
+
+SELECT * FROM columns_locked_v;
+ 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
+----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------+------------+------------+------------+------------
+ 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)
+ 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)
+ 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)
+ 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)
+(4 rows)
+
+SELECT * FROM relations_locked_v;
+ relid | relname | relpages | reltuples | relallvisible | curpages
+--------+---------+----------+-----------+---------------+----------
+ s0.st0 | s0.st0 | (null) | (null) | (null) | (null)
+(1 row)
+
+SELECT dbms_stats.restore(2, 's0.st0', NULL);
+ restore
+---------
+ s0.st0
+(1 row)
+
+SELECT * FROM relations_locked_v;
+ relid | relname | relpages | reltuples | relallvisible | curpages
+--------+---------+----------+-----------+---------------+----------
+ s0.st0 | s0.st0 | 1 | 2 | 1 | 1
+(1 row)
+
+SELECT * FROM columns_locked_v;
+ 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
+----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------------+------------+------------+------------+------------
+ 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)
+ 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)
+ 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)
+ 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)
+(4 rows)
+
+-- No.9-1-24
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT id, unit, comment FROM dbms_stats.backup_history
+ WHERE id = 2;
+ id | unit | comment
+----+------+---------
+ 2 | d | (null)
+(1 row)
+
+SELECT dbms_stats.restore(2, 's0.st0', NULL);
+ restore
+---------
+ s0.st0
+(1 row)
+
+SELECT * FROM relations_locked_v;
+ relid | relname | relpages | reltuples | relallvisible | curpages
+--------+---------+----------+-----------+---------------+----------
+ s0.st0 | s0.st0 | 1 | 2 | 1 | 1
+(1 row)
+
+SELECT * FROM columns_locked_v;
+ 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
+----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------------+------------+------------+------------+------------
+ 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)
+ 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)
+ 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)
+ 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)
+(4 rows)
+
+/*
+ * Stab function dbms_stats.restore
+ */
+CREATE OR REPLACE FUNCTION dbms_stats.restore(
+ backup_id int8,
+ relid regclass DEFAULT NULL,
+ attname text DEFAULT NULL)
+RETURNS SETOF regclass AS
+$$
+BEGIN
+ RAISE NOTICE 'arguments are "%, %, %"', $1, $2, $3;
+ RETURN QUERY
+ SELECT c.oid::regclass
+ FROM pg_class c, dbms_stats.relation_stats_backup b
+ WHERE (c.oid = $2 OR $2 IS NULL)
+ AND c.oid = b.relid
+ AND c.relkind IN ('r', 'i')
+ AND (b.id <= $1 OR $1 IS NOT NULL)
+ GROUP BY c.oid
+ ORDER BY c.oid::regclass::text;
+END;
+$$
+LANGUAGE plpgsql;
+/*
+ * No.10-1 dbms_stats.restore_database_stats
+ */
+-- No.10-1-1
+SELECT dbms_stats.restore_database_stats('2012-02-29 23:59:57');
+NOTICE: arguments are "2, pt0, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, pt0_idx, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, st0, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, st0_idx, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, st1, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, s0.st0, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, s0.st0_idx, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, s0.st1, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, s0.st1_idx, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, s0.st2, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, s0.st2_idx, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, s0.sft0, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, st1_idx, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, st1_exp, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+ restore_database_stats
+------------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+(13 rows)
+
+-- No.10-1-2
+SELECT dbms_stats.restore_database_stats('2012-02-29 23:59:57.000002');
+NOTICE: arguments are "2, pt0, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, pt0_idx, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, st0, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, st0_idx, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, st1, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "3, s0.st0, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, s0.st0_idx, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, s0.st1, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, s0.st1_idx, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, s0.st2, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, s0.st2_idx, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, s0.sft0, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, st1_idx, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, st1_exp, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+ restore_database_stats
+------------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+(13 rows)
+
+-- No.10-1-3
+SELECT dbms_stats.restore_database_stats('2012-01-01 00:00:00');
+ restore_database_stats
+------------------------
+(0 rows)
+
+--#No.10-1-4 is skipped after lock tests
+--#No.10-1-5 is skipped after lock tests
+-- No.10-1-6
+SELECT dbms_stats.restore_database_stats('2012-02-29 23:59:57');
+NOTICE: arguments are "2, pt0, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, pt0_idx, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, st0, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, st0_idx, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, st1, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, s0.st0, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, s0.st0_idx, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, s0.st1, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, s0.st1_idx, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, s0.st2, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, s0.st2_idx, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, s0.sft0, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, st1_idx, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+NOTICE: arguments are "2, st1_exp, "
+CONTEXT: SQL function "restore_database_stats" statement 1
+ restore_database_stats
+------------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+(13 rows)
+
+/*
+ * No.10-2 dbms_stats.restore_schema_stats
+ */
+-- No.10-2-1
+SELECT dbms_stats.restore_schema_stats('s0', '2012-02-29 23:59:57');
+NOTICE: arguments are "2, s0.st0, "
+CONTEXT: PL/pgSQL function dbms_stats.restore_schema_stats(text,timestamp with time zone) line 10 at RETURN QUERY
+NOTICE: arguments are "2, s0.st0_idx, "
+CONTEXT: PL/pgSQL function dbms_stats.restore_schema_stats(text,timestamp with time zone) line 10 at RETURN QUERY
+NOTICE: arguments are "2, s0.st1, "
+CONTEXT: PL/pgSQL function dbms_stats.restore_schema_stats(text,timestamp with time zone) line 10 at RETURN QUERY
+NOTICE: arguments are "2, s0.st1_idx, "
+CONTEXT: PL/pgSQL function dbms_stats.restore_schema_stats(text,timestamp with time zone) line 10 at RETURN QUERY
+NOTICE: arguments are "2, s0.st2, "
+CONTEXT: PL/pgSQL function dbms_stats.restore_schema_stats(text,timestamp with time zone) line 10 at RETURN QUERY
+NOTICE: arguments are "2, s0.st2_idx, "
+CONTEXT: PL/pgSQL function dbms_stats.restore_schema_stats(text,timestamp with time zone) line 10 at RETURN QUERY
+NOTICE: arguments are "2, s0.sft0, "
+CONTEXT: PL/pgSQL function dbms_stats.restore_schema_stats(text,timestamp with time zone) line 10 at RETURN QUERY
+ restore_schema_stats
+----------------------
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+(6 rows)
+
+-- No.10-2-2
+SELECT dbms_stats.restore_schema_stats('s0', '2012-02-29 23:59:57.000002');
+NOTICE: arguments are "3, s0.st0, "
+CONTEXT: PL/pgSQL function dbms_stats.restore_schema_stats(text,timestamp with time zone) line 10 at RETURN QUERY
+NOTICE: arguments are "2, s0.st0_idx, "
+CONTEXT: PL/pgSQL function dbms_stats.restore_schema_stats(text,timestamp with time zone) line 10 at RETURN QUERY
+NOTICE: arguments are "2, s0.st1, "
+CONTEXT: PL/pgSQL function dbms_stats.restore_schema_stats(text,timestamp with time zone) line 10 at RETURN QUERY
+NOTICE: arguments are "2, s0.st1_idx, "
+CONTEXT: PL/pgSQL function dbms_stats.restore_schema_stats(text,timestamp with time zone) line 10 at RETURN QUERY
+NOTICE: arguments are "2, s0.st2, "
+CONTEXT: PL/pgSQL function dbms_stats.restore_schema_stats(text,timestamp with time zone) line 10 at RETURN QUERY
+NOTICE: arguments are "2, s0.st2_idx, "
+CONTEXT: PL/pgSQL function dbms_stats.restore_schema_stats(text,timestamp with time zone) line 10 at RETURN QUERY
+NOTICE: arguments are "2, s0.sft0, "
+CONTEXT: PL/pgSQL function dbms_stats.restore_schema_stats(text,timestamp with time zone) line 10 at RETURN QUERY
+ restore_schema_stats
+----------------------
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+(6 rows)
+
+-- No.10-2-3
+SELECT dbms_stats.restore_schema_stats('s0', '2012-01-01 00:00:00');
+ restore_schema_stats
+----------------------
+(0 rows)
+
+--#No.10-2-4 is skipped after lock tests
+--#No.10-2-5 is skipped after lock tests
+-- No.10-2-6
+SELECT dbms_stats.restore_schema_stats('s0', '2012-02-29 23:59:57');
+NOTICE: arguments are "2, s0.st0, "
+CONTEXT: PL/pgSQL function dbms_stats.restore_schema_stats(text,timestamp with time zone) line 10 at RETURN QUERY
+NOTICE: arguments are "2, s0.st0_idx, "
+CONTEXT: PL/pgSQL function dbms_stats.restore_schema_stats(text,timestamp with time zone) line 10 at RETURN QUERY
+NOTICE: arguments are "2, s0.st1, "
+CONTEXT: PL/pgSQL function dbms_stats.restore_schema_stats(text,timestamp with time zone) line 10 at RETURN QUERY
+NOTICE: arguments are "2, s0.st1_idx, "
+CONTEXT: PL/pgSQL function dbms_stats.restore_schema_stats(text,timestamp with time zone) line 10 at RETURN QUERY
+NOTICE: arguments are "2, s0.st2, "
+CONTEXT: PL/pgSQL function dbms_stats.restore_schema_stats(text,timestamp with time zone) line 10 at RETURN QUERY
+NOTICE: arguments are "2, s0.st2_idx, "
+CONTEXT: PL/pgSQL function dbms_stats.restore_schema_stats(text,timestamp with time zone) line 10 at RETURN QUERY
+NOTICE: arguments are "2, s0.sft0, "
+CONTEXT: PL/pgSQL function dbms_stats.restore_schema_stats(text,timestamp with time zone) line 10 at RETURN QUERY
+ restore_schema_stats
+----------------------
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+(6 rows)
+
+-- No.10-2-7
+SELECT dbms_stats.restore_schema_stats('s0', '2012-02-29 23:59:57');
+NOTICE: arguments are "2, s0.st0, "
+CONTEXT: PL/pgSQL function dbms_stats.restore_schema_stats(text,timestamp with time zone) line 10 at RETURN QUERY
+NOTICE: arguments are "2, s0.st0_idx, "
+CONTEXT: PL/pgSQL function dbms_stats.restore_schema_stats(text,timestamp with time zone) line 10 at RETURN QUERY
+NOTICE: arguments are "2, s0.st1, "
+CONTEXT: PL/pgSQL function dbms_stats.restore_schema_stats(text,timestamp with time zone) line 10 at RETURN QUERY
+NOTICE: arguments are "2, s0.st1_idx, "
+CONTEXT: PL/pgSQL function dbms_stats.restore_schema_stats(text,timestamp with time zone) line 10 at RETURN QUERY
+NOTICE: arguments are "2, s0.st2, "
+CONTEXT: PL/pgSQL function dbms_stats.restore_schema_stats(text,timestamp with time zone) line 10 at RETURN QUERY
+NOTICE: arguments are "2, s0.st2_idx, "
+CONTEXT: PL/pgSQL function dbms_stats.restore_schema_stats(text,timestamp with time zone) line 10 at RETURN QUERY
+NOTICE: arguments are "2, s0.sft0, "
+CONTEXT: PL/pgSQL function dbms_stats.restore_schema_stats(text,timestamp with time zone) line 10 at RETURN QUERY
+ restore_schema_stats
+----------------------
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+(6 rows)
+
+--#No.10-2-8 is skipped after lock tests
+-- No.10-2-9
+SELECT dbms_stats.restore_schema_stats('s00', '2012-02-29 23:59:57');
+ERROR: schema "s00" does not exist
+-- No.10-2-10
+SELECT dbms_stats.restore_schema_stats('pg_catalog', '2012-02-29 23:59:57');
+ERROR: can not restore statistics of relation in system schema "pg_catalog"
+/*
+ * No.10-7 dbms_stats.restore_stats
+ */
+-- No.10-7-1
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore_stats(NULL);
+ restore_stats
+---------------
+(0 rows)
+
+-- No.10-7-2
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore_stats(0);
+ERROR: backup id 0 does not exist
+-- No.10-7-3
+DELETE FROM dbms_stats._relation_stats_locked;
+BEGIN;
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+ relation | mode
+----------+---------------
+ (null) | ExclusiveLock
+(1 row)
+
+SELECT dbms_stats.restore_stats(2);
+ restore_stats
+---------------
+ pt0
+ pt0_idx
+ s0.sft0
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st0
+ st0_idx
+ st1
+ st1_exp
+ st1_idx
+(14 rows)
+
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+ relation | mode
+----------------------------------------+--------------------------
+ dbms_stats._column_stats_locked | RowExclusiveLock
+ dbms_stats._column_stats_locked | ShareUpdateExclusiveLock
+ dbms_stats._column_stats_locked_pkey | RowExclusiveLock
+ dbms_stats._relation_stats_locked | RowExclusiveLock
+ dbms_stats._relation_stats_locked | ShareUpdateExclusiveLock
+ dbms_stats._relation_stats_locked_pkey | RowExclusiveLock
+ (null) | ExclusiveLock
+ (null) | ExclusiveLock
+(8 rows)
+
+COMMIT;
+SELECT relid::regclass FROM dbms_stats.relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+(14 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+(13 rows)
+
+-- No.10-7-4
+DELETE FROM dbms_stats._relation_stats_locked;
+INSERT INTO dbms_stats._relation_stats_locked(relid, relname)
+ SELECT relid::regclass, relname
+ FROM dbms_stats.relation_stats_effective;
+INSERT INTO dbms_stats._column_stats_locked(starelid, staattnum, stainherit)
+ SELECT starelid::regclass, staattnum, stainherit
+ FROM dbms_stats.column_stats_effective;
+SELECT id, unit, comment FROM dbms_stats.backup_history
+ WHERE id = 8;
+ id | unit | comment
+----+------+---------
+ 8 | s | (null)
+(1 row)
+
+SELECT * FROM columns_locked_v;
+ 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
+----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------+------------+------------+------------+------------
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+(15 rows)
+
+SELECT * FROM relations_locked_v;
+ relid | relname | relpages | reltuples | relallvisible | curpages
+------------+----------------+----------+-----------+---------------+----------
+ pt0 | public.pt0 | (null) | (null) | (null) | (null)
+ pt0_idx | public.pt0_idx | (null) | (null) | (null) | (null)
+ st0 | public.st0 | (null) | (null) | (null) | (null)
+ st0_idx | public.st0_idx | (null) | (null) | (null) | (null)
+ st1 | public.st1 | (null) | (null) | (null) | (null)
+ s0.st0 | s0.st0 | (null) | (null) | (null) | (null)
+ s0.st0_idx | s0.st0_idx | (null) | (null) | (null) | (null)
+ s0.st1 | s0.st1 | (null) | (null) | (null) | (null)
+ s0.st1_idx | s0.st1_idx | (null) | (null) | (null) | (null)
+ s0.st2 | s0.st2 | (null) | (null) | (null) | (null)
+ s0.st2_idx | s0.st2_idx | (null) | (null) | (null) | (null)
+ s0.sft0 | s0.sft0 | (null) | (null) | (null) | (null)
+ st1_idx | public.st1_idx | (null) | (null) | (null) | (null)
+ st1_exp | public.st1_exp | (null) | (null) | (null) | (null)
+ s1.st0 | s1.st0 | (null) | (null) | (null) | (null)
+(15 rows)
+
+SELECT dbms_stats.restore_stats(8);
+ restore_stats
+---------------
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+(6 rows)
+
+SELECT * FROM relations_locked_v;
+ relid | relname | relpages | reltuples | relallvisible | curpages
+------------+----------------+----------+-----------+---------------+----------
+ pt0 | public.pt0 | (null) | (null) | (null) | (null)
+ pt0_idx | public.pt0_idx | (null) | (null) | (null) | (null)
+ st0 | public.st0 | (null) | (null) | (null) | (null)
+ st0_idx | public.st0_idx | (null) | (null) | (null) | (null)
+ st1 | public.st1 | (null) | (null) | (null) | (null)
+ s0.st0 | s0.st0 | 1 | 2 | 1 | 1
+ s0.st0_idx | s0.st0_idx | 2 | 2 | 0 | 2
+ s0.st1 | s0.st1 | 1 | 3 | 1 | 1
+ s0.st1_idx | s0.st1_idx | 2 | 3 | 0 | 2
+ s0.st2 | s0.st2 | 1 | 3 | 1 | 1
+ s0.st2_idx | s0.st2_idx | 2 | 3 | 0 | 2
+ s0.sft0 | s0.sft0 | (null) | (null) | (null) | (null)
+ st1_idx | public.st1_idx | (null) | (null) | (null) | (null)
+ st1_exp | public.st1_exp | (null) | (null) | (null) | (null)
+ s1.st0 | s1.st0 | (null) | (null) | (null) | (null)
+(15 rows)
+
+SELECT * FROM columns_locked_v;
+ 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
+----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------------+------------+------------+------------+------------
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+(15 rows)
+
+-- No.10-7-5
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT id, unit, comment FROM dbms_stats.backup_history
+ WHERE id = 8;
+ id | unit | comment
+----+------+---------
+ 8 | s | (null)
+(1 row)
+
+SELECT dbms_stats.restore_stats(8);
+ restore_stats
+---------------
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+(6 rows)
+
+SELECT * FROM relations_locked_v;
+ relid | relname | relpages | reltuples | relallvisible | curpages
+------------+------------+----------+-----------+---------------+----------
+ s0.st0 | s0.st0 | 1 | 2 | 1 | 1
+ s0.st0_idx | s0.st0_idx | 2 | 2 | 0 | 2
+ s0.st1 | s0.st1 | 1 | 3 | 1 | 1
+ s0.st1_idx | s0.st1_idx | 2 | 3 | 0 | 2
+ s0.st2 | s0.st2 | 1 | 3 | 1 | 1
+ s0.st2_idx | s0.st2_idx | 2 | 3 | 0 | 2
+(6 rows)
+
+SELECT * FROM columns_locked_v;
+ 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
+----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------------+------------+------------+------------+------------
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+(8 rows)
+
+/*
+ * No.11-1 dbms_stats.lock(relid, attname)
+ */
+-- No.11-1-1
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock(NULL, NULL);
+ERROR: relation is required
+-- No.11-1-2
+ALTER FUNCTION dbms_stats.lock(relid regclass)
+ RENAME TO truth_lock;
+CREATE FUNCTION dbms_stats.lock(relid regclass)
+RETURNS regclass AS
+$$
+BEGIN
+ RAISE NOTICE 'arguments are %', $1;
+ RETURN $1;
+END
+$$
+LANGUAGE plpgsql;
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.st0', NULL);
+NOTICE: arguments are s0.st0
+CONTEXT: PL/pgSQL function dbms_stats.lock(regclass,text) line 11 at RETURN
+ lock
+--------
+ s0.st0
+(1 row)
+
+DROP FUNCTION dbms_stats.lock(relid regclass);
+ALTER FUNCTION dbms_stats.truth_lock(relid regclass)
+ RENAME TO lock;
+-- No.11-1-3
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock(NULL, 'id');
+ERROR: relation is required
+-- No.11-1-4
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.st0', 'id');
+ lock
+--------
+ s0.st0
+(1 row)
+
+SELECT * FROM relations_locked_v;
+ relid | relname | relpages | reltuples | relallvisible | curpages
+--------+---------+----------+-----------+---------------+----------
+ s0.st0 | s0.st0 | (null) | (null) | (null) | (null)
+(1 row)
+
+SELECT * FROM columns_locked_v c;
+ 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
+----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+-------------+------------+------------+------------+------------
+ 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)
+ 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)
+(2 rows)
+
+-- No.11-1-5
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock(0, 'id');
+ERROR: relation "-" does not exist
+-- No.11-1-6
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.st0', 'id');
+ lock
+--------
+ s0.st0
+(1 row)
+
+SELECT * FROM relations_locked_v;
+ relid | relname | relpages | reltuples | relallvisible | curpages
+--------+---------+----------+-----------+---------------+----------
+ s0.st0 | s0.st0 | (null) | (null) | (null) | (null)
+(1 row)
+
+SELECT * FROM columns_locked_v c;
+ 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
+----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+-------------+------------+------------+------------+------------
+ 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)
+ 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)
+(2 rows)
+
+-- No.11-1-7
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('pg_toast.pg_toast_2618', 'id');
+ERROR: "pg_toast.pg_toast_2618" is not a table nor an index
+-- No.11-1-8
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.st0_idx', 'id');
+ERROR: "s0.st0_idx" is not an indexes on expressions
+-- No.11-1-9
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('st1_exp', 'lower');
+ lock
+---------
+ st1_exp
+(1 row)
+
+SELECT * FROM relations_locked_v;
+ relid | relname | relpages | reltuples | relallvisible | curpages
+---------+----------------+----------+-----------+---------------+----------
+ st1_exp | public.st1_exp | (null) | (null) | (null) | (null)
+(1 row)
+
+SELECT * FROM columns_locked_v c;
+ 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
+----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+------------------------+-------------+-------------+-------------+-------------+------------+------------+------------+------------+------------
+ 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)
+(1 row)
+
+DELETE FROM dbms_stats._relation_stats_locked;
+-- No.11-1-10
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.ss0', 'id');
+ERROR: "s0.ss0" is not a table nor an index
+-- No.11-1-11
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.sc0', 'id');
+ERROR: "s0.sc0" is not a table nor an index
+-- No.11-1-12
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.sft0', 'id');
+ERROR: statistic for column "id" of "s0.sft0" does not exist
+-- No.11-1-13
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('pg_catalog.pg_class', 'id');
+ERROR: can not lock statistics of system catalog "pg_class"
+-- No.11-1-14
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.st0', 'dummy');
+ERROR: column "dummy" of "s0.st0" does not exist
+-- No.11-1-15
+DELETE FROM dbms_stats._relation_stats_locked;
+DELETE FROM pg_statistic
+ WHERE starelid = 's0.st0'::regclass;
+SELECT dbms_stats.lock('s0.st0', 'id');
+ERROR: statistic for column "id" of "s0.st0" does not exist
+VACUUM ANALYZE;
+-- No.11-1-16
+DELETE FROM dbms_stats._relation_stats_locked;
+INSERT INTO dbms_stats._relation_stats_locked(
+ relid, relname, relpages, reltuples,
+ relallvisible,
+ curpages)
+ VALUES('s0.st0'::regclass, 's0.st0', 1, 1640,
+ 1,
+ 1);
+SELECT dbms_stats.lock_column_stats('s0.st0','id');
+ lock_column_stats
+-------------------
+ s0.st0
+(1 row)
+
+UPDATE dbms_stats._column_stats_locked
+ SET (stanullfrac, stawidth, stadistinct,
+ stakind1, stakind2, stakind3, stakind4,
+ stakind5,
+ staop1, staop2, staop3, staop4,
+ staop5,
+ stanumbers1, stanumbers2, stanumbers3, stanumbers4,
+ stanumbers5,
+ stavalues1, stavalues2, stavalues3, stavalues4
+ ,stavalues5
+ ) = (
+ NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL)
+ WHERE starelid = 's0.st0'::regclass;
+SELECT dbms_stats.lock('s0.st0', 'id');
+ lock
+--------
+ s0.st0
+(1 row)
+
+SELECT * FROM relations_locked_v;
+ relid | relname | relpages | reltuples | relallvisible | curpages
+--------+---------+----------+-----------+---------------+----------
+ s0.st0 | s0.st0 | 1 | 1640 | 1 | 1
+(1 row)
+
+SELECT * FROM columns_locked_v c;
+ 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
+----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+-------------+------------+------------+------------+------------
+ 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)
+ 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)
+(2 rows)
+
+-- No.11-1-17
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.st0', 'id');
+ lock
+--------
+ s0.st0
+(1 row)
+
+SELECT * FROM relations_locked_v
+ WHERE relid = 's0.st0'::regclass;
+ relid | relname | relpages | reltuples | relallvisible | curpages
+--------+---------+----------+-----------+---------------+----------
+ s0.st0 | s0.st0 | (null) | (null) | (null) | (null)
+(1 row)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ s0.st0 | id | f
+ s0.st0 | id | t
+(2 rows)
+
+/*
+ * No.11-2 dbms_stats.lock(relid)
+ */
+-- No.11-2-1
+DELETE FROM dbms_stats._relation_stats_locked;
+BEGIN;
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+ relation | mode
+----------+---------------
+ (null) | ExclusiveLock
+(1 row)
+
+SELECT dbms_stats.lock('s0.st0');
+ lock
+--------
+ s0.st0
+(1 row)
+
+SELECT * FROM relations_locked_v;
+ relid | relname | relpages | reltuples | relallvisible | curpages
+--------+---------+----------+-----------+---------------+----------
+ s0.st0 | s0.st0 | 1 | 2 | 1 | 1
+(1 row)
+
+SELECT * FROM columns_locked_v c;
+ 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
+----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------------+------------+------------+------------+------------
+ 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)
+ 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)
+ 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)
+ 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)
+(4 rows)
+
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+ relation | mode
+----------------------------------------+--------------------------
+ dbms_stats._column_stats_locked | RowExclusiveLock
+ dbms_stats._column_stats_locked | ShareUpdateExclusiveLock
+ dbms_stats._column_stats_locked_pkey | RowExclusiveLock
+ dbms_stats._relation_stats_locked | RowExclusiveLock
+ dbms_stats._relation_stats_locked | ShareUpdateExclusiveLock
+ dbms_stats._relation_stats_locked_pkey | RowExclusiveLock
+ (null) | ExclusiveLock
+ (null) | ExclusiveLock
+(8 rows)
+
+COMMIT;
+-- No.11-2-2
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock(NULL);
+ERROR: relation is required
+-- No.11-2-3
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('0');
+ERROR: relation "-" does not exist
+-- No.11-2-4
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.st0');
+ lock
+--------
+ s0.st0
+(1 row)
+
+SELECT * FROM relations_locked_v;
+ relid | relname | relpages | reltuples | relallvisible | curpages
+--------+---------+----------+-----------+---------------+----------
+ s0.st0 | s0.st0 | 1 | 2 | 1 | 1
+(1 row)
+
+SELECT * FROM columns_locked_v c;
+ 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
+----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------------+------------+------------+------------+------------
+ 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)
+ 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)
+ 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)
+ 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)
+(4 rows)
+
+-- No.11-2-5
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('pg_toast.pg_toast_2618');
+ERROR: can not lock statistics of "pg_toast.pg_toast_2618" with relkind "t"
+HINT: only tables and indexes are supported
+-- No.11-2-6
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.st0_idx');
+ lock
+------------
+ s0.st0_idx
+(1 row)
+
+SELECT * FROM relations_locked_v;
+ relid | relname | relpages | reltuples | relallvisible | curpages
+------------+------------+----------+-----------+---------------+----------
+ s0.st0_idx | s0.st0_idx | 2 | 2 | 0 | 2
+(1 row)
+
+SELECT * FROM columns_locked_v c;
+ 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
+----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------+------------+------------+------------+------------
+(0 rows)
+
+-- No.11-2-7
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.ss0');
+ERROR: can not lock statistics of "s0.ss0" with relkind "S"
+HINT: only tables and indexes are supported
+-- No.11-2-8
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.sc0');
+ERROR: can not lock statistics of "s0.sc0" with relkind "c"
+HINT: only tables and indexes are supported
+-- No.11-2-9
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.sft0');
+ lock
+---------
+ s0.sft0
+(1 row)
+
+-- No.11-2-10
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('pg_catalog.pg_class');
+ERROR: can not lock statistics of system catalog "pg_class"
+-- No.11-2-11
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_table_stats('s0.st0');
+ lock_table_stats
+------------------
+ s0.st0
+(1 row)
+
+UPDATE dbms_stats._relation_stats_locked
+ SET (relpages, reltuples,
+ relallvisible,
+ curpages)
+ = (NULL, NULL, NULL
+ ,NULL
+ )
+ WHERE relid = 's0.st0'::regclass;
+SELECT dbms_stats.lock('s0.st0');
+ lock
+--------
+ s0.st0
+(1 row)
+
+SELECT * FROM relations_locked_v;
+ relid | relname | relpages | reltuples | relallvisible | curpages
+--------+---------+----------+-----------+---------------+----------
+ s0.st0 | s0.st0 | 1 | 2 | 1 | 1
+(1 row)
+
+SELECT * FROM columns_locked_v c;
+ 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
+----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------------+------------+------------+------------+------------
+ 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)
+ 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)
+ 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)
+ 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)
+(4 rows)
+
+-- No.11-2-12
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.st0');
+ lock
+--------
+ s0.st0
+(1 row)
+
+SELECT * FROM relations_locked_v;
+ relid | relname | relpages | reltuples | relallvisible | curpages
+--------+---------+----------+-----------+---------------+----------
+ s0.st0 | s0.st0 | 1 | 2 | 1 | 1
+(1 row)
+
+SELECT * FROM columns_locked_v c;
+ 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
+----------+-----------+---------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------------+------------+------------+------------+------------
+ 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)
+ 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)
+ 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)
+ 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)
+(4 rows)
+
+/*
+ * Stab function dbms_stats.lock
+ */
+ALTER FUNCTION dbms_stats.lock(relid regclass)
+ RENAME TO truth_lock;
+CREATE FUNCTION dbms_stats.lock(relid regclass)
+RETURNS regclass AS
+$$
+BEGIN
+ RAISE NOTICE 'arguments are %', $1;
+ RETURN $1;
+END
+$$
+LANGUAGE plpgsql;
+ALTER FUNCTION dbms_stats.lock(relid regclass, attname text)
+ RENAME TO truth_lock;
+CREATE FUNCTION dbms_stats.lock(
+ relid regclass,
+ attname text)
+RETURNS regclass AS
+$$
+BEGIN
+ RAISE NOTICE 'arguments are %, %', $1, $2;
+ RETURN $1;
+END
+$$
+LANGUAGE plpgsql;
+/*
+ * No.12-1 dbms_stats.lock_database_stats
+ */
+-- No.12-1-1
+SELECT dbms_stats.lock_database_stats();
+NOTICE: arguments are pt0
+CONTEXT: SQL function "lock_database_stats" statement 1
+NOTICE: arguments are pt0_idx
+CONTEXT: SQL function "lock_database_stats" statement 1
+NOTICE: arguments are st0
+CONTEXT: SQL function "lock_database_stats" statement 1
+NOTICE: arguments are st0_idx
+CONTEXT: SQL function "lock_database_stats" statement 1
+NOTICE: arguments are st1
+CONTEXT: SQL function "lock_database_stats" statement 1
+NOTICE: arguments are s0.st0
+CONTEXT: SQL function "lock_database_stats" statement 1
+NOTICE: arguments are s0.st0_idx
+CONTEXT: SQL function "lock_database_stats" statement 1
+NOTICE: arguments are s0.st1
+CONTEXT: SQL function "lock_database_stats" statement 1
+NOTICE: arguments are s0.st1_idx
+CONTEXT: SQL function "lock_database_stats" statement 1
+NOTICE: arguments are s0.st2
+CONTEXT: SQL function "lock_database_stats" statement 1
+NOTICE: arguments are s0.st2_idx
+CONTEXT: SQL function "lock_database_stats" statement 1
+NOTICE: arguments are s0.sft0
+CONTEXT: SQL function "lock_database_stats" statement 1
+NOTICE: arguments are st1_idx
+CONTEXT: SQL function "lock_database_stats" statement 1
+NOTICE: arguments are st1_exp
+CONTEXT: SQL function "lock_database_stats" statement 1
+NOTICE: arguments are s1.st0
+CONTEXT: SQL function "lock_database_stats" statement 1
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+/*
+ * No.12-2 dbms_stats.lock_schema_stats
+ */
+-- No.12-2-1
+SELECT dbms_stats.lock_schema_stats('s0');
+NOTICE: arguments are s0.st0
+CONTEXT: PL/pgSQL function dbms_stats.lock_schema_stats(text) line 10 at RETURN QUERY
+NOTICE: arguments are s0.st0_idx
+CONTEXT: PL/pgSQL function dbms_stats.lock_schema_stats(text) line 10 at RETURN QUERY
+NOTICE: arguments are s0.st1
+CONTEXT: PL/pgSQL function dbms_stats.lock_schema_stats(text) line 10 at RETURN QUERY
+NOTICE: arguments are s0.st1_idx
+CONTEXT: PL/pgSQL function dbms_stats.lock_schema_stats(text) line 10 at RETURN QUERY
+NOTICE: arguments are s0.st2
+CONTEXT: PL/pgSQL function dbms_stats.lock_schema_stats(text) line 10 at RETURN QUERY
+NOTICE: arguments are s0.st2_idx
+CONTEXT: PL/pgSQL function dbms_stats.lock_schema_stats(text) line 10 at RETURN QUERY
+NOTICE: arguments are s0.sft0
+CONTEXT: PL/pgSQL function dbms_stats.lock_schema_stats(text) line 10 at RETURN QUERY
+ lock_schema_stats
+-------------------
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+(7 rows)
+
+-- No.12-2-2
+SELECT dbms_stats.lock_schema_stats('s00');
+ERROR: schema "s00" does not exist
+-- No.12-2-3
+SELECT dbms_stats.lock_schema_stats('pg_catalog');
+ERROR: can not lock statistics of relation in system schema "pg_catalog"
+/*
+ * No.12-3 dbms_stats.lock_table_stats(regclass)
+ */
+-- No.12-3-1
+SELECT dbms_stats.lock_table_stats('s0.st0');
+NOTICE: arguments are s0.st0
+CONTEXT: SQL function "lock_table_stats" statement 1
+ lock_table_stats
+------------------
+ s0.st0
+(1 row)
+
+-- No.12-3-2
+SELECT dbms_stats.lock_table_stats('st0');
+NOTICE: arguments are st0
+CONTEXT: SQL function "lock_table_stats" statement 1
+ lock_table_stats
+------------------
+ st0
+(1 row)
+
+-- No.12-3-3
+SELECT dbms_stats.lock_table_stats('s00.s0');
+ERROR: schema "s00" does not exist
+LINE 1: SELECT dbms_stats.lock_table_stats('s00.s0');
+ ^
+/*
+ * No.12-4 dbms_stats.lock_table_stats(schemaname, tablename)
+ */
+-- No.12-4-1
+SELECT dbms_stats.lock_table_stats('s0', 'st0');
+NOTICE: arguments are s0.st0
+CONTEXT: SQL function "lock_table_stats" statement 1
+ lock_table_stats
+------------------
+ s0.st0
+(1 row)
+
+/*
+ * No.12-5 dbms_stats.lock_column_stats(regclass, attname)
+ */
+-- No.12-5-1
+SELECT dbms_stats.lock_column_stats('s0.st0', 'id');
+NOTICE: arguments are s0.st0, id
+CONTEXT: SQL function "lock_column_stats" statement 1
+ lock_column_stats
+-------------------
+ s0.st0
+(1 row)
+
+-- No.12-5-2
+SELECT dbms_stats.lock_column_stats('st0', 'id');
+NOTICE: arguments are st0, id
+CONTEXT: SQL function "lock_column_stats" statement 1
+ lock_column_stats
+-------------------
+ st0
+(1 row)
+
+-- No.12-5-3
+SELECT dbms_stats.lock_column_stats('s00.s0', 'id');
+ERROR: schema "s00" does not exist
+LINE 1: SELECT dbms_stats.lock_column_stats('s00.s0', 'id');
+ ^
+/*
+ * No.12-6 dbms_stats.lock_column_stats(schemaname, tablename, int2)
+ */
+-- No.12-6-1
+SELECT dbms_stats.lock_column_stats('s0', 'st0', 'id');
+NOTICE: arguments are s0.st0, id
+CONTEXT: SQL function "lock_column_stats" statement 1
+ lock_column_stats
+-------------------
+ s0.st0
+(1 row)
+
+/*
+ * Delete Stab function lock
+ */
+DROP FUNCTION dbms_stats.lock(relid regclass);
+ALTER FUNCTION dbms_stats.truth_lock(relid regclass)
+ RENAME TO lock;
+DROP FUNCTION dbms_stats.lock(relid regclass, attname text);
+ALTER FUNCTION dbms_stats.truth_lock(relid regclass, attname text)
+ RENAME TO lock;
+/*
+ * No.13-1 dbms_stats.unlock
+ */
+-- No.13-1-1
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+ id | time | unit | comment
+----+-------------------------------------+------+---------
+ 1 | Wed Feb 29 23:59:56.999999 2012 PST | d | (null)
+ 2 | Wed Feb 29 23:59:57 2012 PST | d | (null)
+ 3 | Wed Feb 29 23:59:57.000001 2012 PST | t | (null)
+ 4 | Wed Feb 29 23:59:58 2012 PST | d | (null)
+ 5 | Thu Mar 01 00:00:00 2012 PST | c | (null)
+ 6 | Thu Mar 01 00:00:02 2012 PST | t | (null)
+ 7 | Thu Mar 01 00:00:04 2012 PST | t | (null)
+ 8 | Thu Mar 01 00:00:06 2012 PST | s | (null)
+(8 rows)
+
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+ count
+-------
+ 25
+(1 row)
+
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+ count
+-------
+ 35
+(1 row)
+
+SELECT dbms_stats.unlock();
+ unlock
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+ id | time | unit | comment
+----+-------------------------------------+------+---------
+ 1 | Wed Feb 29 23:59:56.999999 2012 PST | d | (null)
+ 2 | Wed Feb 29 23:59:57 2012 PST | d | (null)
+ 3 | Wed Feb 29 23:59:57.000001 2012 PST | t | (null)
+ 4 | Wed Feb 29 23:59:58 2012 PST | d | (null)
+ 5 | Thu Mar 01 00:00:00 2012 PST | c | (null)
+ 6 | Thu Mar 01 00:00:02 2012 PST | t | (null)
+ 7 | Thu Mar 01 00:00:04 2012 PST | t | (null)
+ 8 | Thu Mar 01 00:00:06 2012 PST | s | (null)
+(8 rows)
+
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+ count
+-------
+ 25
+(1 row)
+
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+ count
+-------
+ 35
+(1 row)
+
+-- No.13-1-2
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT dbms_stats.unlock();
+ unlock
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+-- No.13-1-3
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+DELETE FROM dbms_stats._column_stats_locked;
+SELECT dbms_stats.unlock();
+ unlock
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+-- No.13-1-4
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.unlock();
+ unlock
+--------
+(0 rows)
+
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+-- No.13-1-5
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+SELECT dbms_stats.unlock('s0.st0');
+ unlock
+--------
+ s0.st0
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(6 rows)
+
+-- No.13-1-6
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+SELECT dbms_stats.unlock('st0');
+ unlock
+--------
+ st0
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(6 rows)
+
+-- No.13-1-7
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+ count
+-------
+ 15
+(1 row)
+
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+ count
+-------
+ 15
+(1 row)
+
+SELECT dbms_stats.unlock('s00.s0');
+ERROR: schema "s00" does not exist
+LINE 1: SELECT dbms_stats.unlock('s00.s0');
+ ^
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+ count
+-------
+ 15
+(1 row)
+
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+ count
+-------
+ 15
+(1 row)
+
+-- No.13-1-8
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+SELECT dbms_stats.unlock('s0.st0', 'id');
+ unlock
+--------
+ s0.st0
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(13 rows)
+
+-- No.13-1-9
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+SELECT dbms_stats.unlock('s0.st0', 'dummy');
+ERROR: column "dummy" of "s0.st0" does not exist
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+-- No.13-1-10
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+DELETE FROM dbms_stats._column_stats_locked;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT dbms_stats.unlock('s0.st0', 'id');
+ unlock
+--------
+ s0.st0
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid::regclass, staattnum FROM dbms_stats._column_stats_locked
+ GROUP BY starelid, staattnum
+ ORDER BY starelid;
+ starelid | staattnum
+----------+-----------
+(0 rows)
+
+-- No.13-1-11
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid::regclass, staattnum FROM dbms_stats._column_stats_locked
+ GROUP BY starelid, staattnum
+ ORDER BY starelid;
+ starelid | staattnum
+----------+-----------
+ st0 | 1
+ st0 | 2
+ st1 | 1
+ st1 | 2
+ s0.st0 | 1
+ s0.st0 | 2
+ s0.st1 | 1
+ s0.st1 | 2
+ s0.st2 | 1
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 1
+ s1.st0 | 2
+(13 rows)
+
+SELECT dbms_stats.unlock(NULL, 'id');
+ERROR: relation is required
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid::regclass, staattnum FROM dbms_stats._column_stats_locked
+ GROUP BY starelid, staattnum
+ ORDER BY starelid;
+ starelid | staattnum
+----------+-----------
+ st0 | 1
+ st0 | 2
+ st1 | 1
+ st1 | 2
+ s0.st0 | 1
+ s0.st0 | 2
+ s0.st1 | 1
+ s0.st1 | 2
+ s0.st2 | 1
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 1
+ s1.st0 | 2
+(13 rows)
+
+-- No.13-1-12
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid::regclass, staattnum FROM dbms_stats._column_stats_locked
+ GROUP BY starelid, staattnum
+ ORDER BY starelid;
+ starelid | staattnum
+----------+-----------
+ st0 | 1
+ st0 | 2
+ st1 | 1
+ st1 | 2
+ s0.st0 | 1
+ s0.st0 | 2
+ s0.st1 | 1
+ s0.st1 | 2
+ s0.st2 | 1
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 1
+ s1.st0 | 2
+(13 rows)
+
+SELECT dbms_stats.unlock('s0.st0', NULL);
+ unlock
+--------
+ s0.st0
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid::regclass, staattnum FROM dbms_stats._column_stats_locked
+ GROUP BY starelid, staattnum
+ ORDER BY starelid;
+ starelid | staattnum
+----------+-----------
+ st0 | 1
+ st0 | 2
+ st1 | 1
+ st1 | 2
+ s0.st1 | 1
+ s0.st1 | 2
+ s0.st2 | 1
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 1
+ s1.st0 | 2
+(11 rows)
+
+-- No.13-1-13
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+ count
+-------
+ 15
+(1 row)
+
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+ count
+-------
+ 15
+(1 row)
+
+BEGIN;
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+ relation | mode
+----------+---------------
+ (null) | ExclusiveLock
+(1 row)
+
+SELECT dbms_stats.unlock();
+ unlock
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+ relation | mode
+--------------------------------------+--------------------------
+ dbms_stats._column_stats_locked | RowExclusiveLock
+ dbms_stats._column_stats_locked | ShareUpdateExclusiveLock
+ dbms_stats._column_stats_locked_pkey | RowExclusiveLock
+ dbms_stats._relation_stats_locked | RowExclusiveLock
+ dbms_stats._relation_stats_locked | ShareUpdateExclusiveLock
+ (null) | ExclusiveLock
+ (null) | ExclusiveLock
+(7 rows)
+
+COMMIT;
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+/*
+ * No.14-1 dbms_stats.unlock_database_stats
+ */
+-- No.14-1-1
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+ id | time | unit | comment
+----+-------------------------------------+------+---------
+ 1 | Wed Feb 29 23:59:56.999999 2012 PST | d | (null)
+ 2 | Wed Feb 29 23:59:57 2012 PST | d | (null)
+ 3 | Wed Feb 29 23:59:57.000001 2012 PST | t | (null)
+ 4 | Wed Feb 29 23:59:58 2012 PST | d | (null)
+ 5 | Thu Mar 01 00:00:00 2012 PST | c | (null)
+ 6 | Thu Mar 01 00:00:02 2012 PST | t | (null)
+ 7 | Thu Mar 01 00:00:04 2012 PST | t | (null)
+ 8 | Thu Mar 01 00:00:06 2012 PST | s | (null)
+(8 rows)
+
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+ count
+-------
+ 25
+(1 row)
+
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+ count
+-------
+ 35
+(1 row)
+
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+ count
+-------
+ 15
+(1 row)
+
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+ count
+-------
+ 15
+(1 row)
+
+SELECT dbms_stats.unlock_database_stats();
+ unlock_database_stats
+-----------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+ id | time | unit | comment
+----+-------------------------------------+------+---------
+ 1 | Wed Feb 29 23:59:56.999999 2012 PST | d | (null)
+ 2 | Wed Feb 29 23:59:57 2012 PST | d | (null)
+ 3 | Wed Feb 29 23:59:57.000001 2012 PST | t | (null)
+ 4 | Wed Feb 29 23:59:58 2012 PST | d | (null)
+ 5 | Thu Mar 01 00:00:00 2012 PST | c | (null)
+ 6 | Thu Mar 01 00:00:02 2012 PST | t | (null)
+ 7 | Thu Mar 01 00:00:04 2012 PST | t | (null)
+ 8 | Thu Mar 01 00:00:06 2012 PST | s | (null)
+(8 rows)
+
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+ count
+-------
+ 25
+(1 row)
+
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+ count
+-------
+ 35
+(1 row)
+
+-- No.14-1-2
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+DELETE FROM dbms_stats._column_stats_locked;
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+ count
+-------
+ 15
+(1 row)
+
+SELECT dbms_stats.unlock_database_stats();
+ unlock_database_stats
+-----------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+-- No.14-1-3
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.unlock_database_stats();
+ unlock_database_stats
+-----------------------
+(0 rows)
+
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+-- No.14-1-4
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+ count
+-------
+ 15
+(1 row)
+
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+ count
+-------
+ 15
+(1 row)
+
+BEGIN;
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+ relation | mode
+----------+---------------
+ (null) | ExclusiveLock
+(1 row)
+
+SELECT dbms_stats.unlock_database_stats();
+ unlock_database_stats
+-----------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+ relation | mode
+-----------------------------------+--------------------------
+ dbms_stats._column_stats_locked | RowExclusiveLock
+ dbms_stats._column_stats_locked | ShareUpdateExclusiveLock
+ dbms_stats._relation_stats_locked | RowExclusiveLock
+ dbms_stats._relation_stats_locked | ShareUpdateExclusiveLock
+ (null) | ExclusiveLock
+ (null) | ExclusiveLock
+(6 rows)
+
+COMMIT;
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+/*
+ * No.14-2 dbms_stats.unlock_schema_stats
+ */
+-- No.14-2-1
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+ id | time | unit | comment
+----+-------------------------------------+------+---------
+ 1 | Wed Feb 29 23:59:56.999999 2012 PST | d | (null)
+ 2 | Wed Feb 29 23:59:57 2012 PST | d | (null)
+ 3 | Wed Feb 29 23:59:57.000001 2012 PST | t | (null)
+ 4 | Wed Feb 29 23:59:58 2012 PST | d | (null)
+ 5 | Thu Mar 01 00:00:00 2012 PST | c | (null)
+ 6 | Thu Mar 01 00:00:02 2012 PST | t | (null)
+ 7 | Thu Mar 01 00:00:04 2012 PST | t | (null)
+ 8 | Thu Mar 01 00:00:06 2012 PST | s | (null)
+(8 rows)
+
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+ count
+-------
+ 25
+(1 row)
+
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+ count
+-------
+ 35
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+SELECT dbms_stats.unlock_schema_stats('s0');
+ unlock_schema_stats
+---------------------
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+(7 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+---------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ st1_idx
+ st1_exp
+ s1.st0
+(8 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(4 rows)
+
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+ id | time | unit | comment
+----+-------------------------------------+------+---------
+ 1 | Wed Feb 29 23:59:56.999999 2012 PST | d | (null)
+ 2 | Wed Feb 29 23:59:57 2012 PST | d | (null)
+ 3 | Wed Feb 29 23:59:57.000001 2012 PST | t | (null)
+ 4 | Wed Feb 29 23:59:58 2012 PST | d | (null)
+ 5 | Thu Mar 01 00:00:00 2012 PST | c | (null)
+ 6 | Thu Mar 01 00:00:02 2012 PST | t | (null)
+ 7 | Thu Mar 01 00:00:04 2012 PST | t | (null)
+ 8 | Thu Mar 01 00:00:06 2012 PST | s | (null)
+(8 rows)
+
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+ count
+-------
+ 25
+(1 row)
+
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+ count
+-------
+ 35
+(1 row)
+
+-- No.14-2-2
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+DELETE FROM dbms_stats._column_stats_locked;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+(0 rows)
+
+SELECT dbms_stats.unlock_schema_stats('s0');
+ unlock_schema_stats
+---------------------
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+(7 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+---------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ st1_idx
+ st1_exp
+ s1.st0
+(8 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+(0 rows)
+
+-- No.14-2-3
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+-------
+(0 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+(0 rows)
+
+SELECT dbms_stats.unlock_schema_stats('s0');
+ unlock_schema_stats
+---------------------
+(0 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+-------
+(0 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+(0 rows)
+
+-- No.14-2-4
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+SELECT dbms_stats.unlock_schema_stats('s0');
+ unlock_schema_stats
+---------------------
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+(7 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+---------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ st1_idx
+ st1_exp
+ s1.st0
+(8 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(4 rows)
+
+-- No.14-2-5
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+SELECT dbms_stats.unlock_schema_stats('s00');
+ERROR: schema "s00" does not exist
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+-- No.14-2-6
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+SELECT dbms_stats.unlock_schema_stats('pg_catalog');
+ERROR: can not unlock statistics of relation in system schema "pg_catalog"
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+-- No.14-2-7
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+SELECT dbms_stats.unlock_schema_stats(NULL);
+ unlock_schema_stats
+---------------------
+(0 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+-- No.14-2-8
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+BEGIN;
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+ relation | mode
+----------+---------------
+ (null) | ExclusiveLock
+(1 row)
+
+SELECT dbms_stats.unlock_schema_stats('s0');
+ unlock_schema_stats
+---------------------
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+(7 rows)
+
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+ relation | mode
+-----------------------------------+--------------------------
+ dbms_stats._column_stats_locked | RowExclusiveLock
+ dbms_stats._column_stats_locked | ShareUpdateExclusiveLock
+ dbms_stats._relation_stats_locked | RowExclusiveLock
+ dbms_stats._relation_stats_locked | ShareUpdateExclusiveLock
+ (null) | ExclusiveLock
+ (null) | ExclusiveLock
+(6 rows)
+
+COMMIT;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+---------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ st1_idx
+ st1_exp
+ s1.st0
+(8 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(4 rows)
+
+/*
+ * No.14-3 dbms_stats.unlock_table_stats(regclass)
+ */
+-- No.14-3-1
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+ id | time | unit | comment
+----+-------------------------------------+------+---------
+ 1 | Wed Feb 29 23:59:56.999999 2012 PST | d | (null)
+ 2 | Wed Feb 29 23:59:57 2012 PST | d | (null)
+ 3 | Wed Feb 29 23:59:57.000001 2012 PST | t | (null)
+ 4 | Wed Feb 29 23:59:58 2012 PST | d | (null)
+ 5 | Thu Mar 01 00:00:00 2012 PST | c | (null)
+ 6 | Thu Mar 01 00:00:02 2012 PST | t | (null)
+ 7 | Thu Mar 01 00:00:04 2012 PST | t | (null)
+ 8 | Thu Mar 01 00:00:06 2012 PST | s | (null)
+(8 rows)
+
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+ count
+-------
+ 25
+(1 row)
+
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+ count
+-------
+ 35
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+SELECT dbms_stats.unlock_table_stats('s0.st0');
+ unlock_table_stats
+--------------------
+ s0.st0
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(6 rows)
+
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+ id | time | unit | comment
+----+-------------------------------------+------+---------
+ 1 | Wed Feb 29 23:59:56.999999 2012 PST | d | (null)
+ 2 | Wed Feb 29 23:59:57 2012 PST | d | (null)
+ 3 | Wed Feb 29 23:59:57.000001 2012 PST | t | (null)
+ 4 | Wed Feb 29 23:59:58 2012 PST | d | (null)
+ 5 | Thu Mar 01 00:00:00 2012 PST | c | (null)
+ 6 | Thu Mar 01 00:00:02 2012 PST | t | (null)
+ 7 | Thu Mar 01 00:00:04 2012 PST | t | (null)
+ 8 | Thu Mar 01 00:00:06 2012 PST | s | (null)
+(8 rows)
+
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+ count
+-------
+ 25
+(1 row)
+
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+ count
+-------
+ 35
+(1 row)
+
+-- No.14-3-2
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+DELETE FROM dbms_stats._column_stats_locked;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+(0 rows)
+
+SELECT dbms_stats.unlock_table_stats('s0.st0');
+ unlock_table_stats
+--------------------
+ s0.st0
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+(0 rows)
+
+-- No.14-3-3
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+-------
+(0 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+(0 rows)
+
+SELECT dbms_stats.unlock_table_stats('s0.st0');
+ unlock_table_stats
+--------------------
+(0 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+-------
+(0 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+(0 rows)
+
+-- No.14-3-4
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+SELECT dbms_stats.unlock_table_stats('s0.st0');
+ unlock_table_stats
+--------------------
+ s0.st0
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(6 rows)
+
+-- No.14-3-5
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+SELECT dbms_stats.unlock_table_stats('st0');
+ unlock_table_stats
+--------------------
+ st0
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(6 rows)
+
+-- No.14-3-6
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+SELECT dbms_stats.unlock_table_stats('s00.s0');
+ERROR: schema "s00" does not exist
+LINE 1: SELECT dbms_stats.unlock_table_stats('s00.s0');
+ ^
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+-- No.14-3-7
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+SELECT dbms_stats.unlock_table_stats(NULL);
+ unlock_table_stats
+--------------------
+(0 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+-- No.14-3-8
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+BEGIN;
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+ relation | mode
+----------+---------------
+ (null) | ExclusiveLock
+(1 row)
+
+SELECT dbms_stats.unlock_table_stats('s0.st0');
+ unlock_table_stats
+--------------------
+ s0.st0
+(1 row)
+
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+ relation | mode
+----------------------------------------+--------------------------
+ dbms_stats._column_stats_locked | RowExclusiveLock
+ dbms_stats._column_stats_locked | ShareUpdateExclusiveLock
+ dbms_stats._relation_stats_locked | RowExclusiveLock
+ dbms_stats._relation_stats_locked | ShareUpdateExclusiveLock
+ dbms_stats._relation_stats_locked_pkey | RowExclusiveLock
+ (null) | ExclusiveLock
+ (null) | ExclusiveLock
+(7 rows)
+
+COMMIT;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(6 rows)
+
+/*
+ * No.14-4 dbms_stats.unlock_table_stats(schemaname, tablename)
+ */
+-- No.14-4-1
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+ id | time | unit | comment
+----+-------------------------------------+------+---------
+ 1 | Wed Feb 29 23:59:56.999999 2012 PST | d | (null)
+ 2 | Wed Feb 29 23:59:57 2012 PST | d | (null)
+ 3 | Wed Feb 29 23:59:57.000001 2012 PST | t | (null)
+ 4 | Wed Feb 29 23:59:58 2012 PST | d | (null)
+ 5 | Thu Mar 01 00:00:00 2012 PST | c | (null)
+ 6 | Thu Mar 01 00:00:02 2012 PST | t | (null)
+ 7 | Thu Mar 01 00:00:04 2012 PST | t | (null)
+ 8 | Thu Mar 01 00:00:06 2012 PST | s | (null)
+(8 rows)
+
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+ count
+-------
+ 25
+(1 row)
+
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+ count
+-------
+ 35
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+SELECT dbms_stats.unlock_table_stats('s0','st0');
+ unlock_table_stats
+--------------------
+ s0.st0
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(6 rows)
+
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+ id | time | unit | comment
+----+-------------------------------------+------+---------
+ 1 | Wed Feb 29 23:59:56.999999 2012 PST | d | (null)
+ 2 | Wed Feb 29 23:59:57 2012 PST | d | (null)
+ 3 | Wed Feb 29 23:59:57.000001 2012 PST | t | (null)
+ 4 | Wed Feb 29 23:59:58 2012 PST | d | (null)
+ 5 | Thu Mar 01 00:00:00 2012 PST | c | (null)
+ 6 | Thu Mar 01 00:00:02 2012 PST | t | (null)
+ 7 | Thu Mar 01 00:00:04 2012 PST | t | (null)
+ 8 | Thu Mar 01 00:00:06 2012 PST | s | (null)
+(8 rows)
+
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+ count
+-------
+ 25
+(1 row)
+
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+ count
+-------
+ 35
+(1 row)
+
+-- No.14-4-2
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+DELETE FROM dbms_stats._column_stats_locked;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+(0 rows)
+
+SELECT dbms_stats.unlock_table_stats('s0', 'st0');
+ unlock_table_stats
+--------------------
+ s0.st0
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+(0 rows)
+
+-- No.14-4-3
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+-------
+(0 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+(0 rows)
+
+SELECT dbms_stats.unlock_table_stats('s0', 'st0');
+ unlock_table_stats
+--------------------
+(0 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+-------
+(0 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+(0 rows)
+
+-- No.14-4-4
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+SELECT dbms_stats.unlock_table_stats('s0', 'st0');
+ unlock_table_stats
+--------------------
+ s0.st0
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(6 rows)
+
+-- No.14-4-5
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+SELECT dbms_stats.unlock_table_stats('s00', 's0');
+ERROR: schema "s00" does not exist
+CONTEXT: SQL function "unlock_table_stats" statement 3
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+-- No.14-4-6
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+SELECT dbms_stats.unlock_table_stats(NULL, 'st0');
+ unlock_table_stats
+--------------------
+(0 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+-- No.14-4-7
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+SELECT dbms_stats.unlock_table_stats('s0', NULL);
+ unlock_table_stats
+--------------------
+(0 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+-- No.14-4-8
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st0 | 4
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(7 rows)
+
+BEGIN;
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+ relation | mode
+----------+---------------
+ (null) | ExclusiveLock
+(1 row)
+
+SELECT dbms_stats.unlock_table_stats('s0', 'st0');
+ unlock_table_stats
+--------------------
+ s0.st0
+(1 row)
+
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+ relation | mode
+----------------------------------------+--------------------------
+ dbms_stats._column_stats_locked | RowExclusiveLock
+ dbms_stats._column_stats_locked | ShareUpdateExclusiveLock
+ dbms_stats._relation_stats_locked | RowExclusiveLock
+ dbms_stats._relation_stats_locked | ShareUpdateExclusiveLock
+ dbms_stats._relation_stats_locked_pkey | RowExclusiveLock
+ (null) | ExclusiveLock
+ (null) | ExclusiveLock
+(7 rows)
+
+COMMIT;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(14 rows)
+
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+ starelid | count
+----------+-------
+ st0 | 2
+ st1 | 2
+ s0.st1 | 2
+ s0.st2 | 2
+ st1_exp | 1
+ s1.st0 | 2
+(6 rows)
+
+/*
+ * No.14-5 dbms_stats.unlock_column_stats(regclass, attname)
+ */
+-- No.14-5-1
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+ id | time | unit | comment
+----+-------------------------------------+------+---------
+ 1 | Wed Feb 29 23:59:56.999999 2012 PST | d | (null)
+ 2 | Wed Feb 29 23:59:57 2012 PST | d | (null)
+ 3 | Wed Feb 29 23:59:57.000001 2012 PST | t | (null)
+ 4 | Wed Feb 29 23:59:58 2012 PST | d | (null)
+ 5 | Thu Mar 01 00:00:00 2012 PST | c | (null)
+ 6 | Thu Mar 01 00:00:02 2012 PST | t | (null)
+ 7 | Thu Mar 01 00:00:04 2012 PST | t | (null)
+ 8 | Thu Mar 01 00:00:06 2012 PST | s | (null)
+(8 rows)
+
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+ count
+-------
+ 25
+(1 row)
+
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+ count
+-------
+ 35
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+SELECT dbms_stats.unlock_column_stats('s0.st0', 'id');
+ unlock_column_stats
+---------------------
+ s0.st0
+(1 row)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(13 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+ id | time | unit | comment
+----+-------------------------------------+------+---------
+ 1 | Wed Feb 29 23:59:56.999999 2012 PST | d | (null)
+ 2 | Wed Feb 29 23:59:57 2012 PST | d | (null)
+ 3 | Wed Feb 29 23:59:57.000001 2012 PST | t | (null)
+ 4 | Wed Feb 29 23:59:58 2012 PST | d | (null)
+ 5 | Thu Mar 01 00:00:00 2012 PST | c | (null)
+ 6 | Thu Mar 01 00:00:02 2012 PST | t | (null)
+ 7 | Thu Mar 01 00:00:04 2012 PST | t | (null)
+ 8 | Thu Mar 01 00:00:06 2012 PST | s | (null)
+(8 rows)
+
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+ count
+-------
+ 25
+(1 row)
+
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+ count
+-------
+ 35
+(1 row)
+
+-- No.14-5-2
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+DELETE FROM dbms_stats._column_stats_locked;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT dbms_stats.unlock_column_stats('s0.st0', 'id');
+ unlock_column_stats
+---------------------
+ s0.st0
+(1 row)
+
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+ count
+-------
+ 0
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+-- No.14-5-3
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+SELECT dbms_stats.unlock_column_stats('s0.st0', 'id');
+ unlock_column_stats
+---------------------
+ s0.st0
+(1 row)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(13 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+-- No.14-5-4
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+SELECT dbms_stats.unlock_column_stats('st0', 'id');
+ unlock_column_stats
+---------------------
+ st0
+(1 row)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(14 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+-- No.14-5-5
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+SELECT dbms_stats.unlock_column_stats('s0.st0', 'dummy');
+ERROR: column "dummy" of "s0.st0" does not exist
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+-- No.14-5-6
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+SELECT dbms_stats.unlock_column_stats('s00.s0', 'id');
+ERROR: schema "s00" does not exist
+LINE 1: SELECT dbms_stats.unlock_column_stats('s00.s0', 'id');
+ ^
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+-- No.14-5-7
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+SELECT dbms_stats.unlock_column_stats(NULL, 'id');
+ unlock_column_stats
+---------------------
+(0 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+-- No.14-5-8
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+SELECT dbms_stats.unlock_column_stats('s0.st0', NULL);
+ unlock_column_stats
+---------------------
+(0 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+-- No.14-5-9
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+BEGIN;
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+ relation | mode
+----------+---------------
+ (null) | ExclusiveLock
+(1 row)
+
+SELECT dbms_stats.unlock_column_stats('s0.st0', 'id');
+ unlock_column_stats
+---------------------
+ s0.st0
+(1 row)
+
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+ relation | mode
+--------------------------------------+--------------------------
+ dbms_stats._column_stats_locked | RowExclusiveLock
+ dbms_stats._column_stats_locked | ShareUpdateExclusiveLock
+ dbms_stats._column_stats_locked_pkey | RowExclusiveLock
+ dbms_stats._relation_stats_locked | ShareUpdateExclusiveLock
+ (null) | ExclusiveLock
+ (null) | ExclusiveLock
+(6 rows)
+
+COMMIT;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(13 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+/*
+ * No.14-6 dbms_stats.unlock_column_stats(schemaname, tablename, attname)
+ */
+-- No.14-6-1
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+ id | time | unit | comment
+----+-------------------------------------+------+---------
+ 1 | Wed Feb 29 23:59:56.999999 2012 PST | d | (null)
+ 2 | Wed Feb 29 23:59:57 2012 PST | d | (null)
+ 3 | Wed Feb 29 23:59:57.000001 2012 PST | t | (null)
+ 4 | Wed Feb 29 23:59:58 2012 PST | d | (null)
+ 5 | Thu Mar 01 00:00:00 2012 PST | c | (null)
+ 6 | Thu Mar 01 00:00:02 2012 PST | t | (null)
+ 7 | Thu Mar 01 00:00:04 2012 PST | t | (null)
+ 8 | Thu Mar 01 00:00:06 2012 PST | s | (null)
+(8 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+SELECT dbms_stats.unlock_column_stats('s0', 'st0', 'id');
+ unlock_column_stats
+---------------------
+ s0.st0
+(1 row)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(13 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+ id | time | unit | comment
+----+-------------------------------------+------+---------
+ 1 | Wed Feb 29 23:59:56.999999 2012 PST | d | (null)
+ 2 | Wed Feb 29 23:59:57 2012 PST | d | (null)
+ 3 | Wed Feb 29 23:59:57.000001 2012 PST | t | (null)
+ 4 | Wed Feb 29 23:59:58 2012 PST | d | (null)
+ 5 | Thu Mar 01 00:00:00 2012 PST | c | (null)
+ 6 | Thu Mar 01 00:00:02 2012 PST | t | (null)
+ 7 | Thu Mar 01 00:00:04 2012 PST | t | (null)
+ 8 | Thu Mar 01 00:00:06 2012 PST | s | (null)
+(8 rows)
+
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+ count
+-------
+ 25
+(1 row)
+
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+ count
+-------
+ 35
+(1 row)
+
+-- No.14-6-2
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+DELETE FROM dbms_stats._column_stats_locked;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT dbms_stats.unlock_column_stats('s0', 'st0', 'id');
+ unlock_column_stats
+---------------------
+ s0.st0
+(1 row)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+(0 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+-- No.14-6-3
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+SELECT dbms_stats.unlock_column_stats('s0', 'st0', 'id');
+ unlock_column_stats
+---------------------
+ s0.st0
+(1 row)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(13 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+-- No.14-6-4
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+SELECT dbms_stats.unlock_column_stats('s0', 'st0', 'dummy');
+ERROR: column "dummy" of "s0.st0" does not exist
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+-- No.14-6-5
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+SELECT dbms_stats.unlock_column_stats(NULL, 'st0', 'id');
+ unlock_column_stats
+---------------------
+(0 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+-- No.14-6-6
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+SELECT dbms_stats.unlock_column_stats('s0', NULL, 'id');
+ unlock_column_stats
+---------------------
+(0 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+-- No.14-6-7
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+SELECT dbms_stats.unlock_column_stats('s0', 'st0', NULL);
+ unlock_column_stats
+---------------------
+(0 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+-- No.14-6-8
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | id | f
+ s0.st0 | id | t
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(15 rows)
+
+BEGIN;
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+ relation | mode
+----------+---------------
+ (null) | ExclusiveLock
+(1 row)
+
+SELECT dbms_stats.unlock_column_stats('s0', 'st0', 'id');
+ unlock_column_stats
+---------------------
+ s0.st0
+(1 row)
+
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+ relation | mode
+--------------------------------------+--------------------------
+ dbms_stats._column_stats_locked | RowExclusiveLock
+ dbms_stats._column_stats_locked | ShareUpdateExclusiveLock
+ dbms_stats._column_stats_locked_pkey | RowExclusiveLock
+ dbms_stats._relation_stats_locked | ShareUpdateExclusiveLock
+ (null) | ExclusiveLock
+ (null) | ExclusiveLock
+(6 rows)
+
+COMMIT;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+ starelid | attname | stainherit
+----------+---------+------------
+ st0 | id | f
+ st0 | name | f
+ st1 | val | f
+ st1 | str | f
+ s0.st0 | num | f
+ s0.st0 | num | t
+ s0.st1 | id | f
+ s0.st1 | num | f
+ s0.st2 | id | f
+ s0.st2 | txt | f
+ st1_exp | lower | f
+ s1.st0 | id | f
+ s1.st0 | num | f
+(13 rows)
+
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+(15 rows)
+
diff --git a/expected/ut-common.out b/expected/ut-common.out
new file mode 100644
index 0000000..c0e18e8
--- /dev/null
+++ b/expected/ut-common.out
@@ -0,0 +1,2396 @@
+\pset null '(null)'
+LOAD 'pg_dbms_stats';
+/*
+ * No.2-3 dbms_stats.backup_history_id_seq
+ */
+-- No.2-3-1
+SELECT setval('dbms_stats.backup_history_id_seq', 0, false);
+ERROR: setval: value 0 is out of bounds for sequence "backup_history_id_seq" (1..9223372036854775807)
+-- No.2-3-2
+SELECT setval('dbms_stats.backup_history_id_seq', 1, false);
+ setval
+--------
+ 1
+(1 row)
+
+INSERT INTO dbms_stats.backup_history(time, unit)
+ VALUES ('2011-01-01', 't');
+SELECT id, time, unit FROM dbms_stats.backup_history
+ ORDER BY id;
+ id | time | unit
+----+------------------------------+------
+ 1 | Sat Jan 01 00:00:00 2011 PST | t
+(1 row)
+
+-- No.2-3-3
+INSERT INTO dbms_stats.backup_history(time, unit)
+ VALUES ('2011-01-02', 'c'), ('2011-01-03', 'd');
+SELECT id, time, unit FROM dbms_stats.backup_history
+ ORDER BY id;
+ id | time | unit
+----+------------------------------+------
+ 1 | Sat Jan 01 00:00:00 2011 PST | t
+ 2 | Sun Jan 02 00:00:00 2011 PST | c
+ 3 | Mon Jan 03 00:00:00 2011 PST | d
+(3 rows)
+
+-- clean up
+SELECT setval('dbms_stats.backup_history_id_seq', 1, false);
+ setval
+--------
+ 1
+(1 row)
+
+DELETE FROM dbms_stats.backup_history;
+/*
+ * No.3-1 dbms_stats.use_locked_stats
+ */
+DELETE FROM dbms_stats._relation_stats_locked;
+EXPLAIN (costs false) SELECT * FROM s0.st2 WHERE id < 1;
+ QUERY PLAN
+--------------------
+ Seq Scan on st2
+ Filter: (id < 1)
+(2 rows)
+
+SELECT dbms_stats.lock_table_stats('s0.st2'::regclass);
+ lock_table_stats
+------------------
+ s0.st2
+(1 row)
+
+UPDATE dbms_stats._relation_stats_locked SET curpages = 10000;
+-- No.3-1-1
+SET pg_dbms_stats.use_locked_stats TO on;
+EXPLAIN (costs false) SELECT * FROM s0.st2 WHERE id < 1;
+ QUERY PLAN
+---------------------------------
+ Index Scan using st2_idx on st2
+ Index Cond: (id < 1)
+(2 rows)
+
+-- No.3-1-2
+SET pg_dbms_stats.use_locked_stats TO off;
+EXPLAIN (costs false) SELECT * FROM s0.st2 WHERE id < 1;
+ QUERY PLAN
+--------------------
+ Seq Scan on st2
+ Filter: (id < 1)
+(2 rows)
+
+-- No.3-1-3
+\c - regular_user
+LOAD '$libdir/plugins/pg_dbms_stats';
+SHOW pg_dbms_stats.use_locked_stats;
+ pg_dbms_stats.use_locked_stats
+--------------------------------
+ on
+(1 row)
+
+SET pg_dbms_stats.use_locked_stats TO OFF;
+SHOW pg_dbms_stats.use_locked_stats;
+ pg_dbms_stats.use_locked_stats
+--------------------------------
+ off
+(1 row)
+
+EXPLAIN (costs false) SELECT * FROM s0.st2 WHERE id < 1;
+ QUERY PLAN
+--------------------
+ Seq Scan on st2
+ Filter: (id < 1)
+(2 rows)
+
+RESET pg_dbms_stats.use_locked_stats;
+EXPLAIN (costs false) SELECT * FROM s0.st2 WHERE id < 1;
+ QUERY PLAN
+---------------------------------
+ Index Scan using st2_idx on st2
+ Index Cond: (id < 1)
+(2 rows)
+
+-- clean up
+\c - postgres
+LOAD 'pg_dbms_stats';
+DELETE FROM dbms_stats._relation_stats_locked;
+/*
+ * No.4-1 DATA TYPE dbms_stats.anyarray
+ */
+CREATE TABLE st3(id integer, name char(1000), num_arr char(5)[]);
+INSERT INTO st3 SELECT i, i , ARRAY[i::char, 'a'] FROM generate_series(1,10) g(i);
+ANALYZE st3;
+SELECT stavalues1 FROM pg_statistic
+ WHERE starelid = 'public.st3'::regclass;
+ stavalues1
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ {1,2,3,4,5,6,7,8,9,10}
+ {"1 ","10 ","2 ","3 ","4 ","5 ","6 ","7 ","8 ","9 "}
+ {"{\"1 \",\"a \"}"}
+(3 rows)
+
+\copy (SELECT stavalues1::dbms_stats.anyarray FROM dbms_stats.column_stats_effective WHERE starelid = 'st3'::regclass) TO 'results/anyarray_test.cp' binary
+CREATE TABLE st4 (arr dbms_stats.anyarray);
+SELECT t.typname, n.nspname,
+ t.typlen, t.typbyval, t.typtype,
+ t.typcategory, t.typispreferred, t.typispreferred,
+ t.typdelim, t.typrelid, t.typmodin,
+ t.typmodout, t.typanalyze, t.typalign,
+ t.typstorage, t.typnotnull, t.typbasetype, t.typtypmod,
+ t.typndims, t.typcollation, t.typdefaultbin, t.typdefault
+ FROM pg_type t, pg_namespace n
+ WHERE t.typname = 'anyarray'
+ AND t.typnamespace = n.oid
+ ORDER BY t.typname;
+ typname | nspname | typlen | typbyval | typtype | typcategory | typispreferred | typispreferred | typdelim | typrelid | typmodin | typmodout | typanalyze | typalign | typstorage | typnotnull | typbasetype | typtypmod | typndims | typcollation | typdefaultbin | typdefault
+----------+------------+--------+----------+---------+-------------+----------------+----------------+----------+----------+----------+-----------+------------+----------+------------+------------+-------------+-----------+----------+--------------+---------------+------------
+ anyarray | pg_catalog | -1 | f | p | P | f | f | , | 0 | - | - | - | d | x | f | 0 | -1 | 0 | 0 | (null) | (null)
+ anyarray | dbms_stats | -1 | f | b | P | f | f | , | 0 | - | - | - | d | x | f | 0 | -1 | 0 | 0 | (null) | (null)
+(2 rows)
+
+-- No.4-1-1
+INSERT INTO st4 VALUES(NULL);
+SELECT * FROM st4;
+ arr
+--------
+ (null)
+(1 row)
+
+-- No.4-1-2
+DELETE FROM st4;
+SELECT stavalues1::dbms_stats.anyarray
+ FROM dbms_stats.column_stats_effective
+ WHERE starelid = 'st3'::regclass
+ AND staattnum = 1;
+ stavalues1
+------------------------
+ {1,2,3,4,5,6,7,8,9,10}
+(1 row)
+
+SELECT count(*) FROM st4;
+ count
+-------
+ 0
+(1 row)
+
+INSERT INTO st4
+ SELECT stavalues1::dbms_stats.anyarray
+ FROM dbms_stats.column_stats_effective
+ WHERE starelid = 'st3'::regclass
+ AND staattnum = 1;
+SELECT * FROM st4;
+ arr
+------------------------
+ {1,2,3,4,5,6,7,8,9,10}
+(1 row)
+
+-- No.4-1-3
+DELETE FROM st4;
+SELECT stavalues1::dbms_stats.anyarray
+ FROM dbms_stats.column_stats_effective
+ WHERE starelid = 'st3'::regclass
+ AND staattnum = 2;
+ stavalues1
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ {"1 ","10 ","2 ","3 ","4 ","5 ","6 ","7 ","8 ","9 "}
+(1 row)
+
+SELECT count(*) FROM st4;
+ count
+-------
+ 0
+(1 row)
+
+INSERT INTO st4
+ SELECT stavalues1::dbms_stats.anyarray
+ FROM dbms_stats.column_stats_effective
+ WHERE starelid = 'st3'::regclass
+ AND staattnum = 2;
+SELECT * FROM st4;
+ arr
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ {"1 ","10 ","2 ","3 ","4 ","5 ","6 ","7 ","8 ","9 "}
+(1 row)
+
+-- No.4-1-4
+DELETE FROM st4;
+SELECT stavalues1::dbms_stats.anyarray
+ FROM dbms_stats.column_stats_effective
+ WHERE starelid = 'st3'::regclass
+ AND staattnum = 1;
+ stavalues1
+------------------------
+ {1,2,3,4,5,6,7,8,9,10}
+(1 row)
+
+SELECT count(*) FROM st4;
+ count
+-------
+ 0
+(1 row)
+
+INSERT INTO st4
+ SELECT stavalues1::dbms_stats.anyarray
+ FROM dbms_stats.column_stats_effective
+ WHERE starelid = 'st3'::regclass
+ AND staattnum = 1;
+SELECT * FROM st4;
+ arr
+------------------------
+ {1,2,3,4,5,6,7,8,9,10}
+(1 row)
+
+-- No.4-1-5
+DELETE FROM st4;
+SELECT stavalues1::dbms_stats.anyarray
+ FROM dbms_stats.column_stats_effective
+ WHERE starelid = 'st3'::regclass
+ AND staattnum = 3;
+ stavalues1
+---------------------------
+ {"{\"1 \",\"a \"}"}
+(1 row)
+
+SELECT count(*) FROM st4;
+ count
+-------
+ 0
+(1 row)
+
+INSERT INTO st4
+ SELECT stavalues1::dbms_stats.anyarray
+ FROM dbms_stats.column_stats_effective
+ WHERE starelid = 'st3'::regclass
+ AND staattnum = 3;
+SELECT * FROM st4;
+ arr
+---------------------------
+ {"{\"1 \",\"a \"}"}
+(1 row)
+
+-- No.4-1-6
+DELETE FROM st4;
+SELECT stavalues1::dbms_stats.anyarray
+ FROM dbms_stats.column_stats_effective
+ WHERE starelid = 'st3'::regclass;
+ stavalues1
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ {1,2,3,4,5,6,7,8,9,10}
+ {"1 ","10 ","2 ","3 ","4 ","5 ","6 ","7 ","8 ","9 "}
+ {"{\"1 \",\"a \"}"}
+(3 rows)
+
+\copy st4(arr) FROM 'results/anyarray_test.cp' binary
+SELECT * FROM st4;
+ arr
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ {1,2,3,4,5,6,7,8,9,10}
+ {"1 ","10 ","2 ","3 ","4 ","5 ","6 ","7 ","8 ","9 "}
+ {"{\"1 \",\"a \"}"}
+(3 rows)
+
+-- clean up
+DROP TABLE st3;
+DROP TABLE st4;
+SELECT dbms_stats.unlock_database_stats();
+ unlock_database_stats
+-----------------------
+(0 rows)
+
+SELECT dbms_stats.lock_table_stats('st1');
+ lock_table_stats
+------------------
+ st1
+(1 row)
+
+/*
+ * No.5-2 dbms_stats.invalidate_column_cache
+ */
+-- No.5-2-1
+SELECT dbms_stats.invalidate_column_cache();
+ERROR: pg_dbms_stats: invalid trigger call
+-- No.5-2-2
+/*
+ * Driver function dbms_stats.invalidate_cache1
+ */
+CREATE TRIGGER invalidate_cache1
+ AFTER INSERT OR DELETE OR UPDATE
+ ON pt0
+ FOR EACH ROW EXECUTE PROCEDURE dbms_stats.invalidate_column_cache();
+INSERT INTO pt0 VALUES (1,'2012/12/12');
+ERROR: pg_dbms_stats: invalid trigger call
+DROP TRIGGER invalidate_cache1 ON pt0;
+-- No.5-2-3
+/*
+ * Driver function dbms_stats.invalidate_cache2
+ */
+CREATE TRIGGER invalidate_cache2
+BEFORE INSERT OR DELETE OR UPDATE
+ ON pt0
+ FOR EACH STATEMENT EXECUTE PROCEDURE dbms_stats.invalidate_column_cache();
+INSERT INTO pt0 VALUES (1,'2012/12/12');
+ERROR: pg_dbms_stats: invalid trigger call
+DROP TRIGGER invalidate_cache2 ON pt0;
+-- No.5-2-4
+/*
+ * Driver function dbms_stats.invalidate_cache3
+ */
+CREATE TRIGGER invalidate_cache3
+BEFORE TRUNCATE
+ ON pt0
+ FOR EACH STATEMENT EXECUTE PROCEDURE dbms_stats.invalidate_column_cache();
+TRUNCATE TABLE pt0;
+ERROR: pg_dbms_stats: invalid trigger call
+DROP TRIGGER invalidate_cache3 ON pt0;
+-- No.5-2-5
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+ QUERY PLAN
+---------------------------------
+ Index Scan using st1_idx on st1
+ Index Cond: (val IS NULL)
+(2 rows)
+
+INSERT INTO dbms_stats._relation_stats_locked (relid, relname) VALUES (0, 'dummy');
+INSERT INTO dbms_stats._column_stats_locked (starelid, staattnum, stainherit)
+ VALUES (0, 1, true);
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+ QUERY PLAN
+---------------------------------
+ Index Scan using st1_idx on st1
+ Index Cond: (val IS NULL)
+(2 rows)
+
+-- No.5-2-6
+INSERT INTO dbms_stats._column_stats_locked (starelid, staattnum, stainherit)
+ VALUES ('st1_idx'::regclass, 1, true);
+ERROR: "st1_idx" is an index except an index expression
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+ QUERY PLAN
+---------------------------------
+ Index Scan using st1_idx on st1
+ Index Cond: (val IS NULL)
+(2 rows)
+
+-- No.5-2-7
+INSERT INTO dbms_stats._column_stats_locked (starelid, staattnum, stainherit)
+ VALUES ('complex'::regclass, 1, true);
+ERROR: "complex" is a composite type
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+ QUERY PLAN
+---------------------------------
+ Index Scan using st1_idx on st1
+ Index Cond: (val IS NULL)
+(2 rows)
+
+-- No.5-2-9
+UPDATE dbms_stats._column_stats_locked SET stanullfrac = 1
+ WHERE starelid = 'st1'::regclass
+ AND staattnum = 1
+ AND stainherit = false;
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+ QUERY PLAN
+-------------------------
+ Seq Scan on st1
+ Filter: (val IS NULL)
+(2 rows)
+
+-- No.5-2-10
+DELETE FROM dbms_stats._column_stats_locked
+ WHERE starelid = 'st1'::regclass
+ AND staattnum = 1
+ AND stainherit = false;
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+ QUERY PLAN
+---------------------------------
+ Index Scan using st1_idx on st1
+ Index Cond: (val IS NULL)
+(2 rows)
+
+-- No.5-2-8
+INSERT INTO dbms_stats._column_stats_locked
+ (starelid, staattnum, stainherit, stanullfrac)
+ VALUES ('st1'::regclass, 1, false, 1);
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+ QUERY PLAN
+-------------------------
+ Seq Scan on st1
+ Filter: (val IS NULL)
+(2 rows)
+
+-- No.5-2-11
+PREPARE p2 AS SELECT str FROM st1 WHERE lower(str) IS NULL;
+EXPLAIN (costs false) SELECT str FROM st1 WHERE lower(str) IS NULL;
+ QUERY PLAN
+------------------------------------
+ Index Scan using st1_exp on st1
+ Index Cond: (lower(str) IS NULL)
+(2 rows)
+
+EXPLAIN (costs false) EXECUTE p2;
+ QUERY PLAN
+------------------------------------
+ Index Scan using st1_exp on st1
+ Index Cond: (lower(str) IS NULL)
+(2 rows)
+
+INSERT INTO dbms_stats._relation_stats_locked (relid, relname)
+ VALUES ('st1_exp'::regclass, 'dummy');
+INSERT INTO dbms_stats._column_stats_locked
+ (starelid, staattnum, stainherit, stanullfrac)
+ VALUES ('st1_exp'::regclass, 1, false, 1);
+EXPLAIN (costs false) SELECT str FROM st1 WHERE lower(str) IS NULL;
+ QUERY PLAN
+--------------------------------
+ Seq Scan on st1
+ Filter: (lower(str) IS NULL)
+(2 rows)
+
+EXPLAIN (costs false) EXECUTE p2;
+ QUERY PLAN
+--------------------------------
+ Seq Scan on st1
+ Filter: (lower(str) IS NULL)
+(2 rows)
+
+DEALLOCATE p2;
+SELECT dbms_stats.unlock_database_stats();
+ unlock_database_stats
+-----------------------
+ -
+ st1
+ st1_exp
+(3 rows)
+
+/*
+ * No.5-3 dbms_stats.invalidate_relation_cache
+ */
+-- No.5-3-1
+SELECT dbms_stats.invalidate_relation_cache();
+ERROR: pg_dbms_stats: invalid trigger call
+-- No.5-3-2
+/*
+ * Driver function dbms_stats.invalidate_cache1
+ */
+CREATE TRIGGER invalidate_cache1
+ AFTER INSERT OR DELETE OR UPDATE
+ ON pt0
+ FOR EACH ROW EXECUTE PROCEDURE dbms_stats.invalidate_relation_cache();
+INSERT INTO pt0 VALUES (1,'2012/12/12');
+ERROR: pg_dbms_stats: invalid trigger call
+DROP TRIGGER invalidate_cache1 ON pt0;
+-- No.5-3-3
+/*
+ * Driver function dbms_stats.invalidate_cache2
+ */
+CREATE TRIGGER invalidate_cache2
+BEFORE INSERT OR DELETE OR UPDATE
+ ON pt0
+ FOR EACH STATEMENT EXECUTE PROCEDURE dbms_stats.invalidate_relation_cache();
+INSERT INTO pt0 VALUES (1,'2012/12/12');
+ERROR: pg_dbms_stats: invalid trigger call
+DROP TRIGGER invalidate_cache2 ON pt0;
+-- No.5-3-4
+/*
+ * Driver function dbms_stats.invalidate_cache3
+ */
+CREATE TRIGGER invalidate_cache3
+BEFORE TRUNCATE
+ ON pt0
+ FOR EACH STATEMENT EXECUTE PROCEDURE dbms_stats.invalidate_relation_cache();
+TRUNCATE TABLE pt0;
+ERROR: pg_dbms_stats: invalid trigger call
+DROP TRIGGER invalidate_cache3 ON pt0;
+-- No.5-3-5
+SELECT dbms_stats.unlock_database_stats();
+ unlock_database_stats
+-----------------------
+(0 rows)
+
+SELECT dbms_stats.lock_table_stats('st1');
+ lock_table_stats
+------------------
+ st1
+(1 row)
+
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+ QUERY PLAN
+---------------------------------
+ Index Scan using st1_idx on st1
+ Index Cond: (val IS NULL)
+(2 rows)
+
+INSERT INTO dbms_stats._relation_stats_locked (relid, relname) VALUES (0, 'dummy');
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+ QUERY PLAN
+---------------------------------
+ Index Scan using st1_idx on st1
+ Index Cond: (val IS NULL)
+(2 rows)
+
+-- No.5-3-6
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+ QUERY PLAN
+---------------------------------
+ Index Scan using st1_idx on st1
+ Index Cond: (val IS NULL)
+(2 rows)
+
+INSERT INTO dbms_stats._relation_stats_locked (relid, relname)
+ VALUES ('st1_idx'::regclass, 'st1_idx');
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+ QUERY PLAN
+---------------------------------
+ Index Scan using st1_idx on st1
+ Index Cond: (val IS NULL)
+(2 rows)
+
+-- No.5-3-7
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+ QUERY PLAN
+---------------------------------
+ Index Scan using st1_idx on st1
+ Index Cond: (val IS NULL)
+(2 rows)
+
+INSERT INTO dbms_stats._relation_stats_locked (relid, relname)
+ VALUES ('complex'::regclass, 'complex');
+ERROR: "complex" is a composite type
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+ QUERY PLAN
+---------------------------------
+ Index Scan using st1_idx on st1
+ Index Cond: (val IS NULL)
+(2 rows)
+
+-- No.5-3-9
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+ QUERY PLAN
+---------------------------------
+ Index Scan using st1_idx on st1
+ Index Cond: (val IS NULL)
+(2 rows)
+
+UPDATE dbms_stats._relation_stats_locked SET curpages = 1
+ WHERE relid = 'st1'::regclass;
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+ QUERY PLAN
+-------------------------
+ Seq Scan on st1
+ Filter: (val IS NULL)
+(2 rows)
+
+-- No.5-3-10
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+ QUERY PLAN
+-------------------------
+ Seq Scan on st1
+ Filter: (val IS NULL)
+(2 rows)
+
+DELETE FROM dbms_stats._relation_stats_locked
+ WHERE relid = 'st1'::regclass;
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+ QUERY PLAN
+---------------------------------
+ Index Scan using st1_idx on st1
+ Index Cond: (val IS NULL)
+(2 rows)
+
+-- No.5-3-8
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+ QUERY PLAN
+---------------------------------
+ Index Scan using st1_idx on st1
+ Index Cond: (val IS NULL)
+(2 rows)
+
+INSERT INTO dbms_stats._relation_stats_locked (relid, relname, curpages)
+ VALUES ('st1'::regclass, 'st1', 1);
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+ QUERY PLAN
+-------------------------
+ Seq Scan on st1
+ Filter: (val IS NULL)
+(2 rows)
+
+-- No.5-3-11
+SELECT dbms_stats.unlock_database_stats();
+ unlock_database_stats
+-----------------------
+ -
+ st1
+ st1_idx
+(3 rows)
+
+SELECT dbms_stats.lock_table_stats('st1');
+ lock_table_stats
+------------------
+ st1
+(1 row)
+
+SELECT relname, curpages FROM dbms_stats.relation_stats_locked
+ WHERE relid = 'st1'::regclass;
+ relname | curpages
+------------+----------
+ public.st1 | 45
+(1 row)
+
+SELECT pg_sleep(0.5);
+ pg_sleep
+----------
+
+(1 row)
+
+SELECT pg_stat_reset();
+ pg_stat_reset
+---------------
+
+(1 row)
+
+UPDATE dbms_stats._relation_stats_locked SET curpages = 1000
+ WHERE relid = 'st1_exp'::regclass;
+SELECT pg_sleep(0.5);
+ pg_sleep
+----------
+
+(1 row)
+
+SELECT * FROM lockd_io;
+ relname | hbr | hbh | ibr | ibh
+------------------------+-----+-----+-----+-----
+ _relation_stats_locked | 0 | 0 | 0 | 1
+ _column_stats_locked | 0 | 0 | 0 | 0
+(2 rows)
+
+SELECT relname, curpages FROM dbms_stats.relation_stats_locked
+ WHERE relid = 'st1'::regclass;
+ relname | curpages
+------------+----------
+ public.st1 | 45
+(1 row)
+
+SELECT pg_sleep(0.5);
+ pg_sleep
+----------
+
+(1 row)
+
+SELECT * FROM lockd_io;
+ relname | hbr | hbh | ibr | ibh
+------------------------+-----+-----+-----+-----
+ _relation_stats_locked | 0 | 1 | 0 | 2
+ _column_stats_locked | 0 | 0 | 0 | 0
+(2 rows)
+
+/*
+ * No.5-4 StatsCacheRelCallback
+ */
+-- No.5-4-1
+UPDATE dbms_stats._relation_stats_locked SET curpages = 1
+ WHERE relid = 'st1'::regclass;
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+ QUERY PLAN
+-------------------------
+ Seq Scan on st1
+ Filter: (val IS NULL)
+(2 rows)
+
+\c
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+ QUERY PLAN
+---------------------------------
+ Index Scan using st1_idx on st1
+ Index Cond: (val IS NULL)
+(2 rows)
+
+LOAD 'pg_dbms_stats';
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+ QUERY PLAN
+-------------------------
+ Seq Scan on st1
+ Filter: (val IS NULL)
+(2 rows)
+
+SELECT dbms_stats.unlock_database_stats();
+ unlock_database_stats
+-----------------------
+ st1
+(1 row)
+
+SELECT dbms_stats.lock_table_stats('st1');
+ lock_table_stats
+------------------
+ st1
+(1 row)
+
+-- No.5-4-3
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+ QUERY PLAN
+---------------------------------
+ Index Scan using st1_idx on st1
+ Index Cond: (val IS NULL)
+(2 rows)
+
+\! psql contrib_regression -c "UPDATE dbms_stats._column_stats_locked SET stanullfrac = 1 WHERE starelid = 'st1'::regclass"
+UPDATE 2
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+ QUERY PLAN
+-------------------------
+ Seq Scan on st1
+ Filter: (val IS NULL)
+(2 rows)
+
+-- No.5-4-4
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+ QUERY PLAN
+-------------------------
+ Seq Scan on st1
+ Filter: (val IS NULL)
+(2 rows)
+
+\! psql contrib_regression -c "DELETE FROM dbms_stats._column_stats_locked WHERE starelid = 'st1'::regclass"
+DELETE 2
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+ QUERY PLAN
+---------------------------------
+ Index Scan using st1_idx on st1
+ Index Cond: (val IS NULL)
+(2 rows)
+
+-- No.5-4-2
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+ QUERY PLAN
+---------------------------------
+ Index Scan using st1_idx on st1
+ Index Cond: (val IS NULL)
+(2 rows)
+
+\! psql contrib_regression -c "INSERT INTO dbms_stats._column_stats_locked (starelid, staattnum, stainherit, stanullfrac) VALUES ('st1'::regclass, 1, false, 1)"
+INSERT 0 1
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+ QUERY PLAN
+-------------------------
+ Seq Scan on st1
+ Filter: (val IS NULL)
+(2 rows)
+
+SELECT dbms_stats.unlock_database_stats();
+ unlock_database_stats
+-----------------------
+ st1
+(1 row)
+
+-- No.5-4-5
+CREATE TABLE s0.droptest(id integer);
+INSERT INTO s0.droptest VALUES (1),(2),(3);
+VACUUM ANALYZE;
+SELECT * FROM s0.droptest
+ WHERE id = 1;
+ id
+----
+ 1
+(1 row)
+
+SELECT pg_sleep(0.5);
+ pg_sleep
+----------
+
+(1 row)
+
+SELECT pg_stat_reset();
+ pg_stat_reset
+---------------
+
+(1 row)
+
+ALTER TABLE s0.droptest RENAME TO test;
+SELECT pg_sleep(0.5);
+ pg_sleep
+----------
+
+(1 row)
+
+SELECT * FROM lockd_io;
+ relname | hbr | hbh | ibr | ibh
+------------------------+-----+-----+-----+-----
+ _relation_stats_locked | 0 | 0 | 0 | 0
+ _column_stats_locked | 0 | 0 | 0 | 0
+(2 rows)
+
+SELECT * FROM s0.test
+ WHERE id = 1;
+ id
+----
+ 1
+(1 row)
+
+SELECT pg_sleep(0.5);
+ pg_sleep
+----------
+
+(1 row)
+
+SELECT * FROM lockd_io;
+ relname | hbr | hbh | ibr | ibh
+------------------------+-----+-----+-----+-----
+ _relation_stats_locked | 0 | 0 | 0 | 1
+ _column_stats_locked | 0 | 0 | 0 | 1
+(2 rows)
+
+ALTER TABLE s0.test RENAME TO droptest;
+-- No.5-4-6
+SELECT * FROM s0.droptest
+ WHERE id = 1;
+ id
+----
+ 1
+(1 row)
+
+SELECT pg_sleep(0.5);
+ pg_sleep
+----------
+
+(1 row)
+
+SELECT pg_stat_reset();
+ pg_stat_reset
+---------------
+
+(1 row)
+
+ALTER TABLE s0.droptest RENAME id TO test;
+SELECT pg_sleep(0.5);
+ pg_sleep
+----------
+
+(1 row)
+
+SELECT * FROM lockd_io;
+ relname | hbr | hbh | ibr | ibh
+------------------------+-----+-----+-----+-----
+ _relation_stats_locked | 0 | 0 | 0 | 0
+ _column_stats_locked | 0 | 0 | 0 | 0
+(2 rows)
+
+SELECT * FROM s0.droptest
+ WHERE test = 1;
+ test
+------
+ 1
+(1 row)
+
+SELECT pg_sleep(0.5);
+ pg_sleep
+----------
+
+(1 row)
+
+SELECT * FROM lockd_io;
+ relname | hbr | hbh | ibr | ibh
+------------------------+-----+-----+-----+-----
+ _relation_stats_locked | 0 | 0 | 0 | 1
+ _column_stats_locked | 0 | 0 | 0 | 1
+(2 rows)
+
+ALTER TABLE s0.droptest RENAME test TO id;
+-- No.5-4-8
+INSERT INTO s0.droptest VALUES (4);
+SELECT * FROM s0.droptest
+ WHERE id = 1;
+ id
+----
+ 1
+(1 row)
+
+SELECT pg_sleep(0.5);
+ pg_sleep
+----------
+
+(1 row)
+
+SELECT pg_stat_reset();
+ pg_stat_reset
+---------------
+
+(1 row)
+
+ANALYZE;
+SELECT pg_sleep(0.5);
+ pg_sleep
+----------
+
+(1 row)
+
+SELECT * FROM lockd_io;
+ relname | hbr | hbh | ibr | ibh
+------------------------+-----+-----+-----+-----
+ _relation_stats_locked | 0 | 0 | 0 | 0
+ _column_stats_locked | 0 | 0 | 0 | 0
+(2 rows)
+
+SELECT * FROM s0.droptest
+ WHERE id = 1;
+ id
+----
+ 1
+(1 row)
+
+SELECT pg_sleep(1.0);
+ pg_sleep
+----------
+
+(1 row)
+
+SELECT * FROM lockd_io;
+ relname | hbr | hbh | ibr | ibh
+------------------------+-----+-----+-----+-----
+ _relation_stats_locked | 0 | 0 | 0 | 1
+ _column_stats_locked | 0 | 0 | 0 | 1
+(2 rows)
+
+-- No.5-4-9
+DELETE FROM s0.droptest;
+INSERT INTO s0.droptest VALUES (4),(5);
+SELECT * FROM s0.droptest
+ WHERE id = 4;
+ id
+----
+ 4
+(1 row)
+
+SELECT pg_sleep(0.5);
+ pg_sleep
+----------
+
+(1 row)
+
+SELECT pg_stat_reset();
+ pg_stat_reset
+---------------
+
+(1 row)
+
+VACUUM;
+SELECT pg_sleep(0.5);
+ pg_sleep
+----------
+
+(1 row)
+
+SELECT * FROM lockd_io;
+ relname | hbr | hbh | ibr | ibh
+------------------------+-----+-----+-----+-----
+ _relation_stats_locked | 0 | 2 | 0 | 1
+ _column_stats_locked | 0 | 2 | 0 | 1
+(2 rows)
+
+SELECT * FROM s0.droptest
+ WHERE id = 4;
+ id
+----
+ 4
+(1 row)
+
+SELECT pg_sleep(0.5);
+ pg_sleep
+----------
+
+(1 row)
+
+SELECT * FROM lockd_io;
+ relname | hbr | hbh | ibr | ibh
+------------------------+-----+-----+-----+-----
+ _relation_stats_locked | 0 | 2 | 0 | 2
+ _column_stats_locked | 0 | 2 | 0 | 2
+(2 rows)
+
+-- clean up
+DROP TABLE s0.droptest;
+/*
+ * No.6-1 dbms_stats.relname
+ */
+-- No.6-1-1
+SELECT dbms_stats.relname('aaa', 'bbb');
+ relname
+---------
+ aaa.bbb
+(1 row)
+
+-- No.6-1-2
+SELECT dbms_stats.relname(NULL, 'bbb');
+ relname
+---------
+ (null)
+(1 row)
+
+-- No.6-1-3
+SELECT dbms_stats.relname('aaa', NULL);
+ relname
+---------
+ (null)
+(1 row)
+
+-- No.6-1-4
+SELECT dbms_stats.relname(NULL, NULL);
+ relname
+---------
+ (null)
+(1 row)
+
+-- No.6-1-5
+SELECT dbms_stats.relname('', '');
+ relname
+---------
+ "".""
+(1 row)
+
+-- No.6-1-6
+SELECT dbms_stats.relname('aAa', 'bBb');
+ relname
+-------------
+ "aAa"."bBb"
+(1 row)
+
+-- No.6-1-7
+SELECT dbms_stats.relname('a a', 'b b');
+ relname
+-------------
+ "a a"."b b"
+(1 row)
+
+-- No.6-1-8
+SELECT dbms_stats.relname('a.a', 'b.b');
+ relname
+-------------
+ "a.a"."b.b"
+(1 row)
+
+-- No.6-1-9
+SELECT dbms_stats.relname(E'a\na', E'b\nb');
+ relname
+---------
+ "a +
+ a"."b +
+ b"
+(1 row)
+
+-- No.6-1-10
+SELECT dbms_stats.relname('a"a', 'b"b');
+ relname
+---------------
+ "a""a"."b""b"
+(1 row)
+
+-- No.6-1-11
+SELECT dbms_stats.relname('ããã', 'äºä¼å¯');
+ relname
+-------------------
+ "ããã"."äºä¼å¯"
+(1 row)
+
+/*
+ * No.6-2 dbms_stats.is_system_schema
+ */
+-- No.6-2-1
+SELECT dbms_stats.is_system_schema('pg_catalog');
+ is_system_schema
+------------------
+ t
+(1 row)
+
+-- No.6-2-2
+SELECT dbms_stats.is_system_schema('pg_toast');
+ is_system_schema
+------------------
+ t
+(1 row)
+
+-- No.6-2-3
+SELECT dbms_stats.is_system_schema('information_schema');
+ is_system_schema
+------------------
+ t
+(1 row)
+
+-- No.6-2-4
+SELECT dbms_stats.is_system_schema('dbms_stats');
+ is_system_schema
+------------------
+ t
+(1 row)
+
+-- No.6-2-5
+SELECT dbms_stats.is_system_schema(NULL);
+ is_system_schema
+------------------
+ (null)
+(1 row)
+
+-- No.6-2-6
+SELECT dbms_stats.is_system_schema('');
+ is_system_schema
+------------------
+ f
+(1 row)
+
+-- No.6-2-7
+SELECT dbms_stats.is_system_schema('s0');
+ is_system_schema
+------------------
+ f
+(1 row)
+
+-- No.6-2-8
+/*
+ * Driver function dbms_stats.is_system_schema1
+ */
+CREATE FUNCTION dbms_stats.is_system_schema1(schemaname text)
+ RETURNS integer AS
+ '$libdir/pg_dbms_stats', 'dbms_stats_is_system_schema'
+ LANGUAGE C IMMUTABLE STRICT;
+SELECT dbms_stats.is_system_schema1('s0');
+ is_system_schema1
+-------------------
+ 0
+(1 row)
+
+DROP FUNCTION dbms_stats.is_system_schema1(schemaname text);
+/*
+ * No.6-3 dbms_stats.is_system_catalog
+ */
+-- No.6-3-1
+SELECT dbms_stats.is_system_catalog('s0.st0');
+ is_system_catalog
+-------------------
+ f
+(1 row)
+
+-- No.6-3-2
+SELECT dbms_stats.is_system_catalog('st0');
+ is_system_catalog
+-------------------
+ f
+(1 row)
+
+-- No.6-3-3
+SELECT dbms_stats.is_system_catalog('s00.s0');
+ERROR: schema "s00" does not exist
+LINE 1: SELECT dbms_stats.is_system_catalog('s00.s0');
+ ^
+-- No.6-3-4
+SELECT dbms_stats.is_system_catalog(NULL);
+ is_system_catalog
+-------------------
+ t
+(1 row)
+
+-- No.6-3-5
+/*
+ * Driver function dbms_stats.is_system_catalog1
+ */
+CREATE FUNCTION dbms_stats.is_system_catalog1(relid regclass)
+RETURNS integer AS
+'$libdir/pg_dbms_stats', 'dbms_stats_is_system_catalog'
+LANGUAGE C STABLE;
+SELECT dbms_stats.is_system_catalog1('s0.st0');
+ is_system_catalog1
+--------------------
+ 0
+(1 row)
+
+DROP FUNCTION dbms_stats.is_system_catalog1(relid regclass);
+/*
+ * No.6-4 dbms_stats.is_target_relkind
+ */
+-- No.6-4-1
+SELECT dbms_stats.is_target_relkind('r');
+ is_target_relkind
+-------------------
+ t
+(1 row)
+
+-- No.6-4-2
+SELECT dbms_stats.is_target_relkind('i');
+ is_target_relkind
+-------------------
+ t
+(1 row)
+
+-- No.6-4-3
+SELECT dbms_stats.is_target_relkind('S');
+ is_target_relkind
+-------------------
+ f
+(1 row)
+
+-- No.6-4-4
+SELECT dbms_stats.is_target_relkind('v');
+ is_target_relkind
+-------------------
+ f
+(1 row)
+
+-- No.6-4-5
+SELECT dbms_stats.is_target_relkind('c');
+ is_target_relkind
+-------------------
+ f
+(1 row)
+
+-- No.6-4-6
+SELECT dbms_stats.is_target_relkind('t');
+ is_target_relkind
+-------------------
+ f
+(1 row)
+
+-- No.6-4-7
+SELECT dbms_stats.is_target_relkind('a');
+ is_target_relkind
+-------------------
+ f
+(1 row)
+
+-- No.6-4-8
+SELECT dbms_stats.is_target_relkind('');
+ is_target_relkind
+-------------------
+ f
+(1 row)
+
+-- No.6-4-9
+SELECT dbms_stats.is_target_relkind(NULL);
+ is_target_relkind
+-------------------
+ (null)
+(1 row)
+
+--#No.6-4-10 result varies according to a version
+/*
+ * No.7-1 dbms_stats.backup
+ */
+INSERT INTO dbms_stats.backup_history(id, time, unit) values(1, '2012-01-01', 'd');
+-- No.7-1-1
+DELETE FROM dbms_stats.relation_stats_backup;
+SELECT dbms_stats.backup(1, 's0.st0'::regclass, NULL);
+ backup
+--------
+ 1
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats.relation_stats_backup
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+--------
+ s0.st0
+(1 row)
+
+SELECT starelid::regclass, staattnum FROM dbms_stats.column_stats_backup
+ GROUP BY starelid, staattnum
+ ORDER BY starelid, staattnum;
+ starelid | staattnum
+----------+-----------
+ s0.st0 | 1
+ s0.st0 | 2
+(2 rows)
+
+-- No.7-1-2
+DELETE FROM dbms_stats.relation_stats_backup;
+SELECT dbms_stats.backup(1, 'st0'::regclass, NULL);
+ backup
+--------
+ 1
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats.relation_stats_backup
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+-------
+ st0
+(1 row)
+
+SELECT starelid::regclass, staattnum FROM dbms_stats.column_stats_backup
+ GROUP BY starelid, staattnum
+ ORDER BY starelid, staattnum;
+ starelid | staattnum
+----------+-----------
+ st0 | 1
+ st0 | 2
+(2 rows)
+
+-- No.7-1-3
+DELETE FROM dbms_stats.relation_stats_backup;
+SELECT dbms_stats.backup(1, 'public.notfound'::regclass, NULL);
+ERROR: relation "public.notfound" does not exist
+LINE 1: SELECT dbms_stats.backup(1, 'public.notfound'::regclass, NUL...
+ ^
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+ count
+-------
+ 0
+(1 row)
+
+-- No.7-1-4
+DELETE FROM dbms_stats.relation_stats_backup;
+SELECT dbms_stats.backup(1, 's0.st0'::regclass, NULL);
+ backup
+--------
+ 1
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats.relation_stats_backup
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+--------
+ s0.st0
+(1 row)
+
+SELECT starelid::regclass, staattnum FROM dbms_stats.column_stats_backup
+ GROUP BY starelid, staattnum
+ ORDER BY starelid, staattnum;
+ starelid | staattnum
+----------+-----------
+ s0.st0 | 1
+ s0.st0 | 2
+(2 rows)
+
+-- No.7-1-5
+DELETE FROM dbms_stats.relation_stats_backup;
+SELECT dbms_stats.backup(1, 'pg_toast.pg_toast_2618'::regclass, NULL);
+ backup
+--------
+ 1
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats.relation_stats_backup
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+-------
+(0 rows)
+
+SELECT starelid::regclass, staattnum FROM dbms_stats.column_stats_backup
+ GROUP BY starelid, staattnum
+ ORDER BY starelid, staattnum;
+ starelid | staattnum
+----------+-----------
+(0 rows)
+
+-- No.7-1-6
+DELETE FROM dbms_stats.relation_stats_backup;
+SELECT dbms_stats.backup(1, 's0.st0_idx'::regclass, NULL);
+ backup
+--------
+ 1
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats.relation_stats_backup
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+------------
+ s0.st0_idx
+(1 row)
+
+SELECT starelid::regclass, staattnum FROM dbms_stats.column_stats_backup
+ GROUP BY starelid, staattnum
+ ORDER BY starelid, staattnum;
+ starelid | staattnum
+----------+-----------
+(0 rows)
+
+-- No.7-1-7
+DELETE FROM dbms_stats.relation_stats_backup;
+SELECT dbms_stats.backup(1, 's0.ss0'::regclass, NULL);
+ backup
+--------
+ 1
+(1 row)
+
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+ count
+-------
+ 0
+(1 row)
+
+-- No.7-1-8
+DELETE FROM dbms_stats.relation_stats_backup;
+SELECT dbms_stats.backup(1, 's0.sc0'::regclass, NULL);
+ backup
+--------
+ 1
+(1 row)
+
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+ count
+-------
+ 0
+(1 row)
+
+--#No.7-1-9 ut-
+-- No.7-1-10
+DELETE FROM dbms_stats.relation_stats_backup;
+SELECT dbms_stats.backup(1, 's0.st0'::regclass, 1::int2);
+ backup
+--------
+ 1
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats.relation_stats_backup
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+--------
+ s0.st0
+(1 row)
+
+SELECT starelid::regclass, staattnum FROM dbms_stats.column_stats_backup
+ GROUP BY starelid, staattnum
+ ORDER BY starelid, staattnum;
+ starelid | staattnum
+----------+-----------
+ s0.st0 | 1
+(1 row)
+
+--#No.7-1-11 ut-
+-- No.7-1-12
+DELETE FROM dbms_stats.relation_stats_backup;
+SELECT dbms_stats.backup(1, 's0.st0'::regclass, NULL);
+ backup
+--------
+ 1
+(1 row)
+
+SELECT relid::regclass FROM dbms_stats.relation_stats_backup
+ GROUP BY relid
+ ORDER BY relid;
+ relid
+--------
+ s0.st0
+(1 row)
+
+SELECT starelid::regclass, staattnum FROM dbms_stats.column_stats_backup
+ GROUP BY starelid, staattnum
+ ORDER BY starelid, staattnum;
+ starelid | staattnum
+----------+-----------
+ s0.st0 | 1
+ s0.st0 | 2
+(2 rows)
+
+--#No.7-1-13 ut-
+-- No.7-1-14
+DELETE FROM dbms_stats.relation_stats_backup;
+SELECT dbms_stats.backup(1, 'pg_catalog.pg_class'::regclass, NULL);
+ backup
+--------
+ 1
+(1 row)
+
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+ count
+-------
+ 0
+(1 row)
+
+-- No.7-1-15
+SELECT dbms_stats.backup(1, 's0.st0'::regclass, NULL);
+ backup
+--------
+ 1
+(1 row)
+
+DELETE FROM dbms_stats.column_stats_backup;
+SELECT starelid::regclass, staattnum FROM dbms_stats.column_stats_backup
+ GROUP BY starelid, staattnum
+ ORDER BY starelid, staattnum;
+ starelid | staattnum
+----------+-----------
+(0 rows)
+
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+ count
+-------
+ 1
+(1 row)
+
+SET client_min_messages TO FATAL;
+SELECT dbms_stats.backup(1, 's0.st0'::regclass, NULL);
+RESET client_min_messages;
+\! tail ${PGDATA}/pg_log/postgresql.log > results/ut_no2_1_15.out
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+ count
+-------
+ 1
+(1 row)
+
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+ count
+-------
+ 0
+(1 row)
+
+--#No.7-1-17 ut-
+/*
+ * Stab function dbms_stats.backup
+ */
+ALTER FUNCTION dbms_stats.backup(
+ backup_id int8,
+ relid regclass,
+ attnum int2)
+ RENAME TO truth_func_backup;
+CREATE OR REPLACE FUNCTION dbms_stats.backup(
+ backup_id int8,
+ regclass,
+ attnum int2)
+RETURNS int8 AS
+$$
+BEGIN
+ RAISE NOTICE 'arguments are %, %, %', $1, $2, $3;
+ RETURN 1;
+END;
+$$
+LANGUAGE plpgsql;
+ALTER FUNCTION dbms_stats.backup(
+ relid regclass,
+ attname text,
+ comment text)
+ RENAME TO truth_func_backup;
+CREATE OR REPLACE FUNCTION dbms_stats.backup(
+ relid regclass DEFAULT NULL,
+ attname text DEFAULT NULL,
+ comment text DEFAULT NULL)
+RETURNS int8 AS
+$$
+BEGIN
+ IF $3 = '' THEN
+ RAISE NOTICE 'third argument is not NULL but string ""';
+ END IF;
+ RAISE NOTICE 'arguments are %, %, %', $1, $2, $3;
+ RETURN 1;
+END;
+$$
+LANGUAGE plpgsql;
+/*
+ * No.8-2 dbms_stats.backup_database_stats
+ */
+SELECT setval('dbms_stats.backup_history_id_seq',8);
+ setval
+--------
+ 8
+(1 row)
+
+-- No.8-2-1
+SELECT dbms_stats.backup_database_stats('comment');
+NOTICE: arguments are , , comment
+ backup_database_stats
+-----------------------
+ 1
+(1 row)
+
+/*
+ * No.8-4 dbms_stats.backup_table_stats(regclass,comment)
+ */
+-- No.8-4-1
+SELECT dbms_stats.backup_table_stats('s0.st0', 'comment');
+NOTICE: arguments are s0.st0, , comment
+ backup_table_stats
+--------------------
+ 1
+(1 row)
+
+-- No.8-4-2
+SELECT dbms_stats.backup_table_stats('st0', 'comment');
+NOTICE: arguments are st0, , comment
+ backup_table_stats
+--------------------
+ 1
+(1 row)
+
+-- No.8-4-3
+SELECT dbms_stats.backup_table_stats('s00.s0', 'comment');
+ERROR: schema "s00" does not exist
+LINE 1: SELECT dbms_stats.backup_table_stats('s00.s0', 'comment');
+ ^
+/*
+ * No.8-5 dbms_stats.backup_table_stats(schemaname, tablename, comment)
+ */
+-- No.8-5-1
+SELECT dbms_stats.backup_table_stats('s0', 'st0', 'comment');
+NOTICE: arguments are s0.st0, , comment
+ backup_table_stats
+--------------------
+ 1
+(1 row)
+
+-- No.8-5-2
+SELECT dbms_stats.backup_table_stats('s00', 's0', 'comment');
+ERROR: schema "s00" does not exist
+/*
+ * No.8-6 dbms_stats.backup_column_stats(regclass, attname, comment)
+ */
+-- No.8-6-1
+SELECT dbms_stats.backup_column_stats('s0.st0', 'id', 'comment');
+NOTICE: arguments are s0.st0, id, comment
+ backup_column_stats
+---------------------
+ 1
+(1 row)
+
+-- No.8-6-2
+SELECT dbms_stats.backup_column_stats('st0', 'id', 'comment');
+NOTICE: arguments are st0, id, comment
+ backup_column_stats
+---------------------
+ 1
+(1 row)
+
+-- No.8-6-3
+SELECT dbms_stats.backup_column_stats('s00.s0', 'id', 'comment');
+ERROR: schema "s00" does not exist
+LINE 1: SELECT dbms_stats.backup_column_stats('s00.s0', 'id', 'comme...
+ ^
+/*
+ * No.8-7 dbms_stats.backup_column_stats(schemaname, tablename, attname, comment)
+ */
+-- No.8-7-1
+SELECT dbms_stats.backup_column_stats('s0', 'st0', 'id', 'comment');
+NOTICE: arguments are s0.st0, id, comment
+ backup_column_stats
+---------------------
+ 1
+(1 row)
+
+-- No.8-7-2
+SELECT dbms_stats.backup_column_stats('s00', 's0', 'id', 'comment');
+ERROR: schema "s00" does not exist
+/*
+ * Delete stab function dbms_stats.backup
+ */
+DROP FUNCTION dbms_stats.backup(
+ backup_id int8,
+ regclass,
+ attnum int2);
+ALTER FUNCTION dbms_stats.truth_func_backup(
+ backup_id int8,
+ regclass,
+ attnum int2)
+ RENAME TO backup;
+DROP FUNCTION dbms_stats.backup(
+ regclass,
+ attname text,
+ comment text);
+ALTER FUNCTION dbms_stats.truth_func_backup(
+ regclass,
+ attname text,
+ comment text)
+ RENAME TO backup;
+VACUUM ANALYZE;
+/*
+ * create backup statistics state A
+ */
+DELETE FROM dbms_stats.backup_history;
+INSERT INTO dbms_stats.backup_history(id, time, unit)
+ VALUES (1, '2012-02-29 23:59:56.999999', 'd');
+SELECT setval('dbms_stats.backup_history_id_seq',1);
+ setval
+--------
+ 1
+(1 row)
+
+SELECT dbms_stats.backup();
+ backup
+--------
+ 2
+(1 row)
+
+UPDATE dbms_stats.backup_history
+ SET time = '2012-02-29 23:59:57'
+ WHERE id = 2;
+SELECT dbms_stats.backup('s0.st0');
+ backup
+--------
+ 3
+(1 row)
+
+UPDATE dbms_stats.backup_history
+ SET time = '2012-02-29 23:59:57.000001'
+ WHERE id = 3;
+SELECT dbms_stats.backup();
+ backup
+--------
+ 4
+(1 row)
+
+UPDATE dbms_stats.backup_history
+ SET time = '2012-02-29 23:59:58'
+ WHERE id = 4;
+DELETE FROM dbms_stats.relation_stats_backup
+ WHERE id = 4;
+SELECT dbms_stats.backup('s0.st0', 'id');
+ backup
+--------
+ 5
+(1 row)
+
+UPDATE dbms_stats.backup_history
+ SET time = '2012-03-01 00:00:00'
+ WHERE id = 5;
+SELECT dbms_stats.backup('s0.st0');
+ backup
+--------
+ 6
+(1 row)
+
+UPDATE dbms_stats.backup_history
+ SET time = '2012-03-01 00:00:02'
+ WHERE id = 6;
+SELECT dbms_stats.backup('public.st0');
+ backup
+--------
+ 7
+(1 row)
+
+UPDATE dbms_stats.backup_history
+ SET time = '2012-03-01 00:00:04'
+ WHERE id = 7;
+INSERT INTO dbms_stats.backup_history(time, unit)
+ VALUES ('2012-03-01 00:00:06', 's');
+SELECT dbms_stats.backup(8, c.oid, NULL)
+ FROM pg_catalog.pg_class c,
+ pg_catalog.pg_namespace n
+ WHERE n.nspname = 's0'
+ AND c.relnamespace = n.oid
+ AND c.relkind IN ('r', 'i');
+ backup
+--------
+ 8
+ 8
+ 8
+ 8
+ 8
+ 8
+(6 rows)
+
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+ id | time | unit | comment
+----+-------------------------------------+------+---------
+ 1 | Wed Feb 29 23:59:56.999999 2012 PST | d | (null)
+ 2 | Wed Feb 29 23:59:57 2012 PST | d | (null)
+ 3 | Wed Feb 29 23:59:57.000001 2012 PST | t | (null)
+ 4 | Wed Feb 29 23:59:58 2012 PST | d | (null)
+ 5 | Thu Mar 01 00:00:00 2012 PST | c | (null)
+ 6 | Thu Mar 01 00:00:02 2012 PST | t | (null)
+ 7 | Thu Mar 01 00:00:04 2012 PST | t | (null)
+ 8 | Thu Mar 01 00:00:06 2012 PST | s | (null)
+(8 rows)
+
+VACUUM ANALYZE;
+/*
+ * Stab function dbms_stats.restore
+ */
+ALTER FUNCTION dbms_stats.restore(int8, regclass, text)
+ RENAME TO truth_func_restore;
+CREATE FUNCTION dbms_stats.restore(int8, regclass DEFAULT NULL, text DEFAULT NULL)
+RETURNS SETOF regclass AS
+$$
+BEGIN
+ RAISE NOTICE 'arguments are "%, %, %"', $1, $2, $3;
+ RETURN QUERY
+ SELECT c.oid::regclass
+ FROM pg_class c, dbms_stats.relation_stats_backup b
+ WHERE (c.oid = $2 OR $2 IS NULL)
+ AND c.oid = b.relid
+ AND c.relkind IN ('r', 'i')
+ AND (b.id <= $1 OR $1 IS NOT NULL)
+ GROUP BY c.oid
+ ORDER BY c.oid::regclass::text;
+END;
+$$
+LANGUAGE plpgsql;
+/*
+ * No.10-3 dbms_stats.restore_table_stats(regclass, as_of_timestamp)
+ */
+-- No.10-3-1
+SELECT dbms_stats.restore_table_stats('s0.st0', '2012-02-29 23:59:57');
+NOTICE: arguments are "2, s0.st0, "
+CONTEXT: SQL function "restore_table_stats" statement 1
+ restore_table_stats
+---------------------
+ s0.st0
+(1 row)
+
+-- No.10-3-2
+SELECT dbms_stats.restore_table_stats('s0.st0', '2012-02-29 23:59:57.000002');
+NOTICE: arguments are "3, s0.st0, "
+CONTEXT: SQL function "restore_table_stats" statement 1
+ restore_table_stats
+---------------------
+ s0.st0
+(1 row)
+
+-- No.10-3-3
+SELECT dbms_stats.restore_table_stats('s0.st0', '2012-01-01 00:00:00');
+NOTICE: arguments are ", s0.st0, "
+CONTEXT: SQL function "restore_table_stats" statement 1
+ restore_table_stats
+---------------------
+(0 rows)
+
+--#No.10-3-4 is skipped after lock tests
+-- No.10-3-5
+SELECT dbms_stats.restore_table_stats('s0.st0', '2012-02-29 23:59:57');
+NOTICE: arguments are "2, s0.st0, "
+CONTEXT: SQL function "restore_table_stats" statement 1
+ restore_table_stats
+---------------------
+ s0.st0
+(1 row)
+
+-- No.10-3-6
+SELECT dbms_stats.restore_table_stats('st0', '2012-02-29 23:59:57');
+NOTICE: arguments are "2, st0, "
+CONTEXT: SQL function "restore_table_stats" statement 1
+ restore_table_stats
+---------------------
+ st0
+(1 row)
+
+-- No.10-3-7
+SELECT dbms_stats.restore_table_stats('s00.s0', '2012-02-29 23:59:57');
+ERROR: schema "s00" does not exist
+LINE 1: SELECT dbms_stats.restore_table_stats('s00.s0', '2012-02-29 ...
+ ^
+/*
+ * Stab dbms_stats.restore_table_stats(regclass, as_of_timestamp)
+ */
+CREATE OR REPLACE FUNCTION dbms_stats.restore_table_stats(
+ relid regclass,
+ as_of_timestamp timestamp with time zone)
+RETURNS SETOF regclass AS
+$$
+BEGIN
+ RAISE NOTICE 'arguments are %, %', $1, $2;
+ RETURN QUERY
+ SELECT $1;
+END
+$$
+LANGUAGE plpgsql;
+/*
+ * No.10-4 dbms_stats.restore_table_stats(schemaname, tablename, as_of_timestamp)
+ */
+-- No.10-4-1
+SELECT dbms_stats.restore_table_stats('s0', 'st0', '2012-02-29 23:59:57');
+NOTICE: arguments are s0.st0, Wed Feb 29 23:59:57 2012 PST
+CONTEXT: SQL function "restore_table_stats" statement 1
+ restore_table_stats
+---------------------
+ s0.st0
+(1 row)
+
+/*
+ * No.10-5 dbms_stats.restore_column_stats(regclass, attname, as_of_timestamp)
+ */
+-- No.10-5-1
+SELECT dbms_stats.restore_column_stats('s0.st0', 'id', '2012-02-29 23:59:57');
+NOTICE: arguments are "2, s0.st0, id"
+CONTEXT: SQL function "restore_column_stats" statement 1
+ restore_column_stats
+----------------------
+ s0.st0
+(1 row)
+
+-- No.10-5-2
+SELECT dbms_stats.restore_column_stats('s0.st0', 'id', '2012-02-29 23:59:57.000002');
+NOTICE: arguments are "3, s0.st0, id"
+CONTEXT: SQL function "restore_column_stats" statement 1
+ restore_column_stats
+----------------------
+ s0.st0
+(1 row)
+
+-- No.10-5-3
+SELECT dbms_stats.restore_column_stats('s0.st0', 'id', '2012-01-01 00:00:00');
+NOTICE: arguments are ", s0.st0, id"
+CONTEXT: SQL function "restore_column_stats" statement 1
+ restore_column_stats
+----------------------
+(0 rows)
+
+--#No.10-5-4 is skipped after lock tests
+-- No.10-5-5
+SELECT dbms_stats.restore_column_stats('s0.st0', 'id', '2012-02-29 23:59:57');
+NOTICE: arguments are "2, s0.st0, id"
+CONTEXT: SQL function "restore_column_stats" statement 1
+ restore_column_stats
+----------------------
+ s0.st0
+(1 row)
+
+-- No.10-5-6
+SELECT dbms_stats.restore_column_stats('st0', 'id', '2012-02-29 23:59:57');
+NOTICE: arguments are "2, st0, id"
+CONTEXT: SQL function "restore_column_stats" statement 1
+ restore_column_stats
+----------------------
+ st0
+(1 row)
+
+-- No.10-5-7
+SELECT dbms_stats.restore_column_stats('s00.s0', 'id', '2012-02-29 23:59:57');
+ERROR: schema "s00" does not exist
+LINE 1: SELECT dbms_stats.restore_column_stats('s00.s0', 'id', '2012...
+ ^
+/*
+ * No.10-6 dbms_stats.restore_column_stats(
+ * schemaname, tablename, attname, as_of_timestamp)
+ */
+-- No.10-6-1
+SELECT dbms_stats.restore_column_stats('s0', 'st0', 'id', '2012-02-29 23:59:57');
+NOTICE: arguments are "2, s0.st0, id"
+CONTEXT: SQL function "restore_column_stats" statement 1
+ restore_column_stats
+----------------------
+ s0.st0
+(1 row)
+
+/*
+ * No.15-1 dbms_stats.purge_stats
+ */
+-- No.15-1-1
+SELECT * FROM dbms_stats.backup_history;
+ id | time | unit | comment
+----+-------------------------------------+------+---------
+ 1 | Wed Feb 29 23:59:56.999999 2012 PST | d | (null)
+ 2 | Wed Feb 29 23:59:57 2012 PST | d | (null)
+ 3 | Wed Feb 29 23:59:57.000001 2012 PST | t | (null)
+ 4 | Wed Feb 29 23:59:58 2012 PST | d | (null)
+ 5 | Thu Mar 01 00:00:00 2012 PST | c | (null)
+ 6 | Thu Mar 01 00:00:02 2012 PST | t | (null)
+ 7 | Thu Mar 01 00:00:04 2012 PST | t | (null)
+ 8 | Thu Mar 01 00:00:06 2012 PST | s | (null)
+(8 rows)
+
+BEGIN;
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+ relation | mode
+----------+---------------
+ (null) | ExclusiveLock
+(1 row)
+
+SELECT id, unit, comment FROM dbms_stats.purge_stats(2);
+ id | unit | comment
+----+------+---------
+ 1 | d | (null)
+ 2 | d | (null)
+(2 rows)
+
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+ relation | mode
+---------------------------------------+--------------------------
+ dbms_stats.backup_history | RowExclusiveLock
+ dbms_stats.backup_history | ShareUpdateExclusiveLock
+ dbms_stats.backup_history_pkey | RowExclusiveLock
+ dbms_stats.column_stats_backup | RowExclusiveLock
+ dbms_stats.column_stats_backup | ShareUpdateExclusiveLock
+ dbms_stats.column_stats_backup_pkey | RowExclusiveLock
+ dbms_stats.relation_stats_backup | RowExclusiveLock
+ dbms_stats.relation_stats_backup | ShareUpdateExclusiveLock
+ dbms_stats.relation_stats_backup_pkey | RowExclusiveLock
+ (null) | ExclusiveLock
+ (null) | ExclusiveLock
+(11 rows)
+
+COMMIT;
+SELECT * FROM dbms_stats.backup_history;
+ id | time | unit | comment
+----+-------------------------------------+------+---------
+ 3 | Wed Feb 29 23:59:57.000001 2012 PST | t | (null)
+ 4 | Wed Feb 29 23:59:58 2012 PST | d | (null)
+ 5 | Thu Mar 01 00:00:00 2012 PST | c | (null)
+ 6 | Thu Mar 01 00:00:02 2012 PST | t | (null)
+ 7 | Thu Mar 01 00:00:04 2012 PST | t | (null)
+ 8 | Thu Mar 01 00:00:06 2012 PST | s | (null)
+(6 rows)
+
+-- No.15-1-6
+SELECT id, unit, comment FROM dbms_stats.purge_stats(NULL);
+ERROR: backup id is required
+-- No.15-1-7
+SELECT id, unit, comment FROM dbms_stats.purge_stats(-1);
+ERROR: backup id -1 does not exist
+-- No.15-1-8
+SELECT id, unit, comment FROM dbms_stats.purge_stats(2, NULL);
+ERROR: force is not null
+-- No.15-1-4
+SELECT * FROM dbms_stats.backup_history;
+ id | time | unit | comment
+----+-------------------------------------+------+---------
+ 3 | Wed Feb 29 23:59:57.000001 2012 PST | t | (null)
+ 4 | Wed Feb 29 23:59:58 2012 PST | d | (null)
+ 5 | Thu Mar 01 00:00:00 2012 PST | c | (null)
+ 6 | Thu Mar 01 00:00:02 2012 PST | t | (null)
+ 7 | Thu Mar 01 00:00:04 2012 PST | t | (null)
+ 8 | Thu Mar 01 00:00:06 2012 PST | s | (null)
+(6 rows)
+
+SELECT id, unit, comment FROM dbms_stats.purge_stats(3);
+ id | unit | comment
+----+------+---------
+ 3 | t | (null)
+(1 row)
+
+SELECT * FROM dbms_stats.backup_history;
+ id | time | unit | comment
+----+------------------------------+------+---------
+ 4 | Wed Feb 29 23:59:58 2012 PST | d | (null)
+ 5 | Thu Mar 01 00:00:00 2012 PST | c | (null)
+ 6 | Thu Mar 01 00:00:02 2012 PST | t | (null)
+ 7 | Thu Mar 01 00:00:04 2012 PST | t | (null)
+ 8 | Thu Mar 01 00:00:06 2012 PST | s | (null)
+(5 rows)
+
+-- No.15-1-5
+SELECT * FROM dbms_stats.backup_history;
+ id | time | unit | comment
+----+------------------------------+------+---------
+ 4 | Wed Feb 29 23:59:58 2012 PST | d | (null)
+ 5 | Thu Mar 01 00:00:00 2012 PST | c | (null)
+ 6 | Thu Mar 01 00:00:02 2012 PST | t | (null)
+ 7 | Thu Mar 01 00:00:04 2012 PST | t | (null)
+ 8 | Thu Mar 01 00:00:06 2012 PST | s | (null)
+(5 rows)
+
+SELECT id, unit, comment FROM dbms_stats.purge_stats(6);
+WARNING: at least one database-wise backup must be remain
+HINT: use true as 2nd parameter, if you want to purge forcibly
+ id | unit | comment
+----+------+---------
+(0 rows)
+
+SELECT * FROM dbms_stats.backup_history;
+ id | time | unit | comment
+----+------------------------------+------+---------
+ 4 | Wed Feb 29 23:59:58 2012 PST | d | (null)
+ 5 | Thu Mar 01 00:00:00 2012 PST | c | (null)
+ 6 | Thu Mar 01 00:00:02 2012 PST | t | (null)
+ 7 | Thu Mar 01 00:00:04 2012 PST | t | (null)
+ 8 | Thu Mar 01 00:00:06 2012 PST | s | (null)
+(5 rows)
+
+-- No.15-1-2
+SELECT * FROM dbms_stats.backup_history;
+ id | time | unit | comment
+----+------------------------------+------+---------
+ 4 | Wed Feb 29 23:59:58 2012 PST | d | (null)
+ 5 | Thu Mar 01 00:00:00 2012 PST | c | (null)
+ 6 | Thu Mar 01 00:00:02 2012 PST | t | (null)
+ 7 | Thu Mar 01 00:00:04 2012 PST | t | (null)
+ 8 | Thu Mar 01 00:00:06 2012 PST | s | (null)
+(5 rows)
+
+SELECT id, unit, comment FROM dbms_stats.purge_stats(8);
+WARNING: at least one database-wise backup must be remain
+HINT: use true as 2nd parameter, if you want to purge forcibly
+ id | unit | comment
+----+------+---------
+(0 rows)
+
+SELECT * FROM dbms_stats.backup_history;
+ id | time | unit | comment
+----+------------------------------+------+---------
+ 4 | Wed Feb 29 23:59:58 2012 PST | d | (null)
+ 5 | Thu Mar 01 00:00:00 2012 PST | c | (null)
+ 6 | Thu Mar 01 00:00:02 2012 PST | t | (null)
+ 7 | Thu Mar 01 00:00:04 2012 PST | t | (null)
+ 8 | Thu Mar 01 00:00:06 2012 PST | s | (null)
+(5 rows)
+
+-- No.15-1-3
+SELECT * FROM dbms_stats.backup_history;
+ id | time | unit | comment
+----+------------------------------+------+---------
+ 4 | Wed Feb 29 23:59:58 2012 PST | d | (null)
+ 5 | Thu Mar 01 00:00:00 2012 PST | c | (null)
+ 6 | Thu Mar 01 00:00:02 2012 PST | t | (null)
+ 7 | Thu Mar 01 00:00:04 2012 PST | t | (null)
+ 8 | Thu Mar 01 00:00:06 2012 PST | s | (null)
+(5 rows)
+
+SELECT id, unit, comment FROM dbms_stats.purge_stats(8, true);
+ id | unit | comment
+----+------+---------
+ 4 | d | (null)
+ 5 | c | (null)
+ 6 | t | (null)
+ 7 | t | (null)
+ 8 | s | (null)
+(5 rows)
+
+SELECT * FROM dbms_stats.backup_history;
+ id | time | unit | comment
+----+------+------+---------
+(0 rows)
+
+/*
+ * create backup statistics state A
+ */
+DELETE FROM dbms_stats.backup_history;
+INSERT INTO dbms_stats.backup_history(id, time, unit)
+ VALUES (1, '2012-02-29 23:59:56.999999', 'd');
+SELECT setval('dbms_stats.backup_history_id_seq',1);
+ setval
+--------
+ 1
+(1 row)
+
+SELECT dbms_stats.backup();
+ backup
+--------
+ 2
+(1 row)
+
+UPDATE dbms_stats.backup_history
+ SET time = '2012-02-29 23:59:57'
+ WHERE id = 2;
+SELECT dbms_stats.backup('s0.st0');
+ backup
+--------
+ 3
+(1 row)
+
+UPDATE dbms_stats.backup_history
+ SET time = '2012-02-29 23:59:57.000001'
+ WHERE id = 3;
+SELECT dbms_stats.backup();
+ backup
+--------
+ 4
+(1 row)
+
+UPDATE dbms_stats.backup_history
+ SET time = '2012-02-29 23:59:58'
+ WHERE id = 4;
+DELETE FROM dbms_stats.relation_stats_backup
+ WHERE id = 4;
+SELECT dbms_stats.backup('s0.st0', 'id');
+ backup
+--------
+ 5
+(1 row)
+
+UPDATE dbms_stats.backup_history
+ SET time = '2012-03-01 00:00:00'
+ WHERE id = 5;
+SELECT dbms_stats.backup('s0.st0');
+ backup
+--------
+ 6
+(1 row)
+
+UPDATE dbms_stats.backup_history
+ SET time = '2012-03-01 00:00:02'
+ WHERE id = 6;
+SELECT dbms_stats.backup('public.st0');
+ backup
+--------
+ 7
+(1 row)
+
+UPDATE dbms_stats.backup_history
+ SET time = '2012-03-01 00:00:04'
+ WHERE id = 7;
+INSERT INTO dbms_stats.backup_history(time, unit)
+ VALUES ('2012-03-01 00:00:06', 's');
+SELECT dbms_stats.backup(8, c.oid, NULL)
+ FROM pg_catalog.pg_class c,
+ pg_catalog.pg_namespace n
+ WHERE n.nspname = 's0'
+ AND c.relnamespace = n.oid
+ AND c.relkind IN ('r', 'i');
+ backup
+--------
+ 8
+ 8
+ 8
+ 8
+ 8
+ 8
+(6 rows)
+
+/*
+ * restore test when only backup data does not exist 's0' schema
+ */
+DELETE FROM dbms_stats.column_stats_backup;
+DELETE FROM dbms_stats.relation_stats_backup
+ WHERE relname LIKE 's0.%';
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+ count
+-------
+ 9
+(1 row)
+
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+ count
+-------
+ 0
+(1 row)
+
+-- No.10-2-8
+SELECT dbms_stats.restore_schema_stats('s0', '2012-03-01 00:00:04');
+ restore_schema_stats
+----------------------
+(0 rows)
+
+/*
+ * restore test when there are only backup hisotory
+ */
+DELETE FROM dbms_stats.relation_stats_backup;
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+ count
+-------
+ 0
+(1 row)
+
+-- No.10-1-5
+SELECT dbms_stats.restore_database_stats('2012-02-29 23:59:58');
+ restore_database_stats
+------------------------
+(0 rows)
+
+-- No.10-2-5
+SELECT dbms_stats.restore_schema_stats('s0', '2012-02-29 23:59:58');
+ restore_schema_stats
+----------------------
+(0 rows)
+
+/*
+ * restore when Backup does not exist
+ */
+DELETE FROM dbms_stats.backup_history;
+SELECT count(*) FROM dbms_stats.backup_history;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+ count
+-------
+ 0
+(1 row)
+
+-- No.10-1-4
+SELECT dbms_stats.restore_database_stats('2012-02-29 23:59:57');
+ restore_database_stats
+------------------------
+(0 rows)
+
+-- No.10-2-4
+SELECT dbms_stats.restore_schema_stats('s0', '2012-02-29 23:59:57');
+ restore_schema_stats
+----------------------
+(0 rows)
+
+-- No.10-3-4
+SELECT dbms_stats.restore_table_stats('s0.st0', '2012-02-29 23:59:57');
+NOTICE: arguments are s0.st0, Wed Feb 29 23:59:57 2012 PST
+ restore_table_stats
+---------------------
+ s0.st0
+(1 row)
+
+-- No.10-5-4
+SELECT dbms_stats.restore_column_stats('s0.st0', 'id', '2012-02-29 23:59:57');
+NOTICE: arguments are ", s0.st0, id"
+CONTEXT: SQL function "restore_column_stats" statement 1
+ restore_column_stats
+----------------------
+(0 rows)
+
+/*
+ * Delete stab function dbms_stats.restore
+ */
+DROP FUNCTION dbms_stats.restore(int8, regclass, text);
+ALTER FUNCTION dbms_stats.truth_func_restore(int8, regclass, text)
+ RENAME TO restore;
+/*
+ * No.18-1 dummy statistics view for general users privileges.
+ */
+\c - regular_user
+-- No.18-1-1
+SELECT count(*) FROM dbms_stats.relation_stats_locked WHERE false;
+ count
+-------
+ 0
+(1 row)
+
+-- No.18-1-2
+SELECT count(*) FROM dbms_stats.column_stats_locked WHERE false;
+ count
+-------
+ 0
+(1 row)
+
+-- No.18-1-3
+SELECT count(*) FROM dbms_stats.stats WHERE false;
+ count
+-------
+ 0
+(1 row)
+
+-- No.18-1-4
+SELECT count(*) FROM dbms_stats._relation_stats_locked WHERE false;
+ERROR: permission denied for relation _relation_stats_locked
+-- No.18-1-5
+SELECT count(*) FROM dbms_stats._columnns_user WHERE false;
+ERROR: relation "dbms_stats._columnns_user" does not exist
+LINE 1: SELECT count(*) FROM dbms_stats._columnns_user WHERE false;
+ ^
+\c - postgres
+LOAD 'pg_dbms_stats';
diff --git a/export_effective_stats-9.1.sql.sample b/export_effective_stats-9.1.sql.sample
new file mode 100644
index 0000000..b8e3f26
--- /dev/null
+++ b/export_effective_stats-9.1.sql.sample
@@ -0,0 +1,63 @@
+/*
+ * If you want the statistics of per-relation or per-column, please modify
+ * nspname, relname, and attname in 'WHERE' clause.
+ */
+
+BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+/*
+ * If you want to chage the output file name, please modify the following name.
+ */
+\o export_stats.dmp
+
+COPY (SELECT n2.nspname,
+ cl.relname,
+ r.relpages,
+ r.reltuples,
+ r.curpages,
+ r.last_analyze,
+ r.last_autoanalyze,
+ COALESCE(a.attname, ''),
+ n1.nspname AS schemaname_of_atttype,
+ t.typname,
+ a.atttypmod,
+ co.stainherit,
+ co.stanullfrac,
+ co.stawidth,
+ co.stadistinct,
+ co.stakind1,
+ co.stakind2,
+ co.stakind3,
+ co.stakind4,
+ co.staop1,
+ co.staop2,
+ co.staop3,
+ co.staop4,
+ co.stanumbers1,
+ co.stanumbers2,
+ co.stanumbers3,
+ co.stanumbers4,
+ co.stavalues1,
+ co.stavalues2,
+ co.stavalues3,
+ co.stavalues4
+ FROM dbms_stats.column_stats_effective co
+ JOIN pg_attribute a
+ ON (co.starelid = a.attrelid AND co.staattnum = a.attnum)
+ JOIN pg_type t
+ ON a.atttypid = t.oid
+ JOIN pg_namespace n1
+ ON t.typnamespace = n1.oid
+ RIGHT JOIN dbms_stats.relation_stats_effective r
+ ON co.starelid = r.relid
+ JOIN pg_catalog.pg_class cl
+ ON r.relid = cl.oid
+ JOIN pg_catalog.pg_namespace n2
+ ON cl.relnamespace = n2.oid
+ -- WHERE n2.nspname = 'public'
+ -- AND cl.relname = 'test'
+ -- AND a.attname = 'id'
+ ORDER BY starelid, staattnum)
+TO STDOUT
+(FORMAT 'binary');
+\o
+COMMIT;
diff --git a/export_effective_stats-9.2.sql.sample b/export_effective_stats-9.2.sql.sample
new file mode 100644
index 0000000..672a7e6
--- /dev/null
+++ b/export_effective_stats-9.2.sql.sample
@@ -0,0 +1,68 @@
+/*
+ * If you want the statistics of per-relation or per-column, please modify
+ * nspname, relname, and attname in 'WHERE' clause.
+ */
+
+BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+/*
+ * If you want to chage the output file name, please modify the following name.
+ */
+\o export_stats.dmp
+
+COPY (SELECT n2.nspname,
+ cl.relname,
+ r.relpages,
+ r.reltuples,
+ r.relallvisible,
+ r.curpages,
+ r.last_analyze,
+ r.last_autoanalyze,
+ COALESCE(a.attname, ''),
+ n1.nspname AS schemaname_of_atttype,
+ t.typname,
+ a.atttypmod,
+ co.stainherit,
+ co.stanullfrac,
+ co.stawidth,
+ co.stadistinct,
+ co.stakind1,
+ co.stakind2,
+ co.stakind3,
+ co.stakind4,
+ co.stakind5,
+ co.staop1,
+ co.staop2,
+ co.staop3,
+ co.staop4,
+ co.staop5,
+ co.stanumbers1,
+ co.stanumbers2,
+ co.stanumbers3,
+ co.stanumbers4,
+ co.stanumbers5,
+ co.stavalues1,
+ co.stavalues2,
+ co.stavalues3,
+ co.stavalues4,
+ co.stavalues5
+ FROM dbms_stats.column_stats_effective co
+ JOIN pg_attribute a
+ ON (co.starelid = a.attrelid AND co.staattnum = a.attnum)
+ JOIN pg_type t
+ ON a.atttypid = t.oid
+ JOIN pg_namespace n1
+ ON t.typnamespace = n1.oid
+ RIGHT JOIN dbms_stats.relation_stats_effective r
+ ON co.starelid = r.relid
+ JOIN pg_catalog.pg_class cl
+ ON r.relid = cl.oid
+ JOIN pg_catalog.pg_namespace n2
+ ON cl.relnamespace = n2.oid
+ -- WHERE n2.nspname = 'public'
+ -- AND cl.relname = 'test'
+ -- AND a.attname = 'id'
+ ORDER BY starelid, staattnum)
+TO STDOUT
+(FORMAT 'binary');
+\o
+COMMIT;
diff --git a/export_plain_stats-9.1.sql.sample b/export_plain_stats-9.1.sql.sample
new file mode 100644
index 0000000..65517c3
--- /dev/null
+++ b/export_plain_stats-9.1.sql.sample
@@ -0,0 +1,69 @@
+/*
+ * If you want the statistics of per-relation or per-column, please modify
+ * nspname, relname, and attname in 'WHERE' clause.
+ */
+
+BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+/*
+ * If you want to chage the output file name, please modify the following name.
+ */
+\o export_stats.dmp
+
+COPY (SELECT n2.nspname,
+ c.relname,
+ c.relpages,
+ c.reltuples,
+ (pg_relation_size(c.oid) / current_setting('block_size')::int4)::int4
+ AS curpages,
+ pg_catalog.pg_stat_get_last_analyze_time(c.oid)
+ AS last_analyze,
+ pg_catalog.pg_stat_get_last_autoanalyze_time(c.oid)
+ AS last_autoanalyze,
+ COALESCE(a.attname, ''),
+ n1.nspname AS schemaname_of_atttype,
+ t.typname,
+ a.atttypmod,
+ s.stainherit,
+ s.stanullfrac,
+ s.stawidth,
+ s.stadistinct,
+ s.stakind1,
+ s.stakind2,
+ s.stakind3,
+ s.stakind4,
+ s.staop1,
+ s.staop2,
+ s.staop3,
+ s.staop4,
+ s.stanumbers1,
+ s.stanumbers2,
+ s.stanumbers3,
+ s.stanumbers4,
+ s.stavalues1,
+ s.stavalues2,
+ s.stavalues3,
+ s.stavalues4
+ FROM pg_statistic s
+ JOIN pg_attribute a
+ ON (s.starelid = a.attrelid AND s.staattnum = a.attnum)
+ JOIN pg_type t
+ ON a.atttypid = t.oid
+ JOIN pg_namespace n1
+ ON t.typnamespace = n1.oid
+ RIGHT JOIN pg_catalog.pg_class c
+ ON s.starelid = c.oid
+ JOIN pg_catalog.pg_namespace n2
+ ON c.relnamespace = n2.oid
+ WHERE c.relkind IN ('r', 'i')
+ AND NOT n2.nspname IN ('pg_catalog',
+ 'pg_toast',
+ 'information_schema',
+ 'dbms_stats')
+ -- AND n2.nspname = 'public'
+ -- AND c.relname = 'test'
+ -- AND a.attname = 'id'
+ ORDER BY starelid, staattnum)
+TO STDOUT
+(FORMAT 'binary');
+\o
+COMMIT;
diff --git a/export_plain_stats-9.2.sql.sample b/export_plain_stats-9.2.sql.sample
new file mode 100644
index 0000000..8dafbab
--- /dev/null
+++ b/export_plain_stats-9.2.sql.sample
@@ -0,0 +1,74 @@
+/*
+ * If you want the statistics of per-relation or per-column, please modify
+ * nspname, relname, and attname in 'WHERE' clause.
+ */
+
+BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+/*
+ * If you want to chage the output file name, please modify the following name.
+ */
+\o export_stats.dmp
+
+COPY (SELECT n2.nspname,
+ c.relname,
+ c.relpages,
+ c.reltuples,
+ c.relallvisible,
+ (pg_relation_size(c.oid) / current_setting('block_size')::int4)::int4
+ AS curpages,
+ pg_catalog.pg_stat_get_last_analyze_time(c.oid)
+ AS last_analyze,
+ pg_catalog.pg_stat_get_last_autoanalyze_time(c.oid)
+ AS last_autoanalyze,
+ COALESCE(a.attname, ''),
+ n1.nspname AS schemaname_of_atttype,
+ t.typname,
+ a.atttypmod,
+ s.stainherit,
+ s.stanullfrac,
+ s.stawidth,
+ s.stadistinct,
+ s.stakind1,
+ s.stakind2,
+ s.stakind3,
+ s.stakind4,
+ s.stakind5,
+ s.staop1,
+ s.staop2,
+ s.staop3,
+ s.staop4,
+ s.staop5,
+ s.stanumbers1,
+ s.stanumbers2,
+ s.stanumbers3,
+ s.stanumbers4,
+ s.stanumbers5,
+ s.stavalues1,
+ s.stavalues2,
+ s.stavalues3,
+ s.stavalues4,
+ s.stavalues5
+ FROM pg_statistic s
+ JOIN pg_attribute a
+ ON (s.starelid = a.attrelid AND s.staattnum = a.attnum)
+ JOIN pg_type t
+ ON a.atttypid = t.oid
+ JOIN pg_namespace n1
+ ON t.typnamespace = n1.oid
+ RIGHT JOIN pg_catalog.pg_class c
+ ON s.starelid = c.oid
+ JOIN pg_catalog.pg_namespace n2
+ ON c.relnamespace = n2.oid
+ WHERE c.relkind IN ('r', 'i', 'f')
+ AND NOT n2.nspname IN ('pg_catalog',
+ 'pg_toast',
+ 'information_schema',
+ 'dbms_stats')
+ -- AND n2.nspname = 'public'
+ -- AND c.relname = 'test'
+ -- AND a.attname = 'id'
+ ORDER BY starelid, staattnum)
+TO STDOUT
+(FORMAT 'binary');
+\o
+COMMIT;
diff --git a/import.c b/import.c
new file mode 100644
index 0000000..ae8c76c
--- /dev/null
+++ b/import.c
@@ -0,0 +1,1020 @@
+/*
+ * import.c
+ *
+ * Copyright (c) 2012, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
+ */
+#include "postgres.h"
+
+#include "access/xact.h"
+#include "catalog/namespace.h"
+#include "catalog/pg_type.h"
+#include "commands/copy.h"
+#include "executor/spi.h"
+#include "libpq/pqformat.h"
+#include "mb/pg_wchar.h"
+#include "tcop/tcopprot.h"
+#include "utils/builtins.h"
+#include "utils/lsyscache.h"
+#include "utils/syscache.h"
+#if PG_VERSION_NUM >= 90200
+#include "catalog/pg_class.h"
+#endif
+
+#include "pg_dbms_stats.h"
+
+#if PG_VERSION_NUM >= 90200
+#define RELATION_PARAM_NUM 9
+#else
+#define RELATION_PARAM_NUM 8
+#endif
+
+extern PGDLLIMPORT bool standard_conforming_strings;
+
+PG_FUNCTION_INFO_V1(dbms_stats_import);
+
+Datum dbms_stats_import(PG_FUNCTION_ARGS);
+
+static void get_args(FunctionCallInfo fcinfo, char **nspname, char **relname,
+ char **attname, char **filename);
+static void spi_exec_utility(const char *query);
+static void spi_exec_query(const char *query, int nargs, Oid *argtypes,
+ SPIPlanPtr *plan, Datum *values, const char *nulls, int result);
+static void import_stats_from_file(char *filename, char *nspname, char *relname,
+ char *attname);
+
+/*
+ * dbms_stats_import
+ * Import exported statistics from stdin or a file.
+ *
+ * Order of arguments:
+ * 1) schema name
+ * 2) relation oid
+ * 3) attribute name
+ * 4) absolute path of source file, or 'stdin' (case insensitive)
+ */
+Datum
+dbms_stats_import(PG_FUNCTION_ARGS)
+{
+ char *nspname;
+ char *relname;
+ char *attname;
+ char *filename; /* filename, or NULL for STDIN */
+ int ret;
+ int i;
+ uint32 r_num;
+ HeapTuple *r_tups;
+ TupleDesc r_tupdesc;
+ SPIPlanPtr r_upd_plan = NULL;
+ SPIPlanPtr r_ins_plan = NULL;
+ SPIPlanPtr c_sel_plan = NULL;
+ SPIPlanPtr c_del_plan = NULL;
+ SPIPlanPtr c_ins_plan = NULL;
+
+ /* get validated arguments */
+ get_args(fcinfo, &nspname, &relname, &attname, &filename);
+
+ /* for debug use */
+ elog(DEBUG3, "%s() f=%s n=%s r=%s a=%s", __FUNCTION__,
+ filename ? filename : "(null)",
+ nspname ? nspname : "(null)",
+ relname ? relname : "(null)",
+ attname ? attname : "(null)");
+
+ /* connect to SPI */
+ ret = SPI_connect();
+ if (ret != SPI_OK_CONNECT)
+ elog(ERROR, "pg_dbms_stats: SPI_connect => %d", ret);
+
+ /* lock dummy statistics tables. */
+ spi_exec_utility("LOCK dbms_stats._relation_stats_locked"
+ " IN SHARE UPDATE EXCLUSIVE MODE");
+ spi_exec_utility("LOCK dbms_stats._column_stats_locked"
+ " IN SHARE UPDATE EXCLUSIVE MODE");
+
+ /*
+ * Create a temp table to save the statistics to import.
+ * This table should fit with the content of export files.
+ */
+ spi_exec_utility("CREATE TEMP TABLE dbms_stats_work_stats ("
+ "nspname name NOT NULL,"
+ "relname name NOT NULL,"
+ "relpages int4 NOT NULL,"
+ "reltuples float4 NOT NULL,"
+#if PG_VERSION_NUM >= 90200
+ "relallvisible int4 NOT NULL,"
+#endif
+ "curpages int4 NOT NULL,"
+ "last_analyze timestamp with time zone,"
+ "last_autoanalyze timestamp with time zone,"
+ "attname name,"
+ "nspname_of_typename name,"
+ "typname name,"
+ "atttypmod int4,"
+ "stainherit bool,"
+ "stanullfrac float4,"
+ "stawidth int4,"
+ "stadistinct float4,"
+ "stakind1 int2,"
+ "stakind2 int2,"
+ "stakind3 int2,"
+ "stakind4 int2,"
+#if PG_VERSION_NUM >= 90200
+ "stakind5 int2,"
+#endif
+ "staop1 oid,"
+ "staop2 oid,"
+ "staop3 oid,"
+ "staop4 oid,"
+#if PG_VERSION_NUM >= 90200
+ "staop5 oid,"
+#endif
+ "stanumbers1 float4[],"
+ "stanumbers2 float4[],"
+ "stanumbers3 float4[],"
+ "stanumbers4 float4[],"
+#if PG_VERSION_NUM >= 90200
+ "stanumbers5 float4[],"
+#endif
+ "stavalues1 dbms_stats.anyarray,"
+ "stavalues2 dbms_stats.anyarray,"
+ "stavalues3 dbms_stats.anyarray,"
+ "stavalues4 dbms_stats.anyarray"
+#if PG_VERSION_NUM >= 90200
+ ",stavalues5 dbms_stats.anyarray"
+#endif
+ ")");
+
+ /* load the statistics from export file to the temp table */
+ import_stats_from_file(filename, nspname, relname, attname);
+
+ /* Determine the Oid of local table from the tablename and schemaname. */
+ /* TODO å¯è¦ãã¼ã¸æ°ã«å¯¾å¿ãã */
+ ret = SPI_execute("SELECT DISTINCT w.nspname, w.relname, c.oid, "
+ "w.relpages, w.reltuples, "
+ "w.curpages, w.last_analyze, w.last_autoanalyze "
+#if PG_VERSION_NUM >= 90200
+ ",w.relallvisible "
+#endif
+ "FROM pg_catalog.pg_class c "
+ "JOIN pg_catalog.pg_namespace n "
+ "ON (c.relnamespace = n.oid) "
+ "RIGHT JOIN dbms_stats_work_stats w "
+ "ON (w.relname = c.relname AND w.nspname = n.nspname) "
+ "ORDER BY 1, 2", false, 0);
+ if (ret != SPI_OK_SELECT)
+ elog(ERROR, "pg_dbms_stats: SPI_execute => %d", ret);
+
+ /*
+ * If there is no record in the staging table after loading source and
+ * deleting unnecessary records, we treat it as an error.
+ */
+ if (SPI_processed == 0)
+ elog(ERROR, "no per-table statistic data to be imported");
+
+ /* */
+ r_num = SPI_processed;
+ r_tups = SPI_tuptable->vals;
+ r_tupdesc = SPI_tuptable->tupdesc;
+ for (i = 0; i < r_num; i++)
+ {
+ bool isnull;
+ Datum w_nspname;
+ Datum w_relname;
+ Datum w_relid;
+ Datum values[9];
+ char nulls[9] = {'t', 't', 't', 't', 't', 't', 't', 't', 't'};
+ Oid r_types[9] = {NAMEOID, NAMEOID, INT4OID, FLOAT4OID, INT4OID,
+ TIMESTAMPTZOID, TIMESTAMPTZOID, OIDOID, INT4OID};
+ Oid c_types[5] = {OIDOID, INT2OID, NAMEOID, NAMEOID,
+ NAMEOID};
+ uint32 c_num;
+ TupleDesc c_tupdesc;
+ HeapTuple *c_tups;
+ int j;
+
+ values[0] = w_nspname = SPI_getbinval(r_tups[i], r_tupdesc, 1, &isnull);
+ values[1] = w_relname = SPI_getbinval(r_tups[i], r_tupdesc, 2, &isnull);
+ values[7] = w_relid = SPI_getbinval(r_tups[i], r_tupdesc, 3, &isnull);
+ if (isnull)
+ {
+ elog(WARNING, "relation \"%s.%s\" does not exist",
+ DatumGetName(w_nspname)->data,
+ DatumGetName(w_relname)->data);
+ continue;
+ }
+
+ values[2] = SPI_getbinval(r_tups[i], r_tupdesc, 4, &isnull);
+ values[3] = SPI_getbinval(r_tups[i], r_tupdesc, 5, &isnull);
+ values[4] = SPI_getbinval(r_tups[i], r_tupdesc, 6, &isnull);
+ values[5] = SPI_getbinval(r_tups[i], r_tupdesc, 7, &isnull);
+ nulls[5] = isnull ? 'n' : 't';
+ values[6] = SPI_getbinval(r_tups[i], r_tupdesc, 8, &isnull);
+ nulls[6] = isnull ? 'n' : 't';
+ values[8] = SPI_getbinval(r_tups[i], r_tupdesc, 9, &isnull);
+
+ /*
+ * First we try UPDATE with the oid. When no record matched, try
+ * INSERT. We can't use DELETE-then-INSERT method because we have FK
+ * on _relation_stats_locked so DELETE would delete child records in
+ * _column_stats_locked undesirably.
+ */
+ spi_exec_query("UPDATE dbms_stats._relation_stats_locked SET "
+ "relname = quote_ident($1) || '.' || quote_ident($2), "
+ "relpages = $3, reltuples = $4, "
+#if PG_VERSION_NUM >= 90200
+ "relallvisible = $9, "
+#endif
+ "curpages = $5, last_analyze = $6, last_autoanalyze = $7 "
+ "WHERE relid = $8",
+ RELATION_PARAM_NUM, r_types, &r_upd_plan, values, nulls,
+ SPI_OK_UPDATE);
+ if (SPI_processed == 0)
+ {
+ spi_exec_query("INSERT INTO dbms_stats._relation_stats_locked "
+ "(relname, relpages, reltuples, curpages, "
+ "last_analyze, last_autoanalyze, relid"
+#if PG_VERSION_NUM >= 90200
+ ", relallvisible"
+#endif
+ ") VALUES (quote_ident($1) || '.' || quote_ident($2), "
+ "$3, $4, $5, $6, $7, $8"
+#if PG_VERSION_NUM >= 90200
+ ", $9"
+#endif
+ ")",
+ RELATION_PARAM_NUM, r_types, &r_ins_plan, values, nulls,
+ SPI_OK_INSERT);
+ /* If we failed to insert, we can't proceed. */
+ if (SPI_processed != 1)
+ elog(ERROR, "failed to insert import data");
+ }
+
+ elog(DEBUG2, "\"%s.%s\" relation statistic import",
+ DatumGetName(w_nspname)->data, DatumGetName(w_relname)->data);
+
+ /*
+ * Determine the attnum of the attribute with given name, and load
+ * statistics from temp table into dbms._column_stats_locked.
+ */
+ spi_exec_query("SELECT w.stainherit, w.attname, a.attnum, "
+ "w.nspname_of_typename, tn.nspname, "
+ "w.typname, t.typname, w.atttypmod, a.atttypmod "
+ "FROM pg_catalog.pg_class c "
+ "JOIN pg_catalog.pg_namespace cn "
+ "ON (cn.oid = c.relnamespace) "
+ "JOIN pg_catalog.pg_attribute a "
+ "ON (a.attrelid = c.oid) "
+ "JOIN pg_catalog.pg_type t "
+ "ON (t.oid = a.atttypid) "
+ "JOIN pg_catalog.pg_namespace tn "
+ "ON (tn.oid = t.typnamespace) "
+ "RIGHT JOIN dbms_stats_work_stats w "
+ "ON (w.nspname = cn.nspname AND w.relname = c.relname "
+ "AND (w.attname = a.attname OR w.attname = '')) "
+ "WHERE w.nspname = $1 AND w.relname = $2 "
+ "AND a.attnum > 0"
+ "ORDER BY 1, 3, 2",
+ 2, r_types, &c_sel_plan, values, NULL, SPI_OK_SELECT);
+
+ /* This query ought to return at least one record. */
+ if (SPI_processed == 0)
+ elog(ERROR, "no per-column statistic data to be imported");
+
+ values[0] = w_relid;
+ values[2] = w_nspname;
+ values[3] = w_relname;
+
+ c_num = SPI_processed;
+ c_tups = SPI_tuptable->vals;
+ c_tupdesc = SPI_tuptable->tupdesc;
+ for (j = 0; j < c_num; j++)
+ {
+ char *w_typnamespace;
+ char *a_typnamespace;
+ char *w_typname;
+ char *a_typname;
+ int w_typmod;
+ int a_typmod;
+
+ /*
+ * If we have only per-relation statistics in source, all of
+ * column_stats_effective for per-column statistics are NULL.
+ */
+ (void) SPI_getbinval(c_tups[j], c_tupdesc, 1, &isnull);
+ if (isnull)
+ continue;
+
+ /*
+ * If there is no column with given name, we skip the rest of
+ * import process.
+ */
+ values[4] = SPI_getbinval(c_tups[j], c_tupdesc, 2, &isnull);
+ values[1] = SPI_getbinval(c_tups[j], c_tupdesc, 3, &isnull);
+ if (isnull)
+ {
+ elog(WARNING, "column \"%s\" of \"%s.%s\" does not exist",
+ DatumGetName(values[4])->data,
+ DatumGetName(w_nspname)->data,
+ DatumGetName(w_relname)->data);
+ continue;
+ }
+
+ /*
+ * If the destination column has different data type from source
+ * column, we stop importing to avoid corrupted statistics.
+ */
+ w_typnamespace = DatumGetName(SPI_getbinval(c_tups[j], c_tupdesc, 4,
+ &isnull))->data;
+ a_typnamespace = DatumGetName(SPI_getbinval(c_tups[j], c_tupdesc, 5,
+ &isnull))->data;
+ w_typname = DatumGetName(SPI_getbinval(c_tups[j], c_tupdesc, 6,
+ &isnull))->data;
+ a_typname = DatumGetName(SPI_getbinval(c_tups[j], c_tupdesc, 7,
+ &isnull))->data;
+ if (strcmp(w_typnamespace, a_typnamespace) != 0 ||
+ strcmp(w_typname, a_typname) != 0)
+ {
+ ereport(WARNING,
+ (errcode(ERRCODE_DATATYPE_MISMATCH),
+ errmsg("column \"%s\" is of type \"%s.%s\""
+ " but import data is of type \"%s.%s\"",
+ DatumGetName(values[4])->data,
+ a_typnamespace, a_typname,
+ w_typnamespace, w_typname)));
+ continue;
+ }
+
+ /*
+ * If the atttypmod of the destination column is different from the
+ * one of source, column, we stop importing to avoid corrupted
+ * statistics.
+ */
+ w_typmod = DatumGetInt32(SPI_getbinval(c_tups[j], c_tupdesc, 8,
+ &isnull));
+ a_typmod = DatumGetInt32(SPI_getbinval(c_tups[j], c_tupdesc, 9,
+ &isnull));
+ if (w_typmod != a_typmod)
+ {
+ ereport(WARNING,
+ (errcode(ERRCODE_DATATYPE_MISMATCH),
+ errmsg("column \"%s\" is of atttypmod %d"
+ " but import data is of atttypmod %d",
+ DatumGetName(values[4])->data,
+ a_typmod, a_typmod)));
+ continue;
+ }
+
+ /*
+ * First delete old dummy statistics, and import new one. We use
+ * DELETE-then-INSERT method here to simplify codes.
+ */
+ spi_exec_query("DELETE FROM dbms_stats._column_stats_locked "
+ "WHERE starelid = $1 AND staattnum = $2", 2, c_types,
+ &c_del_plan, values, NULL, SPI_OK_DELETE);
+
+ spi_exec_query("INSERT INTO dbms_stats._column_stats_locked "
+ "SELECT $1, $2, "
+ "stainherit, stanullfrac, stawidth, stadistinct, "
+ "stakind1, stakind2, stakind3, stakind4, "
+#if PG_VERSION_NUM >= 90200
+ "stakind5, "
+#endif
+ "staop1, staop2, staop3, staop4, "
+#if PG_VERSION_NUM >= 90200
+ "staop5, "
+#endif
+ "stanumbers1, stanumbers2, stanumbers3, stanumbers4, "
+#if PG_VERSION_NUM >= 90200
+ "stanumbers5, "
+#endif
+ "stavalues1, stavalues2, stavalues3, stavalues4 "
+#if PG_VERSION_NUM >= 90200
+ ", stavalues5 "
+#endif
+ "FROM dbms_stats_work_stats "
+ "WHERE nspname = $3 AND relname = $4 "
+ "AND attname = $5 "
+ "ORDER BY 3",
+ 5, c_types, &c_ins_plan, values, NULL, SPI_OK_INSERT);
+
+ elog(DEBUG2, "\"%s.%s.%s\" column statistic import",
+ DatumGetName(w_nspname)->data,
+ DatumGetName(w_relname)->data, DatumGetName(values[4])->data);
+ }
+
+ if (c_num == 0)
+ elog(DEBUG2, "\"%s.%s\" column statistic no data",
+ DatumGetName(w_nspname)->data, DatumGetName(w_relname)->data);
+ }
+
+ /* release the cached plan */
+ SPI_freeplan(r_upd_plan);
+ SPI_freeplan(r_ins_plan);
+ SPI_freeplan(c_sel_plan);
+ SPI_freeplan(c_del_plan);
+ SPI_freeplan(c_ins_plan);
+
+ /* delete the temp table */
+ spi_exec_utility("DROP TABLE dbms_stats_work_stats");
+
+ /* disconnect SPI */
+ ret = SPI_finish();
+ if (ret != SPI_OK_FINISH)
+ elog(ERROR, "pg_dbms_stats: SPI_finish => %d", ret);
+
+ /*
+ * Recover the protocol state because it has been invalidated by our
+ * COPY-from-stdin.
+ */
+ if (filename == NULL)
+ pq_puttextmessage('C', "dbms_stats_import");
+
+ PG_RETURN_VOID();
+}
+
+/*
+ * spi_exec_utility
+ * Execute given utility command via SPI.
+ */
+static void
+spi_exec_utility(const char *query)
+{
+ int ret;
+
+ ret = SPI_exec(query, 0);
+ if (ret != SPI_OK_UTILITY)
+ elog(ERROR, "pg_dbms_stats: SPI_exec => %d", ret);
+}
+
+/*
+ * spi_exec_query
+ * Execute given SQL command via SPI.
+ * The plan will be cached by SPI_prepare if it hasn't been.
+ */
+static void
+spi_exec_query(const char *query, int nargs, Oid *argtypes, SPIPlanPtr *plan,
+ Datum *values, const char *nulls, int result)
+{
+ int ret;
+
+ if (*plan == NULL)
+ *plan = SPI_prepare(query, nargs, argtypes);
+
+ ret = SPI_execute_plan(*plan, values, nulls, false, 0);
+ if (ret != result)
+ elog(ERROR, "pg_dbms_stats: SPI_execute_plan => %d", ret);
+}
+
+static char *
+get_text_arg(FunctionCallInfo fcinfo, int n, bool is_name)
+{
+ text *arg;
+ char *s;
+ int len;
+ char *result;
+
+ arg = PG_GETARG_TEXT_PP(n);
+ s = text_to_cstring(arg);
+ PG_FREE_IF_COPY(arg, n);
+
+ if (!is_name)
+ return s;
+
+ len = strlen(s);
+
+ /* Truncate oversize input */
+ if (len >= NAMEDATALEN)
+ len = pg_mbcliplen(s, len, NAMEDATALEN - 1);
+
+ /* We use palloc0 here to ensure result is zero-padded */
+ result = (char *) palloc0(NAMEDATALEN);
+ memcpy(result, s, len);
+ pfree(s);
+
+ return result;
+}
+
+/*
+ * get_args
+ * Retrieve arguments from FunctionCallInfo and validate them. We assume
+ * that order of arguments is:
+ * 1) schema name
+ * 2) relation oid
+ * 3) attribute name
+ * 4) absolute path of source file, or 'stdin' (case insensitive)
+ */
+static void
+get_args(FunctionCallInfo fcinfo, char **nspname, char **relname,
+ char **attname, char **filename)
+{
+ Oid nspid;
+ Oid relid;
+ AttrNumber attnum;
+ HeapTuple tp;
+ Form_pg_class reltup;
+ char relkind;
+
+ *nspname = *relname = *attname = *filename = NULL;
+
+ /*
+ * First of all, check whether combination of arguments is consistent.
+ *
+ * 1) relid and attname can't be used with schemaname.
+ * 2) relid is required when attname is given.
+ */
+ if (!PG_ARGISNULL(0) && (!PG_ARGISNULL(1) || !PG_ARGISNULL(2)))
+ elog(ERROR, "relid and attnum can not be used with schemaname");
+ else if (PG_ARGISNULL(1) && !PG_ARGISNULL(2))
+ elog(ERROR, "relation is required");
+
+ /* filepath validation */
+ if (!PG_ARGISNULL(3))
+ {
+ *filename = get_text_arg(fcinfo, 3, false);
+
+ /*
+ * If given filepath is "stdin", clear filename to tell caller to
+ * import from standard input. Note that we accept only absolute path
+ * for security reason.
+ */
+ if (pg_strcasecmp(*filename, "stdin") == 0)
+ *filename = NULL;
+ else if (!is_absolute_path(*filename))
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_NAME),
+ errmsg("relative path not allowed for dbms_stats_export"
+ " to file")));
+ }
+
+ /* schemaname validation */
+ if (!PG_ARGISNULL(0))
+ {
+ *nspname = get_text_arg(fcinfo, 0, true);
+
+ /* check that a schema with given name exists */
+ get_namespace_oid(*nspname, false);
+
+ /* check that given schema is not one of system schemas */
+ if (dbms_stats_is_system_schema_internal(*nspname))
+ elog(ERROR, "\"%s\" is a system catalog", *nspname);
+ }
+
+ /* table oid validation */
+ if (!PG_ARGISNULL(1))
+ {
+ relid = PG_GETARG_OID(1);
+ tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid));
+ if (!HeapTupleIsValid(tp))
+ elog(ERROR, "relid %d does not exist", relid);
+
+ /* check that the target is an ordinary table or an index */
+ reltup = (Form_pg_class) GETSTRUCT(tp);
+ *relname = pstrdup(reltup->relname.data);
+ relkind = reltup->relkind;
+ nspid = reltup->relnamespace;
+ ReleaseSysCache(tp);
+
+ if (relkind != RELKIND_RELATION && relkind != RELKIND_INDEX
+#if PG_VERSION_NUM >= 90200
+ && relkind != RELKIND_FOREIGN_TABLE
+#endif
+ )
+ elog(ERROR, "relkind of \"%s\" is \"%c\", can not import",
+ get_rel_name(relid), relkind);
+
+ /* check that the relation is not in one of system schemas */
+ *nspname = get_namespace_name(nspid);
+ if (dbms_stats_is_system_schema_internal(*nspname))
+ elog(ERROR, "\"%s\" is a system catalog", *nspname);
+
+ /* attribute name validation */
+ if (!PG_ARGISNULL(2))
+ {
+ *attname = get_text_arg(fcinfo, 2, true);
+ attnum = get_attnum(relid, *attname);
+ if (!AttributeNumberIsValid(attnum))
+ elog(ERROR, "column \"%s\" of \"%s.%s\" does not exist", *attname, *nspname, *relname);
+ }
+ }
+}
+
+/*
+ * appendLiteral - Format a string as a SQL literal, append to buf
+ *
+ * This function was copied from simple_quote_literal() in
+ * src/backend/utils/adt/ruleutils.c
+ */
+static void
+appendLiteral(StringInfo buf, const char *val)
+{
+ const char *valptr;
+
+ /*
+ * We form the string literal according to the prevailing setting of
+ * standard_conforming_strings; we never use E''. User is responsible for
+ * making sure result is used correctly.
+ */
+ appendStringInfoChar(buf, '\'');
+ for (valptr = val; *valptr; valptr++)
+ {
+ char ch = *valptr;
+
+ if (SQL_STR_DOUBLE(ch, !standard_conforming_strings))
+ appendStringInfoChar(buf, ch);
+ appendStringInfoChar(buf, ch);
+ }
+ appendStringInfoChar(buf, '\'');
+}
+
+/*
+ * import_stats_from_file
+ * load data from file or stdin into work table, and delete unnecessary
+ * records.
+ */
+static void
+import_stats_from_file(char *filename, char *nspname, char *relname,
+ char *attname)
+{
+ StringInfoData buf;
+ List *parsetree_list;
+ uint64 processed;
+ Datum values[3];
+ Oid argtypes[3] = { CSTRINGOID, CSTRINGOID, CSTRINGOID };
+ char nulls[3] = { 'n', 'n', 'n' };
+ int nargs;
+ int ret;
+
+ /* for debug use */
+ elog(DEBUG3, "%s() f=%s n=%s r=%s a=%s", __FUNCTION__,
+ filename ? filename : "(null)",
+ nspname ? nspname : "(null)",
+ relname ? relname : "(null)",
+ attname ? attname : "(null)");
+
+ /*
+ * Construct COPY statement. NULL for filename indicates that source is
+ * stdin.
+ */
+ initStringInfo(&buf);
+ appendStringInfoString(&buf, "COPY dbms_stats_work_stats FROM ");
+ if (filename == NULL)
+ appendStringInfoString(&buf, "stdin");
+ else
+ appendLiteral(&buf, filename);
+
+ appendStringInfoString(&buf, " (FORMAT 'binary')");
+
+ /* Execute COPY FROM command. */
+ parsetree_list = pg_parse_query(buf.data);
+ processed = DoCopy((CopyStmt *)linitial(parsetree_list), buf.data);
+
+ if (processed == 0)
+ elog(ERROR, "no data to be imported");
+
+ /*
+ * Delete the statistics other than the specified object's statistic from
+ * the temp table. We can skip DELETEing staging data when schemaname is
+ * NULL, because it means database-wise import.
+ */
+ if (nspname == NULL)
+ return;
+
+ resetStringInfo(&buf);
+ appendStringInfoString(&buf,
+ "DELETE FROM dbms_stats_work_stats "
+ " WHERE nspname <> $1::text ");
+ values[0] = CStringGetDatum(nspname);
+ nulls[0] = 't';
+ nargs = 1;
+
+ if (relname != NULL)
+ {
+ values[1] = CStringGetDatum(relname);
+ nulls[1] = 't';
+ nargs++;
+ appendStringInfoString(&buf, " OR (relname <> $2::text) ");
+
+ if (attname != NULL)
+ {
+ values[2] = CStringGetDatum(attname);
+ nulls[2] = 't';
+ nargs++;
+ appendStringInfoString(&buf, " OR (attname <> $3::text) ");
+ }
+ }
+
+ ret = SPI_execute_with_args(buf.data, nargs, argtypes, values, nulls,
+ false, 0);
+ if (ret != SPI_OK_DELETE)
+ elog(ERROR, "pg_dbms_stats: SPI_execute_with_args => %d", ret);
+}
+
+#ifdef UNIT_TEST
+void test_import(int *passed, int *total);
+static void test_spi_exec_query(int *passed, int *total);
+static void test_spi_exec_utility(int *passed, int *total);
+static void test_appendLiteral(int *passed, int *total);
+
+#define StringEq(actual, expected) \
+ (strcmp((actual), (expected)) == 0 ? 1 : \
+ (elog(WARNING, "%s-%d failed: [%s]", \
+ __FUNCTION__, caseno, (actual)), 0))
+
+/*
+ * Test appendLiteral function
+ */
+static void
+test_appendLiteral(int *passed, int *total)
+{
+ bool org_standard_conforming_strings;
+ int caseno = 0;
+ StringInfoData buf;
+
+ /* Backup current GUC parameters */
+ NewGUCNestLevel();
+ org_standard_conforming_strings = standard_conforming_strings;
+
+ /* Initialize resources for tests */
+ initStringInfo(&buf);
+
+ /*
+ * *-*-1:
+ * - no special char
+ */
+ caseno++;
+ resetStringInfo(&buf);
+ appendStringInfoString(&buf, "BEFORE");
+ appendLiteral(&buf, "\"abc 123\tããã\n\"");
+ if (StringEq(buf.data, "BEFORE'\"abc 123\tããã\n\"'"))
+ {
+ elog(WARNING, "%s-%d ok", __FUNCTION__, caseno);
+ (*passed)++;
+ }
+
+ /*
+ * *-*-2:
+ * - contains special chars (single quote, back slash),
+ * - standard_conforming_strings is true
+ */
+ caseno++;
+ resetStringInfo(&buf);
+ appendStringInfoString(&buf, "BEFORE");
+ standard_conforming_strings = true;
+ appendLiteral(&buf, "'abc 123\tããã\n\\");
+ if (StringEq(buf.data, "BEFORE'''abc 123\tããã\n\\'"))
+ {
+ elog(WARNING, "%s-%d ok", __FUNCTION__, caseno);
+ (*passed)++;
+ }
+
+ /*
+ * *-*-3:
+ * - contains special chars (single quote, back slash),
+ * - standard_conforming_strings is false
+ */
+ caseno++;
+ resetStringInfo(&buf);
+ appendStringInfoString(&buf, "BEFORE");
+ standard_conforming_strings = false;
+ appendLiteral(&buf, "'abc 123\tããã\n\\");
+ if (StringEq(buf.data, "BEFORE'''abc 123\tããã\n\\\\'"))
+ {
+ elog(WARNING, "%s-%d ok", __FUNCTION__, caseno);
+ (*passed)++;
+ }
+
+ /*
+ * *-*-4:
+ * - empty string
+ */
+ caseno++;
+ resetStringInfo(&buf);
+ appendStringInfoString(&buf, "BEFORE");
+ appendLiteral(&buf, "");
+ if (StringEq(buf.data, "BEFORE''"))
+ {
+ elog(WARNING, "%s-%d ok", __FUNCTION__, caseno);
+ (*passed)++;
+ }
+
+ /* report # of tests */
+ *total += caseno;
+
+ /* Restore GUC parameters */
+ standard_conforming_strings = org_standard_conforming_strings;
+}
+
+static void
+test_spi_exec_query(int *passed, int *total)
+{
+ int rc;
+ volatile int caseno = 0;
+ SPIPlanPtr ptr = NULL;
+ SPIPlanPtr org_ptr;
+
+ /* Initialize */
+ rc = SPI_connect();
+ if (rc != SPI_OK_CONNECT)
+ elog(ERROR, "could not connect SPI: %s", SPI_result_code_string(rc));
+
+ /*
+ * *-*-1
+ * - plan is not cached
+ */
+ caseno++;
+ BeginInternalSubTransaction("test");
+ PG_TRY();
+ {
+ spi_exec_query("SELECT 1", 0, NULL, &ptr, NULL, NULL, SPI_OK_SELECT);
+ if (ptr != NULL && SPI_processed == 1)
+ {
+ elog(WARNING, "%s-%d ok", __FUNCTION__, caseno);
+ (*passed)++;
+ }
+ ReleaseCurrentSubTransaction();
+ }
+ PG_CATCH();
+ {
+ elog(WARNING, "*-*-%d failed", caseno);
+ RollbackAndReleaseCurrentSubTransaction();
+ SPI_restore_connection();
+ }
+ PG_END_TRY();
+
+ /*
+ * *-*-2
+ * - plan is cached
+ */
+ caseno++;
+ BeginInternalSubTransaction("test");
+ PG_TRY();
+ {
+ org_ptr = ptr;
+ spi_exec_query(NULL, 0, NULL, &ptr, NULL, NULL, SPI_OK_SELECT);
+ if (ptr == org_ptr && SPI_processed == 1)
+ {
+ elog(WARNING, "%s-%d ok", __FUNCTION__, caseno);
+ (*passed)++;
+ }
+ ReleaseCurrentSubTransaction();
+ }
+ PG_CATCH();
+ {
+ elog(WARNING, "*-*-%d failed", caseno);
+ RollbackAndReleaseCurrentSubTransaction();
+ FlushErrorState();
+ SPI_restore_connection();
+ }
+ PG_END_TRY();
+ SPI_freeplan(ptr);
+ ptr = NULL;
+
+ /*
+ * *-*-3
+ * - query error
+ */
+ caseno++;
+ BeginInternalSubTransaction("test");
+ PG_TRY();
+ {
+ spi_exec_query("SELECT 1 / 0",
+ 0, NULL, &ptr, NULL, NULL, SPI_OK_SELECT);
+ elog(WARNING, "*-*-%d failed", caseno);
+ ReleaseCurrentSubTransaction();
+ }
+ PG_CATCH();
+ {
+ elog(WARNING, "%s-%d ok", __FUNCTION__, caseno);
+ (*passed)++;
+ RollbackAndReleaseCurrentSubTransaction();
+ FlushErrorState();
+ SPI_restore_connection();
+ }
+ PG_END_TRY();
+ SPI_freeplan(ptr);
+ ptr = NULL;
+
+ /*
+ * *-*-4
+ * - query success
+ */
+ caseno++;
+ BeginInternalSubTransaction("test");
+ PG_TRY();
+ {
+ spi_exec_query("SELECT 1", 0, NULL, &ptr, NULL, NULL, SPI_OK_SELECT);
+ if (ptr != NULL && SPI_processed == 1)
+ {
+ elog(WARNING, "%s-%d ok", __FUNCTION__, caseno);
+ (*passed)++;
+ }
+ ReleaseCurrentSubTransaction();
+ }
+ PG_CATCH();
+ {
+ elog(WARNING, "*-*-%d failed", caseno);
+ PG_RE_THROW();
+ RollbackAndReleaseCurrentSubTransaction();
+ SPI_restore_connection();
+ }
+ PG_END_TRY();
+ SPI_freeplan(ptr);
+ ptr = NULL;
+
+ /* report # of tests */
+ (*total) += caseno;
+
+ /* Cleanup */
+ rc = SPI_finish();
+ if (rc != SPI_OK_FINISH && rc != SPI_ERROR_UNCONNECTED)
+ elog(ERROR, "could not finish SPI: %s", SPI_result_code_string(rc));
+}
+
+static void
+test_spi_exec_utility(int *passed, int *total)
+{
+ int rc;
+ volatile int caseno = 0;
+
+ /* Initialize */
+ rc = SPI_connect();
+ if (rc != SPI_OK_CONNECT)
+ elog(ERROR, "could not connect SPI: %s", SPI_result_code_string(rc));
+
+ /*
+ * *-*-1
+ * - query error
+ */
+ caseno++;
+ BeginInternalSubTransaction("test");
+ PG_TRY();
+ {
+ spi_exec_utility("RESET dummy_parameter");
+ elog(WARNING, "*-*-%d failed", caseno);
+ ReleaseCurrentSubTransaction();
+ }
+ PG_CATCH();
+ {
+ elog(WARNING, "%s-%d ok", __FUNCTION__, caseno);
+ (*passed)++;
+ RollbackAndReleaseCurrentSubTransaction();
+ FlushErrorState();
+ SPI_restore_connection();
+ }
+ PG_END_TRY();
+
+ /*
+ * *-*-2
+ * - query success
+ */
+ caseno++;
+ BeginInternalSubTransaction("test");
+ PG_TRY();
+ {
+ spi_exec_utility("RESET client_min_messages");
+ elog(WARNING, "%s-%d ok", __FUNCTION__, caseno);
+ (*passed)++;
+ ReleaseCurrentSubTransaction();
+ }
+ PG_CATCH();
+ {
+ elog(WARNING, "*-*-%d failed", caseno);
+ RollbackAndReleaseCurrentSubTransaction();
+ SPI_restore_connection();
+ }
+ PG_END_TRY();
+
+ /* report # of tests */
+ (*total) += caseno;
+
+ /* Cleanup */
+ rc = SPI_finish();
+ if (rc != SPI_OK_FINISH && rc != SPI_ERROR_UNCONNECTED)
+ elog(ERROR, "could not finish SPI: %s", SPI_result_code_string(rc));
+}
+
+/*
+ * Unit test entry point for import.c. This will be called by PG_init()
+ * function, after initialization for this extension is completed .
+ * This funciton should add the numbers of tests passed and the total number of
+ * tests to parameter passed and total respectively.
+ */
+void
+test_import(int *passed, int *total)
+{
+ int local_passed = 0;
+ int local_total = 0;
+
+ elog(WARNING, "==========");
+
+ /* Do tests here */
+ test_appendLiteral(&local_passed, &local_total);
+ test_spi_exec_query(&local_passed, &local_total);
+ test_spi_exec_utility(&local_passed, &local_total);
+
+ elog(WARNING, "%s %d/%d passed", __FUNCTION__, local_passed, local_total);
+ *passed += local_passed;
+ *total += local_total;
+}
+
+#endif
diff --git a/input/ut_imp_exp-9.1.source b/input/ut_imp_exp-9.1.source
new file mode 100644
index 0000000..145c321
--- /dev/null
+++ b/input/ut_imp_exp-9.1.source
@@ -0,0 +1,275 @@
+\pset null '(null)'
+CREATE TABLE s0.st3();
+/*
+ * No.16-1 export_plain_stats.sql.sample
+ */
+-- No.16-1-1
+ANALYZE;
+DELETE FROM dbms_stats._column_stats_locked;
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+UPDATE dbms_stats._relation_stats_locked
+ SET (relpages, reltuples, curpages) = (0,0,0);
+UPDATE dbms_stats._column_stats_locked SET
+ stanullfrac = -staattnum,
+ stawidth = -staattnum,
+ stadistinct = -staattnum,
+ stakind1 = 2,
+ stakind2 = 3,
+ stakind3 = 4,
+ stakind4 = 1,
+ staop1 = 22,
+ staop2 = 23,
+ staop3 = 24,
+ staop4 = 21,
+ stanumbers1 = ARRAY[-staattnum,22],
+ stanumbers2 = ARRAY[-staattnum,23],
+ stanumbers3 = ARRAY[-staattnum,24],
+ stanumbers4 = ARRAY[-staattnum,21],
+ stavalues1 = stavalues3,
+ stavalues2 = stavalues2,
+ stavalues3 = stavalues1,
+ stavalues4 = stavalues4;
+\i export_plain_stats.sql.sample
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+TRUNCATE dbms_stats.work;
+-- No.16-1-2
+\! sed '/ORDER/i\\ AND n2.nspname = '"\'s0\'" export_plain_stats.sql.sample > export_plain_stats.sql.sample_test
+\i export_plain_stats.sql.sample_test
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+TRUNCATE dbms_stats.work;
+\! rm export_plain_stats.sql.sample_test
+-- No.16-1-3
+\! sed '/ORDER/i\\ AND c.relname = '"\'st0\'" export_plain_stats.sql.sample > export_plain_stats.sql.sample_test
+\i export_plain_stats.sql.sample_test
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+TRUNCATE dbms_stats.work;
+\! rm export_plain_stats.sql.sample_test
+-- No.16-1-4
+\! sed '/ORDER/i\\ AND c.relname = '"\'pg_toast_1262\'" export_plain_stats.sql.sample > export_plain_stats.sql.sample_test
+\i export_plain_stats.sql.sample_test
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+TRUNCATE dbms_stats.work;
+\! rm export_plain_stats.sql.sample_test
+-- No.16-1-5
+\! sed '/ORDER/i\\ AND c.relname = '"\'st0_idx\'" export_plain_stats.sql.sample > export_plain_stats.sql.sample_test
+\i export_plain_stats.sql.sample_test
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+TRUNCATE dbms_stats.work;
+\! rm export_plain_stats.sql.sample_test
+-- No.16-1-6
+\! sed '/ORDER/i\\ AND c.relname = '"\'ss0\'" export_plain_stats.sql.sample > export_plain_stats.sql.sample_test
+\i export_plain_stats.sql.sample_test
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+TRUNCATE dbms_stats.work;
+\! rm export_plain_stats.sql.sample_test
+-- No.16-1-7
+\! sed '/ORDER/i\\ AND c.relname = '"\'sc0\'" export_plain_stats.sql.sample > export_plain_stats.sql.sample_test
+\i export_plain_stats.sql.sample_test
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+TRUNCATE dbms_stats.work;
+\! rm export_plain_stats.sql.sample_test
+-- No.16-1-8
+\! sed '/ORDER/i\\ AND c.relname = '"\'sft0\'" export_plain_stats.sql.sample > export_plain_stats.sql.sample_test
+\i export_plain_stats.sql.sample_test
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+TRUNCATE dbms_stats.work;
+\! rm export_plain_stats.sql.sample_test
+-- No.16-1-9
+\! sed '/ORDER/i\\ AND n2.nspname = '"\'s0\'"' AND a.attname = '\'id\' export_plain_stats.sql.sample > export_plain_stats.sql.sample_test
+\i export_plain_stats.sql.sample_test
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+TRUNCATE dbms_stats.work;
+\! rm export_plain_stats.sql.sample_test
+-- No.16-1-10
+\! sed '/ORDER/i\\ AND n2.nspname = '"\'s0\'"' AND a.attname IS NULL' export_plain_stats.sql.sample > export_plain_stats.sql.sample_test
+\i export_plain_stats.sql.sample_test
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+TRUNCATE dbms_stats.work;
+\! rm export_plain_stats.sql.sample_test
+-- No.16-1-11
+\! sed '/ORDER/i\\ AND n2.nspname = '"\'s1\'"' AND c.relname IS NULL' export_plain_stats.sql.sample > export_plain_stats.sql.sample_test
+\i export_plain_stats.sql.sample_test
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+TRUNCATE dbms_stats.work;
+\! rm export_plain_stats.sql.sample_test
+
+/*
+ * No.16-2 export_effective_stats.sql.sample
+ */
+-- No.16-2-1
+VACUUM ANALYZE;
+SELECT dbms_stats.lock_database_stats();
+UPDATE dbms_stats._relation_stats_locked
+ SET (relpages, reltuples, curpages) = (NULL, NULL, NULL);
+UPDATE dbms_stats._column_stats_locked
+ SET (stanullfrac, stawidth, stadistinct,
+ stakind1, stakind2, stakind3, stakind4,
+ staop1, staop2, staop3, staop4,
+ stanumbers1, stanumbers2, stanumbers3, stanumbers4,
+ stavalues1, stavalues2, stavalues3, stavalues4)
+ = (NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL)
+ WHERE starelid = 's0.st0'::regclass;
+\i export_effective_stats.sql.sample
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+TRUNCATE dbms_stats.work;
+-- No.16-2-2
+\! sed '/ORDER/i\\ WHERE n2.nspname = '"\'s0\'" export_effective_stats.sql.sample > export_effective_stats.sql.sample_test
+\i export_effective_stats.sql.sample_test
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+\! rm export_effective_stats.sql.sample_test
+TRUNCATE dbms_stats.work;
+-- No.16-2-3
+\! sed '/ORDER/i\\ WHERE cl.relname = '"\'st0\'" export_effective_stats.sql.sample > export_effective_stats.sql.sample_test
+\i export_effective_stats.sql.sample_test
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+\! rm export_effective_stats.sql.sample_test
+TRUNCATE dbms_stats.work;
+-- No.16-2-4
+\! sed '/ORDER/i\\ WHERE cl.relname = '"\'pg_toast_1262\'" export_effective_stats.sql.sample > export_effective_stats.sql.sample_test
+\i export_effective_stats.sql.sample_test
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+\! rm export_effective_stats.sql.sample_test
+TRUNCATE dbms_stats.work;
+-- No.16-2-5
+\! sed '/ORDER/i\\ WHERE cl.relname = '"\'st0_idx\'" export_effective_stats.sql.sample > export_effective_stats.sql.sample_test
+\i export_effective_stats.sql.sample_test
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+\! rm export_effective_stats.sql.sample_test
+TRUNCATE dbms_stats.work;
+-- No.16-2-6
+\! sed '/ORDER/i\\ WHERE cl.relname = '"\'ss0\'" export_effective_stats.sql.sample > export_effective_stats.sql.sample_test
+\i export_effective_stats.sql.sample_test
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+\! rm export_effective_stats.sql.sample_test
+TRUNCATE dbms_stats.work;
+-- No.16-2-7
+\! sed '/ORDER/i\\ WHERE cl.relname = '"\'sc0\'" export_effective_stats.sql.sample > export_effective_stats.sql.sample_test
+\i export_effective_stats.sql.sample_test
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+\! rm export_effective_stats.sql.sample_test
+TRUNCATE dbms_stats.work;
+-- No.16-2-8
+\! sed '/ORDER/i\\ WHERE cl.relname = '"\'sft0\'" export_effective_stats.sql.sample > export_effective_stats.sql.sample_test
+\i export_effective_stats.sql.sample_test
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+\! rm export_effective_stats.sql.sample_test
+TRUNCATE dbms_stats.work;
+-- No.16-2-9
+\! sed '/ORDER/i\\ WHERE n2.nspname = '"\'s0\'"' AND a.attname = '"\'id\'" export_effective_stats.sql.sample > export_effective_stats.sql.sample_test
+\i export_effective_stats.sql.sample_test
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+\! rm export_effective_stats.sql.sample_test
+TRUNCATE dbms_stats.work;
+-- No.16-2-10
+\! sed '/ORDER/i\\ WHERE n2.nspname = '"\'s0\'"' AND a.attname IS NULL' export_effective_stats.sql.sample > export_effective_stats.sql.sample_test
+\i export_effective_stats.sql.sample_test
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+\! rm export_effective_stats.sql.sample_test
+TRUNCATE dbms_stats.work;
+-- No.16-2-11
+\! sed '/ORDER/i\\ WHERE n2.nspname = '"\'s0\'"' AND cl.relname IS NULL' export_effective_stats.sql.sample > export_effective_stats.sql.sample_test
+\i export_effective_stats.sql.sample_test
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+\! rm export_effective_stats.sql.sample_test
+TRUNCATE dbms_stats.work;
+
+/*
+ * Stab function dbms_stats.import
+ */
+ALTER FUNCTION dbms_stats.import(
+ nspname text,
+ relid regclass,
+ attname text,
+ src text
+) RENAME TO truth_import;
+CREATE FUNCTION dbms_stats.import(
+ nspname text,
+ relid regclass,
+ attname text,
+ src text
+) RETURNS void AS
+$$
+BEGIN
+ RAISE NOTICE 'arguments are "%", "%", "%", "%"', $1, $2, $3, $4;
+ RETURN;
+END
+$$
+LANGUAGE plpgsql;
+/*
+ * No.17-1 dbms_stats.import_database_stats(src)
+ */
+-- No.17-1-1
+SELECT dbms_stats.import_database_stats('@abs_srcdir@/export_stats.dmp');
+
+/*
+ * No.17-2 dbms_stats.import_schema_stats(schemaname, src)
+ */
+-- No.17-2-1
+SELECT dbms_stats.import_schema_stats('s0', '@abs_srcdir@/export_stats.dmp');
+
+/*
+ * No.17-3 dbms_stats.import_table_stats(relid, src)
+ */
+-- No.17-3-1
+SELECT dbms_stats.import_table_stats('s0.st0', '@abs_srcdir@/export_stats.dmp');
+
+/*
+ * No.17-4 dbms_stats.import_table_stats(schemaname, tablename, src)
+ */
+-- No.17-4-1
+SELECT dbms_stats.import_table_stats('s0', 'st0', '@abs_srcdir@/export_stats.dmp');
+
+/*
+ * No.17-5 dbms_stats.import_column_stats (relid, attname, src)
+ */
+-- No.17-5-1
+SELECT dbms_stats.import_column_stats('s0.st0', 'id', '@abs_srcdir@/export_stats.dmp');
+
+/*
+ * No.17-6 dbms_stats.import_column_stats (schemaname, tablename, attname, src)
+ */
+-- No.17-6-1
+SELECT dbms_stats.import_column_stats('s0', 'st0', 'id','@abs_srcdir@/export_stats.dmp');
+
+/*
+ * Delete stab function dbms_stats.import
+ */
+DROP FUNCTION dbms_stats.import(
+ nspname text,
+ relid regclass,
+ attname text,
+ src text
+);
+ALTER FUNCTION dbms_stats.truth_import(
+ nspname text,
+ relid regclass,
+ attname text,
+ src text
+) RENAME TO import;
diff --git a/input/ut_imp_exp-9.2.source b/input/ut_imp_exp-9.2.source
new file mode 100644
index 0000000..8641af8
--- /dev/null
+++ b/input/ut_imp_exp-9.2.source
@@ -0,0 +1,279 @@
+\pset null '(null)'
+CREATE TABLE s0.st3();
+/*
+ * No.16-1 export_plain_stats.sql.sample
+ */
+-- No.16-1-1
+ANALYZE;
+DELETE FROM dbms_stats._column_stats_locked;
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+UPDATE dbms_stats._relation_stats_locked
+ SET (relpages, reltuples, relallvisible, curpages) = (0,0,0,0);
+UPDATE dbms_stats._column_stats_locked SET
+ stanullfrac = -staattnum,
+ stawidth = -staattnum,
+ stadistinct = -staattnum,
+ stakind1 = 2,
+ stakind2 = 3,
+ stakind3 = 4,
+ stakind4 = 1,
+ stakind5 = 5,
+ staop1 = 22,
+ staop2 = 23,
+ staop3 = 24,
+ staop4 = 21,
+ staop5 = 25,
+ stanumbers1 = ARRAY[-staattnum,22],
+ stanumbers2 = ARRAY[-staattnum,23],
+ stanumbers3 = ARRAY[-staattnum,24],
+ stanumbers4 = ARRAY[-staattnum,21],
+ stanumbers5 = ARRAY[-staattnum,25],
+ stavalues1 = stavalues3,
+ stavalues2 = stavalues2,
+ stavalues3 = stavalues1,
+ stavalues4 = stavalues4,
+ stavalues5 = stavalues5;
+\i export_plain_stats.sql.sample
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+TRUNCATE dbms_stats.work;
+-- No.16-1-2
+\! sed '/ORDER/i\\ AND n2.nspname = '"\'s0\'" export_plain_stats.sql.sample > export_plain_stats.sql.sample_test
+\i export_plain_stats.sql.sample_test
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+TRUNCATE dbms_stats.work;
+\! rm export_plain_stats.sql.sample_test
+-- No.16-1-3
+\! sed '/ORDER/i\\ AND c.relname = '"\'st0\'" export_plain_stats.sql.sample > export_plain_stats.sql.sample_test
+\i export_plain_stats.sql.sample_test
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+TRUNCATE dbms_stats.work;
+\! rm export_plain_stats.sql.sample_test
+-- No.16-1-4
+\! sed '/ORDER/i\\ AND c.relname = '"\'pg_toast_1262\'" export_plain_stats.sql.sample > export_plain_stats.sql.sample_test
+\i export_plain_stats.sql.sample_test
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+TRUNCATE dbms_stats.work;
+\! rm export_plain_stats.sql.sample_test
+-- No.16-1-5
+\! sed '/ORDER/i\\ AND c.relname = '"\'st0_idx\'" export_plain_stats.sql.sample > export_plain_stats.sql.sample_test
+\i export_plain_stats.sql.sample_test
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+TRUNCATE dbms_stats.work;
+\! rm export_plain_stats.sql.sample_test
+-- No.16-1-6
+\! sed '/ORDER/i\\ AND c.relname = '"\'ss0\'" export_plain_stats.sql.sample > export_plain_stats.sql.sample_test
+\i export_plain_stats.sql.sample_test
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+TRUNCATE dbms_stats.work;
+\! rm export_plain_stats.sql.sample_test
+-- No.16-1-7
+\! sed '/ORDER/i\\ AND c.relname = '"\'sc0\'" export_plain_stats.sql.sample > export_plain_stats.sql.sample_test
+\i export_plain_stats.sql.sample_test
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+TRUNCATE dbms_stats.work;
+\! rm export_plain_stats.sql.sample_test
+-- No.16-1-8
+\! sed '/ORDER/i\\ AND c.relname = '"\'sft0\'" export_plain_stats.sql.sample > export_plain_stats.sql.sample_test
+\i export_plain_stats.sql.sample_test
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+TRUNCATE dbms_stats.work;
+\! rm export_plain_stats.sql.sample_test
+-- No.16-1-9
+\! sed '/ORDER/i\\ AND n2.nspname = '"\'s0\'"' AND a.attname = '\'id\' export_plain_stats.sql.sample > export_plain_stats.sql.sample_test
+\i export_plain_stats.sql.sample_test
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+TRUNCATE dbms_stats.work;
+\! rm export_plain_stats.sql.sample_test
+-- No.16-1-10
+\! sed '/ORDER/i\\ AND n2.nspname = '"\'s0\'"' AND a.attname IS NULL' export_plain_stats.sql.sample > export_plain_stats.sql.sample_test
+\i export_plain_stats.sql.sample_test
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+TRUNCATE dbms_stats.work;
+\! rm export_plain_stats.sql.sample_test
+-- No.16-1-11
+\! sed '/ORDER/i\\ AND n2.nspname = '"\'s1\'"' AND c.relname IS NULL' export_plain_stats.sql.sample > export_plain_stats.sql.sample_test
+\i export_plain_stats.sql.sample_test
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+TRUNCATE dbms_stats.work;
+\! rm export_plain_stats.sql.sample_test
+
+/*
+ * No.16-2 export_effective_stats.sql.sample
+ */
+-- No.16-2-1
+VACUUM ANALYZE;
+SELECT dbms_stats.lock_database_stats();
+UPDATE dbms_stats._relation_stats_locked
+ SET (relpages, reltuples, relallvisible, curpages) = (NULL, NULL, NULL, NULL);
+UPDATE dbms_stats._column_stats_locked
+ SET (stanullfrac, stawidth, stadistinct,
+ stakind1, stakind2, stakind3, stakind4, stakind5,
+ staop1, staop2, staop3, staop4, staop5,
+ stanumbers1, stanumbers2, stanumbers3, stanumbers4, stanumbers5,
+ stavalues1, stavalues2, stavalues3, stavalues4, stavalues5)
+ = (NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL)
+ WHERE starelid = 's0.st0'::regclass;
+\i export_effective_stats.sql.sample
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+TRUNCATE dbms_stats.work;
+-- No.16-2-2
+\! sed '/ORDER/i\\ WHERE n2.nspname = '"\'s0\'" export_effective_stats.sql.sample > export_effective_stats.sql.sample_test
+\i export_effective_stats.sql.sample_test
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+\! rm export_effective_stats.sql.sample_test
+TRUNCATE dbms_stats.work;
+-- No.16-2-3
+\! sed '/ORDER/i\\ WHERE cl.relname = '"\'st0\'" export_effective_stats.sql.sample > export_effective_stats.sql.sample_test
+\i export_effective_stats.sql.sample_test
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+\! rm export_effective_stats.sql.sample_test
+TRUNCATE dbms_stats.work;
+-- No.16-2-4
+\! sed '/ORDER/i\\ WHERE cl.relname = '"\'pg_toast_1262\'" export_effective_stats.sql.sample > export_effective_stats.sql.sample_test
+\i export_effective_stats.sql.sample_test
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+\! rm export_effective_stats.sql.sample_test
+TRUNCATE dbms_stats.work;
+-- No.16-2-5
+\! sed '/ORDER/i\\ WHERE cl.relname = '"\'st0_idx\'" export_effective_stats.sql.sample > export_effective_stats.sql.sample_test
+\i export_effective_stats.sql.sample_test
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+\! rm export_effective_stats.sql.sample_test
+TRUNCATE dbms_stats.work;
+-- No.16-2-6
+\! sed '/ORDER/i\\ WHERE cl.relname = '"\'ss0\'" export_effective_stats.sql.sample > export_effective_stats.sql.sample_test
+\i export_effective_stats.sql.sample_test
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+\! rm export_effective_stats.sql.sample_test
+TRUNCATE dbms_stats.work;
+-- No.16-2-7
+\! sed '/ORDER/i\\ WHERE cl.relname = '"\'sc0\'" export_effective_stats.sql.sample > export_effective_stats.sql.sample_test
+\i export_effective_stats.sql.sample_test
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+\! rm export_effective_stats.sql.sample_test
+TRUNCATE dbms_stats.work;
+-- No.16-2-8
+\! sed '/ORDER/i\\ WHERE cl.relname = '"\'sft0\'" export_effective_stats.sql.sample > export_effective_stats.sql.sample_test
+\i export_effective_stats.sql.sample_test
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+\! rm export_effective_stats.sql.sample_test
+TRUNCATE dbms_stats.work;
+-- No.16-2-9
+\! sed '/ORDER/i\\ WHERE n2.nspname = '"\'s0\'"' AND a.attname = '"\'id\'" export_effective_stats.sql.sample > export_effective_stats.sql.sample_test
+\i export_effective_stats.sql.sample_test
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+\! rm export_effective_stats.sql.sample_test
+TRUNCATE dbms_stats.work;
+-- No.16-2-10
+\! sed '/ORDER/i\\ WHERE n2.nspname = '"\'s0\'"' AND a.attname IS NULL' export_effective_stats.sql.sample > export_effective_stats.sql.sample_test
+\i export_effective_stats.sql.sample_test
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+\! rm export_effective_stats.sql.sample_test
+TRUNCATE dbms_stats.work;
+-- No.16-2-11
+\! sed '/ORDER/i\\ WHERE n2.nspname = '"\'s0\'"' AND cl.relname IS NULL' export_effective_stats.sql.sample > export_effective_stats.sql.sample_test
+\i export_effective_stats.sql.sample_test
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+\! rm export_effective_stats.sql.sample_test
+TRUNCATE dbms_stats.work;
+
+/*
+ * Stab function dbms_stats.import
+ */
+ALTER FUNCTION dbms_stats.import(
+ nspname text,
+ relid regclass,
+ attname text,
+ src text
+) RENAME TO truth_import;
+CREATE FUNCTION dbms_stats.import(
+ nspname text,
+ relid regclass,
+ attname text,
+ src text
+) RETURNS void AS
+$$
+BEGIN
+ RAISE NOTICE 'arguments are "%", "%", "%", "%"', $1, $2, $3, $4;
+ RETURN;
+END
+$$
+LANGUAGE plpgsql;
+/*
+ * No.17-1 dbms_stats.import_database_stats(src)
+ */
+-- No.17-1-1
+SELECT dbms_stats.import_database_stats('@abs_srcdir@/export_stats.dmp');
+
+/*
+ * No.17-2 dbms_stats.import_schema_stats(schemaname, src)
+ */
+-- No.17-2-1
+SELECT dbms_stats.import_schema_stats('s0', '@abs_srcdir@/export_stats.dmp');
+
+/*
+ * No.17-3 dbms_stats.import_table_stats(relid, src)
+ */
+-- No.17-3-1
+SELECT dbms_stats.import_table_stats('s0.st0', '@abs_srcdir@/export_stats.dmp');
+
+/*
+ * No.17-4 dbms_stats.import_table_stats(schemaname, tablename, src)
+ */
+-- No.17-4-1
+SELECT dbms_stats.import_table_stats('s0', 'st0', '@abs_srcdir@/export_stats.dmp');
+
+/*
+ * No.17-5 dbms_stats.import_column_stats (relid, attname, src)
+ */
+-- No.17-5-1
+SELECT dbms_stats.import_column_stats('s0.st0', 'id', '@abs_srcdir@/export_stats.dmp');
+
+/*
+ * No.17-6 dbms_stats.import_column_stats (schemaname, tablename, attname, src)
+ */
+-- No.17-6-1
+SELECT dbms_stats.import_column_stats('s0', 'st0', 'id','@abs_srcdir@/export_stats.dmp');
+
+/*
+ * Delete stab function dbms_stats.import
+ */
+DROP FUNCTION dbms_stats.import(
+ nspname text,
+ relid regclass,
+ attname text,
+ src text
+);
+ALTER FUNCTION dbms_stats.truth_import(
+ nspname text,
+ relid regclass,
+ attname text,
+ src text
+) RENAME TO import;
diff --git a/output/ut_imp_exp-9.1.source b/output/ut_imp_exp-9.1.source
new file mode 100644
index 0000000..26f270b
--- /dev/null
+++ b/output/ut_imp_exp-9.1.source
@@ -0,0 +1,1963 @@
+\pset null '(null)'
+CREATE TABLE s0.st3();
+/*
+ * No.16-1 export_plain_stats.sql.sample
+ */
+-- No.16-1-1
+ANALYZE;
+DELETE FROM dbms_stats._column_stats_locked;
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+ s0.st3
+(15 rows)
+
+UPDATE dbms_stats._relation_stats_locked
+ SET (relpages, reltuples, curpages) = (0,0,0);
+UPDATE dbms_stats._column_stats_locked SET
+ stanullfrac = -staattnum,
+ stawidth = -staattnum,
+ stadistinct = -staattnum,
+ stakind1 = 2,
+ stakind2 = 3,
+ stakind3 = 4,
+ stakind4 = 1,
+ staop1 = 22,
+ staop2 = 23,
+ staop3 = 24,
+ staop4 = 21,
+ stanumbers1 = ARRAY[-staattnum,22],
+ stanumbers2 = ARRAY[-staattnum,23],
+ stanumbers3 = ARRAY[-staattnum,24],
+ stanumbers4 = ARRAY[-staattnum,21],
+ stavalues1 = stavalues3,
+ stavalues2 = stavalues2,
+ stavalues3 = stavalues1,
+ stavalues4 = stavalues4;
+\i export_plain_stats.sql.sample
+/*
+ * If you want the statistics of per-relation or per-column, please modify
+ * nspname, relname, and attname in 'WHERE' clause.
+ */
+BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+/*
+ * If you want to chage the output file name, please modify the following name.
+ */
+\o export_stats.dmp
+COPY (SELECT n2.nspname,
+ c.relname,
+ c.relpages,
+ c.reltuples,
+ (pg_relation_size(c.oid) / current_setting('block_size')::int4)::int4
+ AS curpages,
+ pg_catalog.pg_stat_get_last_analyze_time(c.oid)
+ AS last_analyze,
+ pg_catalog.pg_stat_get_last_autoanalyze_time(c.oid)
+ AS last_autoanalyze,
+ COALESCE(a.attname, ''),
+ n1.nspname AS schemaname_of_atttype,
+ t.typname,
+ a.atttypmod,
+ s.stainherit,
+ s.stanullfrac,
+ s.stawidth,
+ s.stadistinct,
+ s.stakind1,
+ s.stakind2,
+ s.stakind3,
+ s.stakind4,
+ s.staop1,
+ s.staop2,
+ s.staop3,
+ s.staop4,
+ s.stanumbers1,
+ s.stanumbers2,
+ s.stanumbers3,
+ s.stanumbers4,
+ s.stavalues1,
+ s.stavalues2,
+ s.stavalues3,
+ s.stavalues4
+ FROM pg_statistic s
+ JOIN pg_attribute a
+ ON (s.starelid = a.attrelid AND s.staattnum = a.attnum)
+ JOIN pg_type t
+ ON a.atttypid = t.oid
+ JOIN pg_namespace n1
+ ON t.typnamespace = n1.oid
+ RIGHT JOIN pg_catalog.pg_class c
+ ON s.starelid = c.oid
+ JOIN pg_catalog.pg_namespace n2
+ ON c.relnamespace = n2.oid
+ WHERE c.relkind IN ('r', 'i')
+ AND NOT n2.nspname IN ('pg_catalog',
+ 'pg_toast',
+ 'information_schema',
+ 'dbms_stats')
+ -- AND n2.nspname = 'public'
+ -- AND c.relname = 'test'
+ -- AND a.attname = 'id'
+ ORDER BY starelid, staattnum)
+TO STDOUT
+(FORMAT 'binary');
+\o
+COMMIT;
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+ nspname | relname | relpages | reltuples | curpages | attname | nspname_of_typename | typname | atttypmod | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+---------+---------+----------+-----------+----------+---------+---------------------+---------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+------------------------+-------------+-------------+-------------+------------------+------------+------------+------------
+ public | pt0 | 0 | 0 | 0 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ public | pt0_idx | 2 | 0 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ public | st0 | 1 | 2 | 1 | id | pg_catalog | int4 | -1 | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2} | (null) | (null) | (null)
+ public | st0 | 1 | 2 | 1 | name | pg_catalog | bpchar | 9 | f | 0 | 6 | -0.5 | 1 | 3 | 0 | 0 | 1054 | 1058 | 0 | 0 | {1} | {1} | (null) | (null) | {"test "} | (null) | (null) | (null)
+ public | st0_idx | 2 | 2 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ public | st1 | 45 | 10000 | 45 | str | pg_catalog | text | -1 | f | 0 | 2 | 3 | 1 | 3 | 0 | 0 | 98 | 664 | 0 | 0 | {0.3334,0.3333,0.3333} | {0.3332} | (null) | (null) | {1,0,2} | (null) | (null) | (null)
+ public | st1 | 45 | 10000 | 45 | val | pg_catalog | int4 | -1 | f | 0 | 4 | 3 | 1 | 3 | 0 | 0 | 96 | 97 | 0 | 0 | {0.3334,0.3333,0.3333} | {0.3332} | (null) | (null) | {1,0,2} | (null) | (null) | (null)
+ public | st1_exp | 30 | 10000 | 30 | lower | pg_catalog | text | -1 | f | 0 | 5 | 3 | 1 | 3 | 0 | 0 | 98 | 664 | 0 | 0 | {0.3334,0.3333,0.3333} | {0.3332} | (null) | (null) | {1,0,2} | (null) | (null) | (null)
+ public | st1_idx | 30 | 10000 | 30 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | st0 | 1 | 2 | 1 | id | pg_catalog | int4 | -1 | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2} | (null) | (null) | (null)
+ s0 | st0 | 1 | 2 | 1 | id | pg_catalog | int4 | -1 | t | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2,4,5,6} | (null) | (null) | (null)
+ s0 | st0 | 1 | 2 | 1 | num | pg_catalog | int4 | -1 | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {10,20} | (null) | (null) | (null)
+ s0 | st0 | 1 | 2 | 1 | num | pg_catalog | int4 | -1 | t | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {10,20,40,50,60} | (null) | (null) | (null)
+ s0 | st0_idx | 2 | 2 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | st1 | 1 | 3 | 1 | id | pg_catalog | int4 | -1 | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {4,5,6} | (null) | (null) | (null)
+ s0 | st1 | 1 | 3 | 1 | num | pg_catalog | int4 | -1 | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {40,50,60} | (null) | (null) | (null)
+ s0 | st1_idx | 2 | 3 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | st2 | 1 | 3 | 1 | id | pg_catalog | int4 | -1 | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2,3} | (null) | (null) | (null)
+ s0 | st2 | 1 | 3 | 1 | txt | pg_catalog | text | -1 | f | 0 | 5 | -1 | 2 | 3 | 0 | 0 | 664 | 664 | 0 | 0 | (null) | {0.5} | (null) | (null) | {1,comment,test} | (null) | (null) | (null)
+ s0 | st2_idx | 2 | 3 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | st3 | 0 | 0 | 0 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s1 | st0 | 1 | 4 | 1 | id | pg_catalog | int4 | -1 | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2,3,4} | (null) | (null) | (null)
+ s1 | st0 | 1 | 4 | 1 | num | pg_catalog | int4 | -1 | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {15,25,35,45} | (null) | (null) | (null)
+(23 rows)
+
+TRUNCATE dbms_stats.work;
+-- No.16-1-2
+\! sed '/ORDER/i\\ AND n2.nspname = '"\'s0\'" export_plain_stats.sql.sample > export_plain_stats.sql.sample_test
+\i export_plain_stats.sql.sample_test
+/*
+ * If you want the statistics of per-relation or per-column, please modify
+ * nspname, relname, and attname in 'WHERE' clause.
+ */
+BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+/*
+ * If you want to chage the output file name, please modify the following name.
+ */
+\o export_stats.dmp
+COPY (SELECT n2.nspname,
+ c.relname,
+ c.relpages,
+ c.reltuples,
+ (pg_relation_size(c.oid) / current_setting('block_size')::int4)::int4
+ AS curpages,
+ pg_catalog.pg_stat_get_last_analyze_time(c.oid)
+ AS last_analyze,
+ pg_catalog.pg_stat_get_last_autoanalyze_time(c.oid)
+ AS last_autoanalyze,
+ COALESCE(a.attname, ''),
+ n1.nspname AS schemaname_of_atttype,
+ t.typname,
+ a.atttypmod,
+ s.stainherit,
+ s.stanullfrac,
+ s.stawidth,
+ s.stadistinct,
+ s.stakind1,
+ s.stakind2,
+ s.stakind3,
+ s.stakind4,
+ s.staop1,
+ s.staop2,
+ s.staop3,
+ s.staop4,
+ s.stanumbers1,
+ s.stanumbers2,
+ s.stanumbers3,
+ s.stanumbers4,
+ s.stavalues1,
+ s.stavalues2,
+ s.stavalues3,
+ s.stavalues4
+ FROM pg_statistic s
+ JOIN pg_attribute a
+ ON (s.starelid = a.attrelid AND s.staattnum = a.attnum)
+ JOIN pg_type t
+ ON a.atttypid = t.oid
+ JOIN pg_namespace n1
+ ON t.typnamespace = n1.oid
+ RIGHT JOIN pg_catalog.pg_class c
+ ON s.starelid = c.oid
+ JOIN pg_catalog.pg_namespace n2
+ ON c.relnamespace = n2.oid
+ WHERE c.relkind IN ('r', 'i')
+ AND NOT n2.nspname IN ('pg_catalog',
+ 'pg_toast',
+ 'information_schema',
+ 'dbms_stats')
+ -- AND n2.nspname = 'public'
+ -- AND c.relname = 'test'
+ -- AND a.attname = 'id'
+ AND n2.nspname = 's0'
+ ORDER BY starelid, staattnum)
+TO STDOUT
+(FORMAT 'binary');
+\o
+COMMIT;
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+ nspname | relname | relpages | reltuples | curpages | attname | nspname_of_typename | typname | atttypmod | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+---------+---------+----------+-----------+----------+---------+---------------------+---------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+------------------+------------+------------+------------
+ s0 | st0 | 1 | 2 | 1 | id | pg_catalog | int4 | -1 | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2} | (null) | (null) | (null)
+ s0 | st0 | 1 | 2 | 1 | id | pg_catalog | int4 | -1 | t | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2,4,5,6} | (null) | (null) | (null)
+ s0 | st0 | 1 | 2 | 1 | num | pg_catalog | int4 | -1 | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {10,20} | (null) | (null) | (null)
+ s0 | st0 | 1 | 2 | 1 | num | pg_catalog | int4 | -1 | t | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {10,20,40,50,60} | (null) | (null) | (null)
+ s0 | st0_idx | 2 | 2 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | st1 | 1 | 3 | 1 | id | pg_catalog | int4 | -1 | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {4,5,6} | (null) | (null) | (null)
+ s0 | st1 | 1 | 3 | 1 | num | pg_catalog | int4 | -1 | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {40,50,60} | (null) | (null) | (null)
+ s0 | st1_idx | 2 | 3 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | st2 | 1 | 3 | 1 | id | pg_catalog | int4 | -1 | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2,3} | (null) | (null) | (null)
+ s0 | st2 | 1 | 3 | 1 | txt | pg_catalog | text | -1 | f | 0 | 5 | -1 | 2 | 3 | 0 | 0 | 664 | 664 | 0 | 0 | (null) | {0.5} | (null) | (null) | {1,comment,test} | (null) | (null) | (null)
+ s0 | st2_idx | 2 | 3 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | st3 | 0 | 0 | 0 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+(12 rows)
+
+TRUNCATE dbms_stats.work;
+\! rm export_plain_stats.sql.sample_test
+-- No.16-1-3
+\! sed '/ORDER/i\\ AND c.relname = '"\'st0\'" export_plain_stats.sql.sample > export_plain_stats.sql.sample_test
+\i export_plain_stats.sql.sample_test
+/*
+ * If you want the statistics of per-relation or per-column, please modify
+ * nspname, relname, and attname in 'WHERE' clause.
+ */
+BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+/*
+ * If you want to chage the output file name, please modify the following name.
+ */
+\o export_stats.dmp
+COPY (SELECT n2.nspname,
+ c.relname,
+ c.relpages,
+ c.reltuples,
+ (pg_relation_size(c.oid) / current_setting('block_size')::int4)::int4
+ AS curpages,
+ pg_catalog.pg_stat_get_last_analyze_time(c.oid)
+ AS last_analyze,
+ pg_catalog.pg_stat_get_last_autoanalyze_time(c.oid)
+ AS last_autoanalyze,
+ COALESCE(a.attname, ''),
+ n1.nspname AS schemaname_of_atttype,
+ t.typname,
+ a.atttypmod,
+ s.stainherit,
+ s.stanullfrac,
+ s.stawidth,
+ s.stadistinct,
+ s.stakind1,
+ s.stakind2,
+ s.stakind3,
+ s.stakind4,
+ s.staop1,
+ s.staop2,
+ s.staop3,
+ s.staop4,
+ s.stanumbers1,
+ s.stanumbers2,
+ s.stanumbers3,
+ s.stanumbers4,
+ s.stavalues1,
+ s.stavalues2,
+ s.stavalues3,
+ s.stavalues4
+ FROM pg_statistic s
+ JOIN pg_attribute a
+ ON (s.starelid = a.attrelid AND s.staattnum = a.attnum)
+ JOIN pg_type t
+ ON a.atttypid = t.oid
+ JOIN pg_namespace n1
+ ON t.typnamespace = n1.oid
+ RIGHT JOIN pg_catalog.pg_class c
+ ON s.starelid = c.oid
+ JOIN pg_catalog.pg_namespace n2
+ ON c.relnamespace = n2.oid
+ WHERE c.relkind IN ('r', 'i')
+ AND NOT n2.nspname IN ('pg_catalog',
+ 'pg_toast',
+ 'information_schema',
+ 'dbms_stats')
+ -- AND n2.nspname = 'public'
+ -- AND c.relname = 'test'
+ -- AND a.attname = 'id'
+ AND c.relname = 'st0'
+ ORDER BY starelid, staattnum)
+TO STDOUT
+(FORMAT 'binary');
+\o
+COMMIT;
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+ nspname | relname | relpages | reltuples | curpages | attname | nspname_of_typename | typname | atttypmod | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+---------+---------+----------+-----------+----------+---------+---------------------+---------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+------------------+------------+------------+------------
+ public | st0 | 1 | 2 | 1 | id | pg_catalog | int4 | -1 | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2} | (null) | (null) | (null)
+ public | st0 | 1 | 2 | 1 | name | pg_catalog | bpchar | 9 | f | 0 | 6 | -0.5 | 1 | 3 | 0 | 0 | 1054 | 1058 | 0 | 0 | {1} | {1} | (null) | (null) | {"test "} | (null) | (null) | (null)
+ s0 | st0 | 1 | 2 | 1 | id | pg_catalog | int4 | -1 | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2} | (null) | (null) | (null)
+ s0 | st0 | 1 | 2 | 1 | id | pg_catalog | int4 | -1 | t | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2,4,5,6} | (null) | (null) | (null)
+ s0 | st0 | 1 | 2 | 1 | num | pg_catalog | int4 | -1 | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {10,20} | (null) | (null) | (null)
+ s0 | st0 | 1 | 2 | 1 | num | pg_catalog | int4 | -1 | t | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {10,20,40,50,60} | (null) | (null) | (null)
+ s1 | st0 | 1 | 4 | 1 | id | pg_catalog | int4 | -1 | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2,3,4} | (null) | (null) | (null)
+ s1 | st0 | 1 | 4 | 1 | num | pg_catalog | int4 | -1 | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {15,25,35,45} | (null) | (null) | (null)
+(8 rows)
+
+TRUNCATE dbms_stats.work;
+\! rm export_plain_stats.sql.sample_test
+-- No.16-1-4
+\! sed '/ORDER/i\\ AND c.relname = '"\'pg_toast_1262\'" export_plain_stats.sql.sample > export_plain_stats.sql.sample_test
+\i export_plain_stats.sql.sample_test
+/*
+ * If you want the statistics of per-relation or per-column, please modify
+ * nspname, relname, and attname in 'WHERE' clause.
+ */
+BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+/*
+ * If you want to chage the output file name, please modify the following name.
+ */
+\o export_stats.dmp
+COPY (SELECT n2.nspname,
+ c.relname,
+ c.relpages,
+ c.reltuples,
+ (pg_relation_size(c.oid) / current_setting('block_size')::int4)::int4
+ AS curpages,
+ pg_catalog.pg_stat_get_last_analyze_time(c.oid)
+ AS last_analyze,
+ pg_catalog.pg_stat_get_last_autoanalyze_time(c.oid)
+ AS last_autoanalyze,
+ COALESCE(a.attname, ''),
+ n1.nspname AS schemaname_of_atttype,
+ t.typname,
+ a.atttypmod,
+ s.stainherit,
+ s.stanullfrac,
+ s.stawidth,
+ s.stadistinct,
+ s.stakind1,
+ s.stakind2,
+ s.stakind3,
+ s.stakind4,
+ s.staop1,
+ s.staop2,
+ s.staop3,
+ s.staop4,
+ s.stanumbers1,
+ s.stanumbers2,
+ s.stanumbers3,
+ s.stanumbers4,
+ s.stavalues1,
+ s.stavalues2,
+ s.stavalues3,
+ s.stavalues4
+ FROM pg_statistic s
+ JOIN pg_attribute a
+ ON (s.starelid = a.attrelid AND s.staattnum = a.attnum)
+ JOIN pg_type t
+ ON a.atttypid = t.oid
+ JOIN pg_namespace n1
+ ON t.typnamespace = n1.oid
+ RIGHT JOIN pg_catalog.pg_class c
+ ON s.starelid = c.oid
+ JOIN pg_catalog.pg_namespace n2
+ ON c.relnamespace = n2.oid
+ WHERE c.relkind IN ('r', 'i')
+ AND NOT n2.nspname IN ('pg_catalog',
+ 'pg_toast',
+ 'information_schema',
+ 'dbms_stats')
+ -- AND n2.nspname = 'public'
+ -- AND c.relname = 'test'
+ -- AND a.attname = 'id'
+ AND c.relname = 'pg_toast_1262'
+ ORDER BY starelid, staattnum)
+TO STDOUT
+(FORMAT 'binary');
+\o
+COMMIT;
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+ nspname | relname | relpages | reltuples | curpages | attname | nspname_of_typename | typname | atttypmod | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+---------+---------+----------+-----------+----------+---------+---------------------+---------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+------------+------------+------------+------------
+(0 rows)
+
+TRUNCATE dbms_stats.work;
+\! rm export_plain_stats.sql.sample_test
+-- No.16-1-5
+\! sed '/ORDER/i\\ AND c.relname = '"\'st0_idx\'" export_plain_stats.sql.sample > export_plain_stats.sql.sample_test
+\i export_plain_stats.sql.sample_test
+/*
+ * If you want the statistics of per-relation or per-column, please modify
+ * nspname, relname, and attname in 'WHERE' clause.
+ */
+BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+/*
+ * If you want to chage the output file name, please modify the following name.
+ */
+\o export_stats.dmp
+COPY (SELECT n2.nspname,
+ c.relname,
+ c.relpages,
+ c.reltuples,
+ (pg_relation_size(c.oid) / current_setting('block_size')::int4)::int4
+ AS curpages,
+ pg_catalog.pg_stat_get_last_analyze_time(c.oid)
+ AS last_analyze,
+ pg_catalog.pg_stat_get_last_autoanalyze_time(c.oid)
+ AS last_autoanalyze,
+ COALESCE(a.attname, ''),
+ n1.nspname AS schemaname_of_atttype,
+ t.typname,
+ a.atttypmod,
+ s.stainherit,
+ s.stanullfrac,
+ s.stawidth,
+ s.stadistinct,
+ s.stakind1,
+ s.stakind2,
+ s.stakind3,
+ s.stakind4,
+ s.staop1,
+ s.staop2,
+ s.staop3,
+ s.staop4,
+ s.stanumbers1,
+ s.stanumbers2,
+ s.stanumbers3,
+ s.stanumbers4,
+ s.stavalues1,
+ s.stavalues2,
+ s.stavalues3,
+ s.stavalues4
+ FROM pg_statistic s
+ JOIN pg_attribute a
+ ON (s.starelid = a.attrelid AND s.staattnum = a.attnum)
+ JOIN pg_type t
+ ON a.atttypid = t.oid
+ JOIN pg_namespace n1
+ ON t.typnamespace = n1.oid
+ RIGHT JOIN pg_catalog.pg_class c
+ ON s.starelid = c.oid
+ JOIN pg_catalog.pg_namespace n2
+ ON c.relnamespace = n2.oid
+ WHERE c.relkind IN ('r', 'i')
+ AND NOT n2.nspname IN ('pg_catalog',
+ 'pg_toast',
+ 'information_schema',
+ 'dbms_stats')
+ -- AND n2.nspname = 'public'
+ -- AND c.relname = 'test'
+ -- AND a.attname = 'id'
+ AND c.relname = 'st0_idx'
+ ORDER BY starelid, staattnum)
+TO STDOUT
+(FORMAT 'binary');
+\o
+COMMIT;
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+ nspname | relname | relpages | reltuples | curpages | attname | nspname_of_typename | typname | atttypmod | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+---------+---------+----------+-----------+----------+---------+---------------------+---------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+------------+------------+------------+------------
+ public | st0_idx | 2 | 2 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | st0_idx | 2 | 2 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+(2 rows)
+
+TRUNCATE dbms_stats.work;
+\! rm export_plain_stats.sql.sample_test
+-- No.16-1-6
+\! sed '/ORDER/i\\ AND c.relname = '"\'ss0\'" export_plain_stats.sql.sample > export_plain_stats.sql.sample_test
+\i export_plain_stats.sql.sample_test
+/*
+ * If you want the statistics of per-relation or per-column, please modify
+ * nspname, relname, and attname in 'WHERE' clause.
+ */
+BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+/*
+ * If you want to chage the output file name, please modify the following name.
+ */
+\o export_stats.dmp
+COPY (SELECT n2.nspname,
+ c.relname,
+ c.relpages,
+ c.reltuples,
+ (pg_relation_size(c.oid) / current_setting('block_size')::int4)::int4
+ AS curpages,
+ pg_catalog.pg_stat_get_last_analyze_time(c.oid)
+ AS last_analyze,
+ pg_catalog.pg_stat_get_last_autoanalyze_time(c.oid)
+ AS last_autoanalyze,
+ COALESCE(a.attname, ''),
+ n1.nspname AS schemaname_of_atttype,
+ t.typname,
+ a.atttypmod,
+ s.stainherit,
+ s.stanullfrac,
+ s.stawidth,
+ s.stadistinct,
+ s.stakind1,
+ s.stakind2,
+ s.stakind3,
+ s.stakind4,
+ s.staop1,
+ s.staop2,
+ s.staop3,
+ s.staop4,
+ s.stanumbers1,
+ s.stanumbers2,
+ s.stanumbers3,
+ s.stanumbers4,
+ s.stavalues1,
+ s.stavalues2,
+ s.stavalues3,
+ s.stavalues4
+ FROM pg_statistic s
+ JOIN pg_attribute a
+ ON (s.starelid = a.attrelid AND s.staattnum = a.attnum)
+ JOIN pg_type t
+ ON a.atttypid = t.oid
+ JOIN pg_namespace n1
+ ON t.typnamespace = n1.oid
+ RIGHT JOIN pg_catalog.pg_class c
+ ON s.starelid = c.oid
+ JOIN pg_catalog.pg_namespace n2
+ ON c.relnamespace = n2.oid
+ WHERE c.relkind IN ('r', 'i')
+ AND NOT n2.nspname IN ('pg_catalog',
+ 'pg_toast',
+ 'information_schema',
+ 'dbms_stats')
+ -- AND n2.nspname = 'public'
+ -- AND c.relname = 'test'
+ -- AND a.attname = 'id'
+ AND c.relname = 'ss0'
+ ORDER BY starelid, staattnum)
+TO STDOUT
+(FORMAT 'binary');
+\o
+COMMIT;
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+ nspname | relname | relpages | reltuples | curpages | attname | nspname_of_typename | typname | atttypmod | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+---------+---------+----------+-----------+----------+---------+---------------------+---------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+------------+------------+------------+------------
+(0 rows)
+
+TRUNCATE dbms_stats.work;
+\! rm export_plain_stats.sql.sample_test
+-- No.16-1-7
+\! sed '/ORDER/i\\ AND c.relname = '"\'sc0\'" export_plain_stats.sql.sample > export_plain_stats.sql.sample_test
+\i export_plain_stats.sql.sample_test
+/*
+ * If you want the statistics of per-relation or per-column, please modify
+ * nspname, relname, and attname in 'WHERE' clause.
+ */
+BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+/*
+ * If you want to chage the output file name, please modify the following name.
+ */
+\o export_stats.dmp
+COPY (SELECT n2.nspname,
+ c.relname,
+ c.relpages,
+ c.reltuples,
+ (pg_relation_size(c.oid) / current_setting('block_size')::int4)::int4
+ AS curpages,
+ pg_catalog.pg_stat_get_last_analyze_time(c.oid)
+ AS last_analyze,
+ pg_catalog.pg_stat_get_last_autoanalyze_time(c.oid)
+ AS last_autoanalyze,
+ COALESCE(a.attname, ''),
+ n1.nspname AS schemaname_of_atttype,
+ t.typname,
+ a.atttypmod,
+ s.stainherit,
+ s.stanullfrac,
+ s.stawidth,
+ s.stadistinct,
+ s.stakind1,
+ s.stakind2,
+ s.stakind3,
+ s.stakind4,
+ s.staop1,
+ s.staop2,
+ s.staop3,
+ s.staop4,
+ s.stanumbers1,
+ s.stanumbers2,
+ s.stanumbers3,
+ s.stanumbers4,
+ s.stavalues1,
+ s.stavalues2,
+ s.stavalues3,
+ s.stavalues4
+ FROM pg_statistic s
+ JOIN pg_attribute a
+ ON (s.starelid = a.attrelid AND s.staattnum = a.attnum)
+ JOIN pg_type t
+ ON a.atttypid = t.oid
+ JOIN pg_namespace n1
+ ON t.typnamespace = n1.oid
+ RIGHT JOIN pg_catalog.pg_class c
+ ON s.starelid = c.oid
+ JOIN pg_catalog.pg_namespace n2
+ ON c.relnamespace = n2.oid
+ WHERE c.relkind IN ('r', 'i')
+ AND NOT n2.nspname IN ('pg_catalog',
+ 'pg_toast',
+ 'information_schema',
+ 'dbms_stats')
+ -- AND n2.nspname = 'public'
+ -- AND c.relname = 'test'
+ -- AND a.attname = 'id'
+ AND c.relname = 'sc0'
+ ORDER BY starelid, staattnum)
+TO STDOUT
+(FORMAT 'binary');
+\o
+COMMIT;
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+ nspname | relname | relpages | reltuples | curpages | attname | nspname_of_typename | typname | atttypmod | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+---------+---------+----------+-----------+----------+---------+---------------------+---------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+------------+------------+------------+------------
+(0 rows)
+
+TRUNCATE dbms_stats.work;
+\! rm export_plain_stats.sql.sample_test
+-- No.16-1-8
+\! sed '/ORDER/i\\ AND c.relname = '"\'sft0\'" export_plain_stats.sql.sample > export_plain_stats.sql.sample_test
+\i export_plain_stats.sql.sample_test
+/*
+ * If you want the statistics of per-relation or per-column, please modify
+ * nspname, relname, and attname in 'WHERE' clause.
+ */
+BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+/*
+ * If you want to chage the output file name, please modify the following name.
+ */
+\o export_stats.dmp
+COPY (SELECT n2.nspname,
+ c.relname,
+ c.relpages,
+ c.reltuples,
+ (pg_relation_size(c.oid) / current_setting('block_size')::int4)::int4
+ AS curpages,
+ pg_catalog.pg_stat_get_last_analyze_time(c.oid)
+ AS last_analyze,
+ pg_catalog.pg_stat_get_last_autoanalyze_time(c.oid)
+ AS last_autoanalyze,
+ COALESCE(a.attname, ''),
+ n1.nspname AS schemaname_of_atttype,
+ t.typname,
+ a.atttypmod,
+ s.stainherit,
+ s.stanullfrac,
+ s.stawidth,
+ s.stadistinct,
+ s.stakind1,
+ s.stakind2,
+ s.stakind3,
+ s.stakind4,
+ s.staop1,
+ s.staop2,
+ s.staop3,
+ s.staop4,
+ s.stanumbers1,
+ s.stanumbers2,
+ s.stanumbers3,
+ s.stanumbers4,
+ s.stavalues1,
+ s.stavalues2,
+ s.stavalues3,
+ s.stavalues4
+ FROM pg_statistic s
+ JOIN pg_attribute a
+ ON (s.starelid = a.attrelid AND s.staattnum = a.attnum)
+ JOIN pg_type t
+ ON a.atttypid = t.oid
+ JOIN pg_namespace n1
+ ON t.typnamespace = n1.oid
+ RIGHT JOIN pg_catalog.pg_class c
+ ON s.starelid = c.oid
+ JOIN pg_catalog.pg_namespace n2
+ ON c.relnamespace = n2.oid
+ WHERE c.relkind IN ('r', 'i')
+ AND NOT n2.nspname IN ('pg_catalog',
+ 'pg_toast',
+ 'information_schema',
+ 'dbms_stats')
+ -- AND n2.nspname = 'public'
+ -- AND c.relname = 'test'
+ -- AND a.attname = 'id'
+ AND c.relname = 'sft0'
+ ORDER BY starelid, staattnum)
+TO STDOUT
+(FORMAT 'binary');
+\o
+COMMIT;
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+ nspname | relname | relpages | reltuples | curpages | attname | nspname_of_typename | typname | atttypmod | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+---------+---------+----------+-----------+----------+---------+---------------------+---------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+------------+------------+------------+------------
+(0 rows)
+
+TRUNCATE dbms_stats.work;
+\! rm export_plain_stats.sql.sample_test
+-- No.16-1-9
+\! sed '/ORDER/i\\ AND n2.nspname = '"\'s0\'"' AND a.attname = '\'id\' export_plain_stats.sql.sample > export_plain_stats.sql.sample_test
+\i export_plain_stats.sql.sample_test
+/*
+ * If you want the statistics of per-relation or per-column, please modify
+ * nspname, relname, and attname in 'WHERE' clause.
+ */
+BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+/*
+ * If you want to chage the output file name, please modify the following name.
+ */
+\o export_stats.dmp
+COPY (SELECT n2.nspname,
+ c.relname,
+ c.relpages,
+ c.reltuples,
+ (pg_relation_size(c.oid) / current_setting('block_size')::int4)::int4
+ AS curpages,
+ pg_catalog.pg_stat_get_last_analyze_time(c.oid)
+ AS last_analyze,
+ pg_catalog.pg_stat_get_last_autoanalyze_time(c.oid)
+ AS last_autoanalyze,
+ COALESCE(a.attname, ''),
+ n1.nspname AS schemaname_of_atttype,
+ t.typname,
+ a.atttypmod,
+ s.stainherit,
+ s.stanullfrac,
+ s.stawidth,
+ s.stadistinct,
+ s.stakind1,
+ s.stakind2,
+ s.stakind3,
+ s.stakind4,
+ s.staop1,
+ s.staop2,
+ s.staop3,
+ s.staop4,
+ s.stanumbers1,
+ s.stanumbers2,
+ s.stanumbers3,
+ s.stanumbers4,
+ s.stavalues1,
+ s.stavalues2,
+ s.stavalues3,
+ s.stavalues4
+ FROM pg_statistic s
+ JOIN pg_attribute a
+ ON (s.starelid = a.attrelid AND s.staattnum = a.attnum)
+ JOIN pg_type t
+ ON a.atttypid = t.oid
+ JOIN pg_namespace n1
+ ON t.typnamespace = n1.oid
+ RIGHT JOIN pg_catalog.pg_class c
+ ON s.starelid = c.oid
+ JOIN pg_catalog.pg_namespace n2
+ ON c.relnamespace = n2.oid
+ WHERE c.relkind IN ('r', 'i')
+ AND NOT n2.nspname IN ('pg_catalog',
+ 'pg_toast',
+ 'information_schema',
+ 'dbms_stats')
+ -- AND n2.nspname = 'public'
+ -- AND c.relname = 'test'
+ -- AND a.attname = 'id'
+ AND n2.nspname = 's0' AND a.attname = 'id'
+ ORDER BY starelid, staattnum)
+TO STDOUT
+(FORMAT 'binary');
+\o
+COMMIT;
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+ nspname | relname | relpages | reltuples | curpages | attname | nspname_of_typename | typname | atttypmod | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+---------+---------+----------+-----------+----------+---------+---------------------+---------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------+------------+------------
+ s0 | st0 | 1 | 2 | 1 | id | pg_catalog | int4 | -1 | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2} | (null) | (null) | (null)
+ s0 | st0 | 1 | 2 | 1 | id | pg_catalog | int4 | -1 | t | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2,4,5,6} | (null) | (null) | (null)
+ s0 | st1 | 1 | 3 | 1 | id | pg_catalog | int4 | -1 | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {4,5,6} | (null) | (null) | (null)
+ s0 | st2 | 1 | 3 | 1 | id | pg_catalog | int4 | -1 | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2,3} | (null) | (null) | (null)
+(4 rows)
+
+TRUNCATE dbms_stats.work;
+\! rm export_plain_stats.sql.sample_test
+-- No.16-1-10
+\! sed '/ORDER/i\\ AND n2.nspname = '"\'s0\'"' AND a.attname IS NULL' export_plain_stats.sql.sample > export_plain_stats.sql.sample_test
+\i export_plain_stats.sql.sample_test
+/*
+ * If you want the statistics of per-relation or per-column, please modify
+ * nspname, relname, and attname in 'WHERE' clause.
+ */
+BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+/*
+ * If you want to chage the output file name, please modify the following name.
+ */
+\o export_stats.dmp
+COPY (SELECT n2.nspname,
+ c.relname,
+ c.relpages,
+ c.reltuples,
+ (pg_relation_size(c.oid) / current_setting('block_size')::int4)::int4
+ AS curpages,
+ pg_catalog.pg_stat_get_last_analyze_time(c.oid)
+ AS last_analyze,
+ pg_catalog.pg_stat_get_last_autoanalyze_time(c.oid)
+ AS last_autoanalyze,
+ COALESCE(a.attname, ''),
+ n1.nspname AS schemaname_of_atttype,
+ t.typname,
+ a.atttypmod,
+ s.stainherit,
+ s.stanullfrac,
+ s.stawidth,
+ s.stadistinct,
+ s.stakind1,
+ s.stakind2,
+ s.stakind3,
+ s.stakind4,
+ s.staop1,
+ s.staop2,
+ s.staop3,
+ s.staop4,
+ s.stanumbers1,
+ s.stanumbers2,
+ s.stanumbers3,
+ s.stanumbers4,
+ s.stavalues1,
+ s.stavalues2,
+ s.stavalues3,
+ s.stavalues4
+ FROM pg_statistic s
+ JOIN pg_attribute a
+ ON (s.starelid = a.attrelid AND s.staattnum = a.attnum)
+ JOIN pg_type t
+ ON a.atttypid = t.oid
+ JOIN pg_namespace n1
+ ON t.typnamespace = n1.oid
+ RIGHT JOIN pg_catalog.pg_class c
+ ON s.starelid = c.oid
+ JOIN pg_catalog.pg_namespace n2
+ ON c.relnamespace = n2.oid
+ WHERE c.relkind IN ('r', 'i')
+ AND NOT n2.nspname IN ('pg_catalog',
+ 'pg_toast',
+ 'information_schema',
+ 'dbms_stats')
+ -- AND n2.nspname = 'public'
+ -- AND c.relname = 'test'
+ -- AND a.attname = 'id'
+ AND n2.nspname = 's0' AND a.attname IS NULL
+ ORDER BY starelid, staattnum)
+TO STDOUT
+(FORMAT 'binary');
+\o
+COMMIT;
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+ nspname | relname | relpages | reltuples | curpages | attname | nspname_of_typename | typname | atttypmod | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+---------+---------+----------+-----------+----------+---------+---------------------+---------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+------------+------------+------------+------------
+ s0 | st0_idx | 2 | 2 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | st1_idx | 2 | 3 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | st2_idx | 2 | 3 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | st3 | 0 | 0 | 0 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+(4 rows)
+
+TRUNCATE dbms_stats.work;
+\! rm export_plain_stats.sql.sample_test
+-- No.16-1-11
+\! sed '/ORDER/i\\ AND n2.nspname = '"\'s1\'"' AND c.relname IS NULL' export_plain_stats.sql.sample > export_plain_stats.sql.sample_test
+\i export_plain_stats.sql.sample_test
+/*
+ * If you want the statistics of per-relation or per-column, please modify
+ * nspname, relname, and attname in 'WHERE' clause.
+ */
+BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+/*
+ * If you want to chage the output file name, please modify the following name.
+ */
+\o export_stats.dmp
+COPY (SELECT n2.nspname,
+ c.relname,
+ c.relpages,
+ c.reltuples,
+ (pg_relation_size(c.oid) / current_setting('block_size')::int4)::int4
+ AS curpages,
+ pg_catalog.pg_stat_get_last_analyze_time(c.oid)
+ AS last_analyze,
+ pg_catalog.pg_stat_get_last_autoanalyze_time(c.oid)
+ AS last_autoanalyze,
+ COALESCE(a.attname, ''),
+ n1.nspname AS schemaname_of_atttype,
+ t.typname,
+ a.atttypmod,
+ s.stainherit,
+ s.stanullfrac,
+ s.stawidth,
+ s.stadistinct,
+ s.stakind1,
+ s.stakind2,
+ s.stakind3,
+ s.stakind4,
+ s.staop1,
+ s.staop2,
+ s.staop3,
+ s.staop4,
+ s.stanumbers1,
+ s.stanumbers2,
+ s.stanumbers3,
+ s.stanumbers4,
+ s.stavalues1,
+ s.stavalues2,
+ s.stavalues3,
+ s.stavalues4
+ FROM pg_statistic s
+ JOIN pg_attribute a
+ ON (s.starelid = a.attrelid AND s.staattnum = a.attnum)
+ JOIN pg_type t
+ ON a.atttypid = t.oid
+ JOIN pg_namespace n1
+ ON t.typnamespace = n1.oid
+ RIGHT JOIN pg_catalog.pg_class c
+ ON s.starelid = c.oid
+ JOIN pg_catalog.pg_namespace n2
+ ON c.relnamespace = n2.oid
+ WHERE c.relkind IN ('r', 'i')
+ AND NOT n2.nspname IN ('pg_catalog',
+ 'pg_toast',
+ 'information_schema',
+ 'dbms_stats')
+ -- AND n2.nspname = 'public'
+ -- AND c.relname = 'test'
+ -- AND a.attname = 'id'
+ AND n2.nspname = 's1' AND c.relname IS NULL
+ ORDER BY starelid, staattnum)
+TO STDOUT
+(FORMAT 'binary');
+\o
+COMMIT;
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+ nspname | relname | relpages | reltuples | curpages | attname | nspname_of_typename | typname | atttypmod | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+---------+---------+----------+-----------+----------+---------+---------------------+---------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+------------+------------+------------+------------
+(0 rows)
+
+TRUNCATE dbms_stats.work;
+\! rm export_plain_stats.sql.sample_test
+/*
+ * No.16-2 export_effective_stats.sql.sample
+ */
+-- No.16-2-1
+VACUUM ANALYZE;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ st1_idx
+ st1_exp
+ s1.st0
+ s0.st3
+(15 rows)
+
+UPDATE dbms_stats._relation_stats_locked
+ SET (relpages, reltuples, curpages) = (NULL, NULL, NULL);
+UPDATE dbms_stats._column_stats_locked
+ SET (stanullfrac, stawidth, stadistinct,
+ stakind1, stakind2, stakind3, stakind4,
+ staop1, staop2, staop3, staop4,
+ stanumbers1, stanumbers2, stanumbers3, stanumbers4,
+ stavalues1, stavalues2, stavalues3, stavalues4)
+ = (NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL)
+ WHERE starelid = 's0.st0'::regclass;
+\i export_effective_stats.sql.sample
+/*
+ * If you want the statistics of per-relation or per-column, please modify
+ * nspname, relname, and attname in 'WHERE' clause.
+ */
+BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+/*
+ * If you want to chage the output file name, please modify the following name.
+ */
+\o export_stats.dmp
+COPY (SELECT n2.nspname,
+ cl.relname,
+ r.relpages,
+ r.reltuples,
+ r.curpages,
+ r.last_analyze,
+ r.last_autoanalyze,
+ COALESCE(a.attname, ''),
+ n1.nspname AS schemaname_of_atttype,
+ t.typname,
+ a.atttypmod,
+ co.stainherit,
+ co.stanullfrac,
+ co.stawidth,
+ co.stadistinct,
+ co.stakind1,
+ co.stakind2,
+ co.stakind3,
+ co.stakind4,
+ co.staop1,
+ co.staop2,
+ co.staop3,
+ co.staop4,
+ co.stanumbers1,
+ co.stanumbers2,
+ co.stanumbers3,
+ co.stanumbers4,
+ co.stavalues1,
+ co.stavalues2,
+ co.stavalues3,
+ co.stavalues4
+ FROM dbms_stats.column_stats_effective co
+ JOIN pg_attribute a
+ ON (co.starelid = a.attrelid AND co.staattnum = a.attnum)
+ JOIN pg_type t
+ ON a.atttypid = t.oid
+ JOIN pg_namespace n1
+ ON t.typnamespace = n1.oid
+ RIGHT JOIN dbms_stats.relation_stats_effective r
+ ON co.starelid = r.relid
+ JOIN pg_catalog.pg_class cl
+ ON r.relid = cl.oid
+ JOIN pg_catalog.pg_namespace n2
+ ON cl.relnamespace = n2.oid
+ -- WHERE n2.nspname = 'public'
+ -- AND cl.relname = 'test'
+ -- AND a.attname = 'id'
+ ORDER BY starelid, staattnum)
+TO STDOUT
+(FORMAT 'binary');
+\o
+COMMIT;
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+ nspname | relname | relpages | reltuples | curpages | attname | nspname_of_typename | typname | atttypmod | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+---------+---------+----------+-----------+----------+---------+---------------------+---------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+------------------+------------+------------------+------------
+ public | pt0 | 0 | 0 | 0 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ public | pt0_idx | 2 | 0 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ public | st0 | 1 | 2 | 1 | id | pg_catalog | int4 | -1 | f | -1 | -1 | -1 | 2 | 3 | 4 | 1 | 22 | 23 | 24 | 21 | {-1,22} | {-1,23} | {-1,24} | {-1,21} | (null) | (null) | {1,2} | (null)
+ public | st0 | 1 | 2 | 1 | name | pg_catalog | bpchar | 9 | f | -2 | -2 | -2 | 2 | 3 | 4 | 1 | 22 | 23 | 24 | 21 | {-2,22} | {-2,23} | {-2,24} | {-2,21} | (null) | (null) | {"test "} | (null)
+ public | st0_idx | 2 | 2 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ public | st1 | 45 | 10000 | 45 | str | pg_catalog | text | -1 | f | -2 | -2 | -2 | 2 | 3 | 4 | 1 | 22 | 23 | 24 | 21 | {-2,22} | {-2,23} | {-2,24} | {-2,21} | (null) | (null) | {1,0,2} | (null)
+ public | st1 | 45 | 10000 | 45 | val | pg_catalog | int4 | -1 | f | -1 | -1 | -1 | 2 | 3 | 4 | 1 | 22 | 23 | 24 | 21 | {-1,22} | {-1,23} | {-1,24} | {-1,21} | (null) | (null) | {1,0,2} | (null)
+ public | st1_exp | 30 | 10000 | 30 | lower | pg_catalog | text | -1 | f | -1 | -1 | -1 | 2 | 3 | 4 | 1 | 22 | 23 | 24 | 21 | {-1,22} | {-1,23} | {-1,24} | {-1,21} | (null) | (null) | {1,0,2} | (null)
+ public | st1_idx | 30 | 10000 | 30 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | st0 | 1 | 2 | 1 | id | pg_catalog | int4 | -1 | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2} | (null) | (null) | (null)
+ s0 | st0 | 1 | 2 | 1 | id | pg_catalog | int4 | -1 | t | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2,4,5,6} | (null) | (null) | (null)
+ s0 | st0 | 1 | 2 | 1 | num | pg_catalog | int4 | -1 | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {10,20} | (null) | (null) | (null)
+ s0 | st0 | 1 | 2 | 1 | num | pg_catalog | int4 | -1 | t | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {10,20,40,50,60} | (null) | (null) | (null)
+ s0 | st0_idx | 2 | 2 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | st1 | 1 | 3 | 1 | id | pg_catalog | int4 | -1 | f | -1 | -1 | -1 | 2 | 3 | 4 | 1 | 22 | 23 | 24 | 21 | {-1,22} | {-1,23} | {-1,24} | {-1,21} | (null) | (null) | {4,5,6} | (null)
+ s0 | st1 | 1 | 3 | 1 | num | pg_catalog | int4 | -1 | f | -2 | -2 | -2 | 2 | 3 | 4 | 1 | 22 | 23 | 24 | 21 | {-2,22} | {-2,23} | {-2,24} | {-2,21} | (null) | (null) | {40,50,60} | (null)
+ s0 | st1_idx | 2 | 3 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | st2 | 1 | 3 | 1 | id | pg_catalog | int4 | -1 | f | -1 | -1 | -1 | 2 | 3 | 4 | 1 | 22 | 23 | 24 | 21 | {-1,22} | {-1,23} | {-1,24} | {-1,21} | (null) | (null) | {1,2,3} | (null)
+ s0 | st2 | 1 | 3 | 1 | txt | pg_catalog | text | -1 | f | -2 | -2 | -2 | 2 | 3 | 4 | 1 | 22 | 23 | 24 | 21 | {-2,22} | {-2,23} | {-2,24} | {-2,21} | (null) | (null) | {1,comment,test} | (null)
+ s0 | st2_idx | 2 | 3 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | st3 | 0 | 0 | 0 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s1 | st0 | 1 | 4 | 1 | id | pg_catalog | int4 | -1 | f | -1 | -1 | -1 | 2 | 3 | 4 | 1 | 22 | 23 | 24 | 21 | {-1,22} | {-1,23} | {-1,24} | {-1,21} | (null) | (null) | {1,2,3,4} | (null)
+ s1 | st0 | 1 | 4 | 1 | num | pg_catalog | int4 | -1 | f | -2 | -2 | -2 | 2 | 3 | 4 | 1 | 22 | 23 | 24 | 21 | {-2,22} | {-2,23} | {-2,24} | {-2,21} | (null) | (null) | {15,25,35,45} | (null)
+(23 rows)
+
+TRUNCATE dbms_stats.work;
+-- No.16-2-2
+\! sed '/ORDER/i\\ WHERE n2.nspname = '"\'s0\'" export_effective_stats.sql.sample > export_effective_stats.sql.sample_test
+\i export_effective_stats.sql.sample_test
+/*
+ * If you want the statistics of per-relation or per-column, please modify
+ * nspname, relname, and attname in 'WHERE' clause.
+ */
+BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+/*
+ * If you want to chage the output file name, please modify the following name.
+ */
+\o export_stats.dmp
+COPY (SELECT n2.nspname,
+ cl.relname,
+ r.relpages,
+ r.reltuples,
+ r.curpages,
+ r.last_analyze,
+ r.last_autoanalyze,
+ COALESCE(a.attname, ''),
+ n1.nspname AS schemaname_of_atttype,
+ t.typname,
+ a.atttypmod,
+ co.stainherit,
+ co.stanullfrac,
+ co.stawidth,
+ co.stadistinct,
+ co.stakind1,
+ co.stakind2,
+ co.stakind3,
+ co.stakind4,
+ co.staop1,
+ co.staop2,
+ co.staop3,
+ co.staop4,
+ co.stanumbers1,
+ co.stanumbers2,
+ co.stanumbers3,
+ co.stanumbers4,
+ co.stavalues1,
+ co.stavalues2,
+ co.stavalues3,
+ co.stavalues4
+ FROM dbms_stats.column_stats_effective co
+ JOIN pg_attribute a
+ ON (co.starelid = a.attrelid AND co.staattnum = a.attnum)
+ JOIN pg_type t
+ ON a.atttypid = t.oid
+ JOIN pg_namespace n1
+ ON t.typnamespace = n1.oid
+ RIGHT JOIN dbms_stats.relation_stats_effective r
+ ON co.starelid = r.relid
+ JOIN pg_catalog.pg_class cl
+ ON r.relid = cl.oid
+ JOIN pg_catalog.pg_namespace n2
+ ON cl.relnamespace = n2.oid
+ -- WHERE n2.nspname = 'public'
+ -- AND cl.relname = 'test'
+ -- AND a.attname = 'id'
+ WHERE n2.nspname = 's0'
+ ORDER BY starelid, staattnum)
+TO STDOUT
+(FORMAT 'binary');
+\o
+COMMIT;
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+ nspname | relname | relpages | reltuples | curpages | attname | nspname_of_typename | typname | atttypmod | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+---------+---------+----------+-----------+----------+---------+---------------------+---------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+------------------+------------+------------------+------------
+ s0 | st0 | 1 | 2 | 1 | id | pg_catalog | int4 | -1 | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2} | (null) | (null) | (null)
+ s0 | st0 | 1 | 2 | 1 | id | pg_catalog | int4 | -1 | t | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2,4,5,6} | (null) | (null) | (null)
+ s0 | st0 | 1 | 2 | 1 | num | pg_catalog | int4 | -1 | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {10,20} | (null) | (null) | (null)
+ s0 | st0 | 1 | 2 | 1 | num | pg_catalog | int4 | -1 | t | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {10,20,40,50,60} | (null) | (null) | (null)
+ s0 | st0_idx | 2 | 2 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | st1 | 1 | 3 | 1 | id | pg_catalog | int4 | -1 | f | -1 | -1 | -1 | 2 | 3 | 4 | 1 | 22 | 23 | 24 | 21 | {-1,22} | {-1,23} | {-1,24} | {-1,21} | (null) | (null) | {4,5,6} | (null)
+ s0 | st1 | 1 | 3 | 1 | num | pg_catalog | int4 | -1 | f | -2 | -2 | -2 | 2 | 3 | 4 | 1 | 22 | 23 | 24 | 21 | {-2,22} | {-2,23} | {-2,24} | {-2,21} | (null) | (null) | {40,50,60} | (null)
+ s0 | st1_idx | 2 | 3 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | st2 | 1 | 3 | 1 | id | pg_catalog | int4 | -1 | f | -1 | -1 | -1 | 2 | 3 | 4 | 1 | 22 | 23 | 24 | 21 | {-1,22} | {-1,23} | {-1,24} | {-1,21} | (null) | (null) | {1,2,3} | (null)
+ s0 | st2 | 1 | 3 | 1 | txt | pg_catalog | text | -1 | f | -2 | -2 | -2 | 2 | 3 | 4 | 1 | 22 | 23 | 24 | 21 | {-2,22} | {-2,23} | {-2,24} | {-2,21} | (null) | (null) | {1,comment,test} | (null)
+ s0 | st2_idx | 2 | 3 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | st3 | 0 | 0 | 0 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+(12 rows)
+
+\! rm export_effective_stats.sql.sample_test
+TRUNCATE dbms_stats.work;
+-- No.16-2-3
+\! sed '/ORDER/i\\ WHERE cl.relname = '"\'st0\'" export_effective_stats.sql.sample > export_effective_stats.sql.sample_test
+\i export_effective_stats.sql.sample_test
+/*
+ * If you want the statistics of per-relation or per-column, please modify
+ * nspname, relname, and attname in 'WHERE' clause.
+ */
+BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+/*
+ * If you want to chage the output file name, please modify the following name.
+ */
+\o export_stats.dmp
+COPY (SELECT n2.nspname,
+ cl.relname,
+ r.relpages,
+ r.reltuples,
+ r.curpages,
+ r.last_analyze,
+ r.last_autoanalyze,
+ COALESCE(a.attname, ''),
+ n1.nspname AS schemaname_of_atttype,
+ t.typname,
+ a.atttypmod,
+ co.stainherit,
+ co.stanullfrac,
+ co.stawidth,
+ co.stadistinct,
+ co.stakind1,
+ co.stakind2,
+ co.stakind3,
+ co.stakind4,
+ co.staop1,
+ co.staop2,
+ co.staop3,
+ co.staop4,
+ co.stanumbers1,
+ co.stanumbers2,
+ co.stanumbers3,
+ co.stanumbers4,
+ co.stavalues1,
+ co.stavalues2,
+ co.stavalues3,
+ co.stavalues4
+ FROM dbms_stats.column_stats_effective co
+ JOIN pg_attribute a
+ ON (co.starelid = a.attrelid AND co.staattnum = a.attnum)
+ JOIN pg_type t
+ ON a.atttypid = t.oid
+ JOIN pg_namespace n1
+ ON t.typnamespace = n1.oid
+ RIGHT JOIN dbms_stats.relation_stats_effective r
+ ON co.starelid = r.relid
+ JOIN pg_catalog.pg_class cl
+ ON r.relid = cl.oid
+ JOIN pg_catalog.pg_namespace n2
+ ON cl.relnamespace = n2.oid
+ -- WHERE n2.nspname = 'public'
+ -- AND cl.relname = 'test'
+ -- AND a.attname = 'id'
+ WHERE cl.relname = 'st0'
+ ORDER BY starelid, staattnum)
+TO STDOUT
+(FORMAT 'binary');
+\o
+COMMIT;
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+ nspname | relname | relpages | reltuples | curpages | attname | nspname_of_typename | typname | atttypmod | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+---------+---------+----------+-----------+----------+---------+---------------------+---------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+------------------+------------+---------------+------------
+ public | st0 | 1 | 2 | 1 | id | pg_catalog | int4 | -1 | f | -1 | -1 | -1 | 2 | 3 | 4 | 1 | 22 | 23 | 24 | 21 | {-1,22} | {-1,23} | {-1,24} | {-1,21} | (null) | (null) | {1,2} | (null)
+ public | st0 | 1 | 2 | 1 | name | pg_catalog | bpchar | 9 | f | -2 | -2 | -2 | 2 | 3 | 4 | 1 | 22 | 23 | 24 | 21 | {-2,22} | {-2,23} | {-2,24} | {-2,21} | (null) | (null) | {"test "} | (null)
+ s0 | st0 | 1 | 2 | 1 | id | pg_catalog | int4 | -1 | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2} | (null) | (null) | (null)
+ s0 | st0 | 1 | 2 | 1 | id | pg_catalog | int4 | -1 | t | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2,4,5,6} | (null) | (null) | (null)
+ s0 | st0 | 1 | 2 | 1 | num | pg_catalog | int4 | -1 | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {10,20} | (null) | (null) | (null)
+ s0 | st0 | 1 | 2 | 1 | num | pg_catalog | int4 | -1 | t | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {10,20,40,50,60} | (null) | (null) | (null)
+ s1 | st0 | 1 | 4 | 1 | id | pg_catalog | int4 | -1 | f | -1 | -1 | -1 | 2 | 3 | 4 | 1 | 22 | 23 | 24 | 21 | {-1,22} | {-1,23} | {-1,24} | {-1,21} | (null) | (null) | {1,2,3,4} | (null)
+ s1 | st0 | 1 | 4 | 1 | num | pg_catalog | int4 | -1 | f | -2 | -2 | -2 | 2 | 3 | 4 | 1 | 22 | 23 | 24 | 21 | {-2,22} | {-2,23} | {-2,24} | {-2,21} | (null) | (null) | {15,25,35,45} | (null)
+(8 rows)
+
+\! rm export_effective_stats.sql.sample_test
+TRUNCATE dbms_stats.work;
+-- No.16-2-4
+\! sed '/ORDER/i\\ WHERE cl.relname = '"\'pg_toast_1262\'" export_effective_stats.sql.sample > export_effective_stats.sql.sample_test
+\i export_effective_stats.sql.sample_test
+/*
+ * If you want the statistics of per-relation or per-column, please modify
+ * nspname, relname, and attname in 'WHERE' clause.
+ */
+BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+/*
+ * If you want to chage the output file name, please modify the following name.
+ */
+\o export_stats.dmp
+COPY (SELECT n2.nspname,
+ cl.relname,
+ r.relpages,
+ r.reltuples,
+ r.curpages,
+ r.last_analyze,
+ r.last_autoanalyze,
+ COALESCE(a.attname, ''),
+ n1.nspname AS schemaname_of_atttype,
+ t.typname,
+ a.atttypmod,
+ co.stainherit,
+ co.stanullfrac,
+ co.stawidth,
+ co.stadistinct,
+ co.stakind1,
+ co.stakind2,
+ co.stakind3,
+ co.stakind4,
+ co.staop1,
+ co.staop2,
+ co.staop3,
+ co.staop4,
+ co.stanumbers1,
+ co.stanumbers2,
+ co.stanumbers3,
+ co.stanumbers4,
+ co.stavalues1,
+ co.stavalues2,
+ co.stavalues3,
+ co.stavalues4
+ FROM dbms_stats.column_stats_effective co
+ JOIN pg_attribute a
+ ON (co.starelid = a.attrelid AND co.staattnum = a.attnum)
+ JOIN pg_type t
+ ON a.atttypid = t.oid
+ JOIN pg_namespace n1
+ ON t.typnamespace = n1.oid
+ RIGHT JOIN dbms_stats.relation_stats_effective r
+ ON co.starelid = r.relid
+ JOIN pg_catalog.pg_class cl
+ ON r.relid = cl.oid
+ JOIN pg_catalog.pg_namespace n2
+ ON cl.relnamespace = n2.oid
+ -- WHERE n2.nspname = 'public'
+ -- AND cl.relname = 'test'
+ -- AND a.attname = 'id'
+ WHERE cl.relname = 'pg_toast_1262'
+ ORDER BY starelid, staattnum)
+TO STDOUT
+(FORMAT 'binary');
+\o
+COMMIT;
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+ nspname | relname | relpages | reltuples | curpages | attname | nspname_of_typename | typname | atttypmod | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+---------+---------+----------+-----------+----------+---------+---------------------+---------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+------------+------------+------------+------------
+(0 rows)
+
+\! rm export_effective_stats.sql.sample_test
+TRUNCATE dbms_stats.work;
+-- No.16-2-5
+\! sed '/ORDER/i\\ WHERE cl.relname = '"\'st0_idx\'" export_effective_stats.sql.sample > export_effective_stats.sql.sample_test
+\i export_effective_stats.sql.sample_test
+/*
+ * If you want the statistics of per-relation or per-column, please modify
+ * nspname, relname, and attname in 'WHERE' clause.
+ */
+BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+/*
+ * If you want to chage the output file name, please modify the following name.
+ */
+\o export_stats.dmp
+COPY (SELECT n2.nspname,
+ cl.relname,
+ r.relpages,
+ r.reltuples,
+ r.curpages,
+ r.last_analyze,
+ r.last_autoanalyze,
+ COALESCE(a.attname, ''),
+ n1.nspname AS schemaname_of_atttype,
+ t.typname,
+ a.atttypmod,
+ co.stainherit,
+ co.stanullfrac,
+ co.stawidth,
+ co.stadistinct,
+ co.stakind1,
+ co.stakind2,
+ co.stakind3,
+ co.stakind4,
+ co.staop1,
+ co.staop2,
+ co.staop3,
+ co.staop4,
+ co.stanumbers1,
+ co.stanumbers2,
+ co.stanumbers3,
+ co.stanumbers4,
+ co.stavalues1,
+ co.stavalues2,
+ co.stavalues3,
+ co.stavalues4
+ FROM dbms_stats.column_stats_effective co
+ JOIN pg_attribute a
+ ON (co.starelid = a.attrelid AND co.staattnum = a.attnum)
+ JOIN pg_type t
+ ON a.atttypid = t.oid
+ JOIN pg_namespace n1
+ ON t.typnamespace = n1.oid
+ RIGHT JOIN dbms_stats.relation_stats_effective r
+ ON co.starelid = r.relid
+ JOIN pg_catalog.pg_class cl
+ ON r.relid = cl.oid
+ JOIN pg_catalog.pg_namespace n2
+ ON cl.relnamespace = n2.oid
+ -- WHERE n2.nspname = 'public'
+ -- AND cl.relname = 'test'
+ -- AND a.attname = 'id'
+ WHERE cl.relname = 'st0_idx'
+ ORDER BY starelid, staattnum)
+TO STDOUT
+(FORMAT 'binary');
+\o
+COMMIT;
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+ nspname | relname | relpages | reltuples | curpages | attname | nspname_of_typename | typname | atttypmod | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+---------+---------+----------+-----------+----------+---------+---------------------+---------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+------------+------------+------------+------------
+ public | st0_idx | 2 | 2 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | st0_idx | 2 | 2 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+(2 rows)
+
+\! rm export_effective_stats.sql.sample_test
+TRUNCATE dbms_stats.work;
+-- No.16-2-6
+\! sed '/ORDER/i\\ WHERE cl.relname = '"\'ss0\'" export_effective_stats.sql.sample > export_effective_stats.sql.sample_test
+\i export_effective_stats.sql.sample_test
+/*
+ * If you want the statistics of per-relation or per-column, please modify
+ * nspname, relname, and attname in 'WHERE' clause.
+ */
+BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+/*
+ * If you want to chage the output file name, please modify the following name.
+ */
+\o export_stats.dmp
+COPY (SELECT n2.nspname,
+ cl.relname,
+ r.relpages,
+ r.reltuples,
+ r.curpages,
+ r.last_analyze,
+ r.last_autoanalyze,
+ COALESCE(a.attname, ''),
+ n1.nspname AS schemaname_of_atttype,
+ t.typname,
+ a.atttypmod,
+ co.stainherit,
+ co.stanullfrac,
+ co.stawidth,
+ co.stadistinct,
+ co.stakind1,
+ co.stakind2,
+ co.stakind3,
+ co.stakind4,
+ co.staop1,
+ co.staop2,
+ co.staop3,
+ co.staop4,
+ co.stanumbers1,
+ co.stanumbers2,
+ co.stanumbers3,
+ co.stanumbers4,
+ co.stavalues1,
+ co.stavalues2,
+ co.stavalues3,
+ co.stavalues4
+ FROM dbms_stats.column_stats_effective co
+ JOIN pg_attribute a
+ ON (co.starelid = a.attrelid AND co.staattnum = a.attnum)
+ JOIN pg_type t
+ ON a.atttypid = t.oid
+ JOIN pg_namespace n1
+ ON t.typnamespace = n1.oid
+ RIGHT JOIN dbms_stats.relation_stats_effective r
+ ON co.starelid = r.relid
+ JOIN pg_catalog.pg_class cl
+ ON r.relid = cl.oid
+ JOIN pg_catalog.pg_namespace n2
+ ON cl.relnamespace = n2.oid
+ -- WHERE n2.nspname = 'public'
+ -- AND cl.relname = 'test'
+ -- AND a.attname = 'id'
+ WHERE cl.relname = 'ss0'
+ ORDER BY starelid, staattnum)
+TO STDOUT
+(FORMAT 'binary');
+\o
+COMMIT;
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+ nspname | relname | relpages | reltuples | curpages | attname | nspname_of_typename | typname | atttypmod | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+---------+---------+----------+-----------+----------+---------+---------------------+---------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+------------+------------+------------+------------
+(0 rows)
+
+\! rm export_effective_stats.sql.sample_test
+TRUNCATE dbms_stats.work;
+-- No.16-2-7
+\! sed '/ORDER/i\\ WHERE cl.relname = '"\'sc0\'" export_effective_stats.sql.sample > export_effective_stats.sql.sample_test
+\i export_effective_stats.sql.sample_test
+/*
+ * If you want the statistics of per-relation or per-column, please modify
+ * nspname, relname, and attname in 'WHERE' clause.
+ */
+BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+/*
+ * If you want to chage the output file name, please modify the following name.
+ */
+\o export_stats.dmp
+COPY (SELECT n2.nspname,
+ cl.relname,
+ r.relpages,
+ r.reltuples,
+ r.curpages,
+ r.last_analyze,
+ r.last_autoanalyze,
+ COALESCE(a.attname, ''),
+ n1.nspname AS schemaname_of_atttype,
+ t.typname,
+ a.atttypmod,
+ co.stainherit,
+ co.stanullfrac,
+ co.stawidth,
+ co.stadistinct,
+ co.stakind1,
+ co.stakind2,
+ co.stakind3,
+ co.stakind4,
+ co.staop1,
+ co.staop2,
+ co.staop3,
+ co.staop4,
+ co.stanumbers1,
+ co.stanumbers2,
+ co.stanumbers3,
+ co.stanumbers4,
+ co.stavalues1,
+ co.stavalues2,
+ co.stavalues3,
+ co.stavalues4
+ FROM dbms_stats.column_stats_effective co
+ JOIN pg_attribute a
+ ON (co.starelid = a.attrelid AND co.staattnum = a.attnum)
+ JOIN pg_type t
+ ON a.atttypid = t.oid
+ JOIN pg_namespace n1
+ ON t.typnamespace = n1.oid
+ RIGHT JOIN dbms_stats.relation_stats_effective r
+ ON co.starelid = r.relid
+ JOIN pg_catalog.pg_class cl
+ ON r.relid = cl.oid
+ JOIN pg_catalog.pg_namespace n2
+ ON cl.relnamespace = n2.oid
+ -- WHERE n2.nspname = 'public'
+ -- AND cl.relname = 'test'
+ -- AND a.attname = 'id'
+ WHERE cl.relname = 'sc0'
+ ORDER BY starelid, staattnum)
+TO STDOUT
+(FORMAT 'binary');
+\o
+COMMIT;
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+ nspname | relname | relpages | reltuples | curpages | attname | nspname_of_typename | typname | atttypmod | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+---------+---------+----------+-----------+----------+---------+---------------------+---------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+------------+------------+------------+------------
+(0 rows)
+
+\! rm export_effective_stats.sql.sample_test
+TRUNCATE dbms_stats.work;
+-- No.16-2-8
+\! sed '/ORDER/i\\ WHERE cl.relname = '"\'sft0\'" export_effective_stats.sql.sample > export_effective_stats.sql.sample_test
+\i export_effective_stats.sql.sample_test
+/*
+ * If you want the statistics of per-relation or per-column, please modify
+ * nspname, relname, and attname in 'WHERE' clause.
+ */
+BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+/*
+ * If you want to chage the output file name, please modify the following name.
+ */
+\o export_stats.dmp
+COPY (SELECT n2.nspname,
+ cl.relname,
+ r.relpages,
+ r.reltuples,
+ r.curpages,
+ r.last_analyze,
+ r.last_autoanalyze,
+ COALESCE(a.attname, ''),
+ n1.nspname AS schemaname_of_atttype,
+ t.typname,
+ a.atttypmod,
+ co.stainherit,
+ co.stanullfrac,
+ co.stawidth,
+ co.stadistinct,
+ co.stakind1,
+ co.stakind2,
+ co.stakind3,
+ co.stakind4,
+ co.staop1,
+ co.staop2,
+ co.staop3,
+ co.staop4,
+ co.stanumbers1,
+ co.stanumbers2,
+ co.stanumbers3,
+ co.stanumbers4,
+ co.stavalues1,
+ co.stavalues2,
+ co.stavalues3,
+ co.stavalues4
+ FROM dbms_stats.column_stats_effective co
+ JOIN pg_attribute a
+ ON (co.starelid = a.attrelid AND co.staattnum = a.attnum)
+ JOIN pg_type t
+ ON a.atttypid = t.oid
+ JOIN pg_namespace n1
+ ON t.typnamespace = n1.oid
+ RIGHT JOIN dbms_stats.relation_stats_effective r
+ ON co.starelid = r.relid
+ JOIN pg_catalog.pg_class cl
+ ON r.relid = cl.oid
+ JOIN pg_catalog.pg_namespace n2
+ ON cl.relnamespace = n2.oid
+ -- WHERE n2.nspname = 'public'
+ -- AND cl.relname = 'test'
+ -- AND a.attname = 'id'
+ WHERE cl.relname = 'sft0'
+ ORDER BY starelid, staattnum)
+TO STDOUT
+(FORMAT 'binary');
+\o
+COMMIT;
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+ nspname | relname | relpages | reltuples | curpages | attname | nspname_of_typename | typname | atttypmod | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+---------+---------+----------+-----------+----------+---------+---------------------+---------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+------------+------------+------------+------------
+(0 rows)
+
+\! rm export_effective_stats.sql.sample_test
+TRUNCATE dbms_stats.work;
+-- No.16-2-9
+\! sed '/ORDER/i\\ WHERE n2.nspname = '"\'s0\'"' AND a.attname = '"\'id\'" export_effective_stats.sql.sample > export_effective_stats.sql.sample_test
+\i export_effective_stats.sql.sample_test
+/*
+ * If you want the statistics of per-relation or per-column, please modify
+ * nspname, relname, and attname in 'WHERE' clause.
+ */
+BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+/*
+ * If you want to chage the output file name, please modify the following name.
+ */
+\o export_stats.dmp
+COPY (SELECT n2.nspname,
+ cl.relname,
+ r.relpages,
+ r.reltuples,
+ r.curpages,
+ r.last_analyze,
+ r.last_autoanalyze,
+ COALESCE(a.attname, ''),
+ n1.nspname AS schemaname_of_atttype,
+ t.typname,
+ a.atttypmod,
+ co.stainherit,
+ co.stanullfrac,
+ co.stawidth,
+ co.stadistinct,
+ co.stakind1,
+ co.stakind2,
+ co.stakind3,
+ co.stakind4,
+ co.staop1,
+ co.staop2,
+ co.staop3,
+ co.staop4,
+ co.stanumbers1,
+ co.stanumbers2,
+ co.stanumbers3,
+ co.stanumbers4,
+ co.stavalues1,
+ co.stavalues2,
+ co.stavalues3,
+ co.stavalues4
+ FROM dbms_stats.column_stats_effective co
+ JOIN pg_attribute a
+ ON (co.starelid = a.attrelid AND co.staattnum = a.attnum)
+ JOIN pg_type t
+ ON a.atttypid = t.oid
+ JOIN pg_namespace n1
+ ON t.typnamespace = n1.oid
+ RIGHT JOIN dbms_stats.relation_stats_effective r
+ ON co.starelid = r.relid
+ JOIN pg_catalog.pg_class cl
+ ON r.relid = cl.oid
+ JOIN pg_catalog.pg_namespace n2
+ ON cl.relnamespace = n2.oid
+ -- WHERE n2.nspname = 'public'
+ -- AND cl.relname = 'test'
+ -- AND a.attname = 'id'
+ WHERE n2.nspname = 's0' AND a.attname = 'id'
+ ORDER BY starelid, staattnum)
+TO STDOUT
+(FORMAT 'binary');
+\o
+COMMIT;
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+ nspname | relname | relpages | reltuples | curpages | attname | nspname_of_typename | typname | atttypmod | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+---------+---------+----------+-----------+----------+---------+---------------------+---------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------+------------+------------
+ s0 | st0 | 1 | 2 | 1 | id | pg_catalog | int4 | -1 | f | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2} | (null) | (null) | (null)
+ s0 | st0 | 1 | 2 | 1 | id | pg_catalog | int4 | -1 | t | 0 | 4 | -1 | 2 | 3 | 0 | 0 | 97 | 97 | 0 | 0 | (null) | {1} | (null) | (null) | {1,2,4,5,6} | (null) | (null) | (null)
+ s0 | st1 | 1 | 3 | 1 | id | pg_catalog | int4 | -1 | f | -1 | -1 | -1 | 2 | 3 | 4 | 1 | 22 | 23 | 24 | 21 | {-1,22} | {-1,23} | {-1,24} | {-1,21} | (null) | (null) | {4,5,6} | (null)
+ s0 | st2 | 1 | 3 | 1 | id | pg_catalog | int4 | -1 | f | -1 | -1 | -1 | 2 | 3 | 4 | 1 | 22 | 23 | 24 | 21 | {-1,22} | {-1,23} | {-1,24} | {-1,21} | (null) | (null) | {1,2,3} | (null)
+(4 rows)
+
+\! rm export_effective_stats.sql.sample_test
+TRUNCATE dbms_stats.work;
+-- No.16-2-10
+\! sed '/ORDER/i\\ WHERE n2.nspname = '"\'s0\'"' AND a.attname IS NULL' export_effective_stats.sql.sample > export_effective_stats.sql.sample_test
+\i export_effective_stats.sql.sample_test
+/*
+ * If you want the statistics of per-relation or per-column, please modify
+ * nspname, relname, and attname in 'WHERE' clause.
+ */
+BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+/*
+ * If you want to chage the output file name, please modify the following name.
+ */
+\o export_stats.dmp
+COPY (SELECT n2.nspname,
+ cl.relname,
+ r.relpages,
+ r.reltuples,
+ r.curpages,
+ r.last_analyze,
+ r.last_autoanalyze,
+ COALESCE(a.attname, ''),
+ n1.nspname AS schemaname_of_atttype,
+ t.typname,
+ a.atttypmod,
+ co.stainherit,
+ co.stanullfrac,
+ co.stawidth,
+ co.stadistinct,
+ co.stakind1,
+ co.stakind2,
+ co.stakind3,
+ co.stakind4,
+ co.staop1,
+ co.staop2,
+ co.staop3,
+ co.staop4,
+ co.stanumbers1,
+ co.stanumbers2,
+ co.stanumbers3,
+ co.stanumbers4,
+ co.stavalues1,
+ co.stavalues2,
+ co.stavalues3,
+ co.stavalues4
+ FROM dbms_stats.column_stats_effective co
+ JOIN pg_attribute a
+ ON (co.starelid = a.attrelid AND co.staattnum = a.attnum)
+ JOIN pg_type t
+ ON a.atttypid = t.oid
+ JOIN pg_namespace n1
+ ON t.typnamespace = n1.oid
+ RIGHT JOIN dbms_stats.relation_stats_effective r
+ ON co.starelid = r.relid
+ JOIN pg_catalog.pg_class cl
+ ON r.relid = cl.oid
+ JOIN pg_catalog.pg_namespace n2
+ ON cl.relnamespace = n2.oid
+ -- WHERE n2.nspname = 'public'
+ -- AND cl.relname = 'test'
+ -- AND a.attname = 'id'
+ WHERE n2.nspname = 's0' AND a.attname IS NULL
+ ORDER BY starelid, staattnum)
+TO STDOUT
+(FORMAT 'binary');
+\o
+COMMIT;
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+ nspname | relname | relpages | reltuples | curpages | attname | nspname_of_typename | typname | atttypmod | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+---------+---------+----------+-----------+----------+---------+---------------------+---------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+------------+------------+------------+------------
+ s0 | st0_idx | 2 | 2 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | st1_idx | 2 | 3 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | st2_idx | 2 | 3 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | st3 | 0 | 0 | 0 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+(4 rows)
+
+\! rm export_effective_stats.sql.sample_test
+TRUNCATE dbms_stats.work;
+-- No.16-2-11
+\! sed '/ORDER/i\\ WHERE n2.nspname = '"\'s0\'"' AND cl.relname IS NULL' export_effective_stats.sql.sample > export_effective_stats.sql.sample_test
+\i export_effective_stats.sql.sample_test
+/*
+ * If you want the statistics of per-relation or per-column, please modify
+ * nspname, relname, and attname in 'WHERE' clause.
+ */
+BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+/*
+ * If you want to chage the output file name, please modify the following name.
+ */
+\o export_stats.dmp
+COPY (SELECT n2.nspname,
+ cl.relname,
+ r.relpages,
+ r.reltuples,
+ r.curpages,
+ r.last_analyze,
+ r.last_autoanalyze,
+ COALESCE(a.attname, ''),
+ n1.nspname AS schemaname_of_atttype,
+ t.typname,
+ a.atttypmod,
+ co.stainherit,
+ co.stanullfrac,
+ co.stawidth,
+ co.stadistinct,
+ co.stakind1,
+ co.stakind2,
+ co.stakind3,
+ co.stakind4,
+ co.staop1,
+ co.staop2,
+ co.staop3,
+ co.staop4,
+ co.stanumbers1,
+ co.stanumbers2,
+ co.stanumbers3,
+ co.stanumbers4,
+ co.stavalues1,
+ co.stavalues2,
+ co.stavalues3,
+ co.stavalues4
+ FROM dbms_stats.column_stats_effective co
+ JOIN pg_attribute a
+ ON (co.starelid = a.attrelid AND co.staattnum = a.attnum)
+ JOIN pg_type t
+ ON a.atttypid = t.oid
+ JOIN pg_namespace n1
+ ON t.typnamespace = n1.oid
+ RIGHT JOIN dbms_stats.relation_stats_effective r
+ ON co.starelid = r.relid
+ JOIN pg_catalog.pg_class cl
+ ON r.relid = cl.oid
+ JOIN pg_catalog.pg_namespace n2
+ ON cl.relnamespace = n2.oid
+ -- WHERE n2.nspname = 'public'
+ -- AND cl.relname = 'test'
+ -- AND a.attname = 'id'
+ WHERE n2.nspname = 's0' AND cl.relname IS NULL
+ ORDER BY starelid, staattnum)
+TO STDOUT
+(FORMAT 'binary');
+\o
+COMMIT;
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+ nspname | relname | relpages | reltuples | curpages | attname | nspname_of_typename | typname | atttypmod | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | staop1 | staop2 | staop3 | staop4 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stavalues1 | stavalues2 | stavalues3 | stavalues4
+---------+---------+----------+-----------+----------+---------+---------------------+---------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+------------+------------+------------+------------
+(0 rows)
+
+\! rm export_effective_stats.sql.sample_test
+TRUNCATE dbms_stats.work;
+/*
+ * Stab function dbms_stats.import
+ */
+ALTER FUNCTION dbms_stats.import(
+ nspname text,
+ relid regclass,
+ attname text,
+ src text
+) RENAME TO truth_import;
+CREATE FUNCTION dbms_stats.import(
+ nspname text,
+ relid regclass,
+ attname text,
+ src text
+) RETURNS void AS
+$$
+BEGIN
+ RAISE NOTICE 'arguments are "%", "%", "%", "%"', $1, $2, $3, $4;
+ RETURN;
+END
+$$
+LANGUAGE plpgsql;
+/*
+ * No.17-1 dbms_stats.import_database_stats(src)
+ */
+-- No.17-1-1
+SELECT dbms_stats.import_database_stats('@abs_srcdir@/export_stats.dmp');
+NOTICE: arguments are "", "", "", "@abs_srcdir@/export_stats.dmp"
+ import_database_stats
+-----------------------
+
+(1 row)
+
+/*
+ * No.17-2 dbms_stats.import_schema_stats(schemaname, src)
+ */
+-- No.17-2-1
+SELECT dbms_stats.import_schema_stats('s0', '@abs_srcdir@/export_stats.dmp');
+NOTICE: arguments are "s0", "", "", "@abs_srcdir@/export_stats.dmp"
+ import_schema_stats
+---------------------
+
+(1 row)
+
+/*
+ * No.17-3 dbms_stats.import_table_stats(relid, src)
+ */
+-- No.17-3-1
+SELECT dbms_stats.import_table_stats('s0.st0', '@abs_srcdir@/export_stats.dmp');
+NOTICE: arguments are "", "s0.st0", "", "@abs_srcdir@/export_stats.dmp"
+ import_table_stats
+--------------------
+
+(1 row)
+
+/*
+ * No.17-4 dbms_stats.import_table_stats(schemaname, tablename, src)
+ */
+-- No.17-4-1
+SELECT dbms_stats.import_table_stats('s0', 'st0', '@abs_srcdir@/export_stats.dmp');
+NOTICE: arguments are "", "s0.st0", "", "@abs_srcdir@/export_stats.dmp"
+ import_table_stats
+--------------------
+
+(1 row)
+
+/*
+ * No.17-5 dbms_stats.import_column_stats (relid, attname, src)
+ */
+-- No.17-5-1
+SELECT dbms_stats.import_column_stats('s0.st0', 'id', '@abs_srcdir@/export_stats.dmp');
+NOTICE: arguments are "", "s0.st0", "id", "@abs_srcdir@/export_stats.dmp"
+ import_column_stats
+---------------------
+
+(1 row)
+
+/*
+ * No.17-6 dbms_stats.import_column_stats (schemaname, tablename, attname, src)
+ */
+-- No.17-6-1
+SELECT dbms_stats.import_column_stats('s0', 'st0', 'id','@abs_srcdir@/export_stats.dmp');
+NOTICE: arguments are "", "s0.st0", "id", "@abs_srcdir@/export_stats.dmp"
+ import_column_stats
+---------------------
+
+(1 row)
+
+/*
+ * Delete stab function dbms_stats.import
+ */
+DROP FUNCTION dbms_stats.import(
+ nspname text,
+ relid regclass,
+ attname text,
+ src text
+);
+ALTER FUNCTION dbms_stats.truth_import(
+ nspname text,
+ relid regclass,
+ attname text,
+ src text
+) RENAME TO import;
diff --git a/output/ut_imp_exp-9.2.source b/output/ut_imp_exp-9.2.source
new file mode 100644
index 0000000..2049681
--- /dev/null
+++ b/output/ut_imp_exp-9.2.source
@@ -0,0 +1,2087 @@
+\pset null '(null)'
+CREATE TABLE s0.st3();
+/*
+ * No.16-1 export_plain_stats.sql.sample
+ */
+-- No.16-1-1
+ANALYZE;
+DELETE FROM dbms_stats._column_stats_locked;
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+ s0.st3
+(16 rows)
+
+UPDATE dbms_stats._relation_stats_locked
+ SET (relpages, reltuples, relallvisible, curpages) = (0,0,0,0);
+UPDATE dbms_stats._column_stats_locked SET
+ stanullfrac = -staattnum,
+ stawidth = -staattnum,
+ stadistinct = -staattnum,
+ stakind1 = 2,
+ stakind2 = 3,
+ stakind3 = 4,
+ stakind4 = 1,
+ stakind5 = 5,
+ staop1 = 22,
+ staop2 = 23,
+ staop3 = 24,
+ staop4 = 21,
+ staop5 = 25,
+ stanumbers1 = ARRAY[-staattnum,22],
+ stanumbers2 = ARRAY[-staattnum,23],
+ stanumbers3 = ARRAY[-staattnum,24],
+ stanumbers4 = ARRAY[-staattnum,21],
+ stanumbers5 = ARRAY[-staattnum,25],
+ stavalues1 = stavalues3,
+ stavalues2 = stavalues2,
+ stavalues3 = stavalues1,
+ stavalues4 = stavalues4,
+ stavalues5 = stavalues5;
+\i export_plain_stats.sql.sample
+/*
+ * If you want the statistics of per-relation or per-column, please modify
+ * nspname, relname, and attname in 'WHERE' clause.
+ */
+BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+/*
+ * If you want to chage the output file name, please modify the following name.
+ */
+\o export_stats.dmp
+COPY (SELECT n2.nspname,
+ c.relname,
+ c.relpages,
+ c.reltuples,
+ c.relallvisible,
+ (pg_relation_size(c.oid) / current_setting('block_size')::int4)::int4
+ AS curpages,
+ pg_catalog.pg_stat_get_last_analyze_time(c.oid)
+ AS last_analyze,
+ pg_catalog.pg_stat_get_last_autoanalyze_time(c.oid)
+ AS last_autoanalyze,
+ COALESCE(a.attname, ''),
+ n1.nspname AS schemaname_of_atttype,
+ t.typname,
+ a.atttypmod,
+ s.stainherit,
+ s.stanullfrac,
+ s.stawidth,
+ s.stadistinct,
+ s.stakind1,
+ s.stakind2,
+ s.stakind3,
+ s.stakind4,
+ s.stakind5,
+ s.staop1,
+ s.staop2,
+ s.staop3,
+ s.staop4,
+ s.staop5,
+ s.stanumbers1,
+ s.stanumbers2,
+ s.stanumbers3,
+ s.stanumbers4,
+ s.stanumbers5,
+ s.stavalues1,
+ s.stavalues2,
+ s.stavalues3,
+ s.stavalues4,
+ s.stavalues5
+ FROM pg_statistic s
+ JOIN pg_attribute a
+ ON (s.starelid = a.attrelid AND s.staattnum = a.attnum)
+ JOIN pg_type t
+ ON a.atttypid = t.oid
+ JOIN pg_namespace n1
+ ON t.typnamespace = n1.oid
+ RIGHT JOIN pg_catalog.pg_class c
+ ON s.starelid = c.oid
+ JOIN pg_catalog.pg_namespace n2
+ ON c.relnamespace = n2.oid
+ WHERE c.relkind IN ('r', 'i', 'f')
+ AND NOT n2.nspname IN ('pg_catalog',
+ 'pg_toast',
+ 'information_schema',
+ 'dbms_stats')
+ -- AND n2.nspname = 'public'
+ -- AND c.relname = 'test'
+ -- AND a.attname = 'id'
+ ORDER BY starelid, staattnum)
+TO STDOUT
+(FORMAT 'binary');
+\o
+COMMIT;
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+ nspname | relname | relpages | reltuples | relallvisible | curpages | attname | nspname_of_typename | typname | atttypmod | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 | stavalues1 | stavalues2 | stavalues3 | stavalues4 | stavalues5
+---------+---------+----------+-----------+---------------+----------+---------+---------------------+---------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+------------------------+-------------+-------------+-------------+-------------+------------------+------------+------------+------------+------------
+ public | pt0 | 0 | 0 | 0 | 0 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ public | pt0_idx | 2 | 0 | 0 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ public | st0 | 1 | 2 | 1 | 1 | id | pg_catalog | int4 | -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)
+ public | st0 | 1 | 2 | 1 | 1 | name | pg_catalog | bpchar | 9 | 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)
+ public | st0_idx | 2 | 2 | 0 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ public | st1 | 45 | 10000 | 45 | 45 | str | pg_catalog | text | -1 | 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)
+ public | st1 | 45 | 10000 | 45 | 45 | val | pg_catalog | int4 | -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)
+ public | st1_exp | 30 | 10000 | 0 | 30 | lower | pg_catalog | text | -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)
+ public | st1_idx | 30 | 10000 | 0 | 30 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | sft0 | 0 | 0 | 0 | 0 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | st0 | 1 | 2 | 1 | 1 | id | pg_catalog | int4 | -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)
+ s0 | st0 | 1 | 2 | 1 | 1 | id | pg_catalog | int4 | -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)
+ s0 | st0 | 1 | 2 | 1 | 1 | num | pg_catalog | int4 | -1 | 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)
+ s0 | st0 | 1 | 2 | 1 | 1 | num | pg_catalog | int4 | -1 | 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)
+ s0 | st0_idx | 2 | 2 | 0 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | st1 | 1 | 3 | 1 | 1 | id | pg_catalog | int4 | -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)
+ s0 | st1 | 1 | 3 | 1 | 1 | num | pg_catalog | int4 | -1 | 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)
+ s0 | st1_idx | 2 | 3 | 0 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | st2 | 1 | 3 | 1 | 1 | id | pg_catalog | int4 | -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)
+ s0 | st2 | 1 | 3 | 1 | 1 | txt | pg_catalog | text | -1 | 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)
+ s0 | st2_idx | 2 | 3 | 0 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | st3 | 0 | 0 | 0 | 0 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s1 | st0 | 1 | 4 | 1 | 1 | id | pg_catalog | int4 | -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)
+ s1 | st0 | 1 | 4 | 1 | 1 | num | pg_catalog | int4 | -1 | 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)
+(24 rows)
+
+TRUNCATE dbms_stats.work;
+-- No.16-1-2
+\! sed '/ORDER/i\\ AND n2.nspname = '"\'s0\'" export_plain_stats.sql.sample > export_plain_stats.sql.sample_test
+\i export_plain_stats.sql.sample_test
+/*
+ * If you want the statistics of per-relation or per-column, please modify
+ * nspname, relname, and attname in 'WHERE' clause.
+ */
+BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+/*
+ * If you want to chage the output file name, please modify the following name.
+ */
+\o export_stats.dmp
+COPY (SELECT n2.nspname,
+ c.relname,
+ c.relpages,
+ c.reltuples,
+ c.relallvisible,
+ (pg_relation_size(c.oid) / current_setting('block_size')::int4)::int4
+ AS curpages,
+ pg_catalog.pg_stat_get_last_analyze_time(c.oid)
+ AS last_analyze,
+ pg_catalog.pg_stat_get_last_autoanalyze_time(c.oid)
+ AS last_autoanalyze,
+ COALESCE(a.attname, ''),
+ n1.nspname AS schemaname_of_atttype,
+ t.typname,
+ a.atttypmod,
+ s.stainherit,
+ s.stanullfrac,
+ s.stawidth,
+ s.stadistinct,
+ s.stakind1,
+ s.stakind2,
+ s.stakind3,
+ s.stakind4,
+ s.stakind5,
+ s.staop1,
+ s.staop2,
+ s.staop3,
+ s.staop4,
+ s.staop5,
+ s.stanumbers1,
+ s.stanumbers2,
+ s.stanumbers3,
+ s.stanumbers4,
+ s.stanumbers5,
+ s.stavalues1,
+ s.stavalues2,
+ s.stavalues3,
+ s.stavalues4,
+ s.stavalues5
+ FROM pg_statistic s
+ JOIN pg_attribute a
+ ON (s.starelid = a.attrelid AND s.staattnum = a.attnum)
+ JOIN pg_type t
+ ON a.atttypid = t.oid
+ JOIN pg_namespace n1
+ ON t.typnamespace = n1.oid
+ RIGHT JOIN pg_catalog.pg_class c
+ ON s.starelid = c.oid
+ JOIN pg_catalog.pg_namespace n2
+ ON c.relnamespace = n2.oid
+ WHERE c.relkind IN ('r', 'i', 'f')
+ AND NOT n2.nspname IN ('pg_catalog',
+ 'pg_toast',
+ 'information_schema',
+ 'dbms_stats')
+ -- AND n2.nspname = 'public'
+ -- AND c.relname = 'test'
+ -- AND a.attname = 'id'
+ AND n2.nspname = 's0'
+ ORDER BY starelid, staattnum)
+TO STDOUT
+(FORMAT 'binary');
+\o
+COMMIT;
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+ nspname | relname | relpages | reltuples | relallvisible | curpages | attname | nspname_of_typename | typname | atttypmod | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 | stavalues1 | stavalues2 | stavalues3 | stavalues4 | stavalues5
+---------+---------+----------+-----------+---------------+----------+---------+---------------------+---------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------------+------------+------------+------------+------------
+ s0 | sft0 | 0 | 0 | 0 | 0 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | st0 | 1 | 2 | 1 | 1 | id | pg_catalog | int4 | -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)
+ s0 | st0 | 1 | 2 | 1 | 1 | id | pg_catalog | int4 | -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)
+ s0 | st0 | 1 | 2 | 1 | 1 | num | pg_catalog | int4 | -1 | 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)
+ s0 | st0 | 1 | 2 | 1 | 1 | num | pg_catalog | int4 | -1 | 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)
+ s0 | st0_idx | 2 | 2 | 0 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | st1 | 1 | 3 | 1 | 1 | id | pg_catalog | int4 | -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)
+ s0 | st1 | 1 | 3 | 1 | 1 | num | pg_catalog | int4 | -1 | 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)
+ s0 | st1_idx | 2 | 3 | 0 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | st2 | 1 | 3 | 1 | 1 | id | pg_catalog | int4 | -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)
+ s0 | st2 | 1 | 3 | 1 | 1 | txt | pg_catalog | text | -1 | 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)
+ s0 | st2_idx | 2 | 3 | 0 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | st3 | 0 | 0 | 0 | 0 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+(13 rows)
+
+TRUNCATE dbms_stats.work;
+\! rm export_plain_stats.sql.sample_test
+-- No.16-1-3
+\! sed '/ORDER/i\\ AND c.relname = '"\'st0\'" export_plain_stats.sql.sample > export_plain_stats.sql.sample_test
+\i export_plain_stats.sql.sample_test
+/*
+ * If you want the statistics of per-relation or per-column, please modify
+ * nspname, relname, and attname in 'WHERE' clause.
+ */
+BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+/*
+ * If you want to chage the output file name, please modify the following name.
+ */
+\o export_stats.dmp
+COPY (SELECT n2.nspname,
+ c.relname,
+ c.relpages,
+ c.reltuples,
+ c.relallvisible,
+ (pg_relation_size(c.oid) / current_setting('block_size')::int4)::int4
+ AS curpages,
+ pg_catalog.pg_stat_get_last_analyze_time(c.oid)
+ AS last_analyze,
+ pg_catalog.pg_stat_get_last_autoanalyze_time(c.oid)
+ AS last_autoanalyze,
+ COALESCE(a.attname, ''),
+ n1.nspname AS schemaname_of_atttype,
+ t.typname,
+ a.atttypmod,
+ s.stainherit,
+ s.stanullfrac,
+ s.stawidth,
+ s.stadistinct,
+ s.stakind1,
+ s.stakind2,
+ s.stakind3,
+ s.stakind4,
+ s.stakind5,
+ s.staop1,
+ s.staop2,
+ s.staop3,
+ s.staop4,
+ s.staop5,
+ s.stanumbers1,
+ s.stanumbers2,
+ s.stanumbers3,
+ s.stanumbers4,
+ s.stanumbers5,
+ s.stavalues1,
+ s.stavalues2,
+ s.stavalues3,
+ s.stavalues4,
+ s.stavalues5
+ FROM pg_statistic s
+ JOIN pg_attribute a
+ ON (s.starelid = a.attrelid AND s.staattnum = a.attnum)
+ JOIN pg_type t
+ ON a.atttypid = t.oid
+ JOIN pg_namespace n1
+ ON t.typnamespace = n1.oid
+ RIGHT JOIN pg_catalog.pg_class c
+ ON s.starelid = c.oid
+ JOIN pg_catalog.pg_namespace n2
+ ON c.relnamespace = n2.oid
+ WHERE c.relkind IN ('r', 'i', 'f')
+ AND NOT n2.nspname IN ('pg_catalog',
+ 'pg_toast',
+ 'information_schema',
+ 'dbms_stats')
+ -- AND n2.nspname = 'public'
+ -- AND c.relname = 'test'
+ -- AND a.attname = 'id'
+ AND c.relname = 'st0'
+ ORDER BY starelid, staattnum)
+TO STDOUT
+(FORMAT 'binary');
+\o
+COMMIT;
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+ nspname | relname | relpages | reltuples | relallvisible | curpages | attname | nspname_of_typename | typname | atttypmod | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 | stavalues1 | stavalues2 | stavalues3 | stavalues4 | stavalues5
+---------+---------+----------+-----------+---------------+----------+---------+---------------------+---------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------------+------------+------------+------------+------------
+ public | st0 | 1 | 2 | 1 | 1 | id | pg_catalog | int4 | -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)
+ public | st0 | 1 | 2 | 1 | 1 | name | pg_catalog | bpchar | 9 | 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)
+ s0 | st0 | 1 | 2 | 1 | 1 | id | pg_catalog | int4 | -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)
+ s0 | st0 | 1 | 2 | 1 | 1 | id | pg_catalog | int4 | -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)
+ s0 | st0 | 1 | 2 | 1 | 1 | num | pg_catalog | int4 | -1 | 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)
+ s0 | st0 | 1 | 2 | 1 | 1 | num | pg_catalog | int4 | -1 | 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)
+ s1 | st0 | 1 | 4 | 1 | 1 | id | pg_catalog | int4 | -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)
+ s1 | st0 | 1 | 4 | 1 | 1 | num | pg_catalog | int4 | -1 | 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)
+(8 rows)
+
+TRUNCATE dbms_stats.work;
+\! rm export_plain_stats.sql.sample_test
+-- No.16-1-4
+\! sed '/ORDER/i\\ AND c.relname = '"\'pg_toast_1262\'" export_plain_stats.sql.sample > export_plain_stats.sql.sample_test
+\i export_plain_stats.sql.sample_test
+/*
+ * If you want the statistics of per-relation or per-column, please modify
+ * nspname, relname, and attname in 'WHERE' clause.
+ */
+BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+/*
+ * If you want to chage the output file name, please modify the following name.
+ */
+\o export_stats.dmp
+COPY (SELECT n2.nspname,
+ c.relname,
+ c.relpages,
+ c.reltuples,
+ c.relallvisible,
+ (pg_relation_size(c.oid) / current_setting('block_size')::int4)::int4
+ AS curpages,
+ pg_catalog.pg_stat_get_last_analyze_time(c.oid)
+ AS last_analyze,
+ pg_catalog.pg_stat_get_last_autoanalyze_time(c.oid)
+ AS last_autoanalyze,
+ COALESCE(a.attname, ''),
+ n1.nspname AS schemaname_of_atttype,
+ t.typname,
+ a.atttypmod,
+ s.stainherit,
+ s.stanullfrac,
+ s.stawidth,
+ s.stadistinct,
+ s.stakind1,
+ s.stakind2,
+ s.stakind3,
+ s.stakind4,
+ s.stakind5,
+ s.staop1,
+ s.staop2,
+ s.staop3,
+ s.staop4,
+ s.staop5,
+ s.stanumbers1,
+ s.stanumbers2,
+ s.stanumbers3,
+ s.stanumbers4,
+ s.stanumbers5,
+ s.stavalues1,
+ s.stavalues2,
+ s.stavalues3,
+ s.stavalues4,
+ s.stavalues5
+ FROM pg_statistic s
+ JOIN pg_attribute a
+ ON (s.starelid = a.attrelid AND s.staattnum = a.attnum)
+ JOIN pg_type t
+ ON a.atttypid = t.oid
+ JOIN pg_namespace n1
+ ON t.typnamespace = n1.oid
+ RIGHT JOIN pg_catalog.pg_class c
+ ON s.starelid = c.oid
+ JOIN pg_catalog.pg_namespace n2
+ ON c.relnamespace = n2.oid
+ WHERE c.relkind IN ('r', 'i', 'f')
+ AND NOT n2.nspname IN ('pg_catalog',
+ 'pg_toast',
+ 'information_schema',
+ 'dbms_stats')
+ -- AND n2.nspname = 'public'
+ -- AND c.relname = 'test'
+ -- AND a.attname = 'id'
+ AND c.relname = 'pg_toast_1262'
+ ORDER BY starelid, staattnum)
+TO STDOUT
+(FORMAT 'binary');
+\o
+COMMIT;
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+ nspname | relname | relpages | reltuples | relallvisible | curpages | attname | nspname_of_typename | typname | atttypmod | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 | stavalues1 | stavalues2 | stavalues3 | stavalues4 | stavalues5
+---------+---------+----------+-----------+---------------+----------+---------+---------------------+---------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------+------------+------------+------------+------------
+(0 rows)
+
+TRUNCATE dbms_stats.work;
+\! rm export_plain_stats.sql.sample_test
+-- No.16-1-5
+\! sed '/ORDER/i\\ AND c.relname = '"\'st0_idx\'" export_plain_stats.sql.sample > export_plain_stats.sql.sample_test
+\i export_plain_stats.sql.sample_test
+/*
+ * If you want the statistics of per-relation or per-column, please modify
+ * nspname, relname, and attname in 'WHERE' clause.
+ */
+BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+/*
+ * If you want to chage the output file name, please modify the following name.
+ */
+\o export_stats.dmp
+COPY (SELECT n2.nspname,
+ c.relname,
+ c.relpages,
+ c.reltuples,
+ c.relallvisible,
+ (pg_relation_size(c.oid) / current_setting('block_size')::int4)::int4
+ AS curpages,
+ pg_catalog.pg_stat_get_last_analyze_time(c.oid)
+ AS last_analyze,
+ pg_catalog.pg_stat_get_last_autoanalyze_time(c.oid)
+ AS last_autoanalyze,
+ COALESCE(a.attname, ''),
+ n1.nspname AS schemaname_of_atttype,
+ t.typname,
+ a.atttypmod,
+ s.stainherit,
+ s.stanullfrac,
+ s.stawidth,
+ s.stadistinct,
+ s.stakind1,
+ s.stakind2,
+ s.stakind3,
+ s.stakind4,
+ s.stakind5,
+ s.staop1,
+ s.staop2,
+ s.staop3,
+ s.staop4,
+ s.staop5,
+ s.stanumbers1,
+ s.stanumbers2,
+ s.stanumbers3,
+ s.stanumbers4,
+ s.stanumbers5,
+ s.stavalues1,
+ s.stavalues2,
+ s.stavalues3,
+ s.stavalues4,
+ s.stavalues5
+ FROM pg_statistic s
+ JOIN pg_attribute a
+ ON (s.starelid = a.attrelid AND s.staattnum = a.attnum)
+ JOIN pg_type t
+ ON a.atttypid = t.oid
+ JOIN pg_namespace n1
+ ON t.typnamespace = n1.oid
+ RIGHT JOIN pg_catalog.pg_class c
+ ON s.starelid = c.oid
+ JOIN pg_catalog.pg_namespace n2
+ ON c.relnamespace = n2.oid
+ WHERE c.relkind IN ('r', 'i', 'f')
+ AND NOT n2.nspname IN ('pg_catalog',
+ 'pg_toast',
+ 'information_schema',
+ 'dbms_stats')
+ -- AND n2.nspname = 'public'
+ -- AND c.relname = 'test'
+ -- AND a.attname = 'id'
+ AND c.relname = 'st0_idx'
+ ORDER BY starelid, staattnum)
+TO STDOUT
+(FORMAT 'binary');
+\o
+COMMIT;
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+ nspname | relname | relpages | reltuples | relallvisible | curpages | attname | nspname_of_typename | typname | atttypmod | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 | stavalues1 | stavalues2 | stavalues3 | stavalues4 | stavalues5
+---------+---------+----------+-----------+---------------+----------+---------+---------------------+---------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------+------------+------------+------------+------------
+ public | st0_idx | 2 | 2 | 0 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | st0_idx | 2 | 2 | 0 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+(2 rows)
+
+TRUNCATE dbms_stats.work;
+\! rm export_plain_stats.sql.sample_test
+-- No.16-1-6
+\! sed '/ORDER/i\\ AND c.relname = '"\'ss0\'" export_plain_stats.sql.sample > export_plain_stats.sql.sample_test
+\i export_plain_stats.sql.sample_test
+/*
+ * If you want the statistics of per-relation or per-column, please modify
+ * nspname, relname, and attname in 'WHERE' clause.
+ */
+BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+/*
+ * If you want to chage the output file name, please modify the following name.
+ */
+\o export_stats.dmp
+COPY (SELECT n2.nspname,
+ c.relname,
+ c.relpages,
+ c.reltuples,
+ c.relallvisible,
+ (pg_relation_size(c.oid) / current_setting('block_size')::int4)::int4
+ AS curpages,
+ pg_catalog.pg_stat_get_last_analyze_time(c.oid)
+ AS last_analyze,
+ pg_catalog.pg_stat_get_last_autoanalyze_time(c.oid)
+ AS last_autoanalyze,
+ COALESCE(a.attname, ''),
+ n1.nspname AS schemaname_of_atttype,
+ t.typname,
+ a.atttypmod,
+ s.stainherit,
+ s.stanullfrac,
+ s.stawidth,
+ s.stadistinct,
+ s.stakind1,
+ s.stakind2,
+ s.stakind3,
+ s.stakind4,
+ s.stakind5,
+ s.staop1,
+ s.staop2,
+ s.staop3,
+ s.staop4,
+ s.staop5,
+ s.stanumbers1,
+ s.stanumbers2,
+ s.stanumbers3,
+ s.stanumbers4,
+ s.stanumbers5,
+ s.stavalues1,
+ s.stavalues2,
+ s.stavalues3,
+ s.stavalues4,
+ s.stavalues5
+ FROM pg_statistic s
+ JOIN pg_attribute a
+ ON (s.starelid = a.attrelid AND s.staattnum = a.attnum)
+ JOIN pg_type t
+ ON a.atttypid = t.oid
+ JOIN pg_namespace n1
+ ON t.typnamespace = n1.oid
+ RIGHT JOIN pg_catalog.pg_class c
+ ON s.starelid = c.oid
+ JOIN pg_catalog.pg_namespace n2
+ ON c.relnamespace = n2.oid
+ WHERE c.relkind IN ('r', 'i', 'f')
+ AND NOT n2.nspname IN ('pg_catalog',
+ 'pg_toast',
+ 'information_schema',
+ 'dbms_stats')
+ -- AND n2.nspname = 'public'
+ -- AND c.relname = 'test'
+ -- AND a.attname = 'id'
+ AND c.relname = 'ss0'
+ ORDER BY starelid, staattnum)
+TO STDOUT
+(FORMAT 'binary');
+\o
+COMMIT;
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+ nspname | relname | relpages | reltuples | relallvisible | curpages | attname | nspname_of_typename | typname | atttypmod | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 | stavalues1 | stavalues2 | stavalues3 | stavalues4 | stavalues5
+---------+---------+----------+-----------+---------------+----------+---------+---------------------+---------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------+------------+------------+------------+------------
+(0 rows)
+
+TRUNCATE dbms_stats.work;
+\! rm export_plain_stats.sql.sample_test
+-- No.16-1-7
+\! sed '/ORDER/i\\ AND c.relname = '"\'sc0\'" export_plain_stats.sql.sample > export_plain_stats.sql.sample_test
+\i export_plain_stats.sql.sample_test
+/*
+ * If you want the statistics of per-relation or per-column, please modify
+ * nspname, relname, and attname in 'WHERE' clause.
+ */
+BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+/*
+ * If you want to chage the output file name, please modify the following name.
+ */
+\o export_stats.dmp
+COPY (SELECT n2.nspname,
+ c.relname,
+ c.relpages,
+ c.reltuples,
+ c.relallvisible,
+ (pg_relation_size(c.oid) / current_setting('block_size')::int4)::int4
+ AS curpages,
+ pg_catalog.pg_stat_get_last_analyze_time(c.oid)
+ AS last_analyze,
+ pg_catalog.pg_stat_get_last_autoanalyze_time(c.oid)
+ AS last_autoanalyze,
+ COALESCE(a.attname, ''),
+ n1.nspname AS schemaname_of_atttype,
+ t.typname,
+ a.atttypmod,
+ s.stainherit,
+ s.stanullfrac,
+ s.stawidth,
+ s.stadistinct,
+ s.stakind1,
+ s.stakind2,
+ s.stakind3,
+ s.stakind4,
+ s.stakind5,
+ s.staop1,
+ s.staop2,
+ s.staop3,
+ s.staop4,
+ s.staop5,
+ s.stanumbers1,
+ s.stanumbers2,
+ s.stanumbers3,
+ s.stanumbers4,
+ s.stanumbers5,
+ s.stavalues1,
+ s.stavalues2,
+ s.stavalues3,
+ s.stavalues4,
+ s.stavalues5
+ FROM pg_statistic s
+ JOIN pg_attribute a
+ ON (s.starelid = a.attrelid AND s.staattnum = a.attnum)
+ JOIN pg_type t
+ ON a.atttypid = t.oid
+ JOIN pg_namespace n1
+ ON t.typnamespace = n1.oid
+ RIGHT JOIN pg_catalog.pg_class c
+ ON s.starelid = c.oid
+ JOIN pg_catalog.pg_namespace n2
+ ON c.relnamespace = n2.oid
+ WHERE c.relkind IN ('r', 'i', 'f')
+ AND NOT n2.nspname IN ('pg_catalog',
+ 'pg_toast',
+ 'information_schema',
+ 'dbms_stats')
+ -- AND n2.nspname = 'public'
+ -- AND c.relname = 'test'
+ -- AND a.attname = 'id'
+ AND c.relname = 'sc0'
+ ORDER BY starelid, staattnum)
+TO STDOUT
+(FORMAT 'binary');
+\o
+COMMIT;
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+ nspname | relname | relpages | reltuples | relallvisible | curpages | attname | nspname_of_typename | typname | atttypmod | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 | stavalues1 | stavalues2 | stavalues3 | stavalues4 | stavalues5
+---------+---------+----------+-----------+---------------+----------+---------+---------------------+---------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------+------------+------------+------------+------------
+(0 rows)
+
+TRUNCATE dbms_stats.work;
+\! rm export_plain_stats.sql.sample_test
+-- No.16-1-8
+\! sed '/ORDER/i\\ AND c.relname = '"\'sft0\'" export_plain_stats.sql.sample > export_plain_stats.sql.sample_test
+\i export_plain_stats.sql.sample_test
+/*
+ * If you want the statistics of per-relation or per-column, please modify
+ * nspname, relname, and attname in 'WHERE' clause.
+ */
+BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+/*
+ * If you want to chage the output file name, please modify the following name.
+ */
+\o export_stats.dmp
+COPY (SELECT n2.nspname,
+ c.relname,
+ c.relpages,
+ c.reltuples,
+ c.relallvisible,
+ (pg_relation_size(c.oid) / current_setting('block_size')::int4)::int4
+ AS curpages,
+ pg_catalog.pg_stat_get_last_analyze_time(c.oid)
+ AS last_analyze,
+ pg_catalog.pg_stat_get_last_autoanalyze_time(c.oid)
+ AS last_autoanalyze,
+ COALESCE(a.attname, ''),
+ n1.nspname AS schemaname_of_atttype,
+ t.typname,
+ a.atttypmod,
+ s.stainherit,
+ s.stanullfrac,
+ s.stawidth,
+ s.stadistinct,
+ s.stakind1,
+ s.stakind2,
+ s.stakind3,
+ s.stakind4,
+ s.stakind5,
+ s.staop1,
+ s.staop2,
+ s.staop3,
+ s.staop4,
+ s.staop5,
+ s.stanumbers1,
+ s.stanumbers2,
+ s.stanumbers3,
+ s.stanumbers4,
+ s.stanumbers5,
+ s.stavalues1,
+ s.stavalues2,
+ s.stavalues3,
+ s.stavalues4,
+ s.stavalues5
+ FROM pg_statistic s
+ JOIN pg_attribute a
+ ON (s.starelid = a.attrelid AND s.staattnum = a.attnum)
+ JOIN pg_type t
+ ON a.atttypid = t.oid
+ JOIN pg_namespace n1
+ ON t.typnamespace = n1.oid
+ RIGHT JOIN pg_catalog.pg_class c
+ ON s.starelid = c.oid
+ JOIN pg_catalog.pg_namespace n2
+ ON c.relnamespace = n2.oid
+ WHERE c.relkind IN ('r', 'i', 'f')
+ AND NOT n2.nspname IN ('pg_catalog',
+ 'pg_toast',
+ 'information_schema',
+ 'dbms_stats')
+ -- AND n2.nspname = 'public'
+ -- AND c.relname = 'test'
+ -- AND a.attname = 'id'
+ AND c.relname = 'sft0'
+ ORDER BY starelid, staattnum)
+TO STDOUT
+(FORMAT 'binary');
+\o
+COMMIT;
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+ nspname | relname | relpages | reltuples | relallvisible | curpages | attname | nspname_of_typename | typname | atttypmod | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 | stavalues1 | stavalues2 | stavalues3 | stavalues4 | stavalues5
+---------+---------+----------+-----------+---------------+----------+---------+---------------------+---------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------+------------+------------+------------+------------
+ s0 | sft0 | 0 | 0 | 0 | 0 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+(1 row)
+
+TRUNCATE dbms_stats.work;
+\! rm export_plain_stats.sql.sample_test
+-- No.16-1-9
+\! sed '/ORDER/i\\ AND n2.nspname = '"\'s0\'"' AND a.attname = '\'id\' export_plain_stats.sql.sample > export_plain_stats.sql.sample_test
+\i export_plain_stats.sql.sample_test
+/*
+ * If you want the statistics of per-relation or per-column, please modify
+ * nspname, relname, and attname in 'WHERE' clause.
+ */
+BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+/*
+ * If you want to chage the output file name, please modify the following name.
+ */
+\o export_stats.dmp
+COPY (SELECT n2.nspname,
+ c.relname,
+ c.relpages,
+ c.reltuples,
+ c.relallvisible,
+ (pg_relation_size(c.oid) / current_setting('block_size')::int4)::int4
+ AS curpages,
+ pg_catalog.pg_stat_get_last_analyze_time(c.oid)
+ AS last_analyze,
+ pg_catalog.pg_stat_get_last_autoanalyze_time(c.oid)
+ AS last_autoanalyze,
+ COALESCE(a.attname, ''),
+ n1.nspname AS schemaname_of_atttype,
+ t.typname,
+ a.atttypmod,
+ s.stainherit,
+ s.stanullfrac,
+ s.stawidth,
+ s.stadistinct,
+ s.stakind1,
+ s.stakind2,
+ s.stakind3,
+ s.stakind4,
+ s.stakind5,
+ s.staop1,
+ s.staop2,
+ s.staop3,
+ s.staop4,
+ s.staop5,
+ s.stanumbers1,
+ s.stanumbers2,
+ s.stanumbers3,
+ s.stanumbers4,
+ s.stanumbers5,
+ s.stavalues1,
+ s.stavalues2,
+ s.stavalues3,
+ s.stavalues4,
+ s.stavalues5
+ FROM pg_statistic s
+ JOIN pg_attribute a
+ ON (s.starelid = a.attrelid AND s.staattnum = a.attnum)
+ JOIN pg_type t
+ ON a.atttypid = t.oid
+ JOIN pg_namespace n1
+ ON t.typnamespace = n1.oid
+ RIGHT JOIN pg_catalog.pg_class c
+ ON s.starelid = c.oid
+ JOIN pg_catalog.pg_namespace n2
+ ON c.relnamespace = n2.oid
+ WHERE c.relkind IN ('r', 'i', 'f')
+ AND NOT n2.nspname IN ('pg_catalog',
+ 'pg_toast',
+ 'information_schema',
+ 'dbms_stats')
+ -- AND n2.nspname = 'public'
+ -- AND c.relname = 'test'
+ -- AND a.attname = 'id'
+ AND n2.nspname = 's0' AND a.attname = 'id'
+ ORDER BY starelid, staattnum)
+TO STDOUT
+(FORMAT 'binary');
+\o
+COMMIT;
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+ nspname | relname | relpages | reltuples | relallvisible | curpages | attname | nspname_of_typename | typname | atttypmod | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 | stavalues1 | stavalues2 | stavalues3 | stavalues4 | stavalues5
+---------+---------+----------+-----------+---------------+----------+---------+---------------------+---------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+-------------+------------+------------+------------+------------
+ s0 | st0 | 1 | 2 | 1 | 1 | id | pg_catalog | int4 | -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)
+ s0 | st0 | 1 | 2 | 1 | 1 | id | pg_catalog | int4 | -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)
+ s0 | st1 | 1 | 3 | 1 | 1 | id | pg_catalog | int4 | -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)
+ s0 | st2 | 1 | 3 | 1 | 1 | id | pg_catalog | int4 | -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)
+(4 rows)
+
+TRUNCATE dbms_stats.work;
+\! rm export_plain_stats.sql.sample_test
+-- No.16-1-10
+\! sed '/ORDER/i\\ AND n2.nspname = '"\'s0\'"' AND a.attname IS NULL' export_plain_stats.sql.sample > export_plain_stats.sql.sample_test
+\i export_plain_stats.sql.sample_test
+/*
+ * If you want the statistics of per-relation or per-column, please modify
+ * nspname, relname, and attname in 'WHERE' clause.
+ */
+BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+/*
+ * If you want to chage the output file name, please modify the following name.
+ */
+\o export_stats.dmp
+COPY (SELECT n2.nspname,
+ c.relname,
+ c.relpages,
+ c.reltuples,
+ c.relallvisible,
+ (pg_relation_size(c.oid) / current_setting('block_size')::int4)::int4
+ AS curpages,
+ pg_catalog.pg_stat_get_last_analyze_time(c.oid)
+ AS last_analyze,
+ pg_catalog.pg_stat_get_last_autoanalyze_time(c.oid)
+ AS last_autoanalyze,
+ COALESCE(a.attname, ''),
+ n1.nspname AS schemaname_of_atttype,
+ t.typname,
+ a.atttypmod,
+ s.stainherit,
+ s.stanullfrac,
+ s.stawidth,
+ s.stadistinct,
+ s.stakind1,
+ s.stakind2,
+ s.stakind3,
+ s.stakind4,
+ s.stakind5,
+ s.staop1,
+ s.staop2,
+ s.staop3,
+ s.staop4,
+ s.staop5,
+ s.stanumbers1,
+ s.stanumbers2,
+ s.stanumbers3,
+ s.stanumbers4,
+ s.stanumbers5,
+ s.stavalues1,
+ s.stavalues2,
+ s.stavalues3,
+ s.stavalues4,
+ s.stavalues5
+ FROM pg_statistic s
+ JOIN pg_attribute a
+ ON (s.starelid = a.attrelid AND s.staattnum = a.attnum)
+ JOIN pg_type t
+ ON a.atttypid = t.oid
+ JOIN pg_namespace n1
+ ON t.typnamespace = n1.oid
+ RIGHT JOIN pg_catalog.pg_class c
+ ON s.starelid = c.oid
+ JOIN pg_catalog.pg_namespace n2
+ ON c.relnamespace = n2.oid
+ WHERE c.relkind IN ('r', 'i', 'f')
+ AND NOT n2.nspname IN ('pg_catalog',
+ 'pg_toast',
+ 'information_schema',
+ 'dbms_stats')
+ -- AND n2.nspname = 'public'
+ -- AND c.relname = 'test'
+ -- AND a.attname = 'id'
+ AND n2.nspname = 's0' AND a.attname IS NULL
+ ORDER BY starelid, staattnum)
+TO STDOUT
+(FORMAT 'binary');
+\o
+COMMIT;
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+ nspname | relname | relpages | reltuples | relallvisible | curpages | attname | nspname_of_typename | typname | atttypmod | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 | stavalues1 | stavalues2 | stavalues3 | stavalues4 | stavalues5
+---------+---------+----------+-----------+---------------+----------+---------+---------------------+---------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------+------------+------------+------------+------------
+ s0 | sft0 | 0 | 0 | 0 | 0 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | st0_idx | 2 | 2 | 0 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | st1_idx | 2 | 3 | 0 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | st2_idx | 2 | 3 | 0 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | st3 | 0 | 0 | 0 | 0 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+(5 rows)
+
+TRUNCATE dbms_stats.work;
+\! rm export_plain_stats.sql.sample_test
+-- No.16-1-11
+\! sed '/ORDER/i\\ AND n2.nspname = '"\'s1\'"' AND c.relname IS NULL' export_plain_stats.sql.sample > export_plain_stats.sql.sample_test
+\i export_plain_stats.sql.sample_test
+/*
+ * If you want the statistics of per-relation or per-column, please modify
+ * nspname, relname, and attname in 'WHERE' clause.
+ */
+BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+/*
+ * If you want to chage the output file name, please modify the following name.
+ */
+\o export_stats.dmp
+COPY (SELECT n2.nspname,
+ c.relname,
+ c.relpages,
+ c.reltuples,
+ c.relallvisible,
+ (pg_relation_size(c.oid) / current_setting('block_size')::int4)::int4
+ AS curpages,
+ pg_catalog.pg_stat_get_last_analyze_time(c.oid)
+ AS last_analyze,
+ pg_catalog.pg_stat_get_last_autoanalyze_time(c.oid)
+ AS last_autoanalyze,
+ COALESCE(a.attname, ''),
+ n1.nspname AS schemaname_of_atttype,
+ t.typname,
+ a.atttypmod,
+ s.stainherit,
+ s.stanullfrac,
+ s.stawidth,
+ s.stadistinct,
+ s.stakind1,
+ s.stakind2,
+ s.stakind3,
+ s.stakind4,
+ s.stakind5,
+ s.staop1,
+ s.staop2,
+ s.staop3,
+ s.staop4,
+ s.staop5,
+ s.stanumbers1,
+ s.stanumbers2,
+ s.stanumbers3,
+ s.stanumbers4,
+ s.stanumbers5,
+ s.stavalues1,
+ s.stavalues2,
+ s.stavalues3,
+ s.stavalues4,
+ s.stavalues5
+ FROM pg_statistic s
+ JOIN pg_attribute a
+ ON (s.starelid = a.attrelid AND s.staattnum = a.attnum)
+ JOIN pg_type t
+ ON a.atttypid = t.oid
+ JOIN pg_namespace n1
+ ON t.typnamespace = n1.oid
+ RIGHT JOIN pg_catalog.pg_class c
+ ON s.starelid = c.oid
+ JOIN pg_catalog.pg_namespace n2
+ ON c.relnamespace = n2.oid
+ WHERE c.relkind IN ('r', 'i', 'f')
+ AND NOT n2.nspname IN ('pg_catalog',
+ 'pg_toast',
+ 'information_schema',
+ 'dbms_stats')
+ -- AND n2.nspname = 'public'
+ -- AND c.relname = 'test'
+ -- AND a.attname = 'id'
+ AND n2.nspname = 's1' AND c.relname IS NULL
+ ORDER BY starelid, staattnum)
+TO STDOUT
+(FORMAT 'binary');
+\o
+COMMIT;
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+ nspname | relname | relpages | reltuples | relallvisible | curpages | attname | nspname_of_typename | typname | atttypmod | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 | stavalues1 | stavalues2 | stavalues3 | stavalues4 | stavalues5
+---------+---------+----------+-----------+---------------+----------+---------+---------------------+---------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------+------------+------------+------------+------------
+(0 rows)
+
+TRUNCATE dbms_stats.work;
+\! rm export_plain_stats.sql.sample_test
+/*
+ * No.16-2 export_effective_stats.sql.sample
+ */
+-- No.16-2-1
+VACUUM ANALYZE;
+SELECT dbms_stats.lock_database_stats();
+ lock_database_stats
+---------------------
+ pt0
+ pt0_idx
+ st0
+ st0_idx
+ st1
+ s0.st0
+ s0.st0_idx
+ s0.st1
+ s0.st1_idx
+ s0.st2
+ s0.st2_idx
+ s0.sft0
+ st1_idx
+ st1_exp
+ s1.st0
+ s0.st3
+(16 rows)
+
+UPDATE dbms_stats._relation_stats_locked
+ SET (relpages, reltuples, relallvisible, curpages) = (NULL, NULL, NULL, NULL);
+UPDATE dbms_stats._column_stats_locked
+ SET (stanullfrac, stawidth, stadistinct,
+ stakind1, stakind2, stakind3, stakind4, stakind5,
+ staop1, staop2, staop3, staop4, staop5,
+ stanumbers1, stanumbers2, stanumbers3, stanumbers4, stanumbers5,
+ stavalues1, stavalues2, stavalues3, stavalues4, stavalues5)
+ = (NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL)
+ WHERE starelid = 's0.st0'::regclass;
+\i export_effective_stats.sql.sample
+/*
+ * If you want the statistics of per-relation or per-column, please modify
+ * nspname, relname, and attname in 'WHERE' clause.
+ */
+BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+/*
+ * If you want to chage the output file name, please modify the following name.
+ */
+\o export_stats.dmp
+COPY (SELECT n2.nspname,
+ cl.relname,
+ r.relpages,
+ r.reltuples,
+ r.relallvisible,
+ r.curpages,
+ r.last_analyze,
+ r.last_autoanalyze,
+ COALESCE(a.attname, ''),
+ n1.nspname AS schemaname_of_atttype,
+ t.typname,
+ a.atttypmod,
+ co.stainherit,
+ co.stanullfrac,
+ co.stawidth,
+ co.stadistinct,
+ co.stakind1,
+ co.stakind2,
+ co.stakind3,
+ co.stakind4,
+ co.stakind5,
+ co.staop1,
+ co.staop2,
+ co.staop3,
+ co.staop4,
+ co.staop5,
+ co.stanumbers1,
+ co.stanumbers2,
+ co.stanumbers3,
+ co.stanumbers4,
+ co.stanumbers5,
+ co.stavalues1,
+ co.stavalues2,
+ co.stavalues3,
+ co.stavalues4,
+ co.stavalues5
+ FROM dbms_stats.column_stats_effective co
+ JOIN pg_attribute a
+ ON (co.starelid = a.attrelid AND co.staattnum = a.attnum)
+ JOIN pg_type t
+ ON a.atttypid = t.oid
+ JOIN pg_namespace n1
+ ON t.typnamespace = n1.oid
+ RIGHT JOIN dbms_stats.relation_stats_effective r
+ ON co.starelid = r.relid
+ JOIN pg_catalog.pg_class cl
+ ON r.relid = cl.oid
+ JOIN pg_catalog.pg_namespace n2
+ ON cl.relnamespace = n2.oid
+ -- WHERE n2.nspname = 'public'
+ -- AND cl.relname = 'test'
+ -- AND a.attname = 'id'
+ ORDER BY starelid, staattnum)
+TO STDOUT
+(FORMAT 'binary');
+\o
+COMMIT;
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+ nspname | relname | relpages | reltuples | relallvisible | curpages | attname | nspname_of_typename | typname | atttypmod | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 | stavalues1 | stavalues2 | stavalues3 | stavalues4 | stavalues5
+---------+---------+----------+-----------+---------------+----------+---------+---------------------+---------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------------+------------+------------------+------------+------------
+ public | pt0 | 0 | 0 | 0 | 0 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ public | pt0_idx | 2 | 0 | 0 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ public | st0 | 1 | 2 | 1 | 1 | id | pg_catalog | int4 | -1 | f | -1 | -1 | -1 | 2 | 3 | 4 | 1 | 5 | 22 | 23 | 24 | 21 | 25 | {-1,22} | {-1,23} | {-1,24} | {-1,21} | {-1,25} | (null) | (null) | {1,2} | (null) | (null)
+ public | st0 | 1 | 2 | 1 | 1 | name | pg_catalog | bpchar | 9 | f | -2 | -2 | -2 | 2 | 3 | 4 | 1 | 5 | 22 | 23 | 24 | 21 | 25 | {-2,22} | {-2,23} | {-2,24} | {-2,21} | {-2,25} | (null) | (null) | {"test "} | (null) | (null)
+ public | st0_idx | 2 | 2 | 0 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ public | st1 | 45 | 10000 | 45 | 45 | str | pg_catalog | text | -1 | f | -2 | -2 | -2 | 2 | 3 | 4 | 1 | 5 | 22 | 23 | 24 | 21 | 25 | {-2,22} | {-2,23} | {-2,24} | {-2,21} | {-2,25} | (null) | (null) | {1,0,2} | (null) | (null)
+ public | st1 | 45 | 10000 | 45 | 45 | val | pg_catalog | int4 | -1 | f | -1 | -1 | -1 | 2 | 3 | 4 | 1 | 5 | 22 | 23 | 24 | 21 | 25 | {-1,22} | {-1,23} | {-1,24} | {-1,21} | {-1,25} | (null) | (null) | {1,0,2} | (null) | (null)
+ public | st1_exp | 30 | 10000 | 0 | 30 | lower | pg_catalog | text | -1 | f | -1 | -1 | -1 | 2 | 3 | 4 | 1 | 5 | 22 | 23 | 24 | 21 | 25 | {-1,22} | {-1,23} | {-1,24} | {-1,21} | {-1,25} | (null) | (null) | {1,0,2} | (null) | (null)
+ public | st1_idx | 30 | 10000 | 0 | 30 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | sft0 | 0 | 0 | 0 | 0 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | st0 | 1 | 2 | 1 | 1 | id | pg_catalog | int4 | -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)
+ s0 | st0 | 1 | 2 | 1 | 1 | id | pg_catalog | int4 | -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)
+ s0 | st0 | 1 | 2 | 1 | 1 | num | pg_catalog | int4 | -1 | 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)
+ s0 | st0 | 1 | 2 | 1 | 1 | num | pg_catalog | int4 | -1 | 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)
+ s0 | st0_idx | 2 | 2 | 0 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | st1 | 1 | 3 | 1 | 1 | id | pg_catalog | int4 | -1 | f | -1 | -1 | -1 | 2 | 3 | 4 | 1 | 5 | 22 | 23 | 24 | 21 | 25 | {-1,22} | {-1,23} | {-1,24} | {-1,21} | {-1,25} | (null) | (null) | {4,5,6} | (null) | (null)
+ s0 | st1 | 1 | 3 | 1 | 1 | num | pg_catalog | int4 | -1 | f | -2 | -2 | -2 | 2 | 3 | 4 | 1 | 5 | 22 | 23 | 24 | 21 | 25 | {-2,22} | {-2,23} | {-2,24} | {-2,21} | {-2,25} | (null) | (null) | {40,50,60} | (null) | (null)
+ s0 | st1_idx | 2 | 3 | 0 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | st2 | 1 | 3 | 1 | 1 | id | pg_catalog | int4 | -1 | f | -1 | -1 | -1 | 2 | 3 | 4 | 1 | 5 | 22 | 23 | 24 | 21 | 25 | {-1,22} | {-1,23} | {-1,24} | {-1,21} | {-1,25} | (null) | (null) | {1,2,3} | (null) | (null)
+ s0 | st2 | 1 | 3 | 1 | 1 | txt | pg_catalog | text | -1 | f | -2 | -2 | -2 | 2 | 3 | 4 | 1 | 5 | 22 | 23 | 24 | 21 | 25 | {-2,22} | {-2,23} | {-2,24} | {-2,21} | {-2,25} | (null) | (null) | {1,comment,test} | (null) | (null)
+ s0 | st2_idx | 2 | 3 | 0 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | st3 | 0 | 0 | 0 | 0 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s1 | st0 | 1 | 4 | 1 | 1 | id | pg_catalog | int4 | -1 | f | -1 | -1 | -1 | 2 | 3 | 4 | 1 | 5 | 22 | 23 | 24 | 21 | 25 | {-1,22} | {-1,23} | {-1,24} | {-1,21} | {-1,25} | (null) | (null) | {1,2,3,4} | (null) | (null)
+ s1 | st0 | 1 | 4 | 1 | 1 | num | pg_catalog | int4 | -1 | f | -2 | -2 | -2 | 2 | 3 | 4 | 1 | 5 | 22 | 23 | 24 | 21 | 25 | {-2,22} | {-2,23} | {-2,24} | {-2,21} | {-2,25} | (null) | (null) | {15,25,35,45} | (null) | (null)
+(24 rows)
+
+TRUNCATE dbms_stats.work;
+-- No.16-2-2
+\! sed '/ORDER/i\\ WHERE n2.nspname = '"\'s0\'" export_effective_stats.sql.sample > export_effective_stats.sql.sample_test
+\i export_effective_stats.sql.sample_test
+/*
+ * If you want the statistics of per-relation or per-column, please modify
+ * nspname, relname, and attname in 'WHERE' clause.
+ */
+BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+/*
+ * If you want to chage the output file name, please modify the following name.
+ */
+\o export_stats.dmp
+COPY (SELECT n2.nspname,
+ cl.relname,
+ r.relpages,
+ r.reltuples,
+ r.relallvisible,
+ r.curpages,
+ r.last_analyze,
+ r.last_autoanalyze,
+ COALESCE(a.attname, ''),
+ n1.nspname AS schemaname_of_atttype,
+ t.typname,
+ a.atttypmod,
+ co.stainherit,
+ co.stanullfrac,
+ co.stawidth,
+ co.stadistinct,
+ co.stakind1,
+ co.stakind2,
+ co.stakind3,
+ co.stakind4,
+ co.stakind5,
+ co.staop1,
+ co.staop2,
+ co.staop3,
+ co.staop4,
+ co.staop5,
+ co.stanumbers1,
+ co.stanumbers2,
+ co.stanumbers3,
+ co.stanumbers4,
+ co.stanumbers5,
+ co.stavalues1,
+ co.stavalues2,
+ co.stavalues3,
+ co.stavalues4,
+ co.stavalues5
+ FROM dbms_stats.column_stats_effective co
+ JOIN pg_attribute a
+ ON (co.starelid = a.attrelid AND co.staattnum = a.attnum)
+ JOIN pg_type t
+ ON a.atttypid = t.oid
+ JOIN pg_namespace n1
+ ON t.typnamespace = n1.oid
+ RIGHT JOIN dbms_stats.relation_stats_effective r
+ ON co.starelid = r.relid
+ JOIN pg_catalog.pg_class cl
+ ON r.relid = cl.oid
+ JOIN pg_catalog.pg_namespace n2
+ ON cl.relnamespace = n2.oid
+ -- WHERE n2.nspname = 'public'
+ -- AND cl.relname = 'test'
+ -- AND a.attname = 'id'
+ WHERE n2.nspname = 's0'
+ ORDER BY starelid, staattnum)
+TO STDOUT
+(FORMAT 'binary');
+\o
+COMMIT;
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+ nspname | relname | relpages | reltuples | relallvisible | curpages | attname | nspname_of_typename | typname | atttypmod | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 | stavalues1 | stavalues2 | stavalues3 | stavalues4 | stavalues5
+---------+---------+----------+-----------+---------------+----------+---------+---------------------+---------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------------+------------+------------------+------------+------------
+ s0 | sft0 | 0 | 0 | 0 | 0 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | st0 | 1 | 2 | 1 | 1 | id | pg_catalog | int4 | -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)
+ s0 | st0 | 1 | 2 | 1 | 1 | id | pg_catalog | int4 | -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)
+ s0 | st0 | 1 | 2 | 1 | 1 | num | pg_catalog | int4 | -1 | 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)
+ s0 | st0 | 1 | 2 | 1 | 1 | num | pg_catalog | int4 | -1 | 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)
+ s0 | st0_idx | 2 | 2 | 0 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | st1 | 1 | 3 | 1 | 1 | id | pg_catalog | int4 | -1 | f | -1 | -1 | -1 | 2 | 3 | 4 | 1 | 5 | 22 | 23 | 24 | 21 | 25 | {-1,22} | {-1,23} | {-1,24} | {-1,21} | {-1,25} | (null) | (null) | {4,5,6} | (null) | (null)
+ s0 | st1 | 1 | 3 | 1 | 1 | num | pg_catalog | int4 | -1 | f | -2 | -2 | -2 | 2 | 3 | 4 | 1 | 5 | 22 | 23 | 24 | 21 | 25 | {-2,22} | {-2,23} | {-2,24} | {-2,21} | {-2,25} | (null) | (null) | {40,50,60} | (null) | (null)
+ s0 | st1_idx | 2 | 3 | 0 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | st2 | 1 | 3 | 1 | 1 | id | pg_catalog | int4 | -1 | f | -1 | -1 | -1 | 2 | 3 | 4 | 1 | 5 | 22 | 23 | 24 | 21 | 25 | {-1,22} | {-1,23} | {-1,24} | {-1,21} | {-1,25} | (null) | (null) | {1,2,3} | (null) | (null)
+ s0 | st2 | 1 | 3 | 1 | 1 | txt | pg_catalog | text | -1 | f | -2 | -2 | -2 | 2 | 3 | 4 | 1 | 5 | 22 | 23 | 24 | 21 | 25 | {-2,22} | {-2,23} | {-2,24} | {-2,21} | {-2,25} | (null) | (null) | {1,comment,test} | (null) | (null)
+ s0 | st2_idx | 2 | 3 | 0 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | st3 | 0 | 0 | 0 | 0 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+(13 rows)
+
+\! rm export_effective_stats.sql.sample_test
+TRUNCATE dbms_stats.work;
+-- No.16-2-3
+\! sed '/ORDER/i\\ WHERE cl.relname = '"\'st0\'" export_effective_stats.sql.sample > export_effective_stats.sql.sample_test
+\i export_effective_stats.sql.sample_test
+/*
+ * If you want the statistics of per-relation or per-column, please modify
+ * nspname, relname, and attname in 'WHERE' clause.
+ */
+BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+/*
+ * If you want to chage the output file name, please modify the following name.
+ */
+\o export_stats.dmp
+COPY (SELECT n2.nspname,
+ cl.relname,
+ r.relpages,
+ r.reltuples,
+ r.relallvisible,
+ r.curpages,
+ r.last_analyze,
+ r.last_autoanalyze,
+ COALESCE(a.attname, ''),
+ n1.nspname AS schemaname_of_atttype,
+ t.typname,
+ a.atttypmod,
+ co.stainherit,
+ co.stanullfrac,
+ co.stawidth,
+ co.stadistinct,
+ co.stakind1,
+ co.stakind2,
+ co.stakind3,
+ co.stakind4,
+ co.stakind5,
+ co.staop1,
+ co.staop2,
+ co.staop3,
+ co.staop4,
+ co.staop5,
+ co.stanumbers1,
+ co.stanumbers2,
+ co.stanumbers3,
+ co.stanumbers4,
+ co.stanumbers5,
+ co.stavalues1,
+ co.stavalues2,
+ co.stavalues3,
+ co.stavalues4,
+ co.stavalues5
+ FROM dbms_stats.column_stats_effective co
+ JOIN pg_attribute a
+ ON (co.starelid = a.attrelid AND co.staattnum = a.attnum)
+ JOIN pg_type t
+ ON a.atttypid = t.oid
+ JOIN pg_namespace n1
+ ON t.typnamespace = n1.oid
+ RIGHT JOIN dbms_stats.relation_stats_effective r
+ ON co.starelid = r.relid
+ JOIN pg_catalog.pg_class cl
+ ON r.relid = cl.oid
+ JOIN pg_catalog.pg_namespace n2
+ ON cl.relnamespace = n2.oid
+ -- WHERE n2.nspname = 'public'
+ -- AND cl.relname = 'test'
+ -- AND a.attname = 'id'
+ WHERE cl.relname = 'st0'
+ ORDER BY starelid, staattnum)
+TO STDOUT
+(FORMAT 'binary');
+\o
+COMMIT;
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+ nspname | relname | relpages | reltuples | relallvisible | curpages | attname | nspname_of_typename | typname | atttypmod | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 | stavalues1 | stavalues2 | stavalues3 | stavalues4 | stavalues5
+---------+---------+----------+-----------+---------------+----------+---------+---------------------+---------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------------+------------+---------------+------------+------------
+ public | st0 | 1 | 2 | 1 | 1 | id | pg_catalog | int4 | -1 | f | -1 | -1 | -1 | 2 | 3 | 4 | 1 | 5 | 22 | 23 | 24 | 21 | 25 | {-1,22} | {-1,23} | {-1,24} | {-1,21} | {-1,25} | (null) | (null) | {1,2} | (null) | (null)
+ public | st0 | 1 | 2 | 1 | 1 | name | pg_catalog | bpchar | 9 | f | -2 | -2 | -2 | 2 | 3 | 4 | 1 | 5 | 22 | 23 | 24 | 21 | 25 | {-2,22} | {-2,23} | {-2,24} | {-2,21} | {-2,25} | (null) | (null) | {"test "} | (null) | (null)
+ s0 | st0 | 1 | 2 | 1 | 1 | id | pg_catalog | int4 | -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)
+ s0 | st0 | 1 | 2 | 1 | 1 | id | pg_catalog | int4 | -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)
+ s0 | st0 | 1 | 2 | 1 | 1 | num | pg_catalog | int4 | -1 | 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)
+ s0 | st0 | 1 | 2 | 1 | 1 | num | pg_catalog | int4 | -1 | 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)
+ s1 | st0 | 1 | 4 | 1 | 1 | id | pg_catalog | int4 | -1 | f | -1 | -1 | -1 | 2 | 3 | 4 | 1 | 5 | 22 | 23 | 24 | 21 | 25 | {-1,22} | {-1,23} | {-1,24} | {-1,21} | {-1,25} | (null) | (null) | {1,2,3,4} | (null) | (null)
+ s1 | st0 | 1 | 4 | 1 | 1 | num | pg_catalog | int4 | -1 | f | -2 | -2 | -2 | 2 | 3 | 4 | 1 | 5 | 22 | 23 | 24 | 21 | 25 | {-2,22} | {-2,23} | {-2,24} | {-2,21} | {-2,25} | (null) | (null) | {15,25,35,45} | (null) | (null)
+(8 rows)
+
+\! rm export_effective_stats.sql.sample_test
+TRUNCATE dbms_stats.work;
+-- No.16-2-4
+\! sed '/ORDER/i\\ WHERE cl.relname = '"\'pg_toast_1262\'" export_effective_stats.sql.sample > export_effective_stats.sql.sample_test
+\i export_effective_stats.sql.sample_test
+/*
+ * If you want the statistics of per-relation or per-column, please modify
+ * nspname, relname, and attname in 'WHERE' clause.
+ */
+BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+/*
+ * If you want to chage the output file name, please modify the following name.
+ */
+\o export_stats.dmp
+COPY (SELECT n2.nspname,
+ cl.relname,
+ r.relpages,
+ r.reltuples,
+ r.relallvisible,
+ r.curpages,
+ r.last_analyze,
+ r.last_autoanalyze,
+ COALESCE(a.attname, ''),
+ n1.nspname AS schemaname_of_atttype,
+ t.typname,
+ a.atttypmod,
+ co.stainherit,
+ co.stanullfrac,
+ co.stawidth,
+ co.stadistinct,
+ co.stakind1,
+ co.stakind2,
+ co.stakind3,
+ co.stakind4,
+ co.stakind5,
+ co.staop1,
+ co.staop2,
+ co.staop3,
+ co.staop4,
+ co.staop5,
+ co.stanumbers1,
+ co.stanumbers2,
+ co.stanumbers3,
+ co.stanumbers4,
+ co.stanumbers5,
+ co.stavalues1,
+ co.stavalues2,
+ co.stavalues3,
+ co.stavalues4,
+ co.stavalues5
+ FROM dbms_stats.column_stats_effective co
+ JOIN pg_attribute a
+ ON (co.starelid = a.attrelid AND co.staattnum = a.attnum)
+ JOIN pg_type t
+ ON a.atttypid = t.oid
+ JOIN pg_namespace n1
+ ON t.typnamespace = n1.oid
+ RIGHT JOIN dbms_stats.relation_stats_effective r
+ ON co.starelid = r.relid
+ JOIN pg_catalog.pg_class cl
+ ON r.relid = cl.oid
+ JOIN pg_catalog.pg_namespace n2
+ ON cl.relnamespace = n2.oid
+ -- WHERE n2.nspname = 'public'
+ -- AND cl.relname = 'test'
+ -- AND a.attname = 'id'
+ WHERE cl.relname = 'pg_toast_1262'
+ ORDER BY starelid, staattnum)
+TO STDOUT
+(FORMAT 'binary');
+\o
+COMMIT;
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+ nspname | relname | relpages | reltuples | relallvisible | curpages | attname | nspname_of_typename | typname | atttypmod | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 | stavalues1 | stavalues2 | stavalues3 | stavalues4 | stavalues5
+---------+---------+----------+-----------+---------------+----------+---------+---------------------+---------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------+------------+------------+------------+------------
+(0 rows)
+
+\! rm export_effective_stats.sql.sample_test
+TRUNCATE dbms_stats.work;
+-- No.16-2-5
+\! sed '/ORDER/i\\ WHERE cl.relname = '"\'st0_idx\'" export_effective_stats.sql.sample > export_effective_stats.sql.sample_test
+\i export_effective_stats.sql.sample_test
+/*
+ * If you want the statistics of per-relation or per-column, please modify
+ * nspname, relname, and attname in 'WHERE' clause.
+ */
+BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+/*
+ * If you want to chage the output file name, please modify the following name.
+ */
+\o export_stats.dmp
+COPY (SELECT n2.nspname,
+ cl.relname,
+ r.relpages,
+ r.reltuples,
+ r.relallvisible,
+ r.curpages,
+ r.last_analyze,
+ r.last_autoanalyze,
+ COALESCE(a.attname, ''),
+ n1.nspname AS schemaname_of_atttype,
+ t.typname,
+ a.atttypmod,
+ co.stainherit,
+ co.stanullfrac,
+ co.stawidth,
+ co.stadistinct,
+ co.stakind1,
+ co.stakind2,
+ co.stakind3,
+ co.stakind4,
+ co.stakind5,
+ co.staop1,
+ co.staop2,
+ co.staop3,
+ co.staop4,
+ co.staop5,
+ co.stanumbers1,
+ co.stanumbers2,
+ co.stanumbers3,
+ co.stanumbers4,
+ co.stanumbers5,
+ co.stavalues1,
+ co.stavalues2,
+ co.stavalues3,
+ co.stavalues4,
+ co.stavalues5
+ FROM dbms_stats.column_stats_effective co
+ JOIN pg_attribute a
+ ON (co.starelid = a.attrelid AND co.staattnum = a.attnum)
+ JOIN pg_type t
+ ON a.atttypid = t.oid
+ JOIN pg_namespace n1
+ ON t.typnamespace = n1.oid
+ RIGHT JOIN dbms_stats.relation_stats_effective r
+ ON co.starelid = r.relid
+ JOIN pg_catalog.pg_class cl
+ ON r.relid = cl.oid
+ JOIN pg_catalog.pg_namespace n2
+ ON cl.relnamespace = n2.oid
+ -- WHERE n2.nspname = 'public'
+ -- AND cl.relname = 'test'
+ -- AND a.attname = 'id'
+ WHERE cl.relname = 'st0_idx'
+ ORDER BY starelid, staattnum)
+TO STDOUT
+(FORMAT 'binary');
+\o
+COMMIT;
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+ nspname | relname | relpages | reltuples | relallvisible | curpages | attname | nspname_of_typename | typname | atttypmod | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 | stavalues1 | stavalues2 | stavalues3 | stavalues4 | stavalues5
+---------+---------+----------+-----------+---------------+----------+---------+---------------------+---------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------+------------+------------+------------+------------
+ public | st0_idx | 2 | 2 | 0 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | st0_idx | 2 | 2 | 0 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+(2 rows)
+
+\! rm export_effective_stats.sql.sample_test
+TRUNCATE dbms_stats.work;
+-- No.16-2-6
+\! sed '/ORDER/i\\ WHERE cl.relname = '"\'ss0\'" export_effective_stats.sql.sample > export_effective_stats.sql.sample_test
+\i export_effective_stats.sql.sample_test
+/*
+ * If you want the statistics of per-relation or per-column, please modify
+ * nspname, relname, and attname in 'WHERE' clause.
+ */
+BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+/*
+ * If you want to chage the output file name, please modify the following name.
+ */
+\o export_stats.dmp
+COPY (SELECT n2.nspname,
+ cl.relname,
+ r.relpages,
+ r.reltuples,
+ r.relallvisible,
+ r.curpages,
+ r.last_analyze,
+ r.last_autoanalyze,
+ COALESCE(a.attname, ''),
+ n1.nspname AS schemaname_of_atttype,
+ t.typname,
+ a.atttypmod,
+ co.stainherit,
+ co.stanullfrac,
+ co.stawidth,
+ co.stadistinct,
+ co.stakind1,
+ co.stakind2,
+ co.stakind3,
+ co.stakind4,
+ co.stakind5,
+ co.staop1,
+ co.staop2,
+ co.staop3,
+ co.staop4,
+ co.staop5,
+ co.stanumbers1,
+ co.stanumbers2,
+ co.stanumbers3,
+ co.stanumbers4,
+ co.stanumbers5,
+ co.stavalues1,
+ co.stavalues2,
+ co.stavalues3,
+ co.stavalues4,
+ co.stavalues5
+ FROM dbms_stats.column_stats_effective co
+ JOIN pg_attribute a
+ ON (co.starelid = a.attrelid AND co.staattnum = a.attnum)
+ JOIN pg_type t
+ ON a.atttypid = t.oid
+ JOIN pg_namespace n1
+ ON t.typnamespace = n1.oid
+ RIGHT JOIN dbms_stats.relation_stats_effective r
+ ON co.starelid = r.relid
+ JOIN pg_catalog.pg_class cl
+ ON r.relid = cl.oid
+ JOIN pg_catalog.pg_namespace n2
+ ON cl.relnamespace = n2.oid
+ -- WHERE n2.nspname = 'public'
+ -- AND cl.relname = 'test'
+ -- AND a.attname = 'id'
+ WHERE cl.relname = 'ss0'
+ ORDER BY starelid, staattnum)
+TO STDOUT
+(FORMAT 'binary');
+\o
+COMMIT;
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+ nspname | relname | relpages | reltuples | relallvisible | curpages | attname | nspname_of_typename | typname | atttypmod | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 | stavalues1 | stavalues2 | stavalues3 | stavalues4 | stavalues5
+---------+---------+----------+-----------+---------------+----------+---------+---------------------+---------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------+------------+------------+------------+------------
+(0 rows)
+
+\! rm export_effective_stats.sql.sample_test
+TRUNCATE dbms_stats.work;
+-- No.16-2-7
+\! sed '/ORDER/i\\ WHERE cl.relname = '"\'sc0\'" export_effective_stats.sql.sample > export_effective_stats.sql.sample_test
+\i export_effective_stats.sql.sample_test
+/*
+ * If you want the statistics of per-relation or per-column, please modify
+ * nspname, relname, and attname in 'WHERE' clause.
+ */
+BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+/*
+ * If you want to chage the output file name, please modify the following name.
+ */
+\o export_stats.dmp
+COPY (SELECT n2.nspname,
+ cl.relname,
+ r.relpages,
+ r.reltuples,
+ r.relallvisible,
+ r.curpages,
+ r.last_analyze,
+ r.last_autoanalyze,
+ COALESCE(a.attname, ''),
+ n1.nspname AS schemaname_of_atttype,
+ t.typname,
+ a.atttypmod,
+ co.stainherit,
+ co.stanullfrac,
+ co.stawidth,
+ co.stadistinct,
+ co.stakind1,
+ co.stakind2,
+ co.stakind3,
+ co.stakind4,
+ co.stakind5,
+ co.staop1,
+ co.staop2,
+ co.staop3,
+ co.staop4,
+ co.staop5,
+ co.stanumbers1,
+ co.stanumbers2,
+ co.stanumbers3,
+ co.stanumbers4,
+ co.stanumbers5,
+ co.stavalues1,
+ co.stavalues2,
+ co.stavalues3,
+ co.stavalues4,
+ co.stavalues5
+ FROM dbms_stats.column_stats_effective co
+ JOIN pg_attribute a
+ ON (co.starelid = a.attrelid AND co.staattnum = a.attnum)
+ JOIN pg_type t
+ ON a.atttypid = t.oid
+ JOIN pg_namespace n1
+ ON t.typnamespace = n1.oid
+ RIGHT JOIN dbms_stats.relation_stats_effective r
+ ON co.starelid = r.relid
+ JOIN pg_catalog.pg_class cl
+ ON r.relid = cl.oid
+ JOIN pg_catalog.pg_namespace n2
+ ON cl.relnamespace = n2.oid
+ -- WHERE n2.nspname = 'public'
+ -- AND cl.relname = 'test'
+ -- AND a.attname = 'id'
+ WHERE cl.relname = 'sc0'
+ ORDER BY starelid, staattnum)
+TO STDOUT
+(FORMAT 'binary');
+\o
+COMMIT;
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+ nspname | relname | relpages | reltuples | relallvisible | curpages | attname | nspname_of_typename | typname | atttypmod | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 | stavalues1 | stavalues2 | stavalues3 | stavalues4 | stavalues5
+---------+---------+----------+-----------+---------------+----------+---------+---------------------+---------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------+------------+------------+------------+------------
+(0 rows)
+
+\! rm export_effective_stats.sql.sample_test
+TRUNCATE dbms_stats.work;
+-- No.16-2-8
+\! sed '/ORDER/i\\ WHERE cl.relname = '"\'sft0\'" export_effective_stats.sql.sample > export_effective_stats.sql.sample_test
+\i export_effective_stats.sql.sample_test
+/*
+ * If you want the statistics of per-relation or per-column, please modify
+ * nspname, relname, and attname in 'WHERE' clause.
+ */
+BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+/*
+ * If you want to chage the output file name, please modify the following name.
+ */
+\o export_stats.dmp
+COPY (SELECT n2.nspname,
+ cl.relname,
+ r.relpages,
+ r.reltuples,
+ r.relallvisible,
+ r.curpages,
+ r.last_analyze,
+ r.last_autoanalyze,
+ COALESCE(a.attname, ''),
+ n1.nspname AS schemaname_of_atttype,
+ t.typname,
+ a.atttypmod,
+ co.stainherit,
+ co.stanullfrac,
+ co.stawidth,
+ co.stadistinct,
+ co.stakind1,
+ co.stakind2,
+ co.stakind3,
+ co.stakind4,
+ co.stakind5,
+ co.staop1,
+ co.staop2,
+ co.staop3,
+ co.staop4,
+ co.staop5,
+ co.stanumbers1,
+ co.stanumbers2,
+ co.stanumbers3,
+ co.stanumbers4,
+ co.stanumbers5,
+ co.stavalues1,
+ co.stavalues2,
+ co.stavalues3,
+ co.stavalues4,
+ co.stavalues5
+ FROM dbms_stats.column_stats_effective co
+ JOIN pg_attribute a
+ ON (co.starelid = a.attrelid AND co.staattnum = a.attnum)
+ JOIN pg_type t
+ ON a.atttypid = t.oid
+ JOIN pg_namespace n1
+ ON t.typnamespace = n1.oid
+ RIGHT JOIN dbms_stats.relation_stats_effective r
+ ON co.starelid = r.relid
+ JOIN pg_catalog.pg_class cl
+ ON r.relid = cl.oid
+ JOIN pg_catalog.pg_namespace n2
+ ON cl.relnamespace = n2.oid
+ -- WHERE n2.nspname = 'public'
+ -- AND cl.relname = 'test'
+ -- AND a.attname = 'id'
+ WHERE cl.relname = 'sft0'
+ ORDER BY starelid, staattnum)
+TO STDOUT
+(FORMAT 'binary');
+\o
+COMMIT;
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+ nspname | relname | relpages | reltuples | relallvisible | curpages | attname | nspname_of_typename | typname | atttypmod | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 | stavalues1 | stavalues2 | stavalues3 | stavalues4 | stavalues5
+---------+---------+----------+-----------+---------------+----------+---------+---------------------+---------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------+------------+------------+------------+------------
+ s0 | sft0 | 0 | 0 | 0 | 0 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+(1 row)
+
+\! rm export_effective_stats.sql.sample_test
+TRUNCATE dbms_stats.work;
+-- No.16-2-9
+\! sed '/ORDER/i\\ WHERE n2.nspname = '"\'s0\'"' AND a.attname = '"\'id\'" export_effective_stats.sql.sample > export_effective_stats.sql.sample_test
+\i export_effective_stats.sql.sample_test
+/*
+ * If you want the statistics of per-relation or per-column, please modify
+ * nspname, relname, and attname in 'WHERE' clause.
+ */
+BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+/*
+ * If you want to chage the output file name, please modify the following name.
+ */
+\o export_stats.dmp
+COPY (SELECT n2.nspname,
+ cl.relname,
+ r.relpages,
+ r.reltuples,
+ r.relallvisible,
+ r.curpages,
+ r.last_analyze,
+ r.last_autoanalyze,
+ COALESCE(a.attname, ''),
+ n1.nspname AS schemaname_of_atttype,
+ t.typname,
+ a.atttypmod,
+ co.stainherit,
+ co.stanullfrac,
+ co.stawidth,
+ co.stadistinct,
+ co.stakind1,
+ co.stakind2,
+ co.stakind3,
+ co.stakind4,
+ co.stakind5,
+ co.staop1,
+ co.staop2,
+ co.staop3,
+ co.staop4,
+ co.staop5,
+ co.stanumbers1,
+ co.stanumbers2,
+ co.stanumbers3,
+ co.stanumbers4,
+ co.stanumbers5,
+ co.stavalues1,
+ co.stavalues2,
+ co.stavalues3,
+ co.stavalues4,
+ co.stavalues5
+ FROM dbms_stats.column_stats_effective co
+ JOIN pg_attribute a
+ ON (co.starelid = a.attrelid AND co.staattnum = a.attnum)
+ JOIN pg_type t
+ ON a.atttypid = t.oid
+ JOIN pg_namespace n1
+ ON t.typnamespace = n1.oid
+ RIGHT JOIN dbms_stats.relation_stats_effective r
+ ON co.starelid = r.relid
+ JOIN pg_catalog.pg_class cl
+ ON r.relid = cl.oid
+ JOIN pg_catalog.pg_namespace n2
+ ON cl.relnamespace = n2.oid
+ -- WHERE n2.nspname = 'public'
+ -- AND cl.relname = 'test'
+ -- AND a.attname = 'id'
+ WHERE n2.nspname = 's0' AND a.attname = 'id'
+ ORDER BY starelid, staattnum)
+TO STDOUT
+(FORMAT 'binary');
+\o
+COMMIT;
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+ nspname | relname | relpages | reltuples | relallvisible | curpages | attname | nspname_of_typename | typname | atttypmod | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 | stavalues1 | stavalues2 | stavalues3 | stavalues4 | stavalues5
+---------+---------+----------+-----------+---------------+----------+---------+---------------------+---------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+-------------+------------+------------+------------+------------
+ s0 | st0 | 1 | 2 | 1 | 1 | id | pg_catalog | int4 | -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)
+ s0 | st0 | 1 | 2 | 1 | 1 | id | pg_catalog | int4 | -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)
+ s0 | st1 | 1 | 3 | 1 | 1 | id | pg_catalog | int4 | -1 | f | -1 | -1 | -1 | 2 | 3 | 4 | 1 | 5 | 22 | 23 | 24 | 21 | 25 | {-1,22} | {-1,23} | {-1,24} | {-1,21} | {-1,25} | (null) | (null) | {4,5,6} | (null) | (null)
+ s0 | st2 | 1 | 3 | 1 | 1 | id | pg_catalog | int4 | -1 | f | -1 | -1 | -1 | 2 | 3 | 4 | 1 | 5 | 22 | 23 | 24 | 21 | 25 | {-1,22} | {-1,23} | {-1,24} | {-1,21} | {-1,25} | (null) | (null) | {1,2,3} | (null) | (null)
+(4 rows)
+
+\! rm export_effective_stats.sql.sample_test
+TRUNCATE dbms_stats.work;
+-- No.16-2-10
+\! sed '/ORDER/i\\ WHERE n2.nspname = '"\'s0\'"' AND a.attname IS NULL' export_effective_stats.sql.sample > export_effective_stats.sql.sample_test
+\i export_effective_stats.sql.sample_test
+/*
+ * If you want the statistics of per-relation or per-column, please modify
+ * nspname, relname, and attname in 'WHERE' clause.
+ */
+BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+/*
+ * If you want to chage the output file name, please modify the following name.
+ */
+\o export_stats.dmp
+COPY (SELECT n2.nspname,
+ cl.relname,
+ r.relpages,
+ r.reltuples,
+ r.relallvisible,
+ r.curpages,
+ r.last_analyze,
+ r.last_autoanalyze,
+ COALESCE(a.attname, ''),
+ n1.nspname AS schemaname_of_atttype,
+ t.typname,
+ a.atttypmod,
+ co.stainherit,
+ co.stanullfrac,
+ co.stawidth,
+ co.stadistinct,
+ co.stakind1,
+ co.stakind2,
+ co.stakind3,
+ co.stakind4,
+ co.stakind5,
+ co.staop1,
+ co.staop2,
+ co.staop3,
+ co.staop4,
+ co.staop5,
+ co.stanumbers1,
+ co.stanumbers2,
+ co.stanumbers3,
+ co.stanumbers4,
+ co.stanumbers5,
+ co.stavalues1,
+ co.stavalues2,
+ co.stavalues3,
+ co.stavalues4,
+ co.stavalues5
+ FROM dbms_stats.column_stats_effective co
+ JOIN pg_attribute a
+ ON (co.starelid = a.attrelid AND co.staattnum = a.attnum)
+ JOIN pg_type t
+ ON a.atttypid = t.oid
+ JOIN pg_namespace n1
+ ON t.typnamespace = n1.oid
+ RIGHT JOIN dbms_stats.relation_stats_effective r
+ ON co.starelid = r.relid
+ JOIN pg_catalog.pg_class cl
+ ON r.relid = cl.oid
+ JOIN pg_catalog.pg_namespace n2
+ ON cl.relnamespace = n2.oid
+ -- WHERE n2.nspname = 'public'
+ -- AND cl.relname = 'test'
+ -- AND a.attname = 'id'
+ WHERE n2.nspname = 's0' AND a.attname IS NULL
+ ORDER BY starelid, staattnum)
+TO STDOUT
+(FORMAT 'binary');
+\o
+COMMIT;
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+ nspname | relname | relpages | reltuples | relallvisible | curpages | attname | nspname_of_typename | typname | atttypmod | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 | stavalues1 | stavalues2 | stavalues3 | stavalues4 | stavalues5
+---------+---------+----------+-----------+---------------+----------+---------+---------------------+---------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------+------------+------------+------------+------------
+ s0 | sft0 | 0 | 0 | 0 | 0 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | st0_idx | 2 | 2 | 0 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | st1_idx | 2 | 3 | 0 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | st2_idx | 2 | 3 | 0 | 2 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+ s0 | st3 | 0 | 0 | 0 | 0 | | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null)
+(5 rows)
+
+\! rm export_effective_stats.sql.sample_test
+TRUNCATE dbms_stats.work;
+-- No.16-2-11
+\! sed '/ORDER/i\\ WHERE n2.nspname = '"\'s0\'"' AND cl.relname IS NULL' export_effective_stats.sql.sample > export_effective_stats.sql.sample_test
+\i export_effective_stats.sql.sample_test
+/*
+ * If you want the statistics of per-relation or per-column, please modify
+ * nspname, relname, and attname in 'WHERE' clause.
+ */
+BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
+/*
+ * If you want to chage the output file name, please modify the following name.
+ */
+\o export_stats.dmp
+COPY (SELECT n2.nspname,
+ cl.relname,
+ r.relpages,
+ r.reltuples,
+ r.relallvisible,
+ r.curpages,
+ r.last_analyze,
+ r.last_autoanalyze,
+ COALESCE(a.attname, ''),
+ n1.nspname AS schemaname_of_atttype,
+ t.typname,
+ a.atttypmod,
+ co.stainherit,
+ co.stanullfrac,
+ co.stawidth,
+ co.stadistinct,
+ co.stakind1,
+ co.stakind2,
+ co.stakind3,
+ co.stakind4,
+ co.stakind5,
+ co.staop1,
+ co.staop2,
+ co.staop3,
+ co.staop4,
+ co.staop5,
+ co.stanumbers1,
+ co.stanumbers2,
+ co.stanumbers3,
+ co.stanumbers4,
+ co.stanumbers5,
+ co.stavalues1,
+ co.stavalues2,
+ co.stavalues3,
+ co.stavalues4,
+ co.stavalues5
+ FROM dbms_stats.column_stats_effective co
+ JOIN pg_attribute a
+ ON (co.starelid = a.attrelid AND co.staattnum = a.attnum)
+ JOIN pg_type t
+ ON a.atttypid = t.oid
+ JOIN pg_namespace n1
+ ON t.typnamespace = n1.oid
+ RIGHT JOIN dbms_stats.relation_stats_effective r
+ ON co.starelid = r.relid
+ JOIN pg_catalog.pg_class cl
+ ON r.relid = cl.oid
+ JOIN pg_catalog.pg_namespace n2
+ ON cl.relnamespace = n2.oid
+ -- WHERE n2.nspname = 'public'
+ -- AND cl.relname = 'test'
+ -- AND a.attname = 'id'
+ WHERE n2.nspname = 's0' AND cl.relname IS NULL
+ ORDER BY starelid, staattnum)
+TO STDOUT
+(FORMAT 'binary');
+\o
+COMMIT;
+COPY dbms_stats.work FROM '@abs_srcdir@/export_stats.dmp' (FORMAT 'binary');
+SELECT * FROM work_v;
+ nspname | relname | relpages | reltuples | relallvisible | curpages | attname | nspname_of_typename | typname | atttypmod | stainherit | stanullfrac | stawidth | stadistinct | stakind1 | stakind2 | stakind3 | stakind4 | stakind5 | staop1 | staop2 | staop3 | staop4 | staop5 | stanumbers1 | stanumbers2 | stanumbers3 | stanumbers4 | stanumbers5 | stavalues1 | stavalues2 | stavalues3 | stavalues4 | stavalues5
+---------+---------+----------+-----------+---------------+----------+---------+---------------------+---------+-----------+------------+-------------+----------+-------------+----------+----------+----------+----------+----------+--------+--------+--------+--------+--------+-------------+-------------+-------------+-------------+-------------+------------+------------+------------+------------+------------
+(0 rows)
+
+\! rm export_effective_stats.sql.sample_test
+TRUNCATE dbms_stats.work;
+/*
+ * Stab function dbms_stats.import
+ */
+ALTER FUNCTION dbms_stats.import(
+ nspname text,
+ relid regclass,
+ attname text,
+ src text
+) RENAME TO truth_import;
+CREATE FUNCTION dbms_stats.import(
+ nspname text,
+ relid regclass,
+ attname text,
+ src text
+) RETURNS void AS
+$$
+BEGIN
+ RAISE NOTICE 'arguments are "%", "%", "%", "%"', $1, $2, $3, $4;
+ RETURN;
+END
+$$
+LANGUAGE plpgsql;
+/*
+ * No.17-1 dbms_stats.import_database_stats(src)
+ */
+-- No.17-1-1
+SELECT dbms_stats.import_database_stats('@abs_srcdir@/export_stats.dmp');
+NOTICE: arguments are "", "", "", "@abs_srcdir@/export_stats.dmp"
+ import_database_stats
+-----------------------
+
+(1 row)
+
+/*
+ * No.17-2 dbms_stats.import_schema_stats(schemaname, src)
+ */
+-- No.17-2-1
+SELECT dbms_stats.import_schema_stats('s0', '@abs_srcdir@/export_stats.dmp');
+NOTICE: arguments are "s0", "", "", "@abs_srcdir@/export_stats.dmp"
+ import_schema_stats
+---------------------
+
+(1 row)
+
+/*
+ * No.17-3 dbms_stats.import_table_stats(relid, src)
+ */
+-- No.17-3-1
+SELECT dbms_stats.import_table_stats('s0.st0', '@abs_srcdir@/export_stats.dmp');
+NOTICE: arguments are "", "s0.st0", "", "@abs_srcdir@/export_stats.dmp"
+ import_table_stats
+--------------------
+
+(1 row)
+
+/*
+ * No.17-4 dbms_stats.import_table_stats(schemaname, tablename, src)
+ */
+-- No.17-4-1
+SELECT dbms_stats.import_table_stats('s0', 'st0', '@abs_srcdir@/export_stats.dmp');
+NOTICE: arguments are "", "s0.st0", "", "@abs_srcdir@/export_stats.dmp"
+ import_table_stats
+--------------------
+
+(1 row)
+
+/*
+ * No.17-5 dbms_stats.import_column_stats (relid, attname, src)
+ */
+-- No.17-5-1
+SELECT dbms_stats.import_column_stats('s0.st0', 'id', '@abs_srcdir@/export_stats.dmp');
+NOTICE: arguments are "", "s0.st0", "id", "@abs_srcdir@/export_stats.dmp"
+ import_column_stats
+---------------------
+
+(1 row)
+
+/*
+ * No.17-6 dbms_stats.import_column_stats (schemaname, tablename, attname, src)
+ */
+-- No.17-6-1
+SELECT dbms_stats.import_column_stats('s0', 'st0', 'id','@abs_srcdir@/export_stats.dmp');
+NOTICE: arguments are "", "s0.st0", "id", "@abs_srcdir@/export_stats.dmp"
+ import_column_stats
+---------------------
+
+(1 row)
+
+/*
+ * Delete stab function dbms_stats.import
+ */
+DROP FUNCTION dbms_stats.import(
+ nspname text,
+ relid regclass,
+ attname text,
+ src text
+);
+ALTER FUNCTION dbms_stats.truth_import(
+ nspname text,
+ relid regclass,
+ attname text,
+ src text
+) RENAME TO import;
diff --git a/pg_dbms_stats--1.0-9.1.sql b/pg_dbms_stats--1.0-9.1.sql
new file mode 100644
index 0000000..1dc9fbb
--- /dev/null
+++ b/pg_dbms_stats--1.0-9.1.sql
@@ -0,0 +1,1411 @@
+/* pg_dbms_stats/pg_dbms_stats--1.0.sql */
+
+-- complain if script is sourced in psql, rather than via CREATE EXTENSION
+\echo Use "CREATE EXTENSION dbms_stats" to load this file. \quit
+
+-- define alias of anyarray type because parser does not allow to use
+-- anyarray in type definitions.
+--
+CREATE FUNCTION dbms_stats.anyarray_in(cstring) RETURNS dbms_stats.anyarray
+ AS 'anyarray_in' LANGUAGE internal STRICT IMMUTABLE;
+CREATE FUNCTION dbms_stats.anyarray_out(dbms_stats.anyarray) RETURNS cstring
+ AS 'anyarray_out' LANGUAGE internal STRICT IMMUTABLE;
+CREATE FUNCTION dbms_stats.anyarray_recv(internal) RETURNS dbms_stats.anyarray
+ AS 'MODULE_PATHNAME', 'dbms_stats_array_recv' LANGUAGE C STRICT IMMUTABLE;
+CREATE FUNCTION dbms_stats.anyarray_send(dbms_stats.anyarray) RETURNS bytea
+ AS 'anyarray_send' LANGUAGE internal STRICT IMMUTABLE;
+CREATE TYPE dbms_stats.anyarray (
+ INPUT = dbms_stats.anyarray_in,
+ OUTPUT = dbms_stats.anyarray_out,
+ RECEIVE = dbms_stats.anyarray_recv,
+ SEND = dbms_stats.anyarray_send,
+ INTERNALLENGTH = VARIABLE,
+ ALIGNMENT = double,
+ STORAGE = extended,
+ CATEGORY = 'P'
+);
+
+--
+-- User defined stats tables
+--
+
+CREATE TABLE dbms_stats._relation_stats_locked (
+ relid oid NOT NULL,
+ relname text NOT NULL,
+ relpages int4,
+ reltuples float4,
+ curpages int4,
+ last_analyze timestamp with time zone,
+ last_autoanalyze timestamp with time zone,
+ PRIMARY KEY (relid)
+);
+
+CREATE TABLE dbms_stats._column_stats_locked (
+ starelid oid NOT NULL,
+ staattnum int2 NOT NULL,
+ stainherit bool NOT NULL,
+ stanullfrac float4,
+ stawidth int4,
+ stadistinct float4,
+ stakind1 int2,
+ stakind2 int2,
+ stakind3 int2,
+ stakind4 int2,
+ staop1 oid,
+ staop2 oid,
+ staop3 oid,
+ staop4 oid,
+ stanumbers1 float4[],
+ stanumbers2 float4[],
+ stanumbers3 float4[],
+ stanumbers4 float4[],
+ stavalues1 dbms_stats.anyarray,
+ stavalues2 dbms_stats.anyarray,
+ stavalues3 dbms_stats.anyarray,
+ stavalues4 dbms_stats.anyarray,
+ PRIMARY KEY (starelid, staattnum, stainherit),
+ FOREIGN KEY (starelid) REFERENCES dbms_stats._relation_stats_locked (relid) ON DELETE CASCADE
+);
+
+--
+-- Statistics backup tables
+--
+
+CREATE TABLE dbms_stats.backup_history (
+ id serial8 PRIMARY KEY,
+ time timestamp with time zone NOT NULL,
+ unit char(1) NOT NULL,
+ comment text
+);
+
+CREATE TABLE dbms_stats.relation_stats_backup (
+ id int8 NOT NULL,
+ relid oid NOT NULL,
+ relname text NOT NULL,
+ relpages int4 NOT NULL,
+ reltuples float4 NOT NULL,
+ curpages int4 NOT NULL,
+ last_analyze timestamp with time zone,
+ last_autoanalyze timestamp with time zone,
+ PRIMARY KEY (id, relid),
+ FOREIGN KEY (id) REFERENCES dbms_stats.backup_history (id) ON DELETE CASCADE
+);
+
+CREATE TABLE dbms_stats.column_stats_backup (
+ id int8 NOT NULL,
+ statypid oid NOT NULL,
+ starelid oid NOT NULL,
+ staattnum int2 NOT NULL,
+ stainherit bool NOT NULL,
+ stanullfrac float4 NOT NULL,
+ stawidth int4 NOT NULL,
+ stadistinct float4 NOT NULL,
+ stakind1 int2 NOT NULL,
+ stakind2 int2 NOT NULL,
+ stakind3 int2 NOT NULL,
+ stakind4 int2 NOT NULL,
+ staop1 oid NOT NULL,
+ staop2 oid NOT NULL,
+ staop3 oid NOT NULL,
+ staop4 oid NOT NULL,
+ stanumbers1 float4[],
+ stanumbers2 float4[],
+ stanumbers3 float4[],
+ stanumbers4 float4[],
+ stavalues1 dbms_stats.anyarray,
+ stavalues2 dbms_stats.anyarray,
+ stavalues3 dbms_stats.anyarray,
+ stavalues4 dbms_stats.anyarray,
+ PRIMARY KEY (id, starelid, staattnum, stainherit),
+ FOREIGN KEY (id) REFERENCES dbms_stats.backup_history (id) ON DELETE CASCADE,
+ FOREIGN KEY (id, starelid) REFERENCES dbms_stats.relation_stats_backup (id, relid) ON DELETE CASCADE
+);
+
+--
+-- Functions
+--
+
+CREATE FUNCTION dbms_stats.relname(nspname text, relname text)
+RETURNS text AS
+$$SELECT quote_ident($1) || '.' || quote_ident($2)$$
+LANGUAGE sql STABLE STRICT;
+
+CREATE FUNCTION dbms_stats.is_system_schema(schemaname text)
+RETURNS boolean AS
+'MODULE_PATHNAME', 'dbms_stats_is_system_schema'
+LANGUAGE C IMMUTABLE STRICT;
+
+CREATE FUNCTION dbms_stats.is_system_catalog(relid regclass)
+RETURNS boolean AS
+'MODULE_PATHNAME', 'dbms_stats_is_system_catalog'
+LANGUAGE C STABLE;
+
+CREATE FUNCTION dbms_stats.is_target_relkind(relkind "char")
+RETURNS boolean AS
+$$SELECT $1 IN ('r', 'i')$$
+LANGUAGE sql STABLE;
+
+CREATE FUNCTION dbms_stats.merge(
+ lhs dbms_stats._column_stats_locked,
+ rhs pg_catalog.pg_statistic
+) RETURNS dbms_stats._column_stats_locked AS
+'MODULE_PATHNAME', 'dbms_stats_merge'
+LANGUAGE C STABLE;
+
+--
+-- Statistics views for internal use
+-- These views are used to merge authentic stats and dummy stats by hook
+-- function, so we don't grant SELECT privilege to PUBLIC.
+--
+
+CREATE VIEW dbms_stats.relation_stats_effective AS
+ SELECT
+ c.oid AS relid,
+ dbms_stats.relname(nspname, c.relname) AS relname,
+ COALESCE(v.relpages, c.relpages) AS relpages,
+ COALESCE(v.reltuples, c.reltuples) AS reltuples,
+ COALESCE(v.curpages,
+ (pg_relation_size(c.oid) / current_setting('block_size')::int4)::int4)
+ AS curpages,
+ COALESCE(v.last_analyze,
+ pg_catalog.pg_stat_get_last_analyze_time(c.oid))
+ AS last_analyze,
+ COALESCE(v.last_autoanalyze,
+ pg_catalog.pg_stat_get_last_autoanalyze_time(c.oid))
+ AS last_autoanalyze
+ FROM pg_catalog.pg_class c
+ JOIN pg_catalog.pg_namespace n
+ ON c.relnamespace = n.oid
+ LEFT JOIN dbms_stats._relation_stats_locked v
+ ON v.relid = c.oid
+ WHERE dbms_stats.is_target_relkind(c.relkind)
+ AND NOT dbms_stats.is_system_schema(nspname);
+
+CREATE VIEW dbms_stats.column_stats_effective AS
+ SELECT * FROM (
+ SELECT (dbms_stats.merge(v, s)).*
+ FROM pg_catalog.pg_statistic s
+ FULL JOIN dbms_stats._column_stats_locked v
+ USING (starelid, staattnum, stainherit)
+ WHERE NOT dbms_stats.is_system_catalog(starelid)
+ ) m
+ WHERE starelid IS NOT NULL;
+
+--
+-- Statistics views for user use (including non-superusers)
+-- These views allow users to see dummy statistics about tables which the
+-- user has SELECT privilege.
+--
+
+CREATE VIEW dbms_stats.relation_stats_locked
+ AS SELECT *
+ FROM dbms_stats._relation_stats_locked;
+
+GRANT SELECT ON dbms_stats.relation_stats_locked TO PUBLIC;
+
+CREATE VIEW dbms_stats.column_stats_locked
+ AS SELECT *
+ FROM dbms_stats._column_stats_locked
+ WHERE has_column_privilege(starelid, staattnum, 'SELECT');
+
+GRANT SELECT ON dbms_stats.column_stats_locked TO PUBLIC;
+
+--
+-- Note: This view is copied from pg_stats in
+-- src/backend/catalog/system_views.sql in core source tree of version
+-- 9.1, and customized for pg_dbms_stats. Changes from orignal one are:
+-- - rename from pg_stats to dbms_stats.stats by a view name.
+-- - changed the table name from pg_statistic to dbms_stats.column_stats_effective.
+--
+CREATE VIEW dbms_stats.stats AS
+ SELECT
+ nspname AS schemaname,
+ relname AS tablename,
+ attname AS attname,
+ stainherit AS inherited,
+ stanullfrac AS null_frac,
+ stawidth AS avg_width,
+ stadistinct AS n_distinct,
+ CASE
+ WHEN stakind1 IN (1, 4) THEN stavalues1
+ WHEN stakind2 IN (1, 4) THEN stavalues2
+ WHEN stakind3 IN (1, 4) THEN stavalues3
+ WHEN stakind4 IN (1, 4) THEN stavalues4
+ END AS most_common_vals,
+ CASE
+ WHEN stakind1 IN (1, 4) THEN stanumbers1
+ WHEN stakind2 IN (1, 4) THEN stanumbers2
+ WHEN stakind3 IN (1, 4) THEN stanumbers3
+ WHEN stakind4 IN (1, 4) THEN stanumbers4
+ END AS most_common_freqs,
+ CASE
+ WHEN stakind1 = 2 THEN stavalues1
+ WHEN stakind2 = 2 THEN stavalues2
+ WHEN stakind3 = 2 THEN stavalues3
+ WHEN stakind4 = 2 THEN stavalues4
+ END AS histogram_bounds,
+ CASE
+ WHEN stakind1 = 3 THEN stanumbers1[1]
+ WHEN stakind2 = 3 THEN stanumbers2[1]
+ WHEN stakind3 = 3 THEN stanumbers3[1]
+ WHEN stakind4 = 3 THEN stanumbers4[1]
+ END AS correlation
+ FROM dbms_stats.column_stats_effective s JOIN pg_class c ON (c.oid = s.starelid)
+ JOIN pg_attribute a ON (c.oid = attrelid AND attnum = s.staattnum)
+ LEFT JOIN pg_namespace n ON (n.oid = c.relnamespace)
+ WHERE NOT attisdropped AND has_column_privilege(c.oid, a.attnum, 'select');
+
+GRANT SELECT ON dbms_stats.stats TO PUBLIC;
+
+--
+-- Utility functions
+--
+
+CREATE FUNCTION dbms_stats.invalidate_relation_cache()
+ RETURNS trigger AS
+ 'MODULE_PATHNAME', 'dbms_stats_invalidate_relation_cache'
+ LANGUAGE C;
+
+-- Invalidate cached plans when dbms_stats._relation_stats_locked is modified.
+CREATE TRIGGER 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();
+
+CREATE FUNCTION dbms_stats.invalidate_column_cache()
+ RETURNS trigger AS
+ 'MODULE_PATHNAME', 'dbms_stats_invalidate_column_cache'
+ LANGUAGE C;
+
+-- Invalidate cached plans when dbms_stats._column_stats_locked is modified.
+CREATE TRIGGER 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();
+
+--
+-- BACKUP_STATS: Statistic backup functions
+--
+
+CREATE FUNCTION dbms_stats.backup(
+ backup_id int8,
+ relid regclass,
+ attnum int2
+) RETURNS int8 AS
+$$
+INSERT INTO dbms_stats.relation_stats_backup
+ SELECT $1, v.relid, v.relname, v.relpages, v.reltuples,
+ v.curpages, v.last_analyze, v.last_autoanalyze
+ FROM pg_catalog.pg_class c,
+ dbms_stats.relation_stats_effective v
+ WHERE c.oid = v.relid
+ AND dbms_stats.is_target_relkind(relkind)
+ AND NOT dbms_stats.is_system_catalog(v.relid)
+ AND (v.relid = $2 OR $2 IS NULL);
+
+INSERT INTO dbms_stats.column_stats_backup
+ SELECT $1, atttypid, s.*
+ FROM pg_catalog.pg_class c,
+ dbms_stats.column_stats_effective s,
+ pg_catalog.pg_attribute a
+ WHERE c.oid = starelid
+ AND starelid = attrelid
+ AND staattnum = attnum
+ AND dbms_stats.is_target_relkind(relkind)
+ AND NOT dbms_stats.is_system_catalog(c.oid)
+ AND ($2 IS NULL OR starelid = $2)
+ AND ($3 IS NULL OR staattnum = $3);
+
+SELECT $1;
+$$
+LANGUAGE sql;
+
+CREATE FUNCTION dbms_stats.backup(
+ relid regclass DEFAULT NULL,
+ attname text DEFAULT NULL,
+ comment text DEFAULT NULL
+) RETURNS int8 AS
+$$
+DECLARE
+ backup_id int8;
+ backup_relkind "char";
+ set_attnum int2;
+ unit_type char;
+BEGIN
+ IF $1 IS NULL AND $2 IS NOT NULL THEN
+ RAISE EXCEPTION 'relation is required';
+ END IF;
+ IF $1 IS NOT NULL THEN
+ SELECT relkind INTO backup_relkind
+ FROM pg_catalog.pg_class WHERE oid = $1;
+ IF NOT FOUND THEN
+ RAISE EXCEPTION 'relation "%" does not exist', $1;
+ END IF;
+ IF NOT dbms_stats.is_target_relkind(backup_relkind) THEN
+ RAISE EXCEPTION 'can not backup statistics of "%" with relkind "%"',
+ $1, backup_relkind
+ USING HINT = 'only tables and indexes are supported';
+ END IF;
+ IF dbms_stats.is_system_catalog($1) THEN
+ RAISE EXCEPTION 'can not backup statistics of system catalog "%"', $1;
+ END IF;
+ IF $2 IS NOT NULL THEN
+ SELECT a.attnum INTO set_attnum FROM pg_catalog.pg_attribute a
+ WHERE a.attrelid = $1 AND a.attname = $2;
+ IF set_attnum IS NULL THEN
+ RAISE EXCEPTION 'column "%" of "%" does not exist', $2, $1;
+ END IF;
+ IF NOT EXISTS(SELECT * FROM dbms_stats.column_stats_effective WHERE starelid = $1 AND staattnum = set_attnum) THEN
+ RAISE EXCEPTION 'statistic for column "%" of "%" does not exist', $2, $1;
+ END IF;
+ unit_type = 'c';
+ ELSE
+ unit_type = 't';
+ END IF;
+ ELSE
+ unit_type = 'd';
+ END IF;
+
+ INSERT INTO dbms_stats.backup_history(time, unit, comment)
+ VALUES (current_timestamp, unit_type, $3)
+ RETURNING dbms_stats.backup(id, $1, set_attnum) INTO backup_id;
+ RETURN backup_id;
+END;
+$$
+LANGUAGE plpgsql;
+
+CREATE FUNCTION dbms_stats.backup_database_stats(
+ comment text
+) RETURNS int8 AS
+$$
+SELECT dbms_stats.backup(NULL, NULL, $1)
+$$
+LANGUAGE sql;
+
+CREATE FUNCTION dbms_stats.backup_schema_stats(
+ schemaname text,
+ comment text
+) RETURNS int8 AS
+$$
+DECLARE
+ backup_id int8;
+BEGIN
+ IF NOT EXISTS(SELECT * FROM pg_namespace WHERE nspname = $1) THEN
+ RAISE EXCEPTION 'schema "%" does not exist', $1;
+ END IF;
+ IF dbms_stats.is_system_schema($1) THEN
+ RAISE EXCEPTION 'can not backup statistics of relation in system schema "%"', $1;
+ END IF;
+
+ INSERT INTO dbms_stats.backup_history(time, unit, comment)
+ VALUES (current_timestamp, 's', comment)
+ RETURNING id INTO backup_id;
+
+ PERFORM dbms_stats.backup(backup_id, cn.oid, NULL)
+ FROM (SELECT c.oid
+ FROM pg_catalog.pg_class c,
+ pg_catalog.pg_namespace n
+ WHERE n.nspname = schemaname
+ AND c.relnamespace = n.oid
+ AND dbms_stats.is_target_relkind(c.relkind)
+ ORDER BY c.oid
+ ) cn;
+
+ RETURN backup_id;
+END;
+$$
+LANGUAGE plpgsql;
+
+CREATE FUNCTION dbms_stats.backup_table_stats(
+ relid regclass,
+ comment text
+) RETURNS int8 AS
+$$
+SELECT dbms_stats.backup($1, NULL, $2)
+$$
+LANGUAGE sql;
+
+CREATE FUNCTION dbms_stats.backup_table_stats(
+ schemaname text,
+ tablename text,
+ comment text
+) RETURNS int8 AS
+$$
+SELECT dbms_stats.backup(dbms_stats.relname($1, $2)::regclass, NULL, $3)
+$$
+LANGUAGE sql;
+
+CREATE FUNCTION dbms_stats.backup_column_stats(
+ relid regclass,
+ attname text,
+ comment text
+) RETURNS int8 AS
+$$
+SELECT dbms_stats.backup($1, $2, $3)
+$$
+LANGUAGE sql;
+
+CREATE FUNCTION dbms_stats.backup_column_stats(
+ schemaname text,
+ tablename text,
+ attname text,
+ comment text
+) RETURNS int8 AS
+$$
+SELECT dbms_stats.backup(dbms_stats.relname($1, $2)::regclass, $3, $4)
+$$
+LANGUAGE sql;
+
+--
+-- RESTORE_STATS: Statistic restore functions
+--
+CREATE FUNCTION dbms_stats.restore(
+ backup_id int8,
+ relid regclass DEFAULT NULL,
+ attname text DEFAULT NULL
+) RETURNS SETOF regclass AS
+$$
+DECLARE
+ restore_id int8;
+ restore_relid regclass;
+ restore_attnum int2;
+ set_attnum int2;
+ restore_attname text;
+ restore_type regtype;
+ cur_type regtype;
+BEGIN
+ IF $1 IS NULL THEN
+ RAISE EXCEPTION 'backup id is required';
+ END IF;
+ IF $2 IS NULL AND $3 IS NOT NULL THEN
+ RAISE EXCEPTION 'relation is required';
+ END IF;
+ IF NOT EXISTS(SELECT * FROM dbms_stats.backup_history WHERE id <= $1) THEN
+ RAISE EXCEPTION 'backup id % does not exist', $1;
+ END IF;
+ IF $2 IS NOT NULL THEN
+ IF NOT EXISTS(SELECT * FROM pg_catalog.pg_class WHERE oid = $2) THEN
+ RAISE EXCEPTION 'relation "%" does not exist', $2;
+ END IF;
+ IF NOT EXISTS(SELECT * FROM dbms_stats.relation_stats_backup b
+ WHERE b.id <= $1 AND b.relid = $2) THEN
+ RAISE EXCEPTION 'relation "%" does not exist in previous backup', $2;
+ END IF;
+ IF $3 IS NOT NULL THEN
+ SELECT a.attnum INTO set_attnum FROM pg_catalog.pg_attribute a
+ WHERE a.attrelid = $2 AND a.attname = $3;
+ IF set_attnum IS NULL THEN
+ RAISE EXCEPTION 'column "%" of "%" does not exist', $3, $2;
+ END IF;
+ IF NOT EXISTS(SELECT * FROM dbms_stats.column_stats_backup WHERE id <= $1 AND starelid = $2 AND staattnum = set_attnum) THEN
+ RAISE EXCEPTION 'column "%" of "%" does not exist in previous backup',$3, $2;
+ END IF;
+ END IF;
+ END IF;
+
+ LOCK dbms_stats._relation_stats_locked IN SHARE UPDATE EXCLUSIVE MODE;
+ LOCK dbms_stats._column_stats_locked IN SHARE UPDATE EXCLUSIVE MODE;
+
+ FOR restore_id, restore_relid IN
+ SELECT max(b.id), c.oid
+ FROM pg_class c, dbms_stats.relation_stats_backup b
+ WHERE (c.oid = $2 OR $2 IS NULL)
+ AND c.oid = b.relid
+ AND dbms_stats.is_target_relkind(c.relkind)
+ AND NOT dbms_stats.is_system_catalog(c.oid)
+ AND b.id <= $1
+ GROUP BY c.oid
+ ORDER BY c.oid::regclass::text
+ LOOP
+ UPDATE dbms_stats._relation_stats_locked r
+ SET relid = b.relid,
+ relname = b.relname,
+ relpages = b.relpages,
+ reltuples = b.reltuples,
+ curpages = b.curpages,
+ last_analyze = b.last_analyze,
+ last_autoanalyze = b.last_autoanalyze
+ FROM dbms_stats.relation_stats_backup b
+ WHERE r.relid = restore_relid
+ AND b.id = restore_id
+ AND b.relid = restore_relid;
+ IF NOT FOUND THEN
+ INSERT INTO dbms_stats._relation_stats_locked
+ SELECT b.relid,
+ b.relname,
+ b.relpages,
+ b.reltuples,
+ b.curpages,
+ b.last_analyze,
+ b.last_autoanalyze
+ FROM dbms_stats.relation_stats_backup b
+ WHERE b.id = restore_id
+ AND b.relid = restore_relid;
+ END IF;
+ RETURN NEXT restore_relid;
+ END LOOP;
+
+ FOR restore_id, restore_relid, restore_attnum, restore_type, cur_type IN
+ SELECT t.id, t.oid, t.attnum, b.statypid, a.atttypid
+ FROM pg_attribute a,
+ dbms_stats.column_stats_backup b,
+ (SELECT max(b.id) AS id, c.oid, a.attnum
+ FROM pg_class c, pg_attribute a, dbms_stats.column_stats_backup b
+ WHERE (c.oid = $2 OR $2 IS NULL)
+ AND c.oid = a.attrelid
+ AND c.oid = b.starelid
+ AND (a.attnum = set_attnum OR set_attnum IS NULL)
+ AND a.attnum = b.staattnum
+ AND NOT a.attisdropped
+ AND dbms_stats.is_target_relkind(c.relkind)
+ AND b.id <= $1
+ GROUP BY c.oid, a.attnum) t
+ WHERE a.attrelid = t.oid
+ AND a.attnum = t.attnum
+ AND b.id = t.id
+ AND b.starelid = t.oid
+ AND b.staattnum = t.attnum
+ LOOP
+ IF restore_type <> cur_type THEN
+ SELECT a.attname INTO restore_attname
+ FROM pg_catalog.pg_attribute a
+ WHERE a.attrelid = restore_relid
+ AND a.attnum = restore_attnum;
+ RAISE WARNING 'skip "%.%" because of type mismatch: "%" in backup and "%" in database',
+ restore_relid, restore_attname, restore_type, cur_type;
+ ELSE
+ DELETE FROM dbms_stats._column_stats_locked
+ WHERE starelid = restore_relid
+ AND staattnum = restore_attnum;
+ INSERT INTO dbms_stats._column_stats_locked
+ SELECT starelid, staattnum, stainherit,
+ stanullfrac, stawidth, stadistinct,
+ stakind1, stakind2, stakind3, stakind4,
+ staop1, staop2, staop3, staop4,
+ stanumbers1, stanumbers2, stanumbers3, stanumbers4,
+ stavalues1, stavalues2, stavalues3, stavalues4
+ FROM dbms_stats.column_stats_backup
+ WHERE id = restore_id
+ AND starelid = restore_relid
+ AND staattnum = restore_attnum;
+ END IF;
+ END LOOP;
+END;
+$$
+LANGUAGE plpgsql;
+
+CREATE FUNCTION dbms_stats.restore_database_stats(
+ as_of_timestamp timestamp with time zone
+) RETURNS SETOF regclass AS
+$$
+SELECT dbms_stats.restore(m.id, m.relid)
+ FROM (SELECT max(r.id) AS id, r.relid
+ FROM pg_class c, dbms_stats.relation_stats_backup r,
+ dbms_stats.backup_history b
+ WHERE c.oid = r.relid
+ AND r.id = b.id
+ AND b.time <= $1
+ GROUP BY r.relid
+ ORDER BY r.relid
+ ) m;
+$$
+LANGUAGE sql STRICT;
+
+CREATE FUNCTION dbms_stats.restore_schema_stats(
+ schemaname text,
+ as_of_timestamp timestamp with time zone
+) RETURNS SETOF regclass AS
+$$
+BEGIN
+ IF NOT EXISTS(SELECT * FROM pg_namespace WHERE nspname = $1) THEN
+ RAISE EXCEPTION 'schema "%" does not exist', $1;
+ END IF;
+ IF dbms_stats.is_system_schema($1) THEN
+ RAISE EXCEPTION 'can not restore statistics of relation in system schema "%"', $1;
+ END IF;
+
+ RETURN QUERY
+ SELECT dbms_stats.restore(m.id, m.relid)
+ FROM (SELECT max(r.id) AS id, r.relid
+ FROM pg_class c, pg_namespace n,
+ dbms_stats.relation_stats_backup r,
+ dbms_stats.backup_history b
+ WHERE c.oid = r.relid
+ AND c.relnamespace = n.oid
+ AND n.nspname = $1
+ AND r.id = b.id
+ AND b.time <= $2
+ GROUP BY r.relid
+ ORDER BY r.relid
+ ) m;
+END;
+$$
+LANGUAGE plpgsql STRICT;
+
+CREATE FUNCTION dbms_stats.restore_table_stats(
+ relid regclass,
+ as_of_timestamp timestamp with time zone
+) RETURNS SETOF regclass AS
+$$
+SELECT dbms_stats.restore(max(id), $1, NULL)
+ FROM dbms_stats.backup_history WHERE time <= $2
+$$
+LANGUAGE sql STRICT;
+
+CREATE FUNCTION dbms_stats.restore_table_stats(
+ schemaname text,
+ tablename text,
+ as_of_timestamp timestamp with time zone
+) RETURNS SETOF regclass AS
+$$
+SELECT dbms_stats.restore_table_stats(dbms_stats.relname($1, $2)::regclass, $3)
+$$
+LANGUAGE sql STRICT;
+
+CREATE FUNCTION dbms_stats.restore_column_stats(
+ relid regclass,
+ attname text,
+ as_of_timestamp timestamp with time zone
+) RETURNS SETOF regclass AS
+$$
+SELECT dbms_stats.restore(max(id), $1, $2)
+ FROM dbms_stats.backup_history WHERE time <= $3
+$$
+LANGUAGE sql STRICT;
+
+CREATE FUNCTION dbms_stats.restore_column_stats(
+ schemaname text,
+ tablename text,
+ attname text,
+ as_of_timestamp timestamp with time zone
+) RETURNS SETOF regclass AS
+$$
+SELECT dbms_stats.restore(max(id), dbms_stats.relname($1, $2)::regclass, $3)
+ FROM dbms_stats.backup_history WHERE time <= $4
+$$
+LANGUAGE sql STRICT;
+
+CREATE FUNCTION dbms_stats.restore_stats(
+ backup_id int8
+) RETURNS SETOF regclass AS
+$$
+DECLARE
+ restore_relid regclass;
+ restore_attnum int2;
+ restore_attname text;
+ restore_type regtype;
+ cur_type regtype;
+BEGIN
+ IF NOT EXISTS(SELECT * FROM dbms_stats.backup_history WHERE id = $1) THEN
+ RAISE EXCEPTION 'backup id % does not exist', $1;
+ END IF;
+
+ LOCK dbms_stats._relation_stats_locked IN SHARE UPDATE EXCLUSIVE MODE;
+ LOCK dbms_stats._column_stats_locked IN SHARE UPDATE EXCLUSIVE MODE;
+
+ FOR restore_relid IN
+ SELECT b.relid
+ FROM pg_class c
+ JOIN dbms_stats.relation_stats_backup b ON (c.oid = b.relid)
+ WHERE b.id = $1
+ ORDER BY c.oid::regclass::text
+ LOOP
+ UPDATE dbms_stats._relation_stats_locked r
+ SET relid = b.relid,
+ relname = b.relname,
+ relpages = b.relpages,
+ reltuples = b.reltuples,
+ curpages = b.curpages,
+ last_analyze = b.last_analyze,
+ last_autoanalyze = b.last_autoanalyze
+ FROM dbms_stats.relation_stats_backup b
+ WHERE r.relid = restore_relid
+ AND b.id = $1
+ AND b.relid = restore_relid;
+ IF NOT FOUND THEN
+ INSERT INTO dbms_stats._relation_stats_locked
+ SELECT b.relid,
+ b.relname,
+ b.relpages,
+ b.reltuples,
+ b.curpages,
+ b.last_analyze,
+ b.last_autoanalyze
+ FROM dbms_stats.relation_stats_backup b
+ WHERE b.id = $1
+ AND b.relid = restore_relid;
+ END IF;
+ RETURN NEXT restore_relid;
+ END LOOP;
+
+ FOR restore_relid, restore_attnum, restore_type, cur_type IN
+ SELECT c.oid, a.attnum, b.statypid, a.atttypid
+ FROM pg_class c
+ JOIN dbms_stats.column_stats_backup b ON (c.oid = b.starelid)
+ JOIN pg_attribute a ON (b.starelid = attrelid
+ AND b.staattnum = a.attnum)
+ WHERE b.id = $1
+ LOOP
+ IF restore_type <> cur_type THEN
+ SELECT attname INTO restore_attname
+ FROM pg_catalog.pg_attribute
+ WHERE attrelid = restore_relid
+ AND attnum = restore_attnum;
+ RAISE WARNING 'skip "%.%" because of type mismatch: "%" in backup and "%" in database',
+ restore_relid, restore_attname, restore_type, cur_type;
+ ELSE
+ DELETE FROM dbms_stats._column_stats_locked
+ WHERE starelid = restore_relid
+ AND staattnum = restore_attnum;
+ INSERT INTO dbms_stats._column_stats_locked
+ SELECT starelid, staattnum, stainherit,
+ stanullfrac, stawidth, stadistinct,
+ stakind1, stakind2, stakind3, stakind4,
+ staop1, staop2, staop3, staop4,
+ stanumbers1, stanumbers2, stanumbers3, stanumbers4,
+ stavalues1, stavalues2, stavalues3, stavalues4
+ FROM dbms_stats.column_stats_backup
+ WHERE id = $1
+ AND starelid = restore_relid
+ AND staattnum = restore_attnum;
+ END IF;
+ END LOOP;
+
+END;
+$$
+LANGUAGE plpgsql STRICT;
+
+--
+-- LOCK_STATS: Statistic lock functions
+--
+
+CREATE FUNCTION dbms_stats.lock(
+ relid regclass,
+ attname text
+) RETURNS regclass AS
+$$
+DECLARE
+ lock_relkind "char";
+ set_attnum int2;
+ r record;
+BEGIN
+ IF $1 IS NULL THEN
+ RAISE EXCEPTION 'relation is required';
+ END IF;
+ IF $2 IS NULL THEN
+ RETURN dbms_stats.lock($1);
+ END IF;
+ SELECT relkind INTO lock_relkind FROM pg_catalog.pg_class WHERE oid = $1;
+ IF NOT FOUND THEN
+ RAISE EXCEPTION 'relation "%" does not exist', $1;
+ END IF;
+ IF NOT dbms_stats.is_target_relkind(lock_relkind) THEN
+ RAISE EXCEPTION '"%" is not a table nor an index', $1;
+ END IF;
+ IF EXISTS(SELECT * FROM pg_catalog.pg_index WHERE lock_relkind = 'i' AND indexrelid = $1 AND indexprs IS NULL) THEN
+ RAISE EXCEPTION '"%" is not an indexes on expressions', $1;
+ END IF;
+ IF dbms_stats.is_system_catalog($1) THEN
+ RAISE EXCEPTION 'can not lock statistics of system catalog "%"', $1;
+ END IF;
+ SELECT a.attnum INTO set_attnum FROM pg_catalog.pg_attribute a
+ WHERE a.attrelid = $1 AND a.attname = $2;
+ IF set_attnum IS NULL THEN
+ RAISE EXCEPTION 'column "%" of "%" does not exist', $2, $1;
+ END IF;
+
+ LOCK dbms_stats._relation_stats_locked IN SHARE UPDATE EXCLUSIVE MODE;
+ LOCK dbms_stats._column_stats_locked IN SHARE UPDATE EXCLUSIVE MODE;
+
+ /*
+ * If we don't have per-table statistics, create new one which has NULL for
+ * every statistic column_stats_effective.
+ */
+ IF NOT EXISTS(SELECT * FROM dbms_stats._relation_stats_locked ru
+ WHERE ru.relid = $1) THEN
+ INSERT INTO dbms_stats._relation_stats_locked
+ SELECT $1, dbms_stats.relname(nspname, relname),
+ NULL, NULL, NULL, NULL, NULL
+ FROM pg_catalog.pg_class c, pg_catalog.pg_namespace n
+ WHERE c.relnamespace = n.oid
+ AND c.oid = $1;
+ END IF;
+
+ /*
+ * Process for per-column statistics
+ */
+ FOR r IN
+ SELECT stainherit, stanullfrac, stawidth, stadistinct,
+ stakind1, stakind2, stakind3, stakind4,
+ staop1, staop2, staop3, staop4,
+ stanumbers1, stanumbers2, stanumbers3, stanumbers4,
+ stavalues1, stavalues2, stavalues3, stavalues4
+ FROM dbms_stats.column_stats_effective
+ WHERE starelid = $1
+ AND staattnum = set_attnum
+ LOOP
+ UPDATE dbms_stats._column_stats_locked c
+ SET stanullfrac = r.stanullfrac,
+ stawidth = r.stawidth,
+ stadistinct = r.stadistinct,
+ stakind1 = r.stakind1,
+ stakind2 = r.stakind2,
+ stakind3 = r.stakind3,
+ stakind4 = r.stakind4,
+ staop1 = r.staop1,
+ staop2 = r.staop2,
+ staop3 = r.staop3,
+ staop4 = r.staop4,
+ stanumbers1 = r.stanumbers1,
+ stanumbers2 = r.stanumbers2,
+ stanumbers3 = r.stanumbers3,
+ stanumbers4 = r.stanumbers4,
+ stavalues1 = r.stavalues1,
+ stavalues2 = r.stavalues2,
+ stavalues3 = r.stavalues3,
+ stavalues4 = r.stavalues4
+ WHERE c.starelid = $1
+ AND c.staattnum = set_attnum
+ AND c.stainherit = r.stainherit;
+
+ IF NOT FOUND THEN
+ INSERT INTO dbms_stats._column_stats_locked
+ VALUES ($1,
+ set_attnum,
+ r.stainherit,
+ r.stanullfrac,
+ r.stawidth,
+ r.stadistinct,
+ r.stakind1,
+ r.stakind2,
+ r.stakind3,
+ r.stakind4,
+ r.staop1,
+ r.staop2,
+ r.staop3,
+ r.staop4,
+ r.stanumbers1,
+ r.stanumbers2,
+ r.stanumbers3,
+ r.stanumbers4,
+ r.stavalues1,
+ r.stavalues2,
+ r.stavalues3,
+ r.stavalues4);
+ END IF;
+ END LOOP;
+
+ /* If we don't have statistic at all, raise error. */
+ IF NOT FOUND THEN
+ RAISE EXCEPTION 'statistic for column "%" of "%" does not exist', $2, $1::regclass;
+ END IF;
+
+ RETURN $1;
+END;
+$$
+LANGUAGE plpgsql;
+
+CREATE FUNCTION dbms_stats.lock(relid regclass)
+ RETURNS regclass AS
+$$
+DECLARE
+ lock_relkind "char";
+ i record;
+BEGIN
+ IF $1 IS NULL THEN
+ RAISE EXCEPTION 'relation is required';
+ END IF;
+ SELECT relkind INTO lock_relkind FROM pg_catalog.pg_class WHERE oid = $1;
+ IF NOT FOUND THEN
+ RAISE EXCEPTION 'relation "%" does not exist', $1;
+ END IF;
+ IF NOT dbms_stats.is_target_relkind(lock_relkind) THEN
+ RAISE EXCEPTION 'can not lock statistics of "%" with relkind "%"', $1, lock_relkind
+ USING HINT = 'only tables and indexes are supported';
+ END IF;
+ IF dbms_stats.is_system_catalog($1) THEN
+ RAISE EXCEPTION 'can not lock statistics of system catalog "%"', $1;
+ END IF;
+
+ LOCK dbms_stats._relation_stats_locked IN SHARE UPDATE EXCLUSIVE MODE;
+ LOCK dbms_stats._column_stats_locked IN SHARE UPDATE EXCLUSIVE MODE;
+
+ UPDATE dbms_stats._relation_stats_locked r
+ SET relname = dbms_stats.relname(nspname, c.relname),
+ relpages = v.relpages,
+ reltuples = v.reltuples,
+ curpages = v.curpages,
+ last_analyze = v.last_analyze,
+ last_autoanalyze = v.last_autoanalyze
+ FROM pg_catalog.pg_class c,
+ pg_catalog.pg_namespace n,
+ dbms_stats.relation_stats_effective v
+ WHERE r.relid = $1
+ AND c.oid = $1
+ AND c.relnamespace = n.oid
+ AND v.relid = $1;
+ IF NOT FOUND THEN
+ INSERT INTO dbms_stats._relation_stats_locked
+ SELECT $1, dbms_stats.relname(nspname, c.relname),
+ v.relpages, v.reltuples, v.curpages,
+ v.last_analyze, v.last_autoanalyze
+ FROM pg_catalog.pg_class c,
+ pg_catalog.pg_namespace n,
+ dbms_stats.relation_stats_effective v
+ WHERE c.oid = $1
+ AND c.relnamespace = n.oid
+ AND v.relid = $1;
+ END IF;
+
+ IF EXISTS(SELECT *
+ FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_index ind
+ ON c.oid = ind.indexrelid
+ WHERE c.oid = $1
+ AND c.relkind = 'i'
+ AND ind.indexprs IS NULL) THEN
+ RETURN $1;
+ END IF;
+
+ FOR i IN
+ SELECT staattnum, stainherit, stanullfrac,
+ stawidth, stadistinct,
+ stakind1, stakind2, stakind3, stakind4,
+ staop1, staop2, staop3, staop4,
+ stanumbers1, stanumbers2, stanumbers3, stanumbers4,
+ stavalues1, stavalues2, stavalues3, stavalues4
+ FROM dbms_stats.column_stats_effective
+ WHERE starelid = $1
+ LOOP
+ UPDATE dbms_stats._column_stats_locked c
+ SET stanullfrac = i.stanullfrac,
+ stawidth = i.stawidth,
+ stadistinct = i.stadistinct,
+ stakind1 = i.stakind1,
+ stakind2 = i.stakind2,
+ stakind3 = i.stakind3,
+ stakind4 = i.stakind4,
+ staop1 = i.staop1,
+ staop2 = i.staop2,
+ staop3 = i.staop3,
+ staop4 = i.staop4,
+ stanumbers1 = i.stanumbers1,
+ stanumbers2 = i.stanumbers2,
+ stanumbers3 = i.stanumbers3,
+ stanumbers4 = i.stanumbers4,
+ stavalues1 = i.stavalues1,
+ stavalues2 = i.stavalues2,
+ stavalues3 = i.stavalues3,
+ stavalues4 = i.stavalues4
+ WHERE c.starelid = $1
+ AND c.staattnum = i.staattnum
+ AND c.stainherit = i.stainherit;
+
+ IF NOT FOUND THEN
+ INSERT INTO dbms_stats._column_stats_locked
+ VALUES ($1,
+ i.staattnum,
+ i.stainherit,
+ i.stanullfrac,
+ i.stawidth,
+ i.stadistinct,
+ i.stakind1,
+ i.stakind2,
+ i.stakind3,
+ i.stakind4,
+ i.staop1,
+ i.staop2,
+ i.staop3,
+ i.staop4,
+ i.stanumbers1,
+ i.stanumbers2,
+ i.stanumbers3,
+ i.stanumbers4,
+ i.stavalues1,
+ i.stavalues2,
+ i.stavalues3,
+ i.stavalues4);
+ END IF;
+ END LOOP;
+
+ RETURN $1;
+END;
+$$
+LANGUAGE plpgsql;
+
+CREATE FUNCTION dbms_stats.lock_database_stats()
+ RETURNS SETOF regclass AS
+$$
+SELECT dbms_stats.lock(c.oid)
+ FROM (SELECT oid
+ FROM pg_catalog.pg_class
+ WHERE NOT dbms_stats.is_system_catalog(oid)
+ AND dbms_stats.is_target_relkind(relkind)
+ ORDER BY pg_class.oid
+ ) c;
+$$
+LANGUAGE sql;
+
+CREATE FUNCTION dbms_stats.lock_schema_stats(
+ schemaname text
+) RETURNS SETOF regclass AS
+$$
+BEGIN
+ IF NOT EXISTS(SELECT * FROM pg_namespace WHERE nspname = $1) THEN
+ RAISE EXCEPTION 'schema "%" does not exist', $1;
+ END IF;
+ IF dbms_stats.is_system_schema($1) THEN
+ RAISE EXCEPTION 'can not lock statistics of relation in system schema "%"', $1;
+ END IF;
+
+ RETURN QUERY
+ SELECT dbms_stats.lock(cn.oid)
+ FROM (SELECT c.oid
+ FROM pg_class c, pg_namespace n
+ WHERE c.relnamespace = n.oid
+ AND dbms_stats.is_target_relkind(c.relkind)
+ AND n.nspname = $1
+ ORDER BY c.oid
+ ) cn;
+END;
+$$
+LANGUAGE plpgsql STRICT;
+
+CREATE FUNCTION dbms_stats.lock_table_stats(relid regclass)
+ RETURNS regclass AS
+$$
+SELECT dbms_stats.lock($1)
+$$
+LANGUAGE sql STRICT;
+
+CREATE FUNCTION dbms_stats.lock_table_stats(
+ schemaname text,
+ tablename text
+) RETURNS regclass AS
+$$
+SELECT dbms_stats.lock(dbms_stats.relname($1, $2)::regclass)
+$$
+LANGUAGE sql STRICT;
+
+CREATE FUNCTION dbms_stats.lock_column_stats(
+ relid regclass,
+ attname text
+) RETURNS regclass AS
+$$
+SELECT dbms_stats.lock($1, $2)
+$$
+LANGUAGE sql STRICT;
+
+CREATE FUNCTION dbms_stats.lock_column_stats(
+ schemaname text,
+ tablename text,
+ attname text
+) RETURNS regclass AS
+$$
+SELECT dbms_stats.lock(dbms_stats.relname($1, $2)::regclass, $3)
+$$
+LANGUAGE sql STRICT;
+
+--
+-- UNLOCK_STATS: Statistic unlock functions
+--
+
+CREATE FUNCTION dbms_stats.unlock(
+ relid regclass DEFAULT NULL,
+ attname text DEFAULT NULL
+) RETURNS SETOF regclass AS
+$$
+DECLARE
+ set_attnum int2;
+ unlock_id int8;
+BEGIN
+ IF $1 IS NULL AND $2 IS NOT NULL THEN
+ RAISE EXCEPTION 'relation is required';
+ END IF;
+ SELECT a.attnum INTO set_attnum FROM pg_catalog.pg_attribute a
+ WHERE a.attrelid = $1 AND a.attname = $2;
+ IF $2 IS NOT NULL AND set_attnum IS NULL THEN
+ RAISE EXCEPTION 'column "%" of "%" does not exist', $2, $1;
+ END IF;
+
+ LOCK dbms_stats._relation_stats_locked IN SHARE UPDATE EXCLUSIVE MODE;
+ LOCK dbms_stats._column_stats_locked IN SHARE UPDATE EXCLUSIVE MODE;
+
+ DELETE FROM dbms_stats._column_stats_locked
+ WHERE (starelid = $1 OR $1 IS NULL)
+ AND (staattnum = set_attnum OR $2 IS NULL);
+
+ IF $1 IS NOT NULL AND $2 IS NOT NULL THEN
+ RETURN QUERY
+ SELECT $1;
+ END IF;
+ FOR unlock_id IN
+ SELECT ru.relid
+ FROM dbms_stats._relation_stats_locked ru
+ WHERE (ru.relid = $1 OR $1 IS NULL) AND ($2 IS NULL)
+ ORDER BY ru.relid
+ LOOP
+ DELETE FROM dbms_stats._relation_stats_locked ru
+ WHERE ru.relid = unlock_id;
+ RETURN NEXT unlock_id;
+ END LOOP;
+END;
+$$
+LANGUAGE plpgsql;
+
+CREATE FUNCTION dbms_stats.unlock_database_stats()
+ RETURNS SETOF regclass AS
+$$
+DECLARE
+ unlock_id int8;
+BEGIN
+ LOCK dbms_stats._relation_stats_locked IN SHARE UPDATE EXCLUSIVE MODE;
+ LOCK dbms_stats._column_stats_locked IN SHARE UPDATE EXCLUSIVE MODE;
+
+ FOR unlock_id IN
+ SELECT relid
+ FROM dbms_stats._relation_stats_locked
+ ORDER BY relid
+ LOOP
+ DELETE FROM dbms_stats._relation_stats_locked
+ WHERE relid = unlock_id;
+ RETURN NEXT unlock_id;
+ END LOOP;
+END;
+$$
+LANGUAGE plpgsql STRICT;
+
+CREATE FUNCTION dbms_stats.unlock_schema_stats(
+ schemaname text
+) RETURNS SETOF regclass AS
+$$
+DECLARE
+ unlock_id int8;
+BEGIN
+ IF NOT EXISTS(SELECT * FROM pg_namespace WHERE nspname = $1) THEN
+ RAISE EXCEPTION 'schema "%" does not exist', $1;
+ END IF;
+ IF dbms_stats.is_system_schema($1) THEN
+ RAISE EXCEPTION 'can not unlock statistics of relation in system schema "%"', $1;
+ END IF;
+
+ LOCK dbms_stats._relation_stats_locked IN SHARE UPDATE EXCLUSIVE MODE;
+ LOCK dbms_stats._column_stats_locked IN SHARE UPDATE EXCLUSIVE MODE;
+
+ FOR unlock_id IN
+ SELECT relid
+ FROM dbms_stats._relation_stats_locked, pg_class c, pg_namespace n
+ WHERE relid = c.oid
+ AND c.relnamespace = n.oid
+ AND n.nspname = $1
+ ORDER BY relid
+ LOOP
+ DELETE FROM dbms_stats._relation_stats_locked
+ WHERE relid = unlock_id;
+ RETURN NEXT unlock_id;
+ END LOOP;
+END;
+$$
+LANGUAGE plpgsql STRICT;
+
+CREATE FUNCTION dbms_stats.unlock_table_stats(relid regclass)
+ RETURNS SETOF regclass AS
+$$
+
+LOCK dbms_stats._relation_stats_locked IN SHARE UPDATE EXCLUSIVE MODE;
+LOCK dbms_stats._column_stats_locked IN SHARE UPDATE EXCLUSIVE MODE;
+
+DELETE FROM dbms_stats._relation_stats_locked
+ WHERE relid = $1
+ RETURNING relid::regclass
+$$
+LANGUAGE sql STRICT;
+
+CREATE FUNCTION dbms_stats.unlock_table_stats(
+ schemaname text,
+ tablename text
+) RETURNS SETOF regclass AS
+$$
+
+LOCK dbms_stats._relation_stats_locked IN SHARE UPDATE EXCLUSIVE MODE;
+LOCK dbms_stats._column_stats_locked IN SHARE UPDATE EXCLUSIVE MODE;
+
+DELETE FROM dbms_stats._relation_stats_locked
+ WHERE relid = dbms_stats.relname($1, $2)::regclass
+ RETURNING relid::regclass
+$$
+LANGUAGE sql STRICT;
+
+CREATE FUNCTION dbms_stats.unlock_column_stats(
+ relid regclass,
+ attname text
+) RETURNS SETOF regclass AS
+$$
+DECLARE
+ set_attnum int2;
+BEGIN
+ SELECT a.attnum INTO set_attnum FROM pg_catalog.pg_attribute a
+ WHERE a.attrelid = $1 AND a.attname = $2;
+ IF $2 IS NOT NULL AND set_attnum IS NULL THEN
+ RAISE EXCEPTION 'column "%" of "%" does not exist', $2, $1;
+ END IF;
+
+ LOCK dbms_stats._relation_stats_locked IN SHARE UPDATE EXCLUSIVE MODE;
+ LOCK dbms_stats._column_stats_locked IN SHARE UPDATE EXCLUSIVE MODE;
+
+ DELETE FROM dbms_stats._column_stats_locked
+ WHERE starelid = $1
+ AND staattnum = set_attnum;
+ RETURN QUERY
+ SELECT $1;
+END;
+$$
+LANGUAGE plpgsql STRICT;
+
+CREATE FUNCTION dbms_stats.unlock_column_stats(
+ schemaname text,
+ tablename text,
+ attname text
+) RETURNS SETOF regclass AS
+$$
+DECLARE
+ set_attnum int2;
+BEGIN
+ SELECT a.attnum INTO set_attnum FROM pg_catalog.pg_attribute a
+ WHERE a.attrelid = dbms_stats.relname($1, $2)::regclass
+ AND a.attname = $3;
+ IF $3 IS NOT NULL AND set_attnum IS NULL THEN
+ RAISE EXCEPTION 'column "%" of "%.%" does not exist', $3, $1, $2;
+ END IF;
+
+ LOCK dbms_stats._relation_stats_locked IN SHARE UPDATE EXCLUSIVE MODE;
+ LOCK dbms_stats._column_stats_locked IN SHARE UPDATE EXCLUSIVE MODE;
+
+ DELETE FROM dbms_stats._column_stats_locked
+ WHERE starelid = dbms_stats.relname($1, $2)::regclass
+ AND staattnum = set_attnum;
+ RETURN QUERY
+ SELECT dbms_stats.relname($1, $2)::regclass;
+END;
+$$
+LANGUAGE plpgsql STRICT;
+
+--
+-- IMPORT_STATS: Statistic import functions
+--
+
+CREATE FUNCTION dbms_stats.import(
+ nspname text DEFAULT NULL,
+ relid regclass DEFAULT NULL,
+ attname text DEFAULT NULL,
+ src text DEFAULT NULL
+) RETURNS void AS
+'MODULE_PATHNAME', 'dbms_stats_import'
+LANGUAGE C;
+
+CREATE FUNCTION dbms_stats.import_database_stats(src text)
+ RETURNS void AS
+$$
+SELECT dbms_stats.import(NULL, NULL, NULL, $1)
+$$
+LANGUAGE sql;
+
+CREATE FUNCTION dbms_stats.import_schema_stats(
+ schemaname text,
+ src text
+) RETURNS void AS
+$$
+SELECT dbms_stats.import($1, NULL, NULL, $2)
+$$
+LANGUAGE sql;
+
+CREATE FUNCTION dbms_stats.import_table_stats(
+ relid regclass,
+ src text
+) RETURNS void AS
+$$
+SELECT dbms_stats.import(NULL, $1, NULL, $2)
+$$
+LANGUAGE sql;
+
+CREATE FUNCTION dbms_stats.import_table_stats(
+ schemaname text,
+ tablename text,
+ src text
+) RETURNS void AS
+$$
+SELECT dbms_stats.import(NULL, dbms_stats.relname($1, $2)::regclass, NULL, $3)
+$$
+LANGUAGE sql;
+
+CREATE FUNCTION dbms_stats.import_column_stats(
+ relid regclass,
+ attname text,
+ src text
+) RETURNS void AS
+$$
+SELECT dbms_stats.import(NULL, $1, $2, $3)
+$$
+LANGUAGE sql;
+
+CREATE FUNCTION dbms_stats.import_column_stats(
+ schemaname text,
+ tablename text,
+ attname text,
+ src text
+) RETURNS void AS
+$$
+SELECT dbms_stats.import(NULL, dbms_stats.relname($1, $2)::regclass, $3, $4)
+$$
+LANGUAGE sql;
+
+--
+-- PURGE_STATS: Statistic purge function
+--
+
+CREATE OR REPLACE FUNCTION dbms_stats.purge_stats(
+ backup_id int8,
+ force bool DEFAULT false
+) RETURNS SETOF dbms_stats.backup_history AS
+$$
+DECLARE
+ delete_id int8;
+ deleted dbms_stats.backup_history;
+BEGIN
+ IF $1 IS NULL THEN
+ RAISE EXCEPTION 'backup id is required';
+ END IF;
+ IF $2 IS NULL THEN
+ RAISE EXCEPTION 'force is not null';
+ END IF;
+
+ LOCK dbms_stats.backup_history IN SHARE UPDATE EXCLUSIVE MODE;
+ LOCK dbms_stats.relation_stats_backup IN SHARE UPDATE EXCLUSIVE MODE;
+ LOCK dbms_stats.column_stats_backup IN SHARE UPDATE EXCLUSIVE MODE;
+
+ IF NOT EXISTS(SELECT * FROM dbms_stats.backup_history WHERE id = $1) THEN
+ RAISE EXCEPTION 'backup id % does not exist', $1;
+ END IF;
+ IF NOT $2 AND NOT EXISTS(SELECT *
+ FROM dbms_stats.backup_history
+ WHERE unit = 'd'
+ AND id > $1) THEN
+ RAISE WARNING 'at least one database-wise backup must be remain'
+ USING HINT = 'use true as 2nd parameter, if you want to purge forcibly';
+ RETURN;
+ END IF;
+
+ FOR deleted IN
+ SELECT * FROM dbms_stats.backup_history
+ WHERE id <= $1
+ ORDER BY id
+ LOOP
+ DELETE FROM dbms_stats.backup_history
+ WHERE id = deleted.id;
+ RETURN NEXT deleted;
+ END LOOP;
+END;
+$$
+LANGUAGE plpgsql;
+
+GRANT USAGE ON schema dbms_stats TO PUBLIC;
+--
diff --git a/pg_dbms_stats--1.0-9.2.sql b/pg_dbms_stats--1.0-9.2.sql
new file mode 100644
index 0000000..da1f294
--- /dev/null
+++ b/pg_dbms_stats--1.0-9.2.sql
@@ -0,0 +1,1468 @@
+/* pg_dbms_stats/pg_dbms_stats--1.0.sql */
+
+-- complain if script is sourced in psql, rather than via CREATE EXTENSION
+\echo Use "CREATE EXTENSION dbms_stats" to load this file. \quit
+
+-- define alias of anyarray type because parser does not allow to use
+-- anyarray in type definitions.
+--
+CREATE FUNCTION dbms_stats.anyarray_in(cstring) RETURNS dbms_stats.anyarray
+ AS 'anyarray_in' LANGUAGE internal STRICT IMMUTABLE;
+CREATE FUNCTION dbms_stats.anyarray_out(dbms_stats.anyarray) RETURNS cstring
+ AS 'anyarray_out' LANGUAGE internal STRICT IMMUTABLE;
+CREATE FUNCTION dbms_stats.anyarray_recv(internal) RETURNS dbms_stats.anyarray
+ AS 'MODULE_PATHNAME', 'dbms_stats_array_recv' LANGUAGE C STRICT IMMUTABLE;
+CREATE FUNCTION dbms_stats.anyarray_send(dbms_stats.anyarray) RETURNS bytea
+ AS 'anyarray_send' LANGUAGE internal STRICT IMMUTABLE;
+CREATE TYPE dbms_stats.anyarray (
+ INPUT = dbms_stats.anyarray_in,
+ OUTPUT = dbms_stats.anyarray_out,
+ RECEIVE = dbms_stats.anyarray_recv,
+ SEND = dbms_stats.anyarray_send,
+ INTERNALLENGTH = VARIABLE,
+ ALIGNMENT = double,
+ STORAGE = extended,
+ CATEGORY = 'P'
+);
+
+--
+-- User defined stats tables
+--
+
+CREATE TABLE dbms_stats._relation_stats_locked (
+ relid oid NOT NULL,
+ relname text NOT NULL,
+ relpages int4,
+ reltuples float4,
+ relallvisible int4,
+ curpages int4,
+ last_analyze timestamp with time zone,
+ last_autoanalyze timestamp with time zone,
+ PRIMARY KEY (relid)
+);
+
+CREATE TABLE dbms_stats._column_stats_locked (
+ starelid oid NOT NULL,
+ staattnum int2 NOT NULL,
+ stainherit bool NOT NULL,
+ stanullfrac float4,
+ stawidth int4,
+ stadistinct float4,
+ stakind1 int2,
+ stakind2 int2,
+ stakind3 int2,
+ stakind4 int2,
+ stakind5 int2,
+ staop1 oid,
+ staop2 oid,
+ staop3 oid,
+ staop4 oid,
+ staop5 oid,
+ stanumbers1 float4[],
+ stanumbers2 float4[],
+ stanumbers3 float4[],
+ stanumbers4 float4[],
+ stanumbers5 float4[],
+ stavalues1 dbms_stats.anyarray,
+ stavalues2 dbms_stats.anyarray,
+ stavalues3 dbms_stats.anyarray,
+ stavalues4 dbms_stats.anyarray,
+ stavalues5 dbms_stats.anyarray,
+ PRIMARY KEY (starelid, staattnum, stainherit),
+ FOREIGN KEY (starelid) REFERENCES dbms_stats._relation_stats_locked (relid) ON DELETE CASCADE
+);
+
+--
+-- Statistics backup tables
+--
+
+CREATE TABLE dbms_stats.backup_history (
+ id serial8 PRIMARY KEY,
+ time timestamp with time zone NOT NULL,
+ unit char(1) NOT NULL,
+ comment text
+);
+
+CREATE TABLE dbms_stats.relation_stats_backup (
+ id int8 NOT NULL,
+ relid oid NOT NULL,
+ relname text NOT NULL,
+ relpages int4 NOT NULL,
+ reltuples float4 NOT NULL,
+ relallvisible int4 NOT NULL,
+ curpages int4 NOT NULL,
+ last_analyze timestamp with time zone,
+ last_autoanalyze timestamp with time zone,
+ PRIMARY KEY (id, relid),
+ FOREIGN KEY (id) REFERENCES dbms_stats.backup_history (id) ON DELETE CASCADE
+);
+
+CREATE TABLE dbms_stats.column_stats_backup (
+ id int8 NOT NULL,
+ statypid oid NOT NULL,
+ starelid oid NOT NULL,
+ staattnum int2 NOT NULL,
+ stainherit bool NOT NULL,
+ stanullfrac float4 NOT NULL,
+ stawidth int4 NOT NULL,
+ stadistinct float4 NOT NULL,
+ stakind1 int2 NOT NULL,
+ stakind2 int2 NOT NULL,
+ stakind3 int2 NOT NULL,
+ stakind4 int2 NOT NULL,
+ stakind5 int2 NOT NULL,
+ staop1 oid NOT NULL,
+ staop2 oid NOT NULL,
+ staop3 oid NOT NULL,
+ staop4 oid NOT NULL,
+ staop5 oid NOT NULL,
+ stanumbers1 float4[],
+ stanumbers2 float4[],
+ stanumbers3 float4[],
+ stanumbers4 float4[],
+ stanumbers5 float4[],
+ stavalues1 dbms_stats.anyarray,
+ stavalues2 dbms_stats.anyarray,
+ stavalues3 dbms_stats.anyarray,
+ stavalues4 dbms_stats.anyarray,
+ stavalues5 dbms_stats.anyarray,
+ PRIMARY KEY (id, starelid, staattnum, stainherit),
+ FOREIGN KEY (id) REFERENCES dbms_stats.backup_history (id) ON DELETE CASCADE,
+ FOREIGN KEY (id, starelid) REFERENCES dbms_stats.relation_stats_backup (id, relid) ON DELETE CASCADE
+);
+
+--
+-- Functions
+--
+
+CREATE FUNCTION dbms_stats.relname(nspname text, relname text)
+RETURNS text AS
+$$SELECT quote_ident($1) || '.' || quote_ident($2)$$
+LANGUAGE sql STABLE STRICT;
+
+CREATE FUNCTION dbms_stats.is_system_schema(schemaname text)
+RETURNS boolean AS
+'MODULE_PATHNAME', 'dbms_stats_is_system_schema'
+LANGUAGE C IMMUTABLE STRICT;
+
+CREATE FUNCTION dbms_stats.is_system_catalog(relid regclass)
+RETURNS boolean AS
+'MODULE_PATHNAME', 'dbms_stats_is_system_catalog'
+LANGUAGE C STABLE;
+
+CREATE FUNCTION dbms_stats.is_target_relkind(relkind "char")
+RETURNS boolean AS
+$$SELECT $1 IN ('r', 'i', 'f')$$
+LANGUAGE sql STABLE;
+
+CREATE FUNCTION dbms_stats.merge(
+ lhs dbms_stats._column_stats_locked,
+ rhs pg_catalog.pg_statistic
+) RETURNS dbms_stats._column_stats_locked AS
+'MODULE_PATHNAME', 'dbms_stats_merge'
+LANGUAGE C STABLE;
+
+--
+-- Statistics views for internal use
+-- These views are used to merge authentic stats and dummy stats by hook
+-- function, so we don't grant SELECT privilege to PUBLIC.
+--
+
+CREATE VIEW dbms_stats.relation_stats_effective AS
+ SELECT
+ c.oid AS relid,
+ dbms_stats.relname(nspname, c.relname) AS relname,
+ COALESCE(v.relpages, c.relpages) AS relpages,
+ COALESCE(v.reltuples, c.reltuples) AS reltuples,
+ COALESCE(v.relallvisible, c.relallvisible) AS relallvisible,
+ COALESCE(v.curpages,
+ (pg_relation_size(c.oid) / current_setting('block_size')::int4)::int4)
+ AS curpages,
+ COALESCE(v.last_analyze,
+ pg_catalog.pg_stat_get_last_analyze_time(c.oid))
+ AS last_analyze,
+ COALESCE(v.last_autoanalyze,
+ pg_catalog.pg_stat_get_last_autoanalyze_time(c.oid))
+ AS last_autoanalyze
+ FROM pg_catalog.pg_class c
+ JOIN pg_catalog.pg_namespace n
+ ON c.relnamespace = n.oid
+ LEFT JOIN dbms_stats._relation_stats_locked v
+ ON v.relid = c.oid
+ WHERE dbms_stats.is_target_relkind(c.relkind)
+ AND NOT dbms_stats.is_system_schema(nspname);
+
+CREATE VIEW dbms_stats.column_stats_effective AS
+ SELECT * FROM (
+ SELECT (dbms_stats.merge(v, s)).*
+ FROM pg_catalog.pg_statistic s
+ FULL JOIN dbms_stats._column_stats_locked v
+ USING (starelid, staattnum, stainherit)
+ WHERE NOT dbms_stats.is_system_catalog(starelid)
+ ) m
+ WHERE starelid IS NOT NULL;
+
+--
+-- Statistics views for user use (including non-superusers)
+-- These views allow users to see dummy statistics about tables which the
+-- user has SELECT privilege.
+--
+
+CREATE VIEW dbms_stats.relation_stats_locked
+ AS SELECT *
+ FROM dbms_stats._relation_stats_locked;
+
+GRANT SELECT ON dbms_stats.relation_stats_locked TO PUBLIC;
+
+CREATE VIEW dbms_stats.column_stats_locked
+ AS SELECT *
+ FROM dbms_stats._column_stats_locked
+ WHERE has_column_privilege(starelid, staattnum, 'SELECT');
+
+GRANT SELECT ON dbms_stats.column_stats_locked TO PUBLIC;
+
+--
+-- Note: This view is copied from pg_stats in
+-- src/backend/catalog/system_views.sql in core source tree of version
+-- 9.2, and customized for pg_dbms_stats. Changes from orignal one are:
+-- - rename from pg_stats to dbms_stats.stats by a view name.
+-- - changed the table name from pg_statistic to dbms_stats.column_stats_effective.
+--
+CREATE VIEW dbms_stats.stats AS
+ SELECT
+ nspname AS schemaname,
+ relname AS tablename,
+ attname AS attname,
+ stainherit AS inherited,
+ stanullfrac AS null_frac,
+ stawidth AS avg_width,
+ stadistinct AS n_distinct,
+ CASE
+ WHEN stakind1 = 1 THEN stavalues1
+ WHEN stakind2 = 1 THEN stavalues2
+ WHEN stakind3 = 1 THEN stavalues3
+ WHEN stakind4 = 1 THEN stavalues4
+ WHEN stakind5 = 1 THEN stavalues5
+ END AS most_common_vals,
+ CASE
+ WHEN stakind1 = 1 THEN stanumbers1
+ WHEN stakind2 = 1 THEN stanumbers2
+ WHEN stakind3 = 1 THEN stanumbers3
+ WHEN stakind4 = 1 THEN stanumbers4
+ WHEN stakind5 = 1 THEN stanumbers5
+ END AS most_common_freqs,
+ CASE
+ WHEN stakind1 = 2 THEN stavalues1
+ WHEN stakind2 = 2 THEN stavalues2
+ WHEN stakind3 = 2 THEN stavalues3
+ WHEN stakind4 = 2 THEN stavalues4
+ WHEN stakind5 = 2 THEN stavalues5
+ END AS histogram_bounds,
+ CASE
+ WHEN stakind1 = 3 THEN stanumbers1[1]
+ WHEN stakind2 = 3 THEN stanumbers2[1]
+ WHEN stakind3 = 3 THEN stanumbers3[1]
+ WHEN stakind4 = 3 THEN stanumbers4[1]
+ WHEN stakind5 = 3 THEN stanumbers5[1]
+ END AS correlation,
+ CASE
+ WHEN stakind1 = 4 THEN stavalues1
+ WHEN stakind2 = 4 THEN stavalues2
+ WHEN stakind3 = 4 THEN stavalues3
+ WHEN stakind4 = 4 THEN stavalues4
+ WHEN stakind5 = 4 THEN stavalues5
+ END AS most_common_elems,
+ CASE
+ WHEN stakind1 = 4 THEN stanumbers1
+ WHEN stakind2 = 4 THEN stanumbers2
+ WHEN stakind3 = 4 THEN stanumbers3
+ WHEN stakind4 = 4 THEN stanumbers4
+ WHEN stakind5 = 4 THEN stanumbers5
+ END AS most_common_elem_freqs,
+ CASE
+ WHEN stakind1 = 5 THEN stanumbers1
+ WHEN stakind2 = 5 THEN stanumbers2
+ WHEN stakind3 = 5 THEN stanumbers3
+ WHEN stakind4 = 5 THEN stanumbers4
+ WHEN stakind5 = 5 THEN stanumbers5
+ END AS elem_count_histogram
+ FROM dbms_stats.column_stats_effective s JOIN pg_class c ON (c.oid = s.starelid)
+ JOIN pg_attribute a ON (c.oid = attrelid AND attnum = s.staattnum)
+ LEFT JOIN pg_namespace n ON (n.oid = c.relnamespace)
+ WHERE NOT attisdropped AND has_column_privilege(c.oid, a.attnum, 'select');
+
+GRANT SELECT ON dbms_stats.stats TO PUBLIC;
+
+--
+-- Utility functions
+--
+
+CREATE FUNCTION dbms_stats.invalidate_relation_cache()
+ RETURNS trigger AS
+ 'MODULE_PATHNAME', 'dbms_stats_invalidate_relation_cache'
+ LANGUAGE C;
+
+-- Invalidate cached plans when dbms_stats._relation_stats_locked is modified.
+CREATE TRIGGER 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();
+
+CREATE FUNCTION dbms_stats.invalidate_column_cache()
+ RETURNS trigger AS
+ 'MODULE_PATHNAME', 'dbms_stats_invalidate_column_cache'
+ LANGUAGE C;
+
+-- Invalidate cached plans when dbms_stats._column_stats_locked is modified.
+CREATE TRIGGER 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();
+
+--
+-- BACKUP_STATS: Statistic backup functions
+--
+
+CREATE FUNCTION dbms_stats.backup(
+ backup_id int8,
+ relid regclass,
+ attnum int2
+) RETURNS int8 AS
+$$
+INSERT INTO dbms_stats.relation_stats_backup
+ SELECT $1, v.relid, v.relname, v.relpages, v.reltuples, v.relallvisible,
+ v.curpages, v.last_analyze, v.last_autoanalyze
+ FROM pg_catalog.pg_class c,
+ dbms_stats.relation_stats_effective v
+ WHERE c.oid = v.relid
+ AND dbms_stats.is_target_relkind(relkind)
+ AND NOT dbms_stats.is_system_catalog(v.relid)
+ AND (v.relid = $2 OR $2 IS NULL);
+
+INSERT INTO dbms_stats.column_stats_backup
+ SELECT $1, atttypid, s.*
+ FROM pg_catalog.pg_class c,
+ dbms_stats.column_stats_effective s,
+ pg_catalog.pg_attribute a
+ WHERE c.oid = starelid
+ AND starelid = attrelid
+ AND staattnum = attnum
+ AND dbms_stats.is_target_relkind(relkind)
+ AND NOT dbms_stats.is_system_catalog(c.oid)
+ AND ($2 IS NULL OR starelid = $2)
+ AND ($3 IS NULL OR staattnum = $3);
+
+SELECT $1;
+$$
+LANGUAGE sql;
+
+CREATE FUNCTION dbms_stats.backup(
+ relid regclass DEFAULT NULL,
+ attname text DEFAULT NULL,
+ comment text DEFAULT NULL
+) RETURNS int8 AS
+$$
+DECLARE
+ backup_id int8;
+ backup_relkind "char";
+ set_attnum int2;
+ unit_type char;
+BEGIN
+ IF $1 IS NULL AND $2 IS NOT NULL THEN
+ RAISE EXCEPTION 'relation is required';
+ END IF;
+ IF $1 IS NOT NULL THEN
+ SELECT relkind INTO backup_relkind
+ FROM pg_catalog.pg_class WHERE oid = $1;
+ IF NOT FOUND THEN
+ RAISE EXCEPTION 'relation "%" does not exist', $1;
+ END IF;
+ IF NOT dbms_stats.is_target_relkind(backup_relkind) THEN
+ RAISE EXCEPTION 'can not backup statistics of "%" with relkind "%"',
+ $1, backup_relkind
+ USING HINT = 'only tables and indexes are supported';
+ END IF;
+ IF dbms_stats.is_system_catalog($1) THEN
+ RAISE EXCEPTION 'can not backup statistics of system catalog "%"', $1;
+ END IF;
+ IF $2 IS NOT NULL THEN
+ SELECT a.attnum INTO set_attnum FROM pg_catalog.pg_attribute a
+ WHERE a.attrelid = $1 AND a.attname = $2;
+ IF set_attnum IS NULL THEN
+ RAISE EXCEPTION 'column "%" of "%" does not exist', $2, $1;
+ END IF;
+ IF NOT EXISTS(SELECT * FROM dbms_stats.column_stats_effective WHERE starelid = $1 AND staattnum = set_attnum) THEN
+ RAISE EXCEPTION 'statistic for column "%" of "%" does not exist', $2, $1;
+ END IF;
+ unit_type = 'c';
+ ELSE
+ unit_type = 't';
+ END IF;
+ ELSE
+ unit_type = 'd';
+ END IF;
+
+ INSERT INTO dbms_stats.backup_history(time, unit, comment)
+ VALUES (current_timestamp, unit_type, $3)
+ RETURNING dbms_stats.backup(id, $1, set_attnum) INTO backup_id;
+ RETURN backup_id;
+END;
+$$
+LANGUAGE plpgsql;
+
+CREATE FUNCTION dbms_stats.backup_database_stats(
+ comment text
+) RETURNS int8 AS
+$$
+SELECT dbms_stats.backup(NULL, NULL, $1)
+$$
+LANGUAGE sql;
+
+CREATE FUNCTION dbms_stats.backup_schema_stats(
+ schemaname text,
+ comment text
+) RETURNS int8 AS
+$$
+DECLARE
+ backup_id int8;
+BEGIN
+ IF NOT EXISTS(SELECT * FROM pg_namespace WHERE nspname = $1) THEN
+ RAISE EXCEPTION 'schema "%" does not exist', $1;
+ END IF;
+ IF dbms_stats.is_system_schema($1) THEN
+ RAISE EXCEPTION 'can not backup statistics of relation in system schema "%"', $1;
+ END IF;
+
+ INSERT INTO dbms_stats.backup_history(time, unit, comment)
+ VALUES (current_timestamp, 's', comment)
+ RETURNING id INTO backup_id;
+
+ PERFORM dbms_stats.backup(backup_id, cn.oid, NULL)
+ FROM (SELECT c.oid
+ FROM pg_catalog.pg_class c,
+ pg_catalog.pg_namespace n
+ WHERE n.nspname = schemaname
+ AND c.relnamespace = n.oid
+ AND dbms_stats.is_target_relkind(c.relkind)
+ ORDER BY c.oid
+ ) cn;
+
+ RETURN backup_id;
+END;
+$$
+LANGUAGE plpgsql;
+
+CREATE FUNCTION dbms_stats.backup_table_stats(
+ relid regclass,
+ comment text
+) RETURNS int8 AS
+$$
+SELECT dbms_stats.backup($1, NULL, $2)
+$$
+LANGUAGE sql;
+
+CREATE FUNCTION dbms_stats.backup_table_stats(
+ schemaname text,
+ tablename text,
+ comment text
+) RETURNS int8 AS
+$$
+SELECT dbms_stats.backup(dbms_stats.relname($1, $2)::regclass, NULL, $3)
+$$
+LANGUAGE sql;
+
+CREATE FUNCTION dbms_stats.backup_column_stats(
+ relid regclass,
+ attname text,
+ comment text
+) RETURNS int8 AS
+$$
+SELECT dbms_stats.backup($1, $2, $3)
+$$
+LANGUAGE sql;
+
+CREATE FUNCTION dbms_stats.backup_column_stats(
+ schemaname text,
+ tablename text,
+ attname text,
+ comment text
+) RETURNS int8 AS
+$$
+SELECT dbms_stats.backup(dbms_stats.relname($1, $2)::regclass, $3, $4)
+$$
+LANGUAGE sql;
+
+--
+-- RESTORE_STATS: Statistic restore functions
+--
+CREATE FUNCTION dbms_stats.restore(
+ backup_id int8,
+ relid regclass DEFAULT NULL,
+ attname text DEFAULT NULL
+) RETURNS SETOF regclass AS
+$$
+DECLARE
+ restore_id int8;
+ restore_relid regclass;
+ restore_attnum int2;
+ set_attnum int2;
+ restore_attname text;
+ restore_type regtype;
+ cur_type regtype;
+BEGIN
+ IF $1 IS NULL THEN
+ RAISE EXCEPTION 'backup id is required';
+ END IF;
+ IF $2 IS NULL AND $3 IS NOT NULL THEN
+ RAISE EXCEPTION 'relation is required';
+ END IF;
+ IF NOT EXISTS(SELECT * FROM dbms_stats.backup_history WHERE id <= $1) THEN
+ RAISE EXCEPTION 'backup id % does not exist', $1;
+ END IF;
+ IF $2 IS NOT NULL THEN
+ IF NOT EXISTS(SELECT * FROM pg_catalog.pg_class WHERE oid = $2) THEN
+ RAISE EXCEPTION 'relation "%" does not exist', $2;
+ END IF;
+ IF NOT EXISTS(SELECT * FROM dbms_stats.relation_stats_backup b
+ WHERE b.id <= $1 AND b.relid = $2) THEN
+ RAISE EXCEPTION 'relation "%" does not exist in previous backup', $2;
+ END IF;
+ IF $3 IS NOT NULL THEN
+ SELECT a.attnum INTO set_attnum FROM pg_catalog.pg_attribute a
+ WHERE a.attrelid = $2 AND a.attname = $3;
+ IF set_attnum IS NULL THEN
+ RAISE EXCEPTION 'column "%" of "%" does not exist', $3, $2;
+ END IF;
+ IF NOT EXISTS(SELECT * FROM dbms_stats.column_stats_backup WHERE id <= $1 AND starelid = $2 AND staattnum = set_attnum) THEN
+ RAISE EXCEPTION 'column "%" of "%" does not exist in previous backup',$3, $2;
+ END IF;
+ END IF;
+ END IF;
+
+ LOCK dbms_stats._relation_stats_locked IN SHARE UPDATE EXCLUSIVE MODE;
+ LOCK dbms_stats._column_stats_locked IN SHARE UPDATE EXCLUSIVE MODE;
+
+ FOR restore_id, restore_relid IN
+ SELECT max(b.id), c.oid
+ FROM pg_class c, dbms_stats.relation_stats_backup b
+ WHERE (c.oid = $2 OR $2 IS NULL)
+ AND c.oid = b.relid
+ AND dbms_stats.is_target_relkind(c.relkind)
+ AND NOT dbms_stats.is_system_catalog(c.oid)
+ AND b.id <= $1
+ GROUP BY c.oid
+ ORDER BY c.oid::regclass::text
+ LOOP
+ UPDATE dbms_stats._relation_stats_locked r
+ SET relid = b.relid,
+ relname = b.relname,
+ relpages = b.relpages,
+ reltuples = b.reltuples,
+ relallvisible = b.relallvisible,
+ curpages = b.curpages,
+ last_analyze = b.last_analyze,
+ last_autoanalyze = b.last_autoanalyze
+ FROM dbms_stats.relation_stats_backup b
+ WHERE r.relid = restore_relid
+ AND b.id = restore_id
+ AND b.relid = restore_relid;
+ IF NOT FOUND THEN
+ INSERT INTO dbms_stats._relation_stats_locked
+ SELECT b.relid,
+ b.relname,
+ b.relpages,
+ b.reltuples,
+ b.relallvisible,
+ b.curpages,
+ b.last_analyze,
+ b.last_autoanalyze
+ FROM dbms_stats.relation_stats_backup b
+ WHERE b.id = restore_id
+ AND b.relid = restore_relid;
+ END IF;
+ RETURN NEXT restore_relid;
+ END LOOP;
+
+ FOR restore_id, restore_relid, restore_attnum, restore_type, cur_type IN
+ SELECT t.id, t.oid, t.attnum, b.statypid, a.atttypid
+ FROM pg_attribute a,
+ dbms_stats.column_stats_backup b,
+ (SELECT max(b.id) AS id, c.oid, a.attnum
+ FROM pg_class c, pg_attribute a, dbms_stats.column_stats_backup b
+ WHERE (c.oid = $2 OR $2 IS NULL)
+ AND c.oid = a.attrelid
+ AND c.oid = b.starelid
+ AND (a.attnum = set_attnum OR set_attnum IS NULL)
+ AND a.attnum = b.staattnum
+ AND NOT a.attisdropped
+ AND dbms_stats.is_target_relkind(c.relkind)
+ AND b.id <= $1
+ GROUP BY c.oid, a.attnum) t
+ WHERE a.attrelid = t.oid
+ AND a.attnum = t.attnum
+ AND b.id = t.id
+ AND b.starelid = t.oid
+ AND b.staattnum = t.attnum
+ LOOP
+ IF restore_type <> cur_type THEN
+ SELECT a.attname INTO restore_attname
+ FROM pg_catalog.pg_attribute a
+ WHERE a.attrelid = restore_relid
+ AND a.attnum = restore_attnum;
+ RAISE WARNING 'skip "%.%" because of type mismatch: "%" in backup and "%" in database',
+ restore_relid, restore_attname, restore_type, cur_type;
+ ELSE
+ DELETE FROM dbms_stats._column_stats_locked
+ WHERE starelid = restore_relid
+ AND staattnum = restore_attnum;
+ INSERT INTO dbms_stats._column_stats_locked
+ SELECT 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
+ FROM dbms_stats.column_stats_backup
+ WHERE id = restore_id
+ AND starelid = restore_relid
+ AND staattnum = restore_attnum;
+ END IF;
+ END LOOP;
+END;
+$$
+LANGUAGE plpgsql;
+
+CREATE FUNCTION dbms_stats.restore_database_stats(
+ as_of_timestamp timestamp with time zone
+) RETURNS SETOF regclass AS
+$$
+SELECT dbms_stats.restore(m.id, m.relid)
+ FROM (SELECT max(r.id) AS id, r.relid
+ FROM pg_class c, dbms_stats.relation_stats_backup r,
+ dbms_stats.backup_history b
+ WHERE c.oid = r.relid
+ AND r.id = b.id
+ AND b.time <= $1
+ GROUP BY r.relid
+ ORDER BY r.relid
+ ) m;
+$$
+LANGUAGE sql STRICT;
+
+CREATE FUNCTION dbms_stats.restore_schema_stats(
+ schemaname text,
+ as_of_timestamp timestamp with time zone
+) RETURNS SETOF regclass AS
+$$
+BEGIN
+ IF NOT EXISTS(SELECT * FROM pg_namespace WHERE nspname = $1) THEN
+ RAISE EXCEPTION 'schema "%" does not exist', $1;
+ END IF;
+ IF dbms_stats.is_system_schema($1) THEN
+ RAISE EXCEPTION 'can not restore statistics of relation in system schema "%"', $1;
+ END IF;
+
+ RETURN QUERY
+ SELECT dbms_stats.restore(m.id, m.relid)
+ FROM (SELECT max(r.id) AS id, r.relid
+ FROM pg_class c, pg_namespace n,
+ dbms_stats.relation_stats_backup r,
+ dbms_stats.backup_history b
+ WHERE c.oid = r.relid
+ AND c.relnamespace = n.oid
+ AND n.nspname = $1
+ AND r.id = b.id
+ AND b.time <= $2
+ GROUP BY r.relid
+ ORDER BY r.relid
+ ) m;
+END;
+$$
+LANGUAGE plpgsql STRICT;
+
+CREATE FUNCTION dbms_stats.restore_table_stats(
+ relid regclass,
+ as_of_timestamp timestamp with time zone
+) RETURNS SETOF regclass AS
+$$
+SELECT dbms_stats.restore(max(id), $1, NULL)
+ FROM dbms_stats.backup_history WHERE time <= $2
+$$
+LANGUAGE sql STRICT;
+
+CREATE FUNCTION dbms_stats.restore_table_stats(
+ schemaname text,
+ tablename text,
+ as_of_timestamp timestamp with time zone
+) RETURNS SETOF regclass AS
+$$
+SELECT dbms_stats.restore_table_stats(dbms_stats.relname($1, $2)::regclass, $3)
+$$
+LANGUAGE sql STRICT;
+
+CREATE FUNCTION dbms_stats.restore_column_stats(
+ relid regclass,
+ attname text,
+ as_of_timestamp timestamp with time zone
+) RETURNS SETOF regclass AS
+$$
+SELECT dbms_stats.restore(max(id), $1, $2)
+ FROM dbms_stats.backup_history WHERE time <= $3
+$$
+LANGUAGE sql STRICT;
+
+CREATE FUNCTION dbms_stats.restore_column_stats(
+ schemaname text,
+ tablename text,
+ attname text,
+ as_of_timestamp timestamp with time zone
+) RETURNS SETOF regclass AS
+$$
+SELECT dbms_stats.restore(max(id), dbms_stats.relname($1, $2)::regclass, $3)
+ FROM dbms_stats.backup_history WHERE time <= $4
+$$
+LANGUAGE sql STRICT;
+
+CREATE FUNCTION dbms_stats.restore_stats(
+ backup_id int8
+) RETURNS SETOF regclass AS
+$$
+DECLARE
+ restore_relid regclass;
+ restore_attnum int2;
+ restore_attname text;
+ restore_type regtype;
+ cur_type regtype;
+BEGIN
+ IF NOT EXISTS(SELECT * FROM dbms_stats.backup_history WHERE id = $1) THEN
+ RAISE EXCEPTION 'backup id % does not exist', $1;
+ END IF;
+
+ LOCK dbms_stats._relation_stats_locked IN SHARE UPDATE EXCLUSIVE MODE;
+ LOCK dbms_stats._column_stats_locked IN SHARE UPDATE EXCLUSIVE MODE;
+
+ FOR restore_relid IN
+ SELECT b.relid
+ FROM pg_class c
+ JOIN dbms_stats.relation_stats_backup b ON (c.oid = b.relid)
+ WHERE b.id = $1
+ ORDER BY c.oid::regclass::text
+ LOOP
+ UPDATE dbms_stats._relation_stats_locked r
+ SET relid = b.relid,
+ relname = b.relname,
+ relpages = b.relpages,
+ reltuples = b.reltuples,
+ relallvisible = b.relallvisible,
+ curpages = b.curpages,
+ last_analyze = b.last_analyze,
+ last_autoanalyze = b.last_autoanalyze
+ FROM dbms_stats.relation_stats_backup b
+ WHERE r.relid = restore_relid
+ AND b.id = $1
+ AND b.relid = restore_relid;
+ IF NOT FOUND THEN
+ INSERT INTO dbms_stats._relation_stats_locked
+ SELECT b.relid,
+ b.relname,
+ b.relpages,
+ b.reltuples,
+ b.relallvisible,
+ b.curpages,
+ b.last_analyze,
+ b.last_autoanalyze
+ FROM dbms_stats.relation_stats_backup b
+ WHERE b.id = $1
+ AND b.relid = restore_relid;
+ END IF;
+ RETURN NEXT restore_relid;
+ END LOOP;
+
+ FOR restore_relid, restore_attnum, restore_type, cur_type IN
+ SELECT c.oid, a.attnum, b.statypid, a.atttypid
+ FROM pg_class c
+ JOIN dbms_stats.column_stats_backup b ON (c.oid = b.starelid)
+ JOIN pg_attribute a ON (b.starelid = attrelid
+ AND b.staattnum = a.attnum)
+ WHERE b.id = $1
+ LOOP
+ IF restore_type <> cur_type THEN
+ SELECT attname INTO restore_attname
+ FROM pg_catalog.pg_attribute
+ WHERE attrelid = restore_relid
+ AND attnum = restore_attnum;
+ RAISE WARNING 'skip "%.%" because of type mismatch: "%" in backup and "%" in database',
+ restore_relid, restore_attname, restore_type, cur_type;
+ ELSE
+ DELETE FROM dbms_stats._column_stats_locked
+ WHERE starelid = restore_relid
+ AND staattnum = restore_attnum;
+ INSERT INTO dbms_stats._column_stats_locked
+ SELECT 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
+ FROM dbms_stats.column_stats_backup
+ WHERE id = $1
+ AND starelid = restore_relid
+ AND staattnum = restore_attnum;
+ END IF;
+ END LOOP;
+
+END;
+$$
+LANGUAGE plpgsql STRICT;
+
+--
+-- LOCK_STATS: Statistic lock functions
+--
+
+CREATE FUNCTION dbms_stats.lock(
+ relid regclass,
+ attname text
+) RETURNS regclass AS
+$$
+DECLARE
+ lock_relkind "char";
+ set_attnum int2;
+ r record;
+BEGIN
+ IF $1 IS NULL THEN
+ RAISE EXCEPTION 'relation is required';
+ END IF;
+ IF $2 IS NULL THEN
+ RETURN dbms_stats.lock($1);
+ END IF;
+ SELECT relkind INTO lock_relkind FROM pg_catalog.pg_class WHERE oid = $1;
+ IF NOT FOUND THEN
+ RAISE EXCEPTION 'relation "%" does not exist', $1;
+ END IF;
+ IF NOT dbms_stats.is_target_relkind(lock_relkind) THEN
+ RAISE EXCEPTION '"%" is not a table nor an index', $1;
+ END IF;
+ IF EXISTS(SELECT * FROM pg_catalog.pg_index WHERE lock_relkind = 'i' AND indexrelid = $1 AND indexprs IS NULL) THEN
+ RAISE EXCEPTION '"%" is not an indexes on expressions', $1;
+ END IF;
+ IF dbms_stats.is_system_catalog($1) THEN
+ RAISE EXCEPTION 'can not lock statistics of system catalog "%"', $1;
+ END IF;
+ SELECT a.attnum INTO set_attnum FROM pg_catalog.pg_attribute a
+ WHERE a.attrelid = $1 AND a.attname = $2;
+ IF set_attnum IS NULL THEN
+ RAISE EXCEPTION 'column "%" of "%" does not exist', $2, $1;
+ END IF;
+
+ LOCK dbms_stats._relation_stats_locked IN SHARE UPDATE EXCLUSIVE MODE;
+ LOCK dbms_stats._column_stats_locked IN SHARE UPDATE EXCLUSIVE MODE;
+
+ /*
+ * If we don't have per-table statistics, create new one which has NULL for
+ * every statistic column_stats_effective.
+ */
+ IF NOT EXISTS(SELECT * FROM dbms_stats._relation_stats_locked ru
+ WHERE ru.relid = $1) THEN
+ INSERT INTO dbms_stats._relation_stats_locked
+ SELECT $1, dbms_stats.relname(nspname, relname),
+ NULL, NULL, NULL, NULL, NULL
+ FROM pg_catalog.pg_class c, pg_catalog.pg_namespace n
+ WHERE c.relnamespace = n.oid
+ AND c.oid = $1;
+ END IF;
+
+ /*
+ * Process for per-column statistics
+ */
+ FOR r IN
+ SELECT stainherit, stanullfrac, stawidth, stadistinct,
+ stakind1, stakind2, stakind3, stakind4, stakind5,
+ staop1, staop2, staop3, staop4, staop5,
+ stanumbers1, stanumbers2, stanumbers3, stanumbers4, stanumbers5,
+ stavalues1, stavalues2, stavalues3, stavalues4, stavalues5
+ FROM dbms_stats.column_stats_effective
+ WHERE starelid = $1
+ AND staattnum = set_attnum
+ LOOP
+ UPDATE dbms_stats._column_stats_locked c
+ SET stanullfrac = r.stanullfrac,
+ stawidth = r.stawidth,
+ stadistinct = r.stadistinct,
+ stakind1 = r.stakind1,
+ stakind2 = r.stakind2,
+ stakind3 = r.stakind3,
+ stakind4 = r.stakind4,
+ stakind5 = r.stakind5,
+ staop1 = r.staop1,
+ staop2 = r.staop2,
+ staop3 = r.staop3,
+ staop4 = r.staop4,
+ staop5 = r.staop5,
+ stanumbers1 = r.stanumbers1,
+ stanumbers2 = r.stanumbers2,
+ stanumbers3 = r.stanumbers3,
+ stanumbers4 = r.stanumbers4,
+ stanumbers5 = r.stanumbers5,
+ stavalues1 = r.stavalues1,
+ stavalues2 = r.stavalues2,
+ stavalues3 = r.stavalues3,
+ stavalues4 = r.stavalues4,
+ stavalues5 = r.stavalues5
+ WHERE c.starelid = $1
+ AND c.staattnum = set_attnum
+ AND c.stainherit = r.stainherit;
+
+ IF NOT FOUND THEN
+ INSERT INTO dbms_stats._column_stats_locked
+ VALUES ($1,
+ set_attnum,
+ r.stainherit,
+ r.stanullfrac,
+ r.stawidth,
+ r.stadistinct,
+ r.stakind1,
+ r.stakind2,
+ r.stakind3,
+ r.stakind4,
+ r.stakind5,
+ r.staop1,
+ r.staop2,
+ r.staop3,
+ r.staop4,
+ r.staop5,
+ r.stanumbers1,
+ r.stanumbers2,
+ r.stanumbers3,
+ r.stanumbers4,
+ r.stanumbers5,
+ r.stavalues1,
+ r.stavalues2,
+ r.stavalues3,
+ r.stavalues4,
+ r.stavalues5);
+ END IF;
+ END LOOP;
+
+ /* If we don't have statistic at all, raise error. */
+ IF NOT FOUND THEN
+ RAISE EXCEPTION 'statistic for column "%" of "%" does not exist', $2, $1::regclass;
+ END IF;
+
+ RETURN $1;
+END;
+$$
+LANGUAGE plpgsql;
+
+CREATE FUNCTION dbms_stats.lock(relid regclass)
+ RETURNS regclass AS
+$$
+DECLARE
+ lock_relkind "char";
+ i record;
+BEGIN
+ IF $1 IS NULL THEN
+ RAISE EXCEPTION 'relation is required';
+ END IF;
+ SELECT relkind INTO lock_relkind FROM pg_catalog.pg_class WHERE oid = $1;
+ IF NOT FOUND THEN
+ RAISE EXCEPTION 'relation "%" does not exist', $1;
+ END IF;
+ IF NOT dbms_stats.is_target_relkind(lock_relkind) THEN
+ RAISE EXCEPTION 'can not lock statistics of "%" with relkind "%"', $1, lock_relkind
+ USING HINT = 'only tables and indexes are supported';
+ END IF;
+ IF dbms_stats.is_system_catalog($1) THEN
+ RAISE EXCEPTION 'can not lock statistics of system catalog "%"', $1;
+ END IF;
+
+ LOCK dbms_stats._relation_stats_locked IN SHARE UPDATE EXCLUSIVE MODE;
+ LOCK dbms_stats._column_stats_locked IN SHARE UPDATE EXCLUSIVE MODE;
+
+ UPDATE dbms_stats._relation_stats_locked r
+ SET relname = dbms_stats.relname(nspname, c.relname),
+ relpages = v.relpages,
+ reltuples = v.reltuples,
+ relallvisible = v.relallvisible,
+ curpages = v.curpages,
+ last_analyze = v.last_analyze,
+ last_autoanalyze = v.last_autoanalyze
+ FROM pg_catalog.pg_class c,
+ pg_catalog.pg_namespace n,
+ dbms_stats.relation_stats_effective v
+ WHERE r.relid = $1
+ AND c.oid = $1
+ AND c.relnamespace = n.oid
+ AND v.relid = $1;
+ IF NOT FOUND THEN
+ INSERT INTO dbms_stats._relation_stats_locked
+ SELECT $1, dbms_stats.relname(nspname, c.relname),
+ v.relpages, v.reltuples, v.relallvisible, v.curpages,
+ v.last_analyze, v.last_autoanalyze
+ FROM pg_catalog.pg_class c,
+ pg_catalog.pg_namespace n,
+ dbms_stats.relation_stats_effective v
+ WHERE c.oid = $1
+ AND c.relnamespace = n.oid
+ AND v.relid = $1;
+ END IF;
+
+ IF EXISTS(SELECT *
+ FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_index ind
+ ON c.oid = ind.indexrelid
+ WHERE c.oid = $1
+ AND c.relkind = 'i'
+ AND ind.indexprs IS NULL) THEN
+ RETURN $1;
+ END IF;
+
+ FOR i IN
+ SELECT 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
+ FROM dbms_stats.column_stats_effective
+ WHERE starelid = $1
+ LOOP
+ UPDATE dbms_stats._column_stats_locked c
+ SET stanullfrac = i.stanullfrac,
+ stawidth = i.stawidth,
+ stadistinct = i.stadistinct,
+ stakind1 = i.stakind1,
+ stakind2 = i.stakind2,
+ stakind3 = i.stakind3,
+ stakind4 = i.stakind4,
+ stakind5 = i.stakind5,
+ staop1 = i.staop1,
+ staop2 = i.staop2,
+ staop3 = i.staop3,
+ staop4 = i.staop4,
+ staop5 = i.staop5,
+ stanumbers1 = i.stanumbers1,
+ stanumbers2 = i.stanumbers2,
+ stanumbers3 = i.stanumbers3,
+ stanumbers4 = i.stanumbers4,
+ stanumbers5 = i.stanumbers5,
+ stavalues1 = i.stavalues1,
+ stavalues2 = i.stavalues2,
+ stavalues3 = i.stavalues3,
+ stavalues4 = i.stavalues4,
+ stavalues5 = i.stavalues5
+ WHERE c.starelid = $1
+ AND c.staattnum = i.staattnum
+ AND c.stainherit = i.stainherit;
+
+ IF NOT FOUND THEN
+ INSERT INTO dbms_stats._column_stats_locked
+ VALUES ($1,
+ i.staattnum,
+ i.stainherit,
+ i.stanullfrac,
+ i.stawidth,
+ i.stadistinct,
+ i.stakind1,
+ i.stakind2,
+ i.stakind3,
+ i.stakind4,
+ i.stakind5,
+ i.staop1,
+ i.staop2,
+ i.staop3,
+ i.staop4,
+ i.staop5,
+ i.stanumbers1,
+ i.stanumbers2,
+ i.stanumbers3,
+ i.stanumbers4,
+ i.stanumbers5,
+ i.stavalues1,
+ i.stavalues2,
+ i.stavalues3,
+ i.stavalues4,
+ i.stavalues5);
+ END IF;
+ END LOOP;
+
+ RETURN $1;
+END;
+$$
+LANGUAGE plpgsql;
+
+CREATE FUNCTION dbms_stats.lock_database_stats()
+ RETURNS SETOF regclass AS
+$$
+SELECT dbms_stats.lock(c.oid)
+ FROM (SELECT oid
+ FROM pg_catalog.pg_class
+ WHERE NOT dbms_stats.is_system_catalog(oid)
+ AND dbms_stats.is_target_relkind(relkind)
+ ORDER BY pg_class.oid
+ ) c;
+$$
+LANGUAGE sql;
+
+CREATE FUNCTION dbms_stats.lock_schema_stats(
+ schemaname text
+) RETURNS SETOF regclass AS
+$$
+BEGIN
+ IF NOT EXISTS(SELECT * FROM pg_namespace WHERE nspname = $1) THEN
+ RAISE EXCEPTION 'schema "%" does not exist', $1;
+ END IF;
+ IF dbms_stats.is_system_schema($1) THEN
+ RAISE EXCEPTION 'can not lock statistics of relation in system schema "%"', $1;
+ END IF;
+
+ RETURN QUERY
+ SELECT dbms_stats.lock(cn.oid)
+ FROM (SELECT c.oid
+ FROM pg_class c, pg_namespace n
+ WHERE c.relnamespace = n.oid
+ AND dbms_stats.is_target_relkind(c.relkind)
+ AND n.nspname = $1
+ ORDER BY c.oid
+ ) cn;
+END;
+$$
+LANGUAGE plpgsql STRICT;
+
+CREATE FUNCTION dbms_stats.lock_table_stats(relid regclass)
+ RETURNS regclass AS
+$$
+SELECT dbms_stats.lock($1)
+$$
+LANGUAGE sql STRICT;
+
+CREATE FUNCTION dbms_stats.lock_table_stats(
+ schemaname text,
+ tablename text
+) RETURNS regclass AS
+$$
+SELECT dbms_stats.lock(dbms_stats.relname($1, $2)::regclass)
+$$
+LANGUAGE sql STRICT;
+
+CREATE FUNCTION dbms_stats.lock_column_stats(
+ relid regclass,
+ attname text
+) RETURNS regclass AS
+$$
+SELECT dbms_stats.lock($1, $2)
+$$
+LANGUAGE sql STRICT;
+
+CREATE FUNCTION dbms_stats.lock_column_stats(
+ schemaname text,
+ tablename text,
+ attname text
+) RETURNS regclass AS
+$$
+SELECT dbms_stats.lock(dbms_stats.relname($1, $2)::regclass, $3)
+$$
+LANGUAGE sql STRICT;
+
+--
+-- UNLOCK_STATS: Statistic unlock functions
+--
+
+CREATE FUNCTION dbms_stats.unlock(
+ relid regclass DEFAULT NULL,
+ attname text DEFAULT NULL
+) RETURNS SETOF regclass AS
+$$
+DECLARE
+ set_attnum int2;
+ unlock_id int8;
+BEGIN
+ IF $1 IS NULL AND $2 IS NOT NULL THEN
+ RAISE EXCEPTION 'relation is required';
+ END IF;
+ SELECT a.attnum INTO set_attnum FROM pg_catalog.pg_attribute a
+ WHERE a.attrelid = $1 AND a.attname = $2;
+ IF $2 IS NOT NULL AND set_attnum IS NULL THEN
+ RAISE EXCEPTION 'column "%" of "%" does not exist', $2, $1;
+ END IF;
+
+ LOCK dbms_stats._relation_stats_locked IN SHARE UPDATE EXCLUSIVE MODE;
+ LOCK dbms_stats._column_stats_locked IN SHARE UPDATE EXCLUSIVE MODE;
+
+ DELETE FROM dbms_stats._column_stats_locked
+ WHERE (starelid = $1 OR $1 IS NULL)
+ AND (staattnum = set_attnum OR $2 IS NULL);
+
+ IF $1 IS NOT NULL AND $2 IS NOT NULL THEN
+ RETURN QUERY
+ SELECT $1;
+ END IF;
+ FOR unlock_id IN
+ SELECT ru.relid
+ FROM dbms_stats._relation_stats_locked ru
+ WHERE (ru.relid = $1 OR $1 IS NULL) AND ($2 IS NULL)
+ ORDER BY ru.relid
+ LOOP
+ DELETE FROM dbms_stats._relation_stats_locked ru
+ WHERE ru.relid = unlock_id;
+ RETURN NEXT unlock_id;
+ END LOOP;
+END;
+$$
+LANGUAGE plpgsql;
+
+CREATE FUNCTION dbms_stats.unlock_database_stats()
+ RETURNS SETOF regclass AS
+$$
+DECLARE
+ unlock_id int8;
+BEGIN
+ LOCK dbms_stats._relation_stats_locked IN SHARE UPDATE EXCLUSIVE MODE;
+ LOCK dbms_stats._column_stats_locked IN SHARE UPDATE EXCLUSIVE MODE;
+
+ FOR unlock_id IN
+ SELECT relid
+ FROM dbms_stats._relation_stats_locked
+ ORDER BY relid
+ LOOP
+ DELETE FROM dbms_stats._relation_stats_locked
+ WHERE relid = unlock_id;
+ RETURN NEXT unlock_id;
+ END LOOP;
+END;
+$$
+LANGUAGE plpgsql STRICT;
+
+CREATE FUNCTION dbms_stats.unlock_schema_stats(
+ schemaname text
+) RETURNS SETOF regclass AS
+$$
+DECLARE
+ unlock_id int8;
+BEGIN
+ IF NOT EXISTS(SELECT * FROM pg_namespace WHERE nspname = $1) THEN
+ RAISE EXCEPTION 'schema "%" does not exist', $1;
+ END IF;
+ IF dbms_stats.is_system_schema($1) THEN
+ RAISE EXCEPTION 'can not unlock statistics of relation in system schema "%"', $1;
+ END IF;
+
+ LOCK dbms_stats._relation_stats_locked IN SHARE UPDATE EXCLUSIVE MODE;
+ LOCK dbms_stats._column_stats_locked IN SHARE UPDATE EXCLUSIVE MODE;
+
+ FOR unlock_id IN
+ SELECT relid
+ FROM dbms_stats._relation_stats_locked, pg_class c, pg_namespace n
+ WHERE relid = c.oid
+ AND c.relnamespace = n.oid
+ AND n.nspname = $1
+ ORDER BY relid
+ LOOP
+ DELETE FROM dbms_stats._relation_stats_locked
+ WHERE relid = unlock_id;
+ RETURN NEXT unlock_id;
+ END LOOP;
+END;
+$$
+LANGUAGE plpgsql STRICT;
+
+CREATE FUNCTION dbms_stats.unlock_table_stats(relid regclass)
+ RETURNS SETOF regclass AS
+$$
+
+LOCK dbms_stats._relation_stats_locked IN SHARE UPDATE EXCLUSIVE MODE;
+LOCK dbms_stats._column_stats_locked IN SHARE UPDATE EXCLUSIVE MODE;
+
+DELETE FROM dbms_stats._relation_stats_locked
+ WHERE relid = $1
+ RETURNING relid::regclass
+$$
+LANGUAGE sql STRICT;
+
+CREATE FUNCTION dbms_stats.unlock_table_stats(
+ schemaname text,
+ tablename text
+) RETURNS SETOF regclass AS
+$$
+
+LOCK dbms_stats._relation_stats_locked IN SHARE UPDATE EXCLUSIVE MODE;
+LOCK dbms_stats._column_stats_locked IN SHARE UPDATE EXCLUSIVE MODE;
+
+DELETE FROM dbms_stats._relation_stats_locked
+ WHERE relid = dbms_stats.relname($1, $2)::regclass
+ RETURNING relid::regclass
+$$
+LANGUAGE sql STRICT;
+
+CREATE FUNCTION dbms_stats.unlock_column_stats(
+ relid regclass,
+ attname text
+) RETURNS SETOF regclass AS
+$$
+DECLARE
+ set_attnum int2;
+BEGIN
+ SELECT a.attnum INTO set_attnum FROM pg_catalog.pg_attribute a
+ WHERE a.attrelid = $1 AND a.attname = $2;
+ IF $2 IS NOT NULL AND set_attnum IS NULL THEN
+ RAISE EXCEPTION 'column "%" of "%" does not exist', $2, $1;
+ END IF;
+
+ LOCK dbms_stats._relation_stats_locked IN SHARE UPDATE EXCLUSIVE MODE;
+ LOCK dbms_stats._column_stats_locked IN SHARE UPDATE EXCLUSIVE MODE;
+
+ DELETE FROM dbms_stats._column_stats_locked
+ WHERE starelid = $1
+ AND staattnum = set_attnum;
+ RETURN QUERY
+ SELECT $1;
+END;
+$$
+LANGUAGE plpgsql STRICT;
+
+CREATE FUNCTION dbms_stats.unlock_column_stats(
+ schemaname text,
+ tablename text,
+ attname text
+) RETURNS SETOF regclass AS
+$$
+DECLARE
+ set_attnum int2;
+BEGIN
+ SELECT a.attnum INTO set_attnum FROM pg_catalog.pg_attribute a
+ WHERE a.attrelid = dbms_stats.relname($1, $2)::regclass
+ AND a.attname = $3;
+ IF $3 IS NOT NULL AND set_attnum IS NULL THEN
+ RAISE EXCEPTION 'column "%" of "%.%" does not exist', $3, $1, $2;
+ END IF;
+
+ LOCK dbms_stats._relation_stats_locked IN SHARE UPDATE EXCLUSIVE MODE;
+ LOCK dbms_stats._column_stats_locked IN SHARE UPDATE EXCLUSIVE MODE;
+
+ DELETE FROM dbms_stats._column_stats_locked
+ WHERE starelid = dbms_stats.relname($1, $2)::regclass
+ AND staattnum = set_attnum;
+ RETURN QUERY
+ SELECT dbms_stats.relname($1, $2)::regclass;
+END;
+$$
+LANGUAGE plpgsql STRICT;
+
+--
+-- IMPORT_STATS: Statistic import functions
+--
+
+CREATE FUNCTION dbms_stats.import(
+ nspname text DEFAULT NULL,
+ relid regclass DEFAULT NULL,
+ attname text DEFAULT NULL,
+ src text DEFAULT NULL
+) RETURNS void AS
+'MODULE_PATHNAME', 'dbms_stats_import'
+LANGUAGE C;
+
+CREATE FUNCTION dbms_stats.import_database_stats(src text)
+ RETURNS void AS
+$$
+SELECT dbms_stats.import(NULL, NULL, NULL, $1)
+$$
+LANGUAGE sql;
+
+CREATE FUNCTION dbms_stats.import_schema_stats(
+ schemaname text,
+ src text
+) RETURNS void AS
+$$
+SELECT dbms_stats.import($1, NULL, NULL, $2)
+$$
+LANGUAGE sql;
+
+CREATE FUNCTION dbms_stats.import_table_stats(
+ relid regclass,
+ src text
+) RETURNS void AS
+$$
+SELECT dbms_stats.import(NULL, $1, NULL, $2)
+$$
+LANGUAGE sql;
+
+CREATE FUNCTION dbms_stats.import_table_stats(
+ schemaname text,
+ tablename text,
+ src text
+) RETURNS void AS
+$$
+SELECT dbms_stats.import(NULL, dbms_stats.relname($1, $2)::regclass, NULL, $3)
+$$
+LANGUAGE sql;
+
+CREATE FUNCTION dbms_stats.import_column_stats(
+ relid regclass,
+ attname text,
+ src text
+) RETURNS void AS
+$$
+SELECT dbms_stats.import(NULL, $1, $2, $3)
+$$
+LANGUAGE sql;
+
+CREATE FUNCTION dbms_stats.import_column_stats(
+ schemaname text,
+ tablename text,
+ attname text,
+ src text
+) RETURNS void AS
+$$
+SELECT dbms_stats.import(NULL, dbms_stats.relname($1, $2)::regclass, $3, $4)
+$$
+LANGUAGE sql;
+
+--
+-- PURGE_STATS: Statistic purge function
+--
+
+CREATE OR REPLACE FUNCTION dbms_stats.purge_stats(
+ backup_id int8,
+ force bool DEFAULT false
+) RETURNS SETOF dbms_stats.backup_history AS
+$$
+DECLARE
+ delete_id int8;
+ deleted dbms_stats.backup_history;
+BEGIN
+ IF $1 IS NULL THEN
+ RAISE EXCEPTION 'backup id is required';
+ END IF;
+ IF $2 IS NULL THEN
+ RAISE EXCEPTION 'force is not null';
+ END IF;
+
+ LOCK dbms_stats.backup_history IN SHARE UPDATE EXCLUSIVE MODE;
+ LOCK dbms_stats.relation_stats_backup IN SHARE UPDATE EXCLUSIVE MODE;
+ LOCK dbms_stats.column_stats_backup IN SHARE UPDATE EXCLUSIVE MODE;
+
+ IF NOT EXISTS(SELECT * FROM dbms_stats.backup_history WHERE id = $1) THEN
+ RAISE EXCEPTION 'backup id % does not exist', $1;
+ END IF;
+ IF NOT $2 AND NOT EXISTS(SELECT *
+ FROM dbms_stats.backup_history
+ WHERE unit = 'd'
+ AND id > $1) THEN
+ RAISE WARNING 'at least one database-wise backup must be remain'
+ USING HINT = 'use true as 2nd parameter, if you want to purge forcibly';
+ RETURN;
+ END IF;
+
+ FOR deleted IN
+ SELECT * FROM dbms_stats.backup_history
+ WHERE id <= $1
+ ORDER BY id
+ LOOP
+ DELETE FROM dbms_stats.backup_history
+ WHERE id = deleted.id;
+ RETURN NEXT deleted;
+ END LOOP;
+END;
+$$
+LANGUAGE plpgsql;
+
+GRANT USAGE ON schema dbms_stats TO PUBLIC;
+--
diff --git a/pg_dbms_stats.c b/pg_dbms_stats.c
new file mode 100644
index 0000000..2f682d8
--- /dev/null
+++ b/pg_dbms_stats.c
@@ -0,0 +1,1509 @@
+/*
+ * pg_dbms_stats.c
+ *
+ * Copyright (c) 2009-2012, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
+ * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ */
+#include "postgres.h"
+
+#include "access/transam.h"
+#include "catalog/pg_statistic.h"
+#include "catalog/pg_type.h"
+#include "commands/trigger.h"
+#include "executor/spi.h"
+#include "funcapi.h"
+#include "optimizer/plancat.h"
+#include "storage/bufmgr.h"
+#include "utils/builtins.h"
+#include "utils/guc.h"
+#include "utils/inval.h"
+#include "utils/lsyscache.h"
+#include "utils/selfuncs.h"
+#include "utils/syscache.h"
+#if PG_VERSION_NUM >= 90200
+#include "utils/rel.h"
+#endif
+
+#include "pg_dbms_stats.h"
+
+PG_MODULE_MAGIC;
+
+/* Error levels used by pg_dbms_stats */
+#define ELEVEL_DEBUG DEBUG3 /* log level for debug information */
+#define ELEVEL_BADSTATS LOG /* log level for invalid statistics */
+
+#define MAX_REL_CACHE 50 /* expected max # of rel stats entries */
+
+/* represents an element of relation statistics which is cached in hash table */
+typedef struct StatsRelationEntry
+{
+ Oid relid; /* hash key must be at the head */
+
+ bool valid; /* T if the entry has valid stats */
+
+ BlockNumber relpages; /* # of pages as of last ANALYZE */
+ double reltuples; /* # of tuples as of last ANALYZE */
+ BlockNumber relallvisible; /* # of all-visible pages as of last
+ * ANALYZE */
+ BlockNumber curpages; /* # of pages as of lock/restore */
+
+ List *col_stats; /* list of HeapTuple, each element is
+ pg_statistic record of this relation. */
+} StatsRelationEntry;
+
+/* Saved hook functions */
+get_relation_info_hook_type prev_get_relation_info = NULL;
+get_attavgwidth_hook_type prev_get_attavgwidth = NULL;
+get_relation_stats_hook_type prev_get_relation_stats = NULL;
+get_index_stats_hook_type prev_get_index_stats = NULL;
+
+/* rows_query(oid) RETURNS int4, float4, int4 */
+static const char *rows_query =
+ "SELECT relpages, reltuples, curpages"
+#if PG_VERSION_NUM >= 90200
+ ", relallvisible"
+#endif
+ " FROM dbms_stats.relation_stats_locked"
+ " WHERE relid = $1";
+static SPIPlanPtr rows_plan = NULL;
+
+/* tuple_query(oid, int2, bool) RETURNS pg_statistic */
+static const char *tuple_query =
+ "SELECT * "
+ " FROM dbms_stats.column_stats_locked "
+ " WHERE starelid = $1 "
+ " AND staattnum = $2 "
+ " AND stainherit = $3";
+static SPIPlanPtr tuple_plan = NULL;
+
+/* GUC variables */
+static bool pg_dbms_stats_use_locked_stats = true;
+
+/* Current nesting depth of SPI calls, used to prevent recursive calls */
+static int nested_level = 0;
+
+/*
+ * The relation_stats_effective statistic cache is stored in hash table.
+ */
+static HTAB *rel_stats;
+
+#define get_pg_statistic(tuple) ((Form_pg_statistic) GETSTRUCT(tuple))
+
+PG_FUNCTION_INFO_V1(dbms_stats_merge);
+PG_FUNCTION_INFO_V1(dbms_stats_invalidate_relation_cache);
+PG_FUNCTION_INFO_V1(dbms_stats_invalidate_column_cache);
+PG_FUNCTION_INFO_V1(dbms_stats_is_system_schema);
+PG_FUNCTION_INFO_V1(dbms_stats_is_system_catalog);
+
+extern Datum dbms_stats_merge(PG_FUNCTION_ARGS);
+extern Datum dbms_stats_invalidate_relation_cache(PG_FUNCTION_ARGS);
+extern Datum dbms_stats_invalidate_column_cache(PG_FUNCTION_ARGS);
+extern Datum dbms_stats_is_system_schema(PG_FUNCTION_ARGS);
+extern Datum dbms_stats_is_system_catalog(PG_FUNCTION_ARGS);
+
+static HeapTuple dbms_stats_merge_internal(HeapTuple lhs, HeapTuple rhs,
+ TupleDesc tupledesc);
+static void dbms_stats_check_tg_event(FunctionCallInfo fcinfo,
+ TriggerData *trigdata, HeapTuple *invtup, HeapTuple *rettup);
+static void dbms_stats_invalidate_cache_internal(Oid relid, bool sta_col);
+
+/* Module callbacks */
+void _PG_init(void);
+void _PG_fini(void);
+
+static void dbms_stats_get_relation_info(PlannerInfo *root, Oid relid,
+ bool inhparent, RelOptInfo *rel);
+static int32 dbms_stats_get_attavgwidth(Oid relid, AttrNumber attnum);
+static bool dbms_stats_get_relation_stats(PlannerInfo *root, RangeTblEntry *rte,
+ AttrNumber attnum, VariableStatData *vardata);
+static bool dbms_stats_get_index_stats(PlannerInfo *root, Oid indexOid,
+ AttrNumber indexattnum, VariableStatData *vardata);
+
+static void get_merged_relation_stats(Oid relid, BlockNumber *pages,
+ double *tuples, double *allvisfrac, bool estimate);
+static int32 get_merged_avgwidth(Oid relid, AttrNumber attnum);
+static HeapTuple get_merged_column_stats(Oid relid, AttrNumber attnum,
+ bool inh);
+static HeapTuple column_cache_search(Oid relid, AttrNumber attnum, bool inh);
+static HeapTuple column_cache_enter(HeapTuple tuple);
+static bool execute_plan(SPIPlanPtr *plan, const char *query, Oid relid,
+ const AttrNumber *attnum, bool inh);
+static void StatsCacheRelCallback(Datum arg, Oid relid);
+static void init_rel_stats(void);
+static void init_rel_stats_entry(StatsRelationEntry *entry, Oid relid);
+/* copied from PG core source tree */
+static void dbms_stats_estimate_rel_size(Relation rel, int32 *attr_widths,
+ BlockNumber *pages, double *tuples, double *allvisfrac,
+ BlockNumber curpages);
+static int32 dbms_stats_get_rel_data_width(Relation rel, int32 *attr_widths);
+
+/* Unit test suit functions */
+#ifdef UNIT_TEST
+extern void test_import(int *passed, int *total);
+extern void test_dump(int *passed, int *total);
+extern void test_pg_dbms_stats(int *passed, int *total);
+#endif
+
+/*
+ * Module load callback
+ */
+void
+_PG_init(void)
+{
+ /* Execute unit test cases */
+#ifdef UNIT_TEST
+ {
+ int passed = 0;
+ int total = 0;
+
+ test_import(&passed, &total);
+ test_dump(&passed, &total);
+ test_pg_dbms_stats(&passed, &total);
+
+ elog(WARNING, "TOTAL %d/%d passed", passed, total);
+ }
+#endif
+
+ /* Define custom GUC variables. */
+ DefineCustomBoolVariable("pg_dbms_stats.use_locked_stats",
+ "Enable user defined statistics.",
+ NULL,
+ &pg_dbms_stats_use_locked_stats,
+ true,
+ PGC_USERSET,
+ 0,
+ NULL,
+ NULL,
+ NULL);
+
+ EmitWarningsOnPlaceholders("pg_dbms_stats");
+
+ /* Back up old hooks, and install ours. */
+ prev_get_relation_info = get_relation_info_hook;
+ get_relation_info_hook = dbms_stats_get_relation_info;
+ prev_get_attavgwidth = get_attavgwidth_hook;
+ get_attavgwidth_hook = dbms_stats_get_attavgwidth;
+ prev_get_relation_stats = get_relation_stats_hook;
+ get_relation_stats_hook = dbms_stats_get_relation_stats;
+ prev_get_index_stats = get_index_stats_hook;
+ get_index_stats_hook = dbms_stats_get_index_stats;
+
+ /* Initialize hash table for statistics caching. */
+ init_rel_stats();
+
+ /* Also set up a callback for relcache SI invalidations */
+ CacheRegisterRelcacheCallback(StatsCacheRelCallback, (Datum) 0);
+}
+
+/*
+ * Module unload callback
+ */
+void
+_PG_fini(void)
+{
+ /* Restore old hooks. */
+ get_relation_info_hook = prev_get_relation_info;
+ get_attavgwidth_hook = prev_get_attavgwidth;
+ get_relation_stats_hook = prev_get_relation_stats;
+ get_index_stats_hook = prev_get_index_stats;
+
+ /* A function to unregister callback for relcache is NOT provided. */
+}
+
+/*
+ * Store heap tuple header into given heap tuple.
+ */
+static void
+AssignHeapTuple(HeapTuple htup, HeapTupleHeader header)
+{
+ htup->t_len = HeapTupleHeaderGetDatumLength(header);
+ ItemPointerSetInvalid(&htup->t_self);
+ htup->t_tableOid = InvalidOid;
+ htup->t_data = header;
+}
+
+/*
+ * dbms_stats_merge
+ * called by sql function 'dbms_stats.merge', and return the execution result
+ * of the function 'dbms_stats_merge_internal'.
+ */
+Datum
+dbms_stats_merge(PG_FUNCTION_ARGS)
+{
+ HeapTupleData lhs;
+ HeapTupleData rhs;
+ TupleDesc tupdesc;
+ HeapTuple ret = NULL;
+
+ /* assign HeapTuple of the left statistics data unless null. */
+ if (PG_ARGISNULL(0))
+ lhs.t_data = NULL;
+ else
+ AssignHeapTuple(&lhs, PG_GETARG_HEAPTUPLEHEADER(0));
+
+ /* assign HeapTuple of the right statistics data unless null. */
+ if (PG_ARGISNULL(1))
+ rhs.t_data = NULL;
+ else
+ AssignHeapTuple(&rhs, PG_GETARG_HEAPTUPLEHEADER(1));
+
+ /* fast path for one-side is null */
+ if (lhs.t_data == NULL && rhs.t_data == NULL)
+ PG_RETURN_NULL();
+
+ /* build a tuple descriptor for our result type */
+ if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
+ elog(ERROR, "return type must be a row type");
+
+ /* merge two statistics tuples into one, and return it */
+ ret = dbms_stats_merge_internal(&lhs, &rhs, tupdesc);
+
+ if (ret)
+ PG_RETURN_DATUM(HeapTupleGetDatum(ret));
+ else
+ PG_RETURN_NULL();
+}
+
+/*
+ * dbms_stats_merge_internal
+ * merge the dummy statistic (lhs) and the true statistic (rhs), on the basis
+ * of given TupleDesc.
+ */
+static HeapTuple
+dbms_stats_merge_internal(HeapTuple lhs, HeapTuple rhs, TupleDesc tupdesc)
+{
+ Datum values[Natts_pg_statistic];
+ bool nulls[Natts_pg_statistic];
+ int i;
+ Oid atttype = InvalidOid;
+
+ /* fast path for both-sides are null */
+ if ((lhs == NULL || lhs->t_data == NULL) &&
+ (rhs == NULL || rhs->t_data == NULL))
+ return NULL;
+
+ /* fast path for one-side is null */
+ if (lhs == NULL || lhs->t_data == NULL)
+ {
+ /* use right tuple */
+ heap_deform_tuple(rhs, tupdesc, values, nulls);
+ for (i = 0; i < Anum_pg_statistic_staop1 + STATISTIC_NUM_SLOTS - 1; i++)
+ if (nulls[i])
+ return NULL; /* check null constraints */
+ }
+ else if (rhs == NULL || rhs->t_data == NULL)
+ {
+ /* use left tuple */
+ heap_deform_tuple(lhs, tupdesc, values, nulls);
+ for (i = 0; i < Anum_pg_statistic_staop1 + STATISTIC_NUM_SLOTS - 1; i++)
+ if (nulls[i])
+ return NULL; /* check null constraints */
+ }
+ else
+ {
+ /*
+ * If the column value of the dummy statistic is not NULL, in the
+ * statistics except the slot, use it. Otherwise we use the column
+ * value of the true statistic.
+ */
+ heap_deform_tuple(lhs, tupdesc, values, nulls);
+ for (i = 0; i < Anum_pg_statistic_stakind1 - 1; i++)
+ {
+ if (nulls[i])
+ {
+ values[i] = fastgetattr(rhs, i + 1, tupdesc, &nulls[i]);
+ if (nulls[i])
+ {
+ ereport(ELEVEL_BADSTATS,
+ (errmsg("pg_dbms_stats: bad statistics"),
+ errdetail("column \"%s\" should not be null",
+ get_attname(StatisticRelationId,
+ tupdesc->attrs[i]->attnum))));
+ return NULL; /* should not be null */
+ }
+ }
+ }
+
+ /*
+ * If the column value of the dummy statistic is not all NULL, in the
+ * statistics the slot, use it. Otherwise we use the column
+ * value of the true statistic.
+ */
+ for (; i < Anum_pg_statistic_staop1 + STATISTIC_NUM_SLOTS - 1; i++)
+ {
+ if (nulls[i])
+ {
+ for (i = Anum_pg_statistic_stakind1 - 1;
+ i < Anum_pg_statistic_stavalues1 + STATISTIC_NUM_SLOTS - 1;
+ i++)
+ {
+ values[i] = fastgetattr(rhs, i + 1, tupdesc, &nulls[i]);
+ if (i < Anum_pg_statistic_staop1 + STATISTIC_NUM_SLOTS - 1 &&
+ nulls[i])
+ {
+ ereport(ELEVEL_BADSTATS,
+ (errmsg("pg_dbms_stats: bad statistics"),
+ errdetail("column \"%s\" should not be null",
+ get_attname(StatisticRelationId,
+ tupdesc->attrs[i]->attnum))));
+ return NULL; /* should not be null */
+ }
+ }
+
+ break;
+ }
+ }
+ }
+
+ /* verify types to work around for ALTER COLUMN TYPE */
+ for (i = 0; i < STATISTIC_NUM_SLOTS; i++)
+ {
+ if ((i + 1 == STATISTIC_KIND_MCV ||
+ i + 1 == STATISTIC_KIND_HISTOGRAM) &&
+ !nulls[Anum_pg_statistic_stavalues1 + i - 1])
+ {
+ Oid relid = DatumGetObjectId(values[0]);
+ AttrNumber attnum = DatumGetInt16(values[1]);
+ ArrayType *arr;
+
+ if (atttype == InvalidOid)
+ atttype = get_atttype(relid, attnum);
+
+ arr = DatumGetArrayTypeP(
+ values[Anum_pg_statistic_stavalues1 + i - 1]);
+ if (arr == NULL || arr->elemtype != atttype)
+ {
+ char *attname = get_attname(relid,
+ tupdesc->attrs[attnum - 1]->attnum);
+
+ ereport(ELEVEL_BADSTATS,
+ (errmsg("pg_dbms_stats: bad column type"),
+ errdetail("type of column \"%s\" has been changed",
+ attname),
+ errhint("need to execute dbms_stats.unlock('%s', '%s')",
+ get_rel_name(relid), attname)));
+ return NULL;
+ }
+ }
+ }
+
+ return heap_form_tuple(tupdesc, values, nulls);
+}
+
+/*
+ * dbms_stats_invalidate_relation_cache
+ * Register invalidation of the specified relation's relcache.
+ *
+ * CREATE TRIGGER dbms_stats.relation_stats_locked FOR INSERT, UPDATE, DELETE FOR EACH
+ * ROWS EXECUTE ...
+ */
+Datum
+dbms_stats_invalidate_relation_cache(PG_FUNCTION_ARGS)
+{
+ TriggerData *trigdata = (TriggerData *) fcinfo->context;
+ HeapTuple invtup; /* tuple to be invalidated */
+ HeapTuple rettup; /* tuple to be returned */
+ Datum value;
+ bool isnull;
+
+ /* make sure it's called as a before/after trigger */
+ dbms_stats_check_tg_event(fcinfo, trigdata, &invtup, &rettup);
+
+ /*
+ * assume that position of dbms_stats.relation_stats_locked.relid is head value of
+ * tuple.
+ */
+ value = fastgetattr(invtup, 1, trigdata->tg_relation->rd_att, &isnull);
+
+ /*
+ * invalidate prepared statements and force re-planning with pg_dbms_stats.
+ */
+ dbms_stats_invalidate_cache_internal((Oid)value, false);
+
+ PG_RETURN_POINTER(rettup);
+}
+
+/*
+ * dbms_stats_invalidate_column_cache
+ * Register invalidation of the specified relation's relcache.
+ *
+ * CREATE TRIGGER dbms_stats.column_stats_locked FOR INSERT, UPDATE, DELETE FOR EACH
+ * ROWS EXECUTE ...
+ */
+Datum
+dbms_stats_invalidate_column_cache(PG_FUNCTION_ARGS)
+{
+ TriggerData *trigdata = (TriggerData *) fcinfo->context;
+ Form_pg_statistic form;
+ HeapTuple invtup; /* tuple to be invalidated */
+ HeapTuple rettup; /* tuple to be returned */
+
+ /* make sure it's called as a before/after trigger */
+ dbms_stats_check_tg_event(fcinfo, trigdata, &invtup, &rettup);
+
+ /*
+ * assume that both pg_statistic and dbms_stats.column_stats_locked have the same
+ * definition.
+ */
+ form = get_pg_statistic(invtup);
+
+ /*
+ * invalidate prepared statements and force re-planning with pg_dbms_stats.
+ */
+ dbms_stats_invalidate_cache_internal(form->starelid, true);
+
+ PG_RETURN_POINTER(rettup);
+}
+
+static void
+dbms_stats_check_tg_event(FunctionCallInfo fcinfo,
+ TriggerData *trigdata,
+ HeapTuple *invtup,
+ HeapTuple *rettup)
+{
+ /* make sure it's called as a before/after trigger */
+ if (!CALLED_AS_TRIGGER(fcinfo) ||
+ !TRIGGER_FIRED_BEFORE(trigdata->tg_event) ||
+ !TRIGGER_FIRED_FOR_ROW(trigdata->tg_event))
+ elog(ERROR, "pg_dbms_stats: invalid trigger call");
+
+ if (TRIGGER_FIRED_BY_INSERT(trigdata->tg_event))
+ {
+ /* INSERT */
+ *rettup = *invtup = trigdata->tg_trigtuple;
+ }
+ else if (TRIGGER_FIRED_BY_DELETE(trigdata->tg_event))
+ {
+ /* DELETE */
+ *rettup = *invtup = trigdata->tg_trigtuple;
+ }
+ else
+ {
+ /* UPDATE */
+ *invtup = trigdata->tg_trigtuple;
+ *rettup = trigdata->tg_newtuple;
+ }
+}
+
+static void
+dbms_stats_invalidate_cache_internal(Oid relid, bool sta_col)
+{
+ Relation rel;
+
+ /*
+ * invalidate prepared statements and force re-planning with pg_dbms_stats.
+ */
+ rel = try_relation_open(relid, NoLock);
+ if (rel != NULL)
+ {
+ if (sta_col &&
+ rel->rd_rel->relkind == RELKIND_INDEX &&
+ (rel->rd_indextuple == NULL ||
+ heap_attisnull(rel->rd_indextuple, Anum_pg_index_indexprs)))
+ ereport(ERROR,
+ (errcode(ERRCODE_WRONG_OBJECT_TYPE),
+ errmsg("\"%s\" is an index except an index expression",
+ RelationGetRelationName(rel))));
+ if (rel->rd_rel->relkind == RELKIND_COMPOSITE_TYPE)
+ ereport(ERROR,
+ (errcode(ERRCODE_WRONG_OBJECT_TYPE),
+ errmsg("\"%s\" is a composite type",
+ RelationGetRelationName(rel))));
+
+ /*
+ * We need to invalidate relcache of underlying table too, because
+ * CachedPlan mechanism decides to do re-planning when any relcache of
+ * used tables was invalid at EXECUTE.
+ */
+ if (rel->rd_rel->relkind == RELKIND_INDEX &&
+ rel->rd_index && OidIsValid(rel->rd_index->indrelid))
+ CacheInvalidateRelcacheByRelid(rel->rd_index->indrelid);
+
+ CacheInvalidateRelcache(rel);
+ relation_close(rel, NoLock);
+ }
+}
+
+/*
+ * dbms_stats_is_system_schema
+ * called by sql function 'dbms_stats.is_system_schema', and return the
+ * result of the function 'dbms_stats_is_system_internal'.
+ */
+Datum
+dbms_stats_is_system_schema(PG_FUNCTION_ARGS)
+{
+ text *arg0;
+ char *schema_name;
+ bool result;
+
+ arg0 = PG_GETARG_TEXT_PP(0);
+ schema_name = text_to_cstring(arg0);
+ result = dbms_stats_is_system_schema_internal(schema_name);
+
+ PG_FREE_IF_COPY(arg0, 0);
+
+ PG_RETURN_BOOL(result);
+}
+
+/*
+ * dbms_stats_is_system_schema_internal
+ * return whether the given schema contains any system catalog. Here we
+ * treat dbms_stats objects as system catalogs to avoid infinite loop.
+ */
+bool
+dbms_stats_is_system_schema_internal(char *schema_name)
+{
+ Assert(schema_name != NULL);
+
+ /* if the schema is system_schema, return true */
+ if (strcmp(schema_name, "pg_catalog") == 0 ||
+ strcmp(schema_name, "pg_toast") == 0 ||
+ strcmp(schema_name, "information_schema") == 0 ||
+ strcmp(schema_name, "dbms_stats") == 0)
+ return true;
+
+ return false;
+}
+
+/*
+ * dbms_stats_is_system_catalog
+ * called by sql function 'dbms_stats.is_system_catalog', and return the
+ * result of the function 'dbms_stats_is_system_catalog_internal'.
+ */
+Datum
+dbms_stats_is_system_catalog(PG_FUNCTION_ARGS)
+{
+ Oid relid;
+ bool result;
+
+ if (PG_ARGISNULL(0))
+ PG_RETURN_BOOL(true);
+
+ relid = PG_GETARG_OID(0);
+ result = dbms_stats_is_system_catalog_internal(relid);
+
+ PG_RETURN_BOOL(result);
+}
+
+/*
+ * dbms_stats_is_system_catalog_internal
+ * Check whether the given relation is one of system catalogs.
+ */
+bool
+dbms_stats_is_system_catalog_internal(Oid relid)
+{
+ Relation rel;
+ char *schema_name;
+ bool result;
+
+ /* relid is InvalidOid */
+ if (!OidIsValid(relid))
+ return false;
+
+ /* no such relation */
+ rel = try_relation_open(relid, NoLock);
+ if (rel == NULL)
+ return false;
+
+ /* check by namespace name. */
+ schema_name = get_namespace_name(rel->rd_rel->relnamespace);
+ result = dbms_stats_is_system_schema_internal(schema_name);
+ relation_close(rel, NoLock);
+
+ return result;
+}
+
+/*
+ * dbms_stats_get_relation_info
+ * Hook function for get_relation_info_hook, which implements post-process of
+ * get_relation_info().
+ *
+ * This function is designed on the basis of the fact that only expression
+ * indexes have statistics.
+ */
+static void
+dbms_stats_get_relation_info(PlannerInfo *root,
+ Oid relid,
+ bool inhparent,
+ RelOptInfo *rel)
+{
+ ListCell *lc;
+ double allvisfrac; /* dummy */
+
+ /*
+ * Call previously installed hook function regardless to whether
+ * pg_dbms_stats is enabled or not.
+ */
+ if (prev_get_relation_info)
+ prev_get_relation_info(root, relid, inhparent, rel);
+
+ /* If pg_dbms_stats is disabled, there is no more thing to do. */
+ if (!pg_dbms_stats_use_locked_stats)
+ return;
+
+ /*
+ * Adjust stats of table itself, and stats of index
+ * relation_stats_effective as well
+ */
+
+ /*
+ * Estimate relation size --- unless it's an inheritance parent, in which
+ * case the size will be computed later in set_append_rel_pathlist, and we
+ * must leave it zero for now to avoid bollixing the total_table_pages
+ * calculation.
+ */
+ if (!inhparent)
+ {
+#if PG_VERSION_NUM >= 90200
+ get_merged_relation_stats(relid, &rel->pages, &rel->tuples,
+ &rel->allvisfrac, true);
+#else
+ get_merged_relation_stats(relid, &rel->pages, &rel->tuples,
+ &allvisfrac, true);
+#endif
+ }
+ else
+ return;
+
+ foreach(lc, rel->indexlist)
+ {
+ /*
+ * Estimate the index size. If it's not a partial index, we lock
+ * the number-of-tuples estimate to equal the parent table; if it
+ * is partial then we have to use the same methods as we would for
+ * a table, except we can be sure that the index is not larger
+ * than the table.
+ */
+ IndexOptInfo *info = (IndexOptInfo *) lfirst(lc);
+ bool estimate = info->indpred != NIL;
+
+ get_merged_relation_stats(info->indexoid, &info->pages, &info->tuples,
+ &allvisfrac, estimate);
+
+ if (!estimate || (estimate && info->tuples > rel->tuples))
+ info->tuples = rel->tuples;
+ }
+}
+
+/*
+ * dbms_stats_get_attavgwidth
+ * Hook function for get_attavgwidth_hook which replaces get_attavgwidth().
+ * Returning 0 tells caller to use standard routine.
+ */
+static int32
+dbms_stats_get_attavgwidth(Oid relid, AttrNumber attnum)
+{
+ if (pg_dbms_stats_use_locked_stats)
+ {
+ int32 width = get_merged_avgwidth(relid, attnum);
+ if (width > 0)
+ return width;
+ }
+
+ if (prev_get_attavgwidth)
+ return prev_get_attavgwidth(relid, attnum);
+ else
+ return 0;
+}
+
+/*
+ * We do nothing here, to keep the tuple valid even after examination.
+ */
+static void
+FreeHeapTuple(HeapTuple tuple)
+{
+ /* noop */
+}
+
+/*
+ * dbms_stats_get_relation_stats
+ * Hook function for get_relation_stats_hook which provides custom
+ * per-relation statistics.
+ * Returning false tells caller to use standard (true) statistics.
+ */
+static bool
+dbms_stats_get_relation_stats(PlannerInfo *root,
+ RangeTblEntry *rte,
+ AttrNumber attnum,
+ VariableStatData *vardata)
+{
+ if (pg_dbms_stats_use_locked_stats)
+ {
+ HeapTuple tuple;
+
+ tuple = get_merged_column_stats(rte->relid, attnum, rte->inh);
+ if (tuple != NULL)
+ {
+ vardata->statsTuple = tuple;
+ vardata->freefunc = FreeHeapTuple;
+ return true;
+ }
+ }
+
+ if (prev_get_relation_stats)
+ return prev_get_relation_stats(root, rte, attnum, vardata);
+ else
+ return false;
+}
+
+/*
+ * dbms_stats_get_index_stats
+ * Hook function for get_index_stats_hook which provides custom per-relation
+ * statistics.
+ * Returning false tells caller to use standard (true) statistics.
+ */
+static bool
+dbms_stats_get_index_stats(PlannerInfo *root,
+ Oid indexOid,
+ AttrNumber indexattnum,
+ VariableStatData *vardata)
+{
+ if (pg_dbms_stats_use_locked_stats)
+ {
+ HeapTuple tuple;
+
+ tuple = get_merged_column_stats(indexOid, indexattnum, false);
+ if (tuple != NULL)
+ {
+ vardata->statsTuple = tuple;
+ vardata->freefunc = FreeHeapTuple;
+ return true;
+ }
+ }
+
+ if (prev_get_index_stats)
+ return prev_get_index_stats(root, indexOid, indexattnum, vardata);
+ else
+ return false;
+}
+
+/*
+ * Extract binary value from given column.
+ */
+static Datum
+get_binary_datum(int column, bool *isnull)
+{
+ return SPI_getbinval(SPI_tuptable->vals[0],
+ SPI_tuptable->tupdesc, column, isnull);
+}
+
+/*
+ * get_merged_relation_stats
+ * get the statistics of the table, # of pages and # of rows, by executing
+ * SELECT against dbms_stats.relation_stats_locked view.
+ */
+static void
+get_merged_relation_stats(Oid relid, BlockNumber *pages, double *tuples,
+ double *allvisfrac, bool estimate)
+{
+ StatsRelationEntry *entry;
+ bool found;
+ Relation rel;
+
+ /* avoid recursive call and system objects */
+ if (nested_level > 0 || relid < FirstNormalObjectId)
+ return;
+
+ /*
+ * pg_dbms_stats doesn't handle system catalogs and its internal relation_stats_effective
+ */
+ if (dbms_stats_is_system_catalog_internal(relid))
+ return;
+
+ /*
+ * First, search from cache. If we have not cached stats for given relid
+ * yet, initialize newly created entry.
+ */
+ entry = hash_search(rel_stats, &relid, HASH_ENTER, &found);
+ if (!found)
+ init_rel_stats_entry(entry, relid);
+
+ /*
+ * If we don't have valid cache entry, retrieve stats from catalogs,
+ * pg_class and dbms_stats.relation_stats_locked, and merge them for planner use.
+ * We also cache curpages value to make plans stable.
+ */
+ if (!entry->valid)
+ {
+ bool has_dummy;
+
+ PG_TRY();
+ {
+ ++nested_level;
+
+ SPI_connect();
+
+ /*
+ * Retrieve per-tuple dummy statistics from relation_stats_locked table
+ * via SPI. If we don't have dummy statistics, we return false to
+ * tell caller thet we gave up to provide alternative statistics.
+ */
+ has_dummy = execute_plan(&rows_plan, rows_query, relid, NULL, true);
+ if (has_dummy)
+ {
+ HeapTuple tuple;
+ Form_pg_class form;
+ bool isnull;
+ Datum val;
+
+ /*
+ * Retrieve per-relation stats from pg_class system catalog.
+ * We use syscache to support indexes
+ */
+ tuple = SearchSysCache1(RELOID, ObjectIdGetDatum(relid));
+ if (!HeapTupleIsValid(tuple))
+ elog(ERROR, "cache lookup failed for relation %u", relid);
+ form = (Form_pg_class) GETSTRUCT(tuple);
+
+ /* Choose dummy or authentic */
+ val = get_binary_datum(1, &isnull);
+ entry->relpages = isnull ? form->relpages :
+ (BlockNumber) DatumGetInt32(val);
+ val = get_binary_datum(2, &isnull);
+ entry->reltuples = isnull ? form->reltuples :
+ (double) DatumGetFloat4(val);
+ val = get_binary_datum(3, &isnull);
+ entry->curpages = isnull ? InvalidBlockNumber :
+ (BlockNumber) DatumGetInt32(val);
+#if PG_VERSION_NUM >= 90200
+ val = get_binary_datum(4, &isnull);
+ entry->relallvisible = isnull ? form->relallvisible :
+ (BlockNumber) DatumGetInt32(val);
+#endif
+
+ ReleaseSysCache(tuple);
+
+ /* Mark this entry as valid. */
+ entry->valid = true;
+ }
+
+ SPI_finish();
+
+ --nested_level;
+ }
+ PG_CATCH();
+ {
+ --nested_level;
+ PG_RE_THROW();
+ }
+ PG_END_TRY();
+
+ /*
+ * If we don't dummy statistics, tell caller that we didn't change
+ * stats in Relation, and it's ok to use authentic statistics as-is.
+ */
+ if (!has_dummy)
+ return;
+ }
+
+ if (!estimate)
+ {
+ *pages = entry->relpages;
+ *tuples = entry->reltuples;
+ return;
+ }
+
+ /*
+ * Get current # of pages to estimate current # of tuples, based on
+ * tuple density at the last ANALYZE and current # of pages.
+ */
+ rel = relation_open(relid, NoLock);
+ rel->rd_rel->relpages = entry->relpages;
+ rel->rd_rel->reltuples = entry->reltuples;
+#if PG_VERSION_NUM >= 90200
+ rel->rd_rel->relallvisible = entry->relallvisible;
+#endif
+ dbms_stats_estimate_rel_size(rel, NULL, pages, tuples, allvisfrac,
+ entry->curpages);
+ relation_close(rel, NoLock);
+}
+
+/*
+ * get_merged_avgwidth
+ * get average width of the given column by merging dummy and authentic
+ * statistics
+ */
+static int32
+get_merged_avgwidth(Oid relid, AttrNumber attnum)
+{
+ HeapTuple tuple;
+
+ if (nested_level > 0 || relid < FirstNormalObjectId)
+ return 0; /* avoid recursive call and system objects */
+
+ if ((tuple = get_merged_column_stats(relid, attnum, false)) == NULL)
+ return 0;
+
+ return get_pg_statistic(tuple)->stawidth;
+}
+
+/*
+ * get_merged_column_stats
+ * get per-column statistic of given column
+ *
+ * We cache the result because this function is called for every used column.
+ */
+static HeapTuple
+get_merged_column_stats(Oid relid, AttrNumber attnum, bool inh)
+{
+ HeapTuple tuple;
+ HeapTuple statsTuple;
+
+ if (nested_level > 0 || relid < FirstNormalObjectId)
+ return NULL; /* avoid recursive call and system objects */
+
+ /* If the relation is system catalog, return NULL to use true statistics. */
+ if (dbms_stats_is_system_catalog_internal(relid))
+ return NULL;
+
+ /* Return cached statistics, if any. */
+ if ((tuple = column_cache_search(relid, attnum, inh)) != NULL)
+ return tuple;
+
+ /* Obtain statistics from syscache. This must be released afterward. */
+ statsTuple = SearchSysCache3(STATRELATTINH,
+ ObjectIdGetDatum(relid),
+ Int16GetDatum(attnum),
+ BoolGetDatum(inh));
+ PG_TRY();
+ {
+ ++nested_level;
+
+ SPI_connect();
+
+ /* Obtain dummy statistics. */
+ if (execute_plan(&tuple_plan, tuple_query, relid, &attnum, inh))
+ {
+ /* merge the dummy statistics and the true statistics */
+ tuple = dbms_stats_merge_internal(SPI_tuptable->vals[0], statsTuple,
+ SPI_tuptable->tupdesc);
+ }
+ else
+ {
+ /* if dummy statistics does not exist, use the true statistics */
+ tuple = statsTuple;
+ }
+
+ /* Cache merged result for subsequent calls. */
+ if (tuple != NULL)
+ tuple = column_cache_enter(tuple);
+
+ SPI_finish();
+
+ --nested_level;
+ }
+ PG_CATCH();
+ {
+ --nested_level;
+ PG_RE_THROW();
+ }
+ PG_END_TRY();
+
+ if (HeapTupleIsValid(statsTuple))
+ ReleaseSysCache(statsTuple);
+
+ return tuple;
+}
+
+/*
+ * column_cache_search
+ * Search statistic of the given column from the cache.
+ */
+static HeapTuple
+column_cache_search(Oid relid, AttrNumber attnum, bool inh)
+{
+ StatsRelationEntry *entry;
+ bool found;
+ ListCell *lc;
+
+ /*
+ * First, get cached relation stats. If we have not cached relation stats,
+ * we don't have column stats too.
+ */
+ entry = hash_search(rel_stats, &relid, HASH_FIND, &found);
+ if (!found )
+ return NULL;
+
+ /*
+ * It is assumed that not so many column_stats_effective are defined on a relation, so we
+ * use simple linear-search here. Using hash table for each relation would
+ * be another solution, but it seems overkill so far.
+ */
+ foreach(lc, entry->col_stats)
+ {
+ HeapTuple tuple = (HeapTuple) lfirst(lc);
+ Form_pg_statistic form = get_pg_statistic(tuple);
+
+ /* Find statistic of the given column from the cache. */
+ if (form->staattnum == attnum && form->stainherit == inh)
+ return tuple;
+ }
+
+ return NULL; /* not found */
+}
+
+/*
+ * Cache a per-column statistics. Cached statistics are valid through the
+ * current session, unless dummy statistics or table definition have been
+ * changed.
+ *
+ * We store statistics tuple in longer-lifetime context, CacheMemoryContext, to
+ * keep them alive during this session.
+ */
+static HeapTuple
+column_cache_enter(HeapTuple tuple)
+{
+ MemoryContext oldcontext;
+ HeapTuple newtuple;
+ Form_pg_statistic form;
+ StatsRelationEntry *entry;
+ bool found;
+
+ Assert(tuple != NULL);
+ Assert(!heap_attisnull(tuple, 1));
+
+ form = get_pg_statistic(tuple);
+
+ entry = hash_search(rel_stats, &form->starelid, HASH_ENTER, &found);
+ if (!found)
+ init_rel_stats_entry(entry, form->starelid);
+
+ /*
+ * Link new column statistics entry into the list in relation statsstics
+ * entry.
+ */
+ oldcontext = MemoryContextSwitchTo(CacheMemoryContext);
+ newtuple = heap_copytuple(tuple);
+ entry->col_stats = lappend(entry->col_stats, newtuple);
+ MemoryContextSwitchTo(oldcontext);
+
+ return newtuple;
+}
+
+/*
+ * Execute given plan. When given plan is NULL, create new plan from given
+ * query string, and execute it. This function can be used only for retrieving
+ * statistics of column_stats_effective and relation_stats_effective, because we assume #, types, and order
+ * of parameters here.
+ */
+static bool
+execute_plan(SPIPlanPtr *plan,
+ const char *query,
+ Oid relid,
+ const AttrNumber *attnum,
+ bool inh)
+{
+ int ret;
+ Oid argtypes[3] = { OIDOID, INT2OID, BOOLOID };
+ int nargs;
+ Datum values[3];
+ bool nulls[3] = { false, false, false };
+
+ nargs = (attnum ? 3 : 1);
+
+ /* When plan is not given, create plan from query string at first. */
+ if (*plan == NULL)
+ {
+ SPIPlanPtr p;
+ p = SPI_prepare(query, nargs, argtypes);
+ if (p == NULL)
+ elog(ERROR, "pg_dbms_stats: SPI_prepare => %d", SPI_result);
+ *plan = SPI_saveplan(p);
+ SPI_freeplan(p);
+ }
+
+ values[0] = ObjectIdGetDatum(relid);
+ values[1] = Int16GetDatum(attnum ? *attnum : 0);
+ values[2] = BoolGetDatum(inh);
+
+ ret = SPI_execute_plan(*plan, values, nulls, true, 1);
+ if (ret != SPI_OK_SELECT)
+ elog(ERROR, "pg_dbms_stats: SPI_execute_plan => %d", ret);
+
+ return SPI_processed > 0;
+}
+
+/*
+ * StatsCacheRelCallback
+ * Relcache inval callback function
+ *
+ * Invalidate cached statistic info of the given relid, or all cached statistic
+ * info if relid == InvalidOid. We don't complain even when we don't have such
+ * statistics.
+ *
+ * Note: arg is not used.
+ */
+static void
+StatsCacheRelCallback(Datum arg, Oid relid)
+{
+ HASH_SEQ_STATUS status;
+ StatsRelationEntry *entry;
+
+ hash_seq_init(&status, rel_stats);
+ while ((entry = hash_seq_search(&status)) != NULL)
+ {
+ if (relid == InvalidOid || relid == entry->relid)
+ {
+ /* Mark the relation entry as INVALID */
+ entry->valid = false;
+
+ /* Discard every column statistics */
+ list_free_deep(entry->col_stats);
+ entry->col_stats = NIL;
+ }
+ }
+
+ /* We always check throughout the list, so hash_seq_term is not necessary */
+}
+
+/*
+ * Initialize hash table for per-relation statistics.
+ */
+static void
+init_rel_stats(void)
+{
+ HTAB *hash;
+ HASHCTL ctl;
+
+ /* Prevent double initialization. */
+ if (rel_stats != NULL)
+ return;
+
+ MemSet(&ctl, 0, sizeof(ctl));
+ ctl.keysize = sizeof(Oid);
+ ctl.entrysize = sizeof(StatsRelationEntry);
+ ctl.hash = oid_hash;
+ ctl.hcxt = CacheMemoryContext;
+ hash = hash_create("dbms_stats relation statistics cache",
+ MAX_REL_CACHE,
+ &ctl, HASH_ELEM | HASH_CONTEXT);
+
+ rel_stats = hash;
+}
+
+/*
+ * Initialize newly added cache entry so that it represents an invalid cache
+ * entry for given relid.
+ */
+static void
+init_rel_stats_entry(StatsRelationEntry *entry, Oid relid)
+{
+ entry->relid = relid;
+ entry->valid = false;
+ entry->relpages = InvalidBlockNumber;
+ entry->reltuples = 0.0;
+ entry->relallvisible = InvalidBlockNumber;
+ entry->curpages = InvalidBlockNumber;
+ entry->col_stats = NIL;
+}
+
+/*
+ * dbms_stats_estimate_rel_size - estimate # pages and # tuples in a table or
+ * index
+ *
+ * We also estimate the fraction of the pages that are marked all-visible in
+ * the visibility map, for use in estimation of index-only scans.
+ *
+ * If attr_widths isn't NULL, it points to the zero-index entry of the
+ * relation's attr_widths[] cache; we fill this in if we have need to compute
+ * the attribute widths for estimation purposes.
+ *
+ * Note: This function is copied from plancat.c in core source tree of version
+ * 9.2, and customized for pg_dbms_stats. Changes from orignal one are:
+ * - rename by prefixing dbms_stats_
+ * - add 3 parameters (relpages, reltuples, curpage) to pass dummy curpage
+ * values.
+ * - Get current # of pages only when supplied curpages is InvalidBlockNumber
+ * - get franction of all-visible-pages
+ */
+static void
+dbms_stats_estimate_rel_size(Relation rel, int32 *attr_widths,
+ BlockNumber *pages, double *tuples,
+ double *allvisfrac, BlockNumber curpages)
+{
+ BlockNumber relpages;
+ double reltuples;
+ BlockNumber relallvisible;
+ double density;
+
+ switch (rel->rd_rel->relkind)
+ {
+ case RELKIND_RELATION:
+ case RELKIND_INDEX:
+ case RELKIND_TOASTVALUE:
+ /* it has storage, ok to call the smgr */
+ if (curpages == InvalidBlockNumber)
+ curpages = RelationGetNumberOfBlocks(rel);
+
+ /*
+ * HACK: if the relation has never yet been vacuumed, use a
+ * minimum size estimate of 10 pages. The idea here is to avoid
+ * assuming a newly-created table is really small, even if it
+ * currently is, because that may not be true once some data gets
+ * loaded into it. Once a vacuum or analyze cycle has been done
+ * on it, it's more reasonable to believe the size is somewhat
+ * stable.
+ *
+ * (Note that this is only an issue if the plan gets cached and
+ * used again after the table has been filled. What we're trying
+ * to avoid is using a nestloop-type plan on a table that has
+ * grown substantially since the plan was made. Normally,
+ * autovacuum/autoanalyze will occur once enough inserts have
+ * happened and cause cached-plan invalidation; but that doesn't
+ * happen instantaneously, and it won't happen at all for cases
+ * such as temporary tables.)
+ *
+ * We approximate "never vacuumed" by "has relpages = 0", which
+ * means this will also fire on genuinely empty relation_stats_effective. Not
+ * great, but fortunately that's a seldom-seen case in the real
+ * world, and it shouldn't degrade the quality of the plan too
+ * much anyway to err in this direction.
+ *
+ * There are two exceptions wherein we don't apply this heuristic.
+ * One is if the table has inheritance children. Totally empty
+ * parent tables are quite common, so we should be willing to
+ * believe that they are empty. Also, we don't apply the 10-page
+ * minimum to indexes.
+ */
+ if (curpages < 10 &&
+ rel->rd_rel->relpages == 0 &&
+ !rel->rd_rel->relhassubclass &&
+ rel->rd_rel->relkind != RELKIND_INDEX)
+ curpages = 10;
+
+ /* report estimated # pages */
+ *pages = curpages;
+ /* quick exit if rel is clearly empty */
+ if (curpages == 0)
+ {
+ *tuples = 0;
+ *allvisfrac = 0;
+ break;
+ }
+ /* coerce values in pg_class to more desirable types */
+ relpages = (BlockNumber) rel->rd_rel->relpages;
+ reltuples = (double) rel->rd_rel->reltuples;
+#if PG_VERSION_NUM >= 90200
+ relallvisible = (BlockNumber) rel->rd_rel->relallvisible;
+#else
+ relallvisible = 0;
+#endif
+ /*
+ * If it's an index, discount the metapage while estimating the
+ * number of tuples. This is a kluge because it assumes more than
+ * it ought to about index structure. Currently it's OK for
+ * btree, hash, and GIN indexes but suspect for GiST indexes.
+ */
+ if (rel->rd_rel->relkind == RELKIND_INDEX &&
+ relpages > 0)
+ {
+ curpages--;
+ relpages--;
+ }
+
+ /* estimate number of tuples from previous tuple density */
+ if (relpages > 0)
+ density = reltuples / (double) relpages;
+ else
+ {
+ /*
+ * When we have no data because the relation was truncated,
+ * estimate tuple width from attribute datatypes. We assume
+ * here that the pages are completely full, which is OK for
+ * tables (since they've presumably not been VACUUMed yet) but
+ * is probably an overestimate for indexes. Fortunately
+ * get_relation_info() can clamp the overestimate to the
+ * parent table's size.
+ *
+ * Note: this code intentionally disregards alignment
+ * considerations, because (a) that would be gilding the lily
+ * considering how crude the estimate is, and (b) it creates
+ * platform dependencies in the default plans which are kind
+ * of a headache for regression testing.
+ */
+ int32 tuple_width;
+
+ tuple_width = dbms_stats_get_rel_data_width(rel, attr_widths);
+ tuple_width += sizeof(HeapTupleHeaderData);
+ tuple_width += sizeof(ItemPointerData);
+ /* note: integer division is intentional here */
+ density = (BLCKSZ - SizeOfPageHeaderData) / tuple_width;
+ }
+ *tuples = rint(density * (double) curpages);
+
+ /*
+ * We use relallvisible as-is, rather than scaling it up like we
+ * do for the pages and tuples counts, on the theory that any
+ * pages added since the last VACUUM are most likely not marked
+ * all-visible. But costsize.c wants it converted to a fraction.
+ */
+ if (relallvisible == 0 || curpages <= 0)
+ *allvisfrac = 0;
+ else if ((double) relallvisible >= curpages)
+ *allvisfrac = 1;
+ else
+ *allvisfrac = (double) relallvisible / curpages;
+ break;
+ case RELKIND_SEQUENCE:
+ /* Sequences always have a known size */
+ *pages = 1;
+ *tuples = 1;
+ *allvisfrac = 0;
+ break;
+ case RELKIND_FOREIGN_TABLE:
+ /* Just use whatever's in pg_class */
+ *pages = rel->rd_rel->relpages;
+ *tuples = rel->rd_rel->reltuples;
+ *allvisfrac = 0;
+ break;
+ default:
+ /* else it has no disk storage; probably shouldn't get here? */
+ *pages = 0;
+ *tuples = 0;
+ *allvisfrac = 0;
+ break;
+ }
+}
+
+/*
+ * dbms_stats_get_rel_data_width
+ *
+ * Estimate the average width of (the data part of) the relation's tuples.
+ *
+ * If attr_widths isn't NULL, it points to the zero-index entry of the
+ * relation's attr_widths[] cache; use and update that cache as appropriate.
+ *
+ * Currently we ignore dropped column_stats_effective. Ideally those should be included
+ * in the result, but we haven't got any way to get info about them; and
+ * since they might be mostly NULLs, treating them as zero-width is not
+ * necessarily the wrong thing anyway.
+ *
+ * Note: This function is copied from plancat.c in core source tree of version
+ * 9.2, and just renamed.
+ */
+static int32
+dbms_stats_get_rel_data_width(Relation rel, int32 *attr_widths)
+{
+ int32 tuple_width = 0;
+ int i;
+
+ for (i = 1; i <= RelationGetNumberOfAttributes(rel); i++)
+ {
+ Form_pg_attribute att = rel->rd_att->attrs[i - 1];
+ int32 item_width;
+
+ if (att->attisdropped)
+ continue;
+
+ /* use previously cached data, if any */
+ if (attr_widths != NULL && attr_widths[i] > 0)
+ {
+ tuple_width += attr_widths[i];
+ continue;
+ }
+
+ /* This should match set_rel_width() in costsize.c */
+ item_width = get_attavgwidth(RelationGetRelid(rel), i);
+ if (item_width <= 0)
+ {
+ item_width = get_typavgwidth(att->atttypid, att->atttypmod);
+ Assert(item_width > 0);
+ }
+ if (attr_widths != NULL)
+ attr_widths[i] = item_width;
+ tuple_width += item_width;
+ }
+
+ return tuple_width;
+}
+
+#ifdef UNIT_TEST
+void test_pg_dbms_stats(int *passed, int *total);
+static void test_init_rel_stats(int *passed, int *total);
+static void test_init_rel_stats_entry(int *passed, int *total);
+
+void
+test_pg_dbms_stats(int *passed, int *total)
+{
+ int local_passed = 0;
+ int local_total = 0;
+
+ elog(WARNING, "==========");
+
+ /* Do tests here */
+ test_init_rel_stats(&local_passed, &local_total);
+ test_init_rel_stats_entry(&local_passed, &local_total);
+
+ elog(WARNING, "%s %d/%d passed", __FUNCTION__, local_passed, local_total);
+ *passed += local_passed;
+ *total += local_total;
+}
+
+static void
+test_init_rel_stats_entry(int *passed, int *total)
+{
+ int caseno = 0;
+ StatsRelationEntry entry;
+
+ /*
+ * *-*-1
+ */
+ caseno++;
+ init_rel_stats_entry(&entry, 1234);
+ if (entry.relid == 1234 &&
+ entry.valid == false &&
+ entry.relpages == InvalidBlockNumber &&
+ entry.reltuples == 0 &&
+ entry.relallvisible == InvalidBlockNumber &&
+ entry.curpages == InvalidBlockNumber &&
+ entry.col_stats == NIL)
+ {
+ elog(WARNING, "%s-%d ok", __FUNCTION__, caseno);
+ (*passed)++;
+ }
+ else
+ elog(WARNING, "%s-%d failed: initialized", __FUNCTION__, caseno);
+
+ (*total) += caseno;
+}
+
+static void
+test_init_rel_stats(int *passed, int *total)
+{
+ int caseno = 0;
+ static HTAB *org_rel_stats;
+
+ /*
+ * *-*-1
+ * - first call
+ */
+ caseno++;
+ init_rel_stats();
+ if (rel_stats != NULL)
+ {
+ elog(WARNING, "%s-%d ok", __FUNCTION__, caseno);
+ (*passed)++;
+ }
+ else
+ elog(WARNING, "%s-%d failed: rel_stats is NULL", __FUNCTION__, caseno);
+
+ /*
+ * *-*-2
+ * - second call
+ */
+ caseno++;
+ org_rel_stats = rel_stats;
+ init_rel_stats();
+ if (org_rel_stats == rel_stats)
+ {
+ elog(WARNING, "%s-%d ok", __FUNCTION__, caseno);
+ (*passed)++;
+ }
+ else
+ elog(WARNING, "%s-%d failed: rel_stats changed from %p to %p",
+ __FUNCTION__, caseno, org_rel_stats, rel_stats);
+
+ *total += caseno;
+}
+#endif
diff --git a/pg_dbms_stats.control b/pg_dbms_stats.control
new file mode 100644
index 0000000..85ab50d
--- /dev/null
+++ b/pg_dbms_stats.control
@@ -0,0 +1,7 @@
+# pg_dbms_stats extension
+
+comment = 'stabilize plans by fixing statistics'
+default_version = '1.0'
+module_pathname = '$libdir/pg_dbms_stats'
+relocatable = false
+schema = dbms_stats
diff --git a/pg_dbms_stats.h b/pg_dbms_stats.h
new file mode 100644
index 0000000..da786d4
--- /dev/null
+++ b/pg_dbms_stats.h
@@ -0,0 +1,15 @@
+/*
+ * pg_dbms_stats.h
+ *
+ * Copyright (c) 2009-2012, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
+ * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ */
+
+#ifndef PG_DBMS_STATS_H
+#define PG_DBMS_STATS_H
+
+bool dbms_stats_is_system_schema_internal(char *schema_name);
+bool dbms_stats_is_system_catalog_internal(Oid regclass);
+
+#endif /* PG_DBMS_STATS_H */
diff --git a/sql/.gitignore b/sql/.gitignore
new file mode 100644
index 0000000..de486b1
--- /dev/null
+++ b/sql/.gitignore
@@ -0,0 +1,2 @@
+/ut_anyarray-*.sql
+/ut_imp_exp-*.sql
diff --git a/sql/init-9.1.sql b/sql/init-9.1.sql
new file mode 100644
index 0000000..392ac8c
--- /dev/null
+++ b/sql/init-9.1.sql
@@ -0,0 +1,97 @@
+CREATE VIEW plain_relations_statistic_v AS
+SELECT oid::regclass,
+ relpages,
+ reltuples,
+ pg_relation_size(oid) / 8192 curpages
+ FROM pg_class
+ ORDER BY oid::regclass::text;
+CREATE VIEW relations_locked_v AS
+SELECT relid::regclass,
+ relname,
+ relpages,
+ reltuples,
+ curpages
+ FROM dbms_stats._relation_stats_locked
+ ORDER BY relid;
+CREATE VIEW relations_backup_v AS
+SELECT id,
+ relid::regclass,
+ relname,
+ relpages,
+ reltuples,
+ curpages
+ FROM dbms_stats.relation_stats_backup
+ ORDER BY id, relid;
+CREATE VIEW plain_columns_statistic_v AS
+SELECT starelid::regclass, staattnum, stainherit,
+ stanullfrac, stawidth, stadistinct,
+ stakind1, stakind2, stakind3, stakind4,
+ staop1, staop2, staop3, staop4,
+ stanumbers1, stanumbers2, stanumbers3, stanumbers4,
+ stavalues1::text, stavalues2::text, stavalues3::text, stavalues4::text
+ FROM pg_statistic
+ ORDER BY starelid, staattnum, stainherit;
+CREATE VIEW columns_locked_v AS
+SELECT starelid::regclass, staattnum, attname, stainherit,
+ stanullfrac, stawidth, stadistinct,
+ stakind1, stakind2, stakind3, stakind4,
+ staop1, staop2, staop3, staop4,
+ stanumbers1, stanumbers2, stanumbers3, stanumbers4,
+ stavalues1, stavalues2, stavalues3, stavalues4
+ FROM dbms_stats._column_stats_locked c
+ JOIN pg_attribute a
+ ON (c.starelid = a.attrelid AND c.staattnum = a.attnum)
+ ORDER BY starelid, staattnum, stainherit;
+CREATE VIEW columns_backup_v AS
+SELECT id, statypid,
+ starelid::regclass, staattnum, stainherit,
+ stanullfrac, stawidth, stadistinct,
+ stakind1, stakind2, stakind3, stakind4,
+ staop1, staop2, staop3, staop4,
+ stanumbers1, stanumbers2, stanumbers3, stanumbers4,
+ stavalues1, stavalues2, stavalues3, stavalues4
+ FROM dbms_stats.column_stats_backup
+ ORDER BY id, starelid, staattnum, stainherit;
+CREATE TABLE dbms_stats.work (
+ nspname name NOT NULL,
+ relname name NOT NULL,
+ relpages int4 NOT NULL,
+ reltuples float4 NOT NULL,
+ curpages int4 NOT NULL,
+ last_analyze timestamp with time zone,
+ last_autoanalyze timestamp with time zone,
+ attname name,
+ nspname_of_typename name,
+ typname name,
+ atttypmod int4,
+ stainherit bool,
+ stanullfrac float4,
+ stawidth int4,
+ stadistinct float4,
+ stakind1 int2,
+ stakind2 int2,
+ stakind3 int2,
+ stakind4 int2,
+ staop1 oid,
+ staop2 oid,
+ staop3 oid,
+ staop4 oid,
+ stanumbers1 float4[],
+ stanumbers2 float4[],
+ stanumbers3 float4[],
+ stanumbers4 float4[],
+ stavalues1 dbms_stats.anyarray,
+ stavalues2 dbms_stats.anyarray,
+ stavalues3 dbms_stats.anyarray,
+ stavalues4 dbms_stats.anyarray
+);
+CREATE VIEW work_v AS
+SELECT nspname, relname, relpages, reltuples,
+ curpages, attname, nspname_of_typename, typname, atttypmod,
+ stainherit, stanullfrac, stawidth, stadistinct,
+ stakind1, stakind2, stakind3, stakind4,
+ staop1, staop2, staop3, staop4,
+ stanumbers1, stanumbers2, stanumbers3, stanumbers4,
+ stavalues1, stavalues2, stavalues3, stavalues4
+ FROM dbms_stats.work
+ ORDER BY nspname, relname, attname, stainherit;
diff --git a/sql/init-9.2.sql b/sql/init-9.2.sql
new file mode 100644
index 0000000..93c3e91
--- /dev/null
+++ b/sql/init-9.2.sql
@@ -0,0 +1,105 @@
+CREATE VIEW plain_relations_statistic_v AS
+SELECT oid::regclass,
+ relpages,
+ reltuples,
+ relallvisible,
+ pg_relation_size(oid) / 8192 curpages
+ FROM pg_class
+ ORDER BY oid::regclass::text;
+CREATE VIEW relations_locked_v AS
+SELECT relid::regclass,
+ relname,
+ relpages,
+ reltuples,
+ relallvisible,
+ curpages
+ FROM dbms_stats._relation_stats_locked
+ ORDER BY relid;
+CREATE VIEW relations_backup_v AS
+SELECT id,
+ relid::regclass,
+ relname,
+ relpages,
+ reltuples,
+ relallvisible,
+ curpages
+ FROM dbms_stats.relation_stats_backup
+ ORDER BY id, relid;
+CREATE VIEW plain_columns_statistic_v AS
+SELECT starelid::regclass, staattnum, stainherit,
+ stanullfrac, stawidth, stadistinct,
+ stakind1, stakind2, stakind3, stakind4, stakind5,
+ staop1, staop2, staop3, staop4, staop5,
+ stanumbers1, stanumbers2, stanumbers3, stanumbers4, stanumbers5,
+ stavalues1::text, stavalues2::text, stavalues3::text, stavalues4::text, stavalues5::text
+ FROM pg_statistic
+ ORDER BY starelid, staattnum, stainherit;
+CREATE VIEW columns_locked_v AS
+SELECT starelid::regclass, 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
+ FROM dbms_stats._column_stats_locked c
+ JOIN pg_attribute a
+ ON (c.starelid = a.attrelid AND c.staattnum = a.attnum)
+ ORDER BY starelid, staattnum, stainherit;
+CREATE VIEW columns_backup_v AS
+SELECT id, statypid,
+ starelid::regclass, 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
+ FROM dbms_stats.column_stats_backup
+ ORDER BY id, starelid, staattnum, stainherit;
+CREATE TABLE dbms_stats.work (
+ nspname name NOT NULL,
+ relname name NOT NULL,
+ relpages int4 NOT NULL,
+ reltuples float4 NOT NULL,
+ relallvisible int4 NOT NULL,
+ curpages int4 NOT NULL,
+ last_analyze timestamp with time zone,
+ last_autoanalyze timestamp with time zone,
+ attname name,
+ nspname_of_typename name,
+ typname name,
+ atttypmod int4,
+ stainherit bool,
+ stanullfrac float4,
+ stawidth int4,
+ stadistinct float4,
+ stakind1 int2,
+ stakind2 int2,
+ stakind3 int2,
+ stakind4 int2,
+ stakind5 int2,
+ staop1 oid,
+ staop2 oid,
+ staop3 oid,
+ staop4 oid,
+ staop5 oid,
+ stanumbers1 float4[],
+ stanumbers2 float4[],
+ stanumbers3 float4[],
+ stanumbers4 float4[],
+ stanumbers5 float4[],
+ stavalues1 dbms_stats.anyarray,
+ stavalues2 dbms_stats.anyarray,
+ stavalues3 dbms_stats.anyarray,
+ stavalues4 dbms_stats.anyarray
+ ,stavalues5 dbms_stats.anyarray
+);
+CREATE VIEW work_v AS
+SELECT nspname, relname, relpages, reltuples, relallvisible,
+ curpages, attname, nspname_of_typename, typname, atttypmod,
+ stainherit, stanullfrac, stawidth, stadistinct,
+ stakind1, stakind2, stakind3, stakind4, stakind5,
+ staop1, staop2, staop3, staop4, staop5,
+ stanumbers1, stanumbers2, stanumbers3, stanumbers4, stanumbers5,
+ stavalues1, stavalues2, stavalues3, stavalues4, stavalues5
+ FROM dbms_stats.work
+ ORDER BY nspname, relname, attname, stainherit;
diff --git a/sql/init-common.sql b/sql/init-common.sql
new file mode 100644
index 0000000..dfe6cd4
--- /dev/null
+++ b/sql/init-common.sql
@@ -0,0 +1,95 @@
+/*
+ * No.1-1 CREATE EXTENSION
+ */
+-- No.1-1-1
+CREATE EXTENSION pg_dbms_stats;
+-- No.1-1-2
+DROP EXTENSION pg_dbms_stats;
+
+CREATE EXTENSION pg_dbms_stats;
+
+-- create no superuser and superuser
+SET client_min_messages = warning;
+DROP ROLE IF EXISTS regular_user;
+CREATE ROLE regular_user LOGIN;
+SET client_min_messages = fatal;
+CREATE ROLE postgres SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN;
+
+-- create object
+CREATE TABLE pt0(id integer, day date);
+CREATE INDEX pt0_idx ON pt0(id);
+CREATE TABLE st0(id integer, name char(5));
+CREATE INDEX st0_idx ON st0(id);
+CREATE TABLE st1(val integer, str text);
+
+CREATE SCHEMA s0;
+CREATE TABLE s0.st0(id integer, num integer);
+CREATE INDEX st0_idx ON s0.st0(id);
+CREATE TABLE s0.st1() INHERITS(s0.st0);
+CREATE INDEX st1_idx ON s0.st1(id);
+CREATE TABLE s0.st2(id integer, txt text);
+CREATE INDEX st2_idx ON s0.st2(id);
+CREATE VIEW sv0 AS
+ SELECT st0.id, st0.num, st2.txt
+ FROM s0.st0 st0, s0.st2 st2
+ WHERE st0.id = st2.id;
+CREATE TYPE s0.sc0 AS (num integer, txt text);
+CREATE FOREIGN DATA WRAPPER test_wrapper;
+CREATE SERVER test_server
+ FOREIGN DATA WRAPPER test_wrapper;
+CREATE FOREIGN TABLE s0.sft0(id integer)
+ SERVER test_server;
+CREATE SEQUENCE s0.ss0 START 1;
+
+CREATE SCHEMA s1;
+CREATE TABLE s1.st0(id integer, num integer);
+CREATE SCHEMA s2;
+
+GRANT USAGE ON SCHEMA s0 TO regular_user;
+GRANT SELECT ON TABLE s0.st2 TO regular_user;
+
+CREATE TYPE complex AS (
+ r double precision,
+ i double precision
+);
+
+CREATE FUNCTION inform(VARIADIC arr text[]) RETURNS int AS $$
+DECLARE
+ str text := 'arguments are ';
+ count int;
+BEGIN
+ FOR count IN SELECT i FROM generate_subscripts($1, 1) g(i) LOOP
+ IF count != 1 THEN
+ str := str || ', ';
+ END IF;
+ IF $1[count] IS NULL THEN
+ str := str || '';
+ ELSE
+ str := str || $1[count];
+ END IF;
+ END LOOP;
+ RAISE NOTICE '%', str;
+ RETURN 1;
+END;
+$$LANGUAGE plpgsql;
+
+CREATE VIEW lockd_io AS
+ SELECT relname, heap_blks_read hbr, heap_blks_hit hbh,
+ idx_blks_read ibr, idx_blks_hit ibh
+ FROM pg_statio_user_tables
+ WHERE schemaname = 'dbms_stats'
+ AND relname LIKE '%stats_locked'
+ ORDER BY relid;
+
+-- load data
+INSERT INTO st0 VALUES (1, 'test'), (2, 'test');
+INSERT INTO st1 SELECT i % 3, i % 3 FROM generate_series(1, 10000) t(i);
+INSERT INTO s0.st0 VALUES (1, 10), (2, 20);
+INSERT INTO s0.st1 VALUES (4, 40), (5, 50), (6, 60);
+INSERT INTO s0.st2 VALUES (1, '1'), (2, 'test'), (3, 'comment');
+INSERT INTO s1.st0 VALUES (1, 15), (2, 25), (3, 35), (4, 45);
+
+CREATE INDEX st1_idx ON st1 (val);
+CREATE INDEX st1_exp ON st1 (lower(str));
+
+VACUUM ANALYZE;
diff --git a/sql/ut-9.1.sql b/sql/ut-9.1.sql
new file mode 100644
index 0000000..a9fa614
--- /dev/null
+++ b/sql/ut-9.1.sql
@@ -0,0 +1,2561 @@
+\pset null '(null)'
+/*
+ * No.2-1 table definitions.
+ */
+-- No.2-1-1
+\d dbms_stats.backup_history
+-- No.2-1-2
+\d dbms_stats.column_stats_backup
+-- No.2-1-3
+\d dbms_stats._column_stats_locked
+-- No.2-1-4
+\d dbms_stats.relation_stats_backup
+-- No.2-1-5
+\d dbms_stats._relation_stats_locked
+
+/*
+ * No.2-2 view definitions.
+ */
+-- No.2-2-1
+\dS+ dbms_stats.column_stats_effective
+-- No.2-2-2
+\dS+ dbms_stats.relation_stats_effective
+-- No.2-2-3
+\dS+ dbms_stats.stats
+-- No.2-2-4
+\dS+ dbms_stats.column_stats_locked
+-- No.2-2-5
+\dS+ dbms_stats.relation_stats_locked
+
+/*
+ * No.5-1 dbms_stats.merge
+ */
+UPDATE pg_statistic SET
+ stanullfrac = staattnum,
+ stawidth = staattnum,
+ stadistinct = staattnum,
+ stakind1 = 4,
+ stakind2 = 1,
+ stakind3 = 2,
+ stakind4 = 3,
+ staop1 = 14,
+ staop2 = 11,
+ staop3 = 12,
+ staop4 = 13,
+ stanumbers1 = ARRAY[staattnum,4],
+ stanumbers2 = ARRAY[staattnum,1],
+ stanumbers3 = ARRAY[staattnum,2],
+ stanumbers4 = ARRAY[staattnum,3],
+ stavalues2 = array_cat(stavalues1,stavalues1),
+ stavalues3 = array_cat(array_cat(stavalues1,stavalues1),stavalues1),
+ stavalues4 = array_cat(array_cat(array_cat(stavalues1,stavalues1),stavalues1),stavalues1)
+ WHERE starelid = 'st0'::regclass;
+SELECT dbms_stats.lock_table_stats('st0');
+UPDATE dbms_stats._column_stats_locked SET
+ stainherit = 't',
+ stanullfrac = -staattnum,
+ stawidth = -staattnum,
+ stadistinct = -staattnum,
+ stakind1 = 2,
+ stakind2 = 3,
+ stakind3 = 4,
+ stakind4 = 1,
+ staop1 = 22,
+ staop2 = 23,
+ staop3 = 24,
+ staop4 = 21,
+ stanumbers1 = ARRAY[-staattnum,22],
+ stanumbers2 = ARRAY[-staattnum,23],
+ stanumbers3 = ARRAY[-staattnum,24],
+ stanumbers4 = ARRAY[-staattnum,21],
+ stavalues1 = stavalues3,
+ stavalues2 = stavalues2,
+ stavalues3 = stavalues1,
+ stavalues4 = stavalues4
+;
+
+/*
+ * Driver function dbms_stats.merge1
+ */
+CREATE FUNCTION dbms_stats.merge1(
+ lhs dbms_stats._column_stats_locked,
+ rhs pg_catalog.pg_statistic
+) RETURNS integer AS
+'$libdir/pg_dbms_stats', 'dbms_stats_merge'
+LANGUAGE C STABLE;
+
+SELECT * FROM columns_locked_v
+ WHERE starelid = 'st0'::regclass;
+SELECT * FROM plain_columns_statistic_v
+ WHERE starelid = 'st0'::regclass;
+
+SET client_min_messages TO LOG;
+
+-- No.5-1-1
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ FROM (SELECT dbms_stats.merge(NULL, s)
+ FROM pg_statistic s
+ WHERE starelid = 'st0'::regclass
+ AND staattnum = '1'::int2) m;
+
+-- No.5-1-2
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ FROM (SELECT dbms_stats.merge(v, NULL)
+ FROM dbms_stats._column_stats_locked v
+ WHERE starelid = 'st0'::regclass
+ AND staattnum = '2'::int2) m;
+
+-- No.5-1-3
+SELECT dbms_stats.merge(NULL, NULL);
+
+-- No.5-1-4
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ FROM (SELECT dbms_stats.merge(v, s)
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '2'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2) m;
+
+-- No.5-1-5
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ FROM (SELECT dbms_stats.merge(v, s)
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '2'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2) m;
+
+-- No.5-1-6
+SELECT dbms_stats.merge1(v, s)
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '2'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2;
+
+-- No.5-1-7
+SELECT dbms_stats.merge(NULL, (
+ s.starelid::regclass, s.staattnum, s.stainherit,
+ s.stanullfrac, s.stawidth, s.stadistinct,
+ s.stakind1, s.stakind2, s.stakind3, s.stakind4,
+ s.staop1, s.staop2, s.staop3,
+ NULL, s.stanumbers1, s.stanumbers2, s.stanumbers3, s.stanumbers4,
+ s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
+ ))
+ FROM pg_statistic s
+ WHERE s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2;
+
+-- No.5-1-8
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ FROM (SELECT dbms_stats.merge(NULL, (
+ s.starelid::regclass, s.staattnum, s.stainherit,
+ s.stanullfrac, s.stawidth, s.stadistinct,
+ s.stakind1, s.stakind2, s.stakind3, s.stakind4,
+ s.staop1, s.staop2, s.staop3, s.staop4,
+ NULL, s.stanumbers2, s.stanumbers3, s.stanumbers4,
+ s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
+ ))
+ FROM pg_statistic s
+ WHERE s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2) m;
+
+-- No.5-1-9
+SELECT dbms_stats.merge((
+ v.starelid::regclass, v.staattnum, v.stainherit,
+ v.stanullfrac, v.stawidth, v.stadistinct,
+ v.stakind1, v.stakind2, v.stakind3, v.stakind4,
+ v.staop1, v.staop2, v.staop3,
+ NULL, v.stanumbers1, v.stanumbers2, v.stanumbers3, v.stanumbers4,
+ v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
+ ), NULL)
+ FROM dbms_stats._column_stats_locked v
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '2'::int2;
+
+-- No.5-1-10
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ FROM (SELECT dbms_stats.merge((
+ v.starelid::regclass, v.staattnum, v.stainherit,
+ v.stanullfrac, v.stawidth, v.stadistinct,
+ v.stakind1, v.stakind2, v.stakind3, v.stakind4,
+ v.staop1, v.staop2, v.staop3, v.staop4,
+ NULL, v.stanumbers2, v.stanumbers3, v.stanumbers4,
+ v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
+ ), NULL)
+ FROM dbms_stats._column_stats_locked v
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '2'::int2) m;
+
+-- No.5-1-11
+SELECT dbms_stats.merge((
+ v.starelid::regclass, v.staattnum, v.stainherit,
+ v.stanullfrac, v.stawidth, v.stadistinct,
+ v.stakind1, v.stakind2, v.stakind3, v.stakind4,
+ v.staop1, v.staop2, v.staop3,
+ NULL, v.stanumbers1, v.stanumbers2, v.stanumbers3, v.stanumbers4,
+ v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
+ ), (
+ s.starelid::regclass, s.staattnum, s.stainherit,
+ s.stanullfrac, s.stawidth, s.stadistinct,
+ s.stakind1, s.stakind2, s.stakind3, s.stakind4,
+ s.staop1, s.staop2, s.staop3,
+ NULL, s.stanumbers1, s.stanumbers2, s.stanumbers3, s.stanumbers4,
+ s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
+ ))
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '2'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2;
+
+-- No.5-1-12
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ FROM (SELECT dbms_stats.merge((
+ v.starelid::regclass, v.staattnum, v.stainherit,
+ v.stanullfrac, v.stawidth, v.stadistinct,
+ v.stakind1, v.stakind2, v.stakind3, v.stakind4,
+ v.staop1, v.staop2, v.staop3, v.staop4,
+ NULL, v.stanumbers2, v.stanumbers3, v.stanumbers4,
+ v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
+ ), (
+ s.starelid::regclass, s.staattnum, s.stainherit,
+ s.stanullfrac, s.stawidth, s.stadistinct,
+ s.stakind1, s.stakind2, s.stakind3, s.stakind4,
+ s.staop1, s.staop2, s.staop3, s.staop4,
+ NULL, s.stanumbers2, s.stanumbers3, s.stanumbers4,
+ s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
+ ))
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '2'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2) m;
+
+-- No.5-1-13
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ FROM (SELECT dbms_stats.merge((
+ NULL, NULL, NULL,
+ NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL
+ ), s)
+ FROM pg_statistic s
+ WHERE s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2) m;
+
+-- No.5-1-14
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ FROM (SELECT dbms_stats.merge(v, (
+ NULL, NULL, NULL,
+ NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL))
+ FROM dbms_stats._column_stats_locked v
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '2'::int2) m;
+
+-- No.5-1-15
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ FROM (SELECT dbms_stats.merge(v, s)
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '2'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2) m;
+
+-- No.5-1-16
+SELECT dbms_stats.merge((
+ v.starelid::regclass, v.staattnum, v.stainherit,
+ v.stanullfrac, v.stawidth, v.stadistinct,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL
+ ), (
+ s.starelid::regclass, s.staattnum, s.stainherit,
+ s.stanullfrac, s.stawidth, s.stadistinct,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL))
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '2'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2;
+
+-- No.5-1-17
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ FROM (SELECT dbms_stats.merge((
+ v.starelid::regclass, v.staattnum, v.stainherit,
+ v.stanullfrac, v.stawidth, v.stadistinct,
+ v.stakind1, v.stakind2, v.stakind3, v.stakind4,
+ v.staop1, v.staop2, v.staop3,
+ NULL, v.stanumbers1, v.stanumbers2, v.stanumbers3, v.stanumbers4,
+ v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
+ ), (
+ s.starelid::regclass, s.staattnum, s.stainherit,
+ s.stanullfrac, s.stawidth, s.stadistinct,
+ s.stakind1, s.stakind2, s.stakind3, s.stakind4,
+ s.staop1, s.staop2, s.staop3, s.staop4,
+ s.stanumbers1, s.stanumbers2, s.stanumbers3, s.stanumbers4,
+ s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
+ ))
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '1'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2) m;
+
+-- No.5-1-18
+SELECT dbms_stats.merge((
+ v.starelid::regclass, v.staattnum, v.stainherit,
+ v.stanullfrac, v.stawidth, v.stadistinct,
+ v.stakind1, v.stakind2, v.stakind3, v.stakind4,
+ v.staop1, v.staop2, v.staop3,
+ NULL, v.stanumbers1, v.stanumbers2, v.stanumbers3, v.stanumbers4,
+ v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
+ ), (
+ s.starelid::regclass, s.staattnum, s.stainherit,
+ s.stanullfrac, s.stawidth, s.stadistinct,
+ s.stakind1, s.stakind2, s.stakind3, s.stakind4,
+ s.staop1, s.staop2, s.staop3,
+ NULL, s.stanumbers1, s.stanumbers2, s.stanumbers3, s.stanumbers4,
+ s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
+ ))
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '1'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2;
+
+-- No.5-1-19
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ FROM (SELECT dbms_stats.merge((
+ v.starelid::regclass, v.staattnum, v.stainherit,
+ v.stanullfrac, v.stawidth, v.stadistinct,
+ '1', '1', '1', '1',
+ v.staop1, v.staop2, v.staop3, v.staop4,
+ v.stanumbers1, v.stanumbers2, v.stanumbers3, v.stanumbers4,
+ v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
+ ), (
+ s.starelid::regclass, s.staattnum, s.stainherit,
+ s.stanullfrac, s.stawidth, s.stadistinct,
+ '1', '1', '1', '1',
+ s.staop1, s.staop2, s.staop3, s.staop4,
+ s.stanumbers1, s.stanumbers2, s.stanumbers3, s.stanumbers4,
+ s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
+ ))
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '2'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2) m;
+
+-- No.5-1-20
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ FROM (SELECT dbms_stats.merge((v.starelid::regclass, v.staattnum, v.stainherit,
+ v.stanullfrac, v.stawidth, v.stadistinct,
+ '2', '2', '2', '2',
+ v.staop1, v.staop2, v.staop3, v.staop4,
+ v.stanumbers1, v.stanumbers2, v.stanumbers3, v.stanumbers4,
+ v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
+ ), (
+ s.starelid::regclass, s.staattnum, s.stainherit,
+ s.stanullfrac, s.stawidth, s.stadistinct,
+ '2', '2', '2', '2',
+ s.staop1, s.staop2, s.staop3, s.staop4,
+ s.stanumbers1, s.stanumbers2, s.stanumbers3, s.stanumbers4,
+ s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
+ ))
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '2'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2) m;
+
+-- No.5-1-21
+SELECT dbms_stats.merge((v.starelid::regclass, '2', v.stainherit,
+ v.stanullfrac, v.stawidth, v.stadistinct,
+ '1', '1', '1', '1',
+ v.staop1, v.staop2, v.staop3, v.staop4,
+ v.stanumbers1, v.stanumbers2, v.stanumbers3, v.stanumbers4,
+ v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
+ ), (
+ s.starelid::regclass, s.staattnum, s.stainherit,
+ s.stanullfrac, s.stawidth, s.stadistinct,
+ '1', '1', '1', '1',
+ s.staop1, s.staop2, s.staop3, s.staop4,
+ s.stanumbers1, s.stanumbers2, s.stanumbers3, s.stanumbers4,
+ s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
+ ))
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '1'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2;
+
+-- No.5-1-22
+SELECT dbms_stats.merge((v.starelid::regclass, '2', v.stainherit,
+ v.stanullfrac, v.stawidth, v.stadistinct,
+ '2', '2', '2', '2',
+ v.staop1, v.staop2, v.staop3, v.staop4,
+ v.stanumbers1, v.stanumbers2, v.stanumbers3, v.stanumbers4,
+ v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
+ ), (
+ s.starelid::regclass, s.staattnum, s.stainherit,
+ s.stanullfrac, s.stawidth, s.stadistinct,
+ '2', '2', '2', '2',
+ s.staop1, s.staop2, s.staop3, s.staop4,
+ s.stanumbers1, s.stanumbers2, s.stanumbers3, s.stanumbers4,
+ s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
+ ))
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '1'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2;
+RESET client_min_messages;
+SELECT dbms_stats.unlock_database_stats();
+
+/*
+ * No.6-4 dbms_stats.is_target_relkind
+ */
+-- No.6-4-10
+SELECT dbms_stats.is_target_relkind('f');
+
+/*
+ * No.7-1 dbms_stats.backup
+ */
+DELETE FROM dbms_stats.backup_history;
+INSERT INTO dbms_stats.backup_history(id, time, unit) values(1, '2012-01-01', 'd');
+-- No.7-1-9
+SELECT dbms_stats.backup(1, 's0.sft0'::regclass, NULL);
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+
+-- No.7-1-11
+DELETE FROM dbms_stats.relation_stats_backup;
+SELECT dbms_stats.backup(1, NULL, 1::int2);
+SELECT relid::regclass FROM dbms_stats.relation_stats_backup
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, staattnum FROM dbms_stats.column_stats_backup
+ GROUP BY starelid, staattnum
+ ORDER BY starelid, staattnum;
+
+-- No.7-1-13
+DELETE FROM dbms_stats.relation_stats_backup;
+SELECT dbms_stats.backup(1, NULL::regclass, NULL);
+SELECT relid::regclass FROM dbms_stats.relation_stats_backup
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, staattnum FROM dbms_stats.column_stats_backup
+ GROUP BY starelid, staattnum
+ ORDER BY starelid, staattnum;
+
+-- No.7-1-17
+DELETE FROM dbms_stats.relation_stats_backup;
+SELECT dbms_stats.backup(NULL, 's0.st0'::regclass, NULL);
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+
+/*
+ * No.8-1 dbms_stats.backup
+ */
+SELECT setval('dbms_stats.backup_history_id_seq',1, false);
+/*
+ * Stab function dbms_stats.backup
+ */
+ALTER FUNCTION dbms_stats.backup(
+ backup_id int8,
+ relid regclass,
+ attnum int2)
+ RENAME TO truth_func_backup;
+
+CREATE OR REPLACE FUNCTION dbms_stats.backup(
+ backup_id int8,
+ regclass,
+ attnum int2)
+RETURNS int8 AS
+$$
+BEGIN
+ RAISE NOTICE 'arguments are %, %, %', $1, $2, $3;
+ RETURN 1;
+END;
+$$
+LANGUAGE plpgsql;
+
+-- No.8-1-1
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup('s0.st0'::regclass, 'id', 'dummy comment');
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+
+-- No.8-1-2
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup('s0.st0'::regclass, NULL, 'dummy comment');
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+
+-- No.8-1-3
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup(NULL::regclass, 'id', 'dummy comment');
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+
+-- No.8-1-4
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup(NULL::regclass, NULL, 'dummy comment');
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+
+-- No.8-1-5
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup(0, NULL, 'dummy comment');
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+
+-- No.8-1-6
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup('s0.st0'::regclass, NULL, 'dummy comment');
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+
+-- No.8-1-7
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup(
+ 'pg_toast.pg_toast_2618'::regclass,
+ NULL,
+ 'dummy comment');
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+
+-- No.8-1-8
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup('s0.st0_idx'::regclass, NULL, 'dummy comment');
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+
+-- No.8-1-9
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup('s0.ss0'::regclass, NULL, 'dummy comment');
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+
+-- No.8-1-10
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup('s0.sc0'::regclass, NULL, 'dummy comment');
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+
+-- No.8-1-11
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup('s0.sft0'::regclass, NULL, 'dummy comment');
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+
+-- No.8-1-12
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup('pg_catalog.pg_class'::regclass, NULL, 'dummy comment');
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+
+-- No.8-1-13
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup('s0.st0'::regclass, 'dummy', 'dummy comment');
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+
+-- No.8-1-14
+DELETE FROM dbms_stats.backup_history;
+DELETE FROM pg_statistic
+ WHERE starelid = 's0.st0'::regclass
+ AND staattnum = 1::int2;
+SELECT count(*) FROM dbms_stats.column_stats_effective
+ WHERE starelid = 's0.st0'::regclass
+ AND staattnum = 1::int2;
+SELECT dbms_stats.backup('s0.st0'::regclass, 'id', 'dummy comment');
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+
+/*
+ * Stab function dbms_stats.backup
+ */
+ALTER FUNCTION dbms_stats.backup(
+ relid regclass,
+ attname text,
+ comment text)
+ RENAME TO truth_func_backup;
+CREATE OR REPLACE FUNCTION dbms_stats.backup(
+ relid regclass DEFAULT NULL,
+ attname text DEFAULT NULL,
+ comment text DEFAULT NULL)
+RETURNS int8 AS
+$$
+BEGIN
+ IF $3 = '' THEN
+ RAISE NOTICE 'third argument is not NULL but string ""';
+ END IF;
+ RAISE NOTICE 'arguments are %, %, %', $1, $2, $3;
+ RETURN 1;
+END;
+$$
+LANGUAGE plpgsql;
+
+/*
+ * No.8-3 dbms_stats.backup_schema_stats
+ */
+SELECT setval('dbms_stats.backup_history_id_seq',9, false);
+-- No.8-3-1
+SELECT dbms_stats.backup_schema_stats('s0', 'comment');
+SELECT id, unit, comment FROM dbms_stats.backup_history
+ ORDER BY id DESC
+ LIMIT 1;
+-- No.8-3-2
+SELECT dbms_stats.backup_schema_stats('s00', 'comment');
+SELECT id, unit, comment FROM dbms_stats.backup_history
+ ORDER BY id DESC
+ LIMIT 1;
+-- No.8-3-3
+SELECT dbms_stats.backup_schema_stats('pg_catalog', 'comment');
+SELECT id, unit, comment FROM dbms_stats.backup_history
+ ORDER BY id DESC
+ LIMIT 1;
+
+/*
+ * Delete stab function dbms_stats.backup
+ */
+DROP FUNCTION dbms_stats.backup(
+ backup_id int8,
+ regclass,
+ attnum int2);
+ALTER FUNCTION dbms_stats.truth_func_backup(
+ backup_id int8,
+ regclass,
+ attnum int2)
+ RENAME TO backup;
+DROP FUNCTION dbms_stats.backup(
+ regclass,
+ attname text,
+ comment text);
+ALTER FUNCTION dbms_stats.truth_func_backup(
+ regclass,
+ attname text,
+ comment text)
+ RENAME TO backup;
+VACUUM ANALYZE;
+
+/*
+ * create backup statistics state A
+ */
+DELETE FROM dbms_stats.backup_history;
+
+INSERT INTO dbms_stats.backup_history(id, time, unit)
+ VALUES (1, '2012-02-29 23:59:56.999999', 'd');
+
+SELECT setval('dbms_stats.backup_history_id_seq',1);
+SELECT dbms_stats.backup();
+UPDATE dbms_stats.backup_history
+ SET time = '2012-02-29 23:59:57'
+ WHERE id = 2;
+SELECT dbms_stats.backup('s0.st0');
+UPDATE dbms_stats.backup_history
+ SET time = '2012-02-29 23:59:57.000001'
+ WHERE id = 3;
+SELECT dbms_stats.backup();
+UPDATE dbms_stats.backup_history
+ SET time = '2012-02-29 23:59:58'
+ WHERE id = 4;
+DELETE FROM dbms_stats.relation_stats_backup
+ WHERE id = 4;
+SELECT dbms_stats.backup('s0.st0', 'id');
+UPDATE dbms_stats.backup_history
+ SET time = '2012-03-01 00:00:00'
+ WHERE id = 5;
+SELECT dbms_stats.backup('s0.st0');
+UPDATE dbms_stats.backup_history
+ SET time = '2012-03-01 00:00:02'
+ WHERE id = 6;
+SELECT dbms_stats.backup('public.st0');
+UPDATE dbms_stats.backup_history
+ SET time = '2012-03-01 00:00:04'
+ WHERE id = 7;
+INSERT INTO dbms_stats.backup_history(time, unit)
+ VALUES ('2012-03-01 00:00:06', 's');
+SELECT dbms_stats.backup(8, c.oid, NULL)
+ FROM pg_catalog.pg_class c,
+ pg_catalog.pg_namespace n
+ WHERE n.nspname = 's0'
+ AND c.relnamespace = n.oid
+ AND c.relkind IN ('r', 'i');
+
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+SELECT * FROM relations_backup_v;
+SELECT * FROM columns_backup_v;
+
+VACUUM ANALYZE;
+
+/*
+ * No.9-1 dbms_stats.restore
+ */
+-- No.9-1-1
+DELETE FROM dbms_stats._relation_stats_locked;
+BEGIN;
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+SELECT dbms_stats.restore(2, 's0.st0', NULL);
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+COMMIT;
+SELECT relid::regclass FROM dbms_stats.relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+
+-- No.9-1-2
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(2, 'st0', NULL);
+SELECT relid::regclass FROM dbms_stats.relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+
+-- No.9-1-3
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(2, 's00.s0', NULL);
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+
+-- No.9-1-4
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(NULL, 's0.st0', NULL);
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+
+-- No.9-1-5
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(2, 's0.st0', 'id');
+SELECT relid::regclass FROM dbms_stats.relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+
+-- No.9-1-6
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(2, NULL, 'id');
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+
+-- No.9-1-7
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(2, 's0.st0', NULL);
+SELECT relid::regclass FROM dbms_stats.relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+
+-- No.9-1-8
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(2, NULL, NULL);
+SELECT relid::regclass FROM dbms_stats.relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+
+-- No.9-1-9
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(0, 's0.st0', NULL);
+SELECT relid::regclass FROM dbms_stats.relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+
+-- No.9-1-10
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(2, 0, 'id');
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+
+-- No.9-1-11
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(1, 's0.st0', NULL);
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+
+-- No.9-1-12
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(2, 's0.st0', 'dummy');
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+
+-- No.9-1-13
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(1, 's0.st0', 'id');
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+
+-- No.9-1-15
+DELETE FROM dbms_stats._relation_stats_locked;
+ALTER TABLE s1.st0 DROP COLUMN id;
+SELECT dbms_stats.restore(2, 's1.st0', 'id');
+SELECT relid::regclass FROM dbms_stats.relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+
+-- No.9-1-14
+DELETE FROM dbms_stats._relation_stats_locked;
+\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';"`
+DROP TABLE s1.st0;
+SET client_min_messages TO FATAL;
+SELECT dbms_stats.restore(2, :s1_st0_oid, NULL);
+RESET client_min_messages;
+\! tail ${PGDATA}/pg_log/postgresql.log > results/ut_no3_1_14.out
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+CREATE TABLE s1.st0(id integer, num integer);
+INSERT INTO s1.st0 VALUES (1, 15), (2, 25), (3, 35), (4, 45);
+VACUUM ANALYZE;
+-- No.9-1-16
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(2, 's0.st0', NULL);
+SELECT relid::regclass FROM dbms_stats.relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+
+-- No.9-1-17
+DELETE FROM dbms_stats._relation_stats_locked;
+INSERT INTO dbms_stats.relation_stats_backup(
+ id, relid, relname, relpages, reltuples,
+ curpages)
+ VALUES (2,
+ 'pg_toast.pg_toast_2618'::regclass,
+ 'pg_toast.pg_toast_2618', 1, 1,
+ 1);
+SELECT * FROM relations_backup_v
+ WHERE id = 2
+ AND relname = 'pg_toast.pg_toast_2618';
+SELECT dbms_stats.restore(2, 'pg_toast.pg_toast_2618', NULL);
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+DELETE FROM dbms_stats.relation_stats_backup
+ WHERE id = 2
+ AND relname = 'pg_toast.pg_toast_2618';
+
+-- No.9-1-18
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(2, 's0.st0_idx', NULL);
+SELECT relid::regclass FROM dbms_stats.relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+
+-- No.9-1-19
+DELETE FROM dbms_stats._relation_stats_locked;
+INSERT INTO dbms_stats.relation_stats_backup(
+ id, relid, relname, relpages, reltuples,
+ curpages)
+ VALUES (2, 's0.ss0'::regclass, 's0.ss0', 1, 1,
+ 1);
+SELECT * FROM relations_backup_v
+ WHERE id = 2
+ AND relname = 's0.ss0';
+SELECT dbms_stats.restore(2, 's0.ss0', NULL);
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+DELETE FROM dbms_stats.relation_stats_backup
+ WHERE id = 2
+ AND relname = 's0.ss0';
+
+-- No.9-1-20
+DELETE FROM dbms_stats._relation_stats_locked;
+INSERT INTO dbms_stats.relation_stats_backup(
+ id, relid, relname, relpages, reltuples,
+ curpages)
+ VALUES (2, 's0.sc0'::regclass, 's0.sc0', 1, 1,
+ 1);
+SELECT * FROM relations_backup_v
+ WHERE id = 2
+ AND relname = 's0.sc0';
+SELECT dbms_stats.restore(2, 's0.sc0', NULL);
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+DELETE FROM dbms_stats.relation_stats_backup
+ WHERE id = 2
+ AND relname = 's0.sc0';
+
+-- No.9-1-21
+DELETE FROM dbms_stats._relation_stats_locked;
+INSERT INTO dbms_stats.relation_stats_backup(
+ id, relid, relname, relpages, reltuples,
+ curpages)
+ VALUES (2, 's0.sft0'::regclass, 's0.sft0', 1, 1,
+ 1);
+SELECT * FROM relations_backup_v
+ WHERE id = 2
+ AND relname = 's0.sft0';
+SELECT dbms_stats.restore(2, 's0.sft0', NULL);
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+DELETE FROM dbms_stats.relation_stats_backup
+ WHERE id = 2
+ AND relname = 's0.sft0';
+
+-- No.9-1-22
+DELETE FROM dbms_stats._relation_stats_locked;
+INSERT INTO dbms_stats.relation_stats_backup(
+ id, relid, relname, relpages, reltuples,
+ curpages)
+ VALUES (2, 'pg_catalog.pg_class'::regclass, 'pg_catalog.pg_class', 1, 1,
+ 1);
+SELECT * FROM relations_backup_v
+ WHERE id = 2
+ AND relname = 'pg_catalog.pg_class';
+SELECT dbms_stats.restore(2, 'pg_catalog.pg_class', NULL);
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+DELETE FROM dbms_stats.relation_stats_backup
+ WHERE id = 2
+ AND relname = 'pg_catalog.pg_class';
+
+-- No.9-1-23
+DELETE FROM dbms_stats._relation_stats_locked;
+INSERT INTO dbms_stats._relation_stats_locked(relid, relname)
+ VALUES ('s0.st0'::regclass, 's0.st0');
+INSERT INTO dbms_stats._column_stats_locked(starelid, staattnum, stainherit)
+ SELECT starelid::regclass, staattnum, stainherit
+ FROM dbms_stats.column_stats_effective
+ WHERE starelid = 's0.st0'::regclass;
+SELECT id, unit, comment FROM dbms_stats.backup_history
+ WHERE id = 2;
+SELECT * FROM columns_locked_v;
+SELECT * FROM relations_locked_v;
+SELECT dbms_stats.restore(2, 's0.st0', NULL);
+SELECT * FROM relations_locked_v;
+SELECT * FROM columns_locked_v;
+
+-- No.9-1-24
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT id, unit, comment FROM dbms_stats.backup_history
+ WHERE id = 2;
+SELECT dbms_stats.restore(2, 's0.st0', NULL);
+SELECT * FROM relations_locked_v;
+SELECT * FROM columns_locked_v;
+
+/*
+ * Stab function dbms_stats.restore
+ */
+CREATE OR REPLACE FUNCTION dbms_stats.restore(
+ backup_id int8,
+ relid regclass DEFAULT NULL,
+ attname text DEFAULT NULL)
+RETURNS SETOF regclass AS
+$$
+BEGIN
+ RAISE NOTICE 'arguments are "%, %, %"', $1, $2, $3;
+ RETURN QUERY
+ SELECT c.oid::regclass
+ FROM pg_class c, dbms_stats.relation_stats_backup b
+ WHERE (c.oid = $2 OR $2 IS NULL)
+ AND c.oid = b.relid
+ AND c.relkind IN ('r', 'i')
+ AND (b.id <= $1 OR $1 IS NOT NULL)
+ GROUP BY c.oid
+ ORDER BY c.oid::regclass::text;
+END;
+$$
+LANGUAGE plpgsql;
+
+/*
+ * No.10-1 dbms_stats.restore_database_stats
+ */
+-- No.10-1-1
+SELECT dbms_stats.restore_database_stats('2012-02-29 23:59:57');
+-- No.10-1-2
+SELECT dbms_stats.restore_database_stats('2012-02-29 23:59:57.000002');
+-- No.10-1-3
+SELECT dbms_stats.restore_database_stats('2012-01-01 00:00:00');
+--#No.10-1-4 is skipped after lock tests
+--#No.10-1-5 is skipped after lock tests
+-- No.10-1-6
+SELECT dbms_stats.restore_database_stats('2012-02-29 23:59:57');
+
+/*
+ * No.10-2 dbms_stats.restore_schema_stats
+ */
+-- No.10-2-1
+SELECT dbms_stats.restore_schema_stats('s0', '2012-02-29 23:59:57');
+-- No.10-2-2
+SELECT dbms_stats.restore_schema_stats('s0', '2012-02-29 23:59:57.000002');
+-- No.10-2-3
+SELECT dbms_stats.restore_schema_stats('s0', '2012-01-01 00:00:00');
+--#No.10-2-4 is skipped after lock tests
+--#No.10-2-5 is skipped after lock tests
+-- No.10-2-6
+SELECT dbms_stats.restore_schema_stats('s0', '2012-02-29 23:59:57');
+-- No.10-2-7
+SELECT dbms_stats.restore_schema_stats('s0', '2012-02-29 23:59:57');
+--#No.10-2-8 is skipped after lock tests
+-- No.10-2-9
+SELECT dbms_stats.restore_schema_stats('s00', '2012-02-29 23:59:57');
+-- No.10-2-10
+SELECT dbms_stats.restore_schema_stats('pg_catalog', '2012-02-29 23:59:57');
+
+/*
+ * No.10-7 dbms_stats.restore_stats
+ */
+-- No.10-7-1
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore_stats(NULL);
+
+-- No.10-7-2
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore_stats(0);
+
+-- No.10-7-3
+DELETE FROM dbms_stats._relation_stats_locked;
+BEGIN;
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+SELECT dbms_stats.restore_stats(2);
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+COMMIT;
+SELECT relid::regclass FROM dbms_stats.relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+
+-- No.10-7-4
+DELETE FROM dbms_stats._relation_stats_locked;
+INSERT INTO dbms_stats._relation_stats_locked(relid, relname)
+ SELECT relid::regclass, relname
+ FROM dbms_stats.relation_stats_effective;
+INSERT INTO dbms_stats._column_stats_locked(starelid, staattnum, stainherit)
+ SELECT starelid::regclass, staattnum, stainherit
+ FROM dbms_stats.column_stats_effective;
+SELECT id, unit, comment FROM dbms_stats.backup_history
+ WHERE id = 8;
+SELECT * FROM columns_locked_v;
+SELECT * FROM relations_locked_v;
+SELECT dbms_stats.restore_stats(8);
+SELECT * FROM relations_locked_v;
+SELECT * FROM columns_locked_v;
+
+-- No.10-7-5
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT id, unit, comment FROM dbms_stats.backup_history
+ WHERE id = 8;
+SELECT dbms_stats.restore_stats(8);
+SELECT * FROM relations_locked_v;
+SELECT * FROM columns_locked_v;
+
+/*
+ * No.11-1 dbms_stats.lock(relid, attname)
+ */
+-- No.11-1-1
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock(NULL, NULL);
+-- No.11-1-2
+ALTER FUNCTION dbms_stats.lock(relid regclass)
+ RENAME TO truth_lock;
+CREATE FUNCTION dbms_stats.lock(relid regclass)
+RETURNS regclass AS
+$$
+BEGIN
+ RAISE NOTICE 'arguments are %', $1;
+ RETURN $1;
+END
+$$
+LANGUAGE plpgsql;
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.st0', NULL);
+DROP FUNCTION dbms_stats.lock(relid regclass);
+ALTER FUNCTION dbms_stats.truth_lock(relid regclass)
+ RENAME TO lock;
+-- No.11-1-3
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock(NULL, 'id');
+-- No.11-1-4
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.st0', 'id');
+SELECT * FROM relations_locked_v;
+SELECT * FROM columns_locked_v c;
+-- No.11-1-5
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock(0, 'id');
+-- No.11-1-6
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.st0', 'id');
+SELECT * FROM relations_locked_v;
+SELECT * FROM columns_locked_v c;
+-- No.11-1-7
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('pg_toast.pg_toast_2618', 'id');
+-- No.11-1-8
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.st0_idx', 'id');
+-- No.11-1-9
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('st1_exp', 'lower');
+SELECT * FROM relations_locked_v;
+SELECT * FROM columns_locked_v c;
+DELETE FROM dbms_stats._relation_stats_locked;
+
+-- No.11-1-10
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.ss0', 'id');
+-- No.11-1-11
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.sc0', 'id');
+-- No.11-1-12
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.sft0', 'id');
+-- No.11-1-13
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('pg_catalog.pg_class', 'id');
+-- No.11-1-14
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.st0', 'dummy');
+-- No.11-1-15
+DELETE FROM dbms_stats._relation_stats_locked;
+DELETE FROM pg_statistic
+ WHERE starelid = 's0.st0'::regclass;
+SELECT dbms_stats.lock('s0.st0', 'id');
+VACUUM ANALYZE;
+-- No.11-1-16
+DELETE FROM dbms_stats._relation_stats_locked;
+INSERT INTO dbms_stats._relation_stats_locked(
+ relid, relname, relpages, reltuples,
+ curpages)
+ VALUES('s0.st0'::regclass, 's0.st0', 1, 1640,
+ 1);
+SELECT dbms_stats.lock_column_stats('s0.st0','id');
+UPDATE dbms_stats._column_stats_locked
+ SET (stanullfrac, stawidth, stadistinct,
+ stakind1, stakind2, stakind3, stakind4,
+ staop1, staop2, staop3, staop4,
+ stanumbers1, stanumbers2, stanumbers3, stanumbers4,
+ stavalues1, stavalues2, stavalues3, stavalues4
+ ) = (
+ NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL)
+ WHERE starelid = 's0.st0'::regclass;
+SELECT dbms_stats.lock('s0.st0', 'id');
+SELECT * FROM relations_locked_v;
+SELECT * FROM columns_locked_v c;
+-- No.11-1-17
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.st0', 'id');
+SELECT * FROM relations_locked_v
+ WHERE relid = 's0.st0'::regclass;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+
+/*
+ * No.11-2 dbms_stats.lock(relid)
+ */
+-- No.11-2-1
+DELETE FROM dbms_stats._relation_stats_locked;
+BEGIN;
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+SELECT dbms_stats.lock('s0.st0');
+SELECT * FROM relations_locked_v;
+SELECT * FROM columns_locked_v c;
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+COMMIT;
+
+-- No.11-2-2
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock(NULL);
+-- No.11-2-3
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('0');
+-- No.11-2-4
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.st0');
+SELECT * FROM relations_locked_v;
+SELECT * FROM columns_locked_v c;
+-- No.11-2-5
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('pg_toast.pg_toast_2618');
+-- No.11-2-6
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.st0_idx');
+SELECT * FROM relations_locked_v;
+SELECT * FROM columns_locked_v c;
+-- No.11-2-7
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.ss0');
+-- No.11-2-8
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.sc0');
+-- No.11-2-9
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.sft0');
+-- No.11-2-10
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('pg_catalog.pg_class');
+-- No.11-2-11
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_table_stats('s0.st0');
+UPDATE dbms_stats._relation_stats_locked
+ SET (relpages, reltuples,
+ curpages)
+ = (NULL, NULL, NULL
+ )
+ WHERE relid = 's0.st0'::regclass;
+SELECT dbms_stats.lock('s0.st0');
+SELECT * FROM relations_locked_v;
+SELECT * FROM columns_locked_v c;
+-- No.11-2-12
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.st0');
+SELECT * FROM relations_locked_v;
+SELECT * FROM columns_locked_v c;
+
+/*
+ * Stab function dbms_stats.lock
+ */
+ALTER FUNCTION dbms_stats.lock(relid regclass)
+ RENAME TO truth_lock;
+CREATE FUNCTION dbms_stats.lock(relid regclass)
+RETURNS regclass AS
+$$
+BEGIN
+ RAISE NOTICE 'arguments are %', $1;
+ RETURN $1;
+END
+$$
+LANGUAGE plpgsql;
+
+ALTER FUNCTION dbms_stats.lock(relid regclass, attname text)
+ RENAME TO truth_lock;
+CREATE FUNCTION dbms_stats.lock(
+ relid regclass,
+ attname text)
+RETURNS regclass AS
+$$
+BEGIN
+ RAISE NOTICE 'arguments are %, %', $1, $2;
+ RETURN $1;
+END
+$$
+LANGUAGE plpgsql;
+
+/*
+ * No.12-1 dbms_stats.lock_database_stats
+ */
+-- No.12-1-1
+SELECT dbms_stats.lock_database_stats();
+
+/*
+ * No.12-2 dbms_stats.lock_schema_stats
+ */
+-- No.12-2-1
+SELECT dbms_stats.lock_schema_stats('s0');
+-- No.12-2-2
+SELECT dbms_stats.lock_schema_stats('s00');
+-- No.12-2-3
+SELECT dbms_stats.lock_schema_stats('pg_catalog');
+
+/*
+ * No.12-3 dbms_stats.lock_table_stats(regclass)
+ */
+-- No.12-3-1
+SELECT dbms_stats.lock_table_stats('s0.st0');
+-- No.12-3-2
+SELECT dbms_stats.lock_table_stats('st0');
+-- No.12-3-3
+SELECT dbms_stats.lock_table_stats('s00.s0');
+
+/*
+ * No.12-4 dbms_stats.lock_table_stats(schemaname, tablename)
+ */
+-- No.12-4-1
+SELECT dbms_stats.lock_table_stats('s0', 'st0');
+
+/*
+ * No.12-5 dbms_stats.lock_column_stats(regclass, attname)
+ */
+-- No.12-5-1
+SELECT dbms_stats.lock_column_stats('s0.st0', 'id');
+-- No.12-5-2
+SELECT dbms_stats.lock_column_stats('st0', 'id');
+-- No.12-5-3
+SELECT dbms_stats.lock_column_stats('s00.s0', 'id');
+
+/*
+ * No.12-6 dbms_stats.lock_column_stats(schemaname, tablename, int2)
+ */
+-- No.12-6-1
+SELECT dbms_stats.lock_column_stats('s0', 'st0', 'id');
+
+/*
+ * Delete Stab function lock
+ */
+DROP FUNCTION dbms_stats.lock(relid regclass);
+ALTER FUNCTION dbms_stats.truth_lock(relid regclass)
+ RENAME TO lock;
+DROP FUNCTION dbms_stats.lock(relid regclass, attname text);
+ALTER FUNCTION dbms_stats.truth_lock(relid regclass, attname text)
+ RENAME TO lock;
+
+/*
+ * No.13-1 dbms_stats.unlock
+ */
+-- No.13-1-1
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+SELECT dbms_stats.unlock();
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+
+-- No.13-1-2
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT dbms_stats.unlock();
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+
+-- No.13-1-3
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+DELETE FROM dbms_stats._column_stats_locked;
+SELECT dbms_stats.unlock();
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+
+-- No.13-1-4
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.unlock();
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+
+-- No.13-1-5
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT dbms_stats.unlock('s0.st0');
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+
+-- No.13-1-6
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT dbms_stats.unlock('st0');
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+
+-- No.13-1-7
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+SELECT dbms_stats.unlock('s00.s0');
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+
+-- No.13-1-8
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT dbms_stats.unlock('s0.st0', 'id');
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+
+-- No.13-1-9
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT dbms_stats.unlock('s0.st0', 'dummy');
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+
+-- No.13-1-10
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+DELETE FROM dbms_stats._column_stats_locked;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT dbms_stats.unlock('s0.st0', 'id');
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, staattnum FROM dbms_stats._column_stats_locked
+ GROUP BY starelid, staattnum
+ ORDER BY starelid;
+
+-- No.13-1-11
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, staattnum FROM dbms_stats._column_stats_locked
+ GROUP BY starelid, staattnum
+ ORDER BY starelid;
+SELECT dbms_stats.unlock(NULL, 'id');
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, staattnum FROM dbms_stats._column_stats_locked
+ GROUP BY starelid, staattnum
+ ORDER BY starelid;
+
+-- No.13-1-12
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, staattnum FROM dbms_stats._column_stats_locked
+ GROUP BY starelid, staattnum
+ ORDER BY starelid;
+SELECT dbms_stats.unlock('s0.st0', NULL);
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, staattnum FROM dbms_stats._column_stats_locked
+ GROUP BY starelid, staattnum
+ ORDER BY starelid;
+
+-- No.13-1-13
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+BEGIN;
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+SELECT dbms_stats.unlock();
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+COMMIT;
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+
+/*
+ * No.14-1 dbms_stats.unlock_database_stats
+ */
+-- No.14-1-1
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+SELECT dbms_stats.unlock_database_stats();
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+
+-- No.14-1-2
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+DELETE FROM dbms_stats._column_stats_locked;
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.unlock_database_stats();
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+
+-- No.14-1-3
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.unlock_database_stats();
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+
+-- No.14-1-4
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+BEGIN;
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+SELECT dbms_stats.unlock_database_stats();
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+COMMIT;
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+
+/*
+ * No.14-2 dbms_stats.unlock_schema_stats
+ */
+-- No.14-2-1
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT dbms_stats.unlock_schema_stats('s0');
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+
+-- No.14-2-2
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+DELETE FROM dbms_stats._column_stats_locked;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT dbms_stats.unlock_schema_stats('s0');
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+
+-- No.14-2-3
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT dbms_stats.unlock_schema_stats('s0');
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+
+-- No.14-2-4
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT dbms_stats.unlock_schema_stats('s0');
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+
+-- No.14-2-5
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT dbms_stats.unlock_schema_stats('s00');
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+
+-- No.14-2-6
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT dbms_stats.unlock_schema_stats('pg_catalog');
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+
+-- No.14-2-7
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT dbms_stats.unlock_schema_stats(NULL);
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+
+-- No.14-2-8
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+BEGIN;
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+SELECT dbms_stats.unlock_schema_stats('s0');
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+COMMIT;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+
+/*
+ * No.14-3 dbms_stats.unlock_table_stats(regclass)
+ */
+-- No.14-3-1
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT dbms_stats.unlock_table_stats('s0.st0');
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+
+-- No.14-3-2
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+DELETE FROM dbms_stats._column_stats_locked;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT dbms_stats.unlock_table_stats('s0.st0');
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+
+-- No.14-3-3
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT dbms_stats.unlock_table_stats('s0.st0');
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+
+-- No.14-3-4
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT dbms_stats.unlock_table_stats('s0.st0');
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+
+-- No.14-3-5
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT dbms_stats.unlock_table_stats('st0');
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+
+-- No.14-3-6
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT dbms_stats.unlock_table_stats('s00.s0');
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+
+-- No.14-3-7
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT dbms_stats.unlock_table_stats(NULL);
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+
+-- No.14-3-8
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+BEGIN;
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+SELECT dbms_stats.unlock_table_stats('s0.st0');
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+COMMIT;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+
+/*
+ * No.14-4 dbms_stats.unlock_table_stats(schemaname, tablename)
+ */
+-- No.14-4-1
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT dbms_stats.unlock_table_stats('s0','st0');
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+
+-- No.14-4-2
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+DELETE FROM dbms_stats._column_stats_locked;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT dbms_stats.unlock_table_stats('s0', 'st0');
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+
+-- No.14-4-3
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT dbms_stats.unlock_table_stats('s0', 'st0');
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+
+-- No.14-4-4
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT dbms_stats.unlock_table_stats('s0', 'st0');
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+
+-- No.14-4-5
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT dbms_stats.unlock_table_stats('s00', 's0');
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+
+-- No.14-4-6
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT dbms_stats.unlock_table_stats(NULL, 'st0');
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+
+-- No.14-4-7
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT dbms_stats.unlock_table_stats('s0', NULL);
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+
+-- No.14-4-8
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+BEGIN;
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+SELECT dbms_stats.unlock_table_stats('s0', 'st0');
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+COMMIT;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+
+/*
+ * No.14-5 dbms_stats.unlock_column_stats(regclass, attname)
+ */
+-- No.14-5-1
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT dbms_stats.unlock_column_stats('s0.st0', 'id');
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+
+-- No.14-5-2
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+DELETE FROM dbms_stats._column_stats_locked;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT dbms_stats.unlock_column_stats('s0.st0', 'id');
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+
+-- No.14-5-3
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT dbms_stats.unlock_column_stats('s0.st0', 'id');
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+
+-- No.14-5-4
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT dbms_stats.unlock_column_stats('st0', 'id');
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+
+-- No.14-5-5
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT dbms_stats.unlock_column_stats('s0.st0', 'dummy');
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+
+-- No.14-5-6
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT dbms_stats.unlock_column_stats('s00.s0', 'id');
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+
+-- No.14-5-7
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT dbms_stats.unlock_column_stats(NULL, 'id');
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+
+-- No.14-5-8
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT dbms_stats.unlock_column_stats('s0.st0', NULL);
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+
+-- No.14-5-9
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+BEGIN;
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+SELECT dbms_stats.unlock_column_stats('s0.st0', 'id');
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+COMMIT;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+
+/*
+ * No.14-6 dbms_stats.unlock_column_stats(schemaname, tablename, attname)
+ */
+-- No.14-6-1
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT dbms_stats.unlock_column_stats('s0', 'st0', 'id');
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+
+-- No.14-6-2
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+DELETE FROM dbms_stats._column_stats_locked;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT dbms_stats.unlock_column_stats('s0', 'st0', 'id');
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+
+-- No.14-6-3
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT dbms_stats.unlock_column_stats('s0', 'st0', 'id');
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+
+-- No.14-6-4
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT dbms_stats.unlock_column_stats('s0', 'st0', 'dummy');
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+
+-- No.14-6-5
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT dbms_stats.unlock_column_stats(NULL, 'st0', 'id');
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+
+-- No.14-6-6
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT dbms_stats.unlock_column_stats('s0', NULL, 'id');
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+
+-- No.14-6-7
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT dbms_stats.unlock_column_stats('s0', 'st0', NULL);
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+
+-- No.14-6-8
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+BEGIN;
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+SELECT dbms_stats.unlock_column_stats('s0', 'st0', 'id');
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+COMMIT;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
diff --git a/sql/ut-9.2.sql b/sql/ut-9.2.sql
new file mode 100644
index 0000000..8b09948
--- /dev/null
+++ b/sql/ut-9.2.sql
@@ -0,0 +1,2724 @@
+\pset null '(null)'
+/*
+ * No.2-1 table definitions.
+ */
+-- No.2-1-1
+\d dbms_stats.backup_history
+-- No.2-1-2
+\d dbms_stats.column_stats_backup
+-- No.2-1-3
+\d dbms_stats._column_stats_locked
+-- No.2-1-4
+\d dbms_stats.relation_stats_backup
+-- No.2-1-5
+\d dbms_stats._relation_stats_locked
+
+/*
+ * No.2-2 view definitions.
+ */
+-- No.2-2-1
+\dS+ dbms_stats.column_stats_effective
+-- No.2-2-2
+\dS+ dbms_stats.relation_stats_effective
+-- No.2-2-3
+\dS+ dbms_stats.stats
+-- No.2-2-4
+\dS+ dbms_stats.column_stats_locked
+-- No.2-2-5
+\dS+ dbms_stats.relation_stats_locked
+
+/*
+ * No.5-1 dbms_stats.merge
+ */
+UPDATE pg_statistic SET
+ stanullfrac = staattnum,
+ stawidth = staattnum,
+ stadistinct = staattnum,
+ stakind1 = 4,
+ stakind2 = 1,
+ stakind3 = 2,
+ stakind4 = 3,
+ stakind5 = 5,
+ staop1 = 14,
+ staop2 = 11,
+ staop3 = 12,
+ staop4 = 13,
+ staop5 = 15,
+ stanumbers1 = ARRAY[staattnum,4],
+ stanumbers2 = ARRAY[staattnum,1],
+ stanumbers3 = ARRAY[staattnum,2],
+ stanumbers4 = ARRAY[staattnum,3],
+ stanumbers5 = ARRAY[staattnum,5],
+ stavalues2 = array_cat(stavalues1,stavalues1),
+ stavalues3 = array_cat(array_cat(stavalues1,stavalues1),stavalues1),
+ stavalues4 = array_cat(array_cat(array_cat(stavalues1,stavalues1),stavalues1),stavalues1)
+ ,stavalues5 = array_cat(array_cat(array_cat(array_cat(stavalues1,stavalues1),stavalues1),stavalues1),stavalues1)
+ WHERE starelid = 'st0'::regclass;
+SELECT dbms_stats.lock_table_stats('st0');
+UPDATE dbms_stats._column_stats_locked SET
+ stainherit = 't',
+ stanullfrac = -staattnum,
+ stawidth = -staattnum,
+ stadistinct = -staattnum,
+ stakind1 = 2,
+ stakind2 = 3,
+ stakind3 = 4,
+ stakind4 = 1,
+ stakind5 = 5,
+ staop1 = 22,
+ staop2 = 23,
+ staop3 = 24,
+ staop4 = 21,
+ staop5 = 25,
+ stanumbers1 = ARRAY[-staattnum,22],
+ stanumbers2 = ARRAY[-staattnum,23],
+ stanumbers3 = ARRAY[-staattnum,24],
+ stanumbers4 = ARRAY[-staattnum,21],
+ stanumbers5 = ARRAY[-staattnum,25],
+ stavalues1 = stavalues3,
+ stavalues2 = stavalues2,
+ stavalues3 = stavalues1,
+ stavalues4 = stavalues4
+ ,stavalues5 = stavalues5
+;
+
+/*
+ * Driver function dbms_stats.merge1
+ */
+CREATE FUNCTION dbms_stats.merge1(
+ lhs dbms_stats._column_stats_locked,
+ rhs pg_catalog.pg_statistic
+) RETURNS integer AS
+'$libdir/pg_dbms_stats', 'dbms_stats_merge'
+LANGUAGE C STABLE;
+
+SELECT * FROM columns_locked_v
+ WHERE starelid = 'st0'::regclass;
+SELECT * FROM plain_columns_statistic_v
+ WHERE starelid = 'st0'::regclass;
+
+SET client_min_messages TO LOG;
+
+-- No.5-1-1
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).stakind5,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).staop5,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stanumbers5,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ ,(m.merge).stavalues5
+ FROM (SELECT dbms_stats.merge(NULL, s)
+ FROM pg_statistic s
+ WHERE starelid = 'st0'::regclass
+ AND staattnum = '1'::int2) m;
+
+-- No.5-1-2
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).stakind5,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).staop5,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stanumbers5,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ ,(m.merge).stavalues5
+ FROM (SELECT dbms_stats.merge(v, NULL)
+ FROM dbms_stats._column_stats_locked v
+ WHERE starelid = 'st0'::regclass
+ AND staattnum = '2'::int2) m;
+
+-- No.5-1-3
+SELECT dbms_stats.merge(NULL, NULL);
+
+-- No.5-1-4
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).stakind5,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).staop5,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stanumbers5,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ ,(m.merge).stavalues5
+ FROM (SELECT dbms_stats.merge(v, s)
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '2'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2) m;
+
+-- No.5-1-5
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).stakind5,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).staop5,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stanumbers5,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ ,(m.merge).stavalues5
+ FROM (SELECT dbms_stats.merge(v, s)
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '2'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2) m;
+
+-- No.5-1-6
+SELECT dbms_stats.merge1(v, s)
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '2'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2;
+
+-- No.5-1-7
+SELECT dbms_stats.merge(NULL, (
+ s.starelid::regclass, s.staattnum, s.stainherit,
+ s.stanullfrac, s.stawidth, s.stadistinct,
+ s.stakind1, s.stakind2, s.stakind3, s.stakind4,
+ s.stakind5,
+ s.staop1, s.staop2, s.staop3,
+ s.staop4,
+ NULL, s.stanumbers1, s.stanumbers2, s.stanumbers3, s.stanumbers4,
+ s.stanumbers5,
+ s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
+ ,s.stavalues5
+ ))
+ FROM pg_statistic s
+ WHERE s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2;
+
+-- No.5-1-8
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).stakind5,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).staop5,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stanumbers5,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ ,(m.merge).stavalues5
+ FROM (SELECT dbms_stats.merge(NULL, (
+ s.starelid::regclass, s.staattnum, s.stainherit,
+ s.stanullfrac, s.stawidth, s.stadistinct,
+ s.stakind1, s.stakind2, s.stakind3, s.stakind4,
+ s.stakind5,
+ s.staop1, s.staop2, s.staop3, s.staop4,
+ s.staop5,
+ NULL, s.stanumbers2, s.stanumbers3, s.stanumbers4,
+ s.stanumbers5,
+ s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
+ ,s.stavalues5
+ ))
+ FROM pg_statistic s
+ WHERE s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2) m;
+
+-- No.5-1-9
+SELECT dbms_stats.merge((
+ v.starelid::regclass, v.staattnum, v.stainherit,
+ v.stanullfrac, v.stawidth, v.stadistinct,
+ v.stakind1, v.stakind2, v.stakind3, v.stakind4,
+ v.stakind5,
+ v.staop1, v.staop2, v.staop3,
+ v.staop4,
+ NULL, v.stanumbers1, v.stanumbers2, v.stanumbers3, v.stanumbers4,
+ v.stanumbers5,
+ v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
+ ,v.stavalues5
+ ), NULL)
+ FROM dbms_stats._column_stats_locked v
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '2'::int2;
+
+-- No.5-1-10
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).stakind5,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).staop5,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stanumbers5,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ ,(m.merge).stavalues5
+ FROM (SELECT dbms_stats.merge((
+ v.starelid::regclass, v.staattnum, v.stainherit,
+ v.stanullfrac, v.stawidth, v.stadistinct,
+ v.stakind1, v.stakind2, v.stakind3, v.stakind4,
+ v.stakind5,
+ v.staop1, v.staop2, v.staop3, v.staop4,
+ v.staop5,
+ NULL, v.stanumbers2, v.stanumbers3, v.stanumbers4,
+ v.stanumbers5,
+ v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
+ ,v.stavalues5
+ ), NULL)
+ FROM dbms_stats._column_stats_locked v
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '2'::int2) m;
+
+-- No.5-1-11
+SELECT dbms_stats.merge((
+ v.starelid::regclass, v.staattnum, v.stainherit,
+ v.stanullfrac, v.stawidth, v.stadistinct,
+ v.stakind1, v.stakind2, v.stakind3, v.stakind4,
+ v.stakind5,
+ v.staop1, v.staop2, v.staop3,
+ v.staop4,
+ NULL, v.stanumbers1, v.stanumbers2, v.stanumbers3, v.stanumbers4,
+ v.stanumbers5,
+ v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
+ ,v.stavalues5
+ ), (
+ s.starelid::regclass, s.staattnum, s.stainherit,
+ s.stanullfrac, s.stawidth, s.stadistinct,
+ s.stakind1, s.stakind2, s.stakind3, s.stakind4,
+ s.stakind5,
+ s.staop1, s.staop2, s.staop3,
+ s.staop4,
+ NULL, s.stanumbers1, s.stanumbers2, s.stanumbers3, s.stanumbers4,
+ s.stanumbers5,
+ s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
+ ,s.stavalues5
+ ))
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '2'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2;
+
+-- No.5-1-12
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).stakind5,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).staop5,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stanumbers5,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ ,(m.merge).stavalues5
+ FROM (SELECT dbms_stats.merge((
+ v.starelid::regclass, v.staattnum, v.stainherit,
+ v.stanullfrac, v.stawidth, v.stadistinct,
+ v.stakind1, v.stakind2, v.stakind3, v.stakind4,
+ v.stakind5,
+ v.staop1, v.staop2, v.staop3, v.staop4,
+ v.staop5,
+ NULL, v.stanumbers2, v.stanumbers3, v.stanumbers4,
+ v.stanumbers5,
+ v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
+ ,v.stavalues5
+ ), (
+ s.starelid::regclass, s.staattnum, s.stainherit,
+ s.stanullfrac, s.stawidth, s.stadistinct,
+ s.stakind1, s.stakind2, s.stakind3, s.stakind4,
+ s.stakind5,
+ s.staop1, s.staop2, s.staop3, s.staop4,
+ s.staop5,
+ NULL, s.stanumbers2, s.stanumbers3, s.stanumbers4,
+ s.stanumbers5,
+ s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
+ ,s.stavalues5
+ ))
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '2'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2) m;
+
+-- No.5-1-13
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).stakind5,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).staop5,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stanumbers5,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ ,(m.merge).stavalues5
+ FROM (SELECT dbms_stats.merge((
+ NULL, NULL, NULL,
+ NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL
+ ,NULL, NULL, NULL, NULL
+ ), s)
+ FROM pg_statistic s
+ WHERE s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2) m;
+
+-- No.5-1-14
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).stakind5,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).staop5,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stanumbers5,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ ,(m.merge).stavalues5
+ FROM (SELECT dbms_stats.merge(v, (
+ NULL, NULL, NULL,
+ NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL))
+ FROM dbms_stats._column_stats_locked v
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '2'::int2) m;
+
+-- No.5-1-15
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).stakind5,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).staop5,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stanumbers5,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ ,(m.merge).stavalues5
+ FROM (SELECT dbms_stats.merge(v, s)
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '2'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2) m;
+
+-- No.5-1-16
+SELECT dbms_stats.merge((
+ v.starelid::regclass, v.staattnum, v.stainherit,
+ v.stanullfrac, v.stawidth, v.stadistinct,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL
+ ,NULL, NULL, NULL, NULL
+ ), (
+ s.starelid::regclass, s.staattnum, s.stainherit,
+ s.stanullfrac, s.stawidth, s.stadistinct,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL))
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '2'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2;
+
+-- No.5-1-17
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).stakind5,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).staop5,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stanumbers5,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ ,(m.merge).stavalues5
+ FROM (SELECT dbms_stats.merge((
+ v.starelid::regclass, v.staattnum, v.stainherit,
+ v.stanullfrac, v.stawidth, v.stadistinct,
+ v.stakind1, v.stakind2, v.stakind3, v.stakind4,
+ v.stakind5,
+ v.staop1, v.staop2, v.staop3,
+ v.staop4,
+ NULL, v.stanumbers1, v.stanumbers2, v.stanumbers3, v.stanumbers4,
+ v.stanumbers5,
+ v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
+ ,v.stavalues5
+ ), (
+ s.starelid::regclass, s.staattnum, s.stainherit,
+ s.stanullfrac, s.stawidth, s.stadistinct,
+ s.stakind1, s.stakind2, s.stakind3, s.stakind4,
+ s.stakind5,
+ s.staop1, s.staop2, s.staop3, s.staop4,
+ s.staop5,
+ s.stanumbers1, s.stanumbers2, s.stanumbers3, s.stanumbers4,
+ s.stanumbers5,
+ s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
+ ,s.stavalues5
+ ))
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '1'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2) m;
+
+-- No.5-1-18
+SELECT dbms_stats.merge((
+ v.starelid::regclass, v.staattnum, v.stainherit,
+ v.stanullfrac, v.stawidth, v.stadistinct,
+ v.stakind1, v.stakind2, v.stakind3, v.stakind4,
+ v.stakind5,
+ v.staop1, v.staop2, v.staop3,
+ v.staop4,
+ NULL, v.stanumbers1, v.stanumbers2, v.stanumbers3, v.stanumbers4,
+ v.stanumbers5,
+ v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
+ ,v.stavalues5
+ ), (
+ s.starelid::regclass, s.staattnum, s.stainherit,
+ s.stanullfrac, s.stawidth, s.stadistinct,
+ s.stakind1, s.stakind2, s.stakind3, s.stakind4,
+ s.stakind5,
+ s.staop1, s.staop2, s.staop3,
+ s.staop4,
+ NULL, s.stanumbers1, s.stanumbers2, s.stanumbers3, s.stanumbers4,
+ s.stanumbers5,
+ s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
+ ,s.stavalues5
+ ))
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '1'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2;
+
+-- No.5-1-19
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).stakind5,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).staop5,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stanumbers5,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ ,(m.merge).stavalues5
+ FROM (SELECT dbms_stats.merge((
+ v.starelid::regclass, v.staattnum, v.stainherit,
+ v.stanullfrac, v.stawidth, v.stadistinct,
+ '1', '1', '1', '1',
+ '1',
+ v.staop1, v.staop2, v.staop3, v.staop4,
+ v.staop5,
+ v.stanumbers1, v.stanumbers2, v.stanumbers3, v.stanumbers4,
+ v.stanumbers5,
+ v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
+ ,v.stavalues5
+ ), (
+ s.starelid::regclass, s.staattnum, s.stainherit,
+ s.stanullfrac, s.stawidth, s.stadistinct,
+ '1', '1', '1', '1',
+ '1',
+ s.staop1, s.staop2, s.staop3, s.staop4,
+ s.staop5,
+ s.stanumbers1, s.stanumbers2, s.stanumbers3, s.stanumbers4,
+ s.stanumbers5,
+ s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
+ ,s.stavalues5
+ ))
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '2'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2) m;
+
+-- No.5-1-20
+SELECT (m.merge).starelid::regclass,
+ (m.merge).staattnum,
+ (m.merge).stainherit,
+ (m.merge).stanullfrac,
+ (m.merge).stawidth,
+ (m.merge).stadistinct,
+ (m.merge).stakind1,
+ (m.merge).stakind2,
+ (m.merge).stakind3,
+ (m.merge).stakind4,
+ (m.merge).stakind5,
+ (m.merge).staop1,
+ (m.merge).staop2,
+ (m.merge).staop3,
+ (m.merge).staop4,
+ (m.merge).staop5,
+ (m.merge).stanumbers1,
+ (m.merge).stanumbers2,
+ (m.merge).stanumbers3,
+ (m.merge).stanumbers4,
+ (m.merge).stanumbers5,
+ (m.merge).stavalues1,
+ (m.merge).stavalues2,
+ (m.merge).stavalues3,
+ (m.merge).stavalues4
+ ,(m.merge).stavalues5
+ FROM (SELECT dbms_stats.merge((v.starelid::regclass, v.staattnum, v.stainherit,
+ v.stanullfrac, v.stawidth, v.stadistinct,
+ '2', '2', '2', '2',
+ '2',
+ v.staop1, v.staop2, v.staop3, v.staop4,
+ v.staop5,
+ v.stanumbers1, v.stanumbers2, v.stanumbers3, v.stanumbers4,
+ v.stanumbers5,
+ v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
+ ,v.stavalues5
+ ), (
+ s.starelid::regclass, s.staattnum, s.stainherit,
+ s.stanullfrac, s.stawidth, s.stadistinct,
+ '2', '2', '2', '2',
+ '2',
+ s.staop1, s.staop2, s.staop3, s.staop4,
+ s.staop5,
+ s.stanumbers1, s.stanumbers2, s.stanumbers3, s.stanumbers4,
+ s.stanumbers5,
+ s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
+ ,s.stavalues5
+ ))
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '2'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2) m;
+
+-- No.5-1-21
+SELECT dbms_stats.merge((v.starelid::regclass, '2', v.stainherit,
+ v.stanullfrac, v.stawidth, v.stadistinct,
+ '1', '1', '1', '1',
+ '1',
+ v.staop1, v.staop2, v.staop3, v.staop4,
+ v.staop5,
+ v.stanumbers1, v.stanumbers2, v.stanumbers3, v.stanumbers4,
+ v.stanumbers5,
+ v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
+ ,v.stavalues5
+ ), (
+ s.starelid::regclass, s.staattnum, s.stainherit,
+ s.stanullfrac, s.stawidth, s.stadistinct,
+ '1', '1', '1', '1',
+ '1',
+ s.staop1, s.staop2, s.staop3, s.staop4,
+ s.staop5,
+ s.stanumbers1, s.stanumbers2, s.stanumbers3, s.stanumbers4,
+ s.stanumbers5,
+ s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
+ ,s.stavalues5
+ ))
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '1'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2;
+
+-- No.5-1-22
+SELECT dbms_stats.merge((v.starelid::regclass, '2', v.stainherit,
+ v.stanullfrac, v.stawidth, v.stadistinct,
+ '2', '2', '2', '2',
+ '2',
+ v.staop1, v.staop2, v.staop3, v.staop4,
+ v.staop5,
+ v.stanumbers1, v.stanumbers2, v.stanumbers3, v.stanumbers4,
+ v.stanumbers5,
+ v.stavalues1, v.stavalues2, v.stavalues3, v.stavalues4
+ ,v.stavalues5
+ ), (
+ s.starelid::regclass, s.staattnum, s.stainherit,
+ s.stanullfrac, s.stawidth, s.stadistinct,
+ '2', '2', '2', '2',
+ '2',
+ s.staop1, s.staop2, s.staop3, s.staop4,
+ s.staop5,
+ s.stanumbers1, s.stanumbers2, s.stanumbers3, s.stanumbers4,
+ s.stanumbers5,
+ s.stavalues1, s.stavalues2, s.stavalues3, s.stavalues4
+ ,s.stavalues5
+ ))
+ FROM dbms_stats._column_stats_locked v,
+ pg_statistic s
+ WHERE v.starelid = 'st0'::regclass
+ AND v.staattnum = '1'::int2
+ AND s.starelid = 'st0'::regclass
+ AND s.staattnum = '1'::int2;
+RESET client_min_messages;
+SELECT dbms_stats.unlock_database_stats();
+
+/*
+ * No.6-4 dbms_stats.is_target_relkind
+ */
+-- No.6-4-10
+SELECT dbms_stats.is_target_relkind('f');
+
+/*
+ * No.7-1 dbms_stats.backup
+ */
+DELETE FROM dbms_stats.backup_history;
+INSERT INTO dbms_stats.backup_history(id, time, unit) values(1, '2012-01-01', 'd');
+-- No.7-1-9
+SELECT dbms_stats.backup(1, 's0.sft0'::regclass, NULL);
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+
+-- No.7-1-11
+DELETE FROM dbms_stats.relation_stats_backup;
+SELECT dbms_stats.backup(1, NULL, 1::int2);
+SELECT relid::regclass FROM dbms_stats.relation_stats_backup
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, staattnum FROM dbms_stats.column_stats_backup
+ GROUP BY starelid, staattnum
+ ORDER BY starelid, staattnum;
+
+-- No.7-1-13
+DELETE FROM dbms_stats.relation_stats_backup;
+SELECT dbms_stats.backup(1, NULL::regclass, NULL);
+SELECT relid::regclass FROM dbms_stats.relation_stats_backup
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, staattnum FROM dbms_stats.column_stats_backup
+ GROUP BY starelid, staattnum
+ ORDER BY starelid, staattnum;
+
+-- No.7-1-17
+DELETE FROM dbms_stats.relation_stats_backup;
+\! psql contrib_regression -c "SELECT dbms_stats.backup(NULL, 's0.st0'::regclass, NULL)" > results/ut_no2_1_17.out 2>&1
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+
+/*
+ * No.8-1 dbms_stats.backup
+ */
+SELECT setval('dbms_stats.backup_history_id_seq',1, false);
+/*
+ * Stab function dbms_stats.backup
+ */
+ALTER FUNCTION dbms_stats.backup(
+ backup_id int8,
+ relid regclass,
+ attnum int2)
+ RENAME TO truth_func_backup;
+
+CREATE OR REPLACE FUNCTION dbms_stats.backup(
+ backup_id int8,
+ regclass,
+ attnum int2)
+RETURNS int8 AS
+$$
+BEGIN
+ RAISE NOTICE 'arguments are %, %, %', $1, $2, $3;
+ RETURN 1;
+END;
+$$
+LANGUAGE plpgsql;
+
+-- No.8-1-1
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup('s0.st0'::regclass, 'id', 'dummy comment');
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+
+-- No.8-1-2
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup('s0.st0'::regclass, NULL, 'dummy comment');
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+
+-- No.8-1-3
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup(NULL::regclass, 'id', 'dummy comment');
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+
+-- No.8-1-4
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup(NULL::regclass, NULL, 'dummy comment');
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+
+-- No.8-1-5
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup(0, NULL, 'dummy comment');
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+
+-- No.8-1-6
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup('s0.st0'::regclass, NULL, 'dummy comment');
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+
+-- No.8-1-7
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup(
+ 'pg_toast.pg_toast_2618'::regclass,
+ NULL,
+ 'dummy comment');
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+
+-- No.8-1-8
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup('s0.st0_idx'::regclass, NULL, 'dummy comment');
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+
+-- No.8-1-9
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup('s0.ss0'::regclass, NULL, 'dummy comment');
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+
+-- No.8-1-10
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup('s0.sc0'::regclass, NULL, 'dummy comment');
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+
+-- No.8-1-11
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup('s0.sft0'::regclass, NULL, 'dummy comment');
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+
+-- No.8-1-12
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup('pg_catalog.pg_class'::regclass, NULL, 'dummy comment');
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+
+-- No.8-1-13
+DELETE FROM dbms_stats.backup_history;
+SELECT dbms_stats.backup('s0.st0'::regclass, 'dummy', 'dummy comment');
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+
+-- No.8-1-14
+DELETE FROM dbms_stats.backup_history;
+DELETE FROM pg_statistic
+ WHERE starelid = 's0.st0'::regclass
+ AND staattnum = 1::int2;
+SELECT count(*) FROM dbms_stats.column_stats_effective
+ WHERE starelid = 's0.st0'::regclass
+ AND staattnum = 1::int2;
+SELECT dbms_stats.backup('s0.st0'::regclass, 'id', 'dummy comment');
+SELECT id, unit, comment FROM dbms_stats.backup_history;
+
+/*
+ * Stab function dbms_stats.backup
+ */
+ALTER FUNCTION dbms_stats.backup(
+ relid regclass,
+ attname text,
+ comment text)
+ RENAME TO truth_func_backup;
+CREATE OR REPLACE FUNCTION dbms_stats.backup(
+ relid regclass DEFAULT NULL,
+ attname text DEFAULT NULL,
+ comment text DEFAULT NULL)
+RETURNS int8 AS
+$$
+BEGIN
+ IF $3 = '' THEN
+ RAISE NOTICE 'third argument is not NULL but string ""';
+ END IF;
+ RAISE NOTICE 'arguments are %, %, %', $1, $2, $3;
+ RETURN 1;
+END;
+$$
+LANGUAGE plpgsql;
+
+/*
+ * No.8-3 dbms_stats.backup_schema_stats
+ */
+SELECT setval('dbms_stats.backup_history_id_seq',9, false);
+-- No.8-3-1
+SELECT dbms_stats.backup_schema_stats('s0', 'comment');
+SELECT id, unit, comment FROM dbms_stats.backup_history
+ ORDER BY id DESC
+ LIMIT 1;
+-- No.8-3-2
+SELECT dbms_stats.backup_schema_stats('s00', 'comment');
+SELECT id, unit, comment FROM dbms_stats.backup_history
+ ORDER BY id DESC
+ LIMIT 1;
+-- No.8-3-3
+SELECT dbms_stats.backup_schema_stats('pg_catalog', 'comment');
+SELECT id, unit, comment FROM dbms_stats.backup_history
+ ORDER BY id DESC
+ LIMIT 1;
+
+/*
+ * Delete stab function dbms_stats.backup
+ */
+DROP FUNCTION dbms_stats.backup(
+ backup_id int8,
+ regclass,
+ attnum int2);
+ALTER FUNCTION dbms_stats.truth_func_backup(
+ backup_id int8,
+ regclass,
+ attnum int2)
+ RENAME TO backup;
+DROP FUNCTION dbms_stats.backup(
+ regclass,
+ attname text,
+ comment text);
+ALTER FUNCTION dbms_stats.truth_func_backup(
+ regclass,
+ attname text,
+ comment text)
+ RENAME TO backup;
+VACUUM ANALYZE;
+
+/*
+ * create backup statistics state A
+ */
+DELETE FROM dbms_stats.backup_history;
+
+INSERT INTO dbms_stats.backup_history(id, time, unit)
+ VALUES (1, '2012-02-29 23:59:56.999999', 'd');
+
+SELECT setval('dbms_stats.backup_history_id_seq',1);
+SELECT dbms_stats.backup();
+UPDATE dbms_stats.backup_history
+ SET time = '2012-02-29 23:59:57'
+ WHERE id = 2;
+SELECT dbms_stats.backup('s0.st0');
+UPDATE dbms_stats.backup_history
+ SET time = '2012-02-29 23:59:57.000001'
+ WHERE id = 3;
+SELECT dbms_stats.backup();
+UPDATE dbms_stats.backup_history
+ SET time = '2012-02-29 23:59:58'
+ WHERE id = 4;
+DELETE FROM dbms_stats.relation_stats_backup
+ WHERE id = 4;
+SELECT dbms_stats.backup('s0.st0', 'id');
+UPDATE dbms_stats.backup_history
+ SET time = '2012-03-01 00:00:00'
+ WHERE id = 5;
+SELECT dbms_stats.backup('s0.st0');
+UPDATE dbms_stats.backup_history
+ SET time = '2012-03-01 00:00:02'
+ WHERE id = 6;
+SELECT dbms_stats.backup('public.st0');
+UPDATE dbms_stats.backup_history
+ SET time = '2012-03-01 00:00:04'
+ WHERE id = 7;
+INSERT INTO dbms_stats.backup_history(time, unit)
+ VALUES ('2012-03-01 00:00:06', 's');
+SELECT dbms_stats.backup(8, c.oid, NULL)
+ FROM pg_catalog.pg_class c,
+ pg_catalog.pg_namespace n
+ WHERE n.nspname = 's0'
+ AND c.relnamespace = n.oid
+ AND c.relkind IN ('r', 'i');
+
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+SELECT * FROM relations_backup_v;
+SELECT * FROM columns_backup_v;
+
+VACUUM ANALYZE;
+
+/*
+ * No.9-1 dbms_stats.restore
+ */
+-- No.9-1-1
+DELETE FROM dbms_stats._relation_stats_locked;
+BEGIN;
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+SELECT dbms_stats.restore(2, 's0.st0', NULL);
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+COMMIT;
+SELECT relid::regclass FROM dbms_stats.relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+
+-- No.9-1-2
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(2, 'st0', NULL);
+SELECT relid::regclass FROM dbms_stats.relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+
+-- No.9-1-3
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(2, 's00.s0', NULL);
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+
+-- No.9-1-4
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(NULL, 's0.st0', NULL);
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+
+-- No.9-1-5
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(2, 's0.st0', 'id');
+SELECT relid::regclass FROM dbms_stats.relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+
+-- No.9-1-6
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(2, NULL, 'id');
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+
+-- No.9-1-7
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(2, 's0.st0', NULL);
+SELECT relid::regclass FROM dbms_stats.relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+
+-- No.9-1-8
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(2, NULL, NULL);
+SELECT relid::regclass FROM dbms_stats.relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+
+-- No.9-1-9
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(0, 's0.st0', NULL);
+SELECT relid::regclass FROM dbms_stats.relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+
+-- No.9-1-10
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(2, 0, 'id');
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+
+-- No.9-1-11
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(1, 's0.st0', NULL);
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+
+-- No.9-1-12
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(2, 's0.st0', 'dummy');
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+
+-- No.9-1-13
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(1, 's0.st0', 'id');
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+
+-- No.9-1-15
+DELETE FROM dbms_stats._relation_stats_locked;
+ALTER TABLE s1.st0 DROP COLUMN id;
+SELECT dbms_stats.restore(2, 's1.st0', 'id');
+SELECT relid::regclass FROM dbms_stats.relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+
+-- No.9-1-14
+DELETE FROM dbms_stats._relation_stats_locked;
+\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';"`
+DROP TABLE s1.st0;
+SET client_min_messages TO FATAL;
+SELECT dbms_stats.restore(2, :s1_st0_oid, NULL);
+RESET client_min_messages;
+\! tail ${PGDATA}/pg_log/postgresql.log > results/ut_no3_1_14.out
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+CREATE TABLE s1.st0(id integer, num integer);
+INSERT INTO s1.st0 VALUES (1, 15), (2, 25), (3, 35), (4, 45);
+VACUUM ANALYZE;
+-- No.9-1-16
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(2, 's0.st0', NULL);
+SELECT relid::regclass FROM dbms_stats.relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+
+-- No.9-1-17
+DELETE FROM dbms_stats._relation_stats_locked;
+INSERT INTO dbms_stats.relation_stats_backup(
+ id, relid, relname, relpages, reltuples,
+ relallvisible,
+ curpages)
+ VALUES (2,
+ 'pg_toast.pg_toast_2618'::regclass,
+ 'pg_toast.pg_toast_2618', 1, 1,
+ 1,
+ 1);
+SELECT * FROM relations_backup_v
+ WHERE id = 2
+ AND relname = 'pg_toast.pg_toast_2618';
+SELECT dbms_stats.restore(2, 'pg_toast.pg_toast_2618', NULL);
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+DELETE FROM dbms_stats.relation_stats_backup
+ WHERE id = 2
+ AND relname = 'pg_toast.pg_toast_2618';
+
+-- No.9-1-18
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore(2, 's0.st0_idx', NULL);
+SELECT relid::regclass FROM dbms_stats.relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+
+-- No.9-1-19
+DELETE FROM dbms_stats._relation_stats_locked;
+INSERT INTO dbms_stats.relation_stats_backup(
+ id, relid, relname, relpages, reltuples,
+ relallvisible,
+ curpages)
+ VALUES (2, 's0.ss0'::regclass, 's0.ss0', 1, 1,
+ 1,
+ 1);
+SELECT * FROM relations_backup_v
+ WHERE id = 2
+ AND relname = 's0.ss0';
+SELECT dbms_stats.restore(2, 's0.ss0', NULL);
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+DELETE FROM dbms_stats.relation_stats_backup
+ WHERE id = 2
+ AND relname = 's0.ss0';
+
+-- No.9-1-20
+DELETE FROM dbms_stats._relation_stats_locked;
+INSERT INTO dbms_stats.relation_stats_backup(
+ id, relid, relname, relpages, reltuples,
+ relallvisible,
+ curpages)
+ VALUES (2, 's0.sc0'::regclass, 's0.sc0', 1, 1,
+ 1,
+ 1);
+SELECT * FROM relations_backup_v
+ WHERE id = 2
+ AND relname = 's0.sc0';
+SELECT dbms_stats.restore(2, 's0.sc0', NULL);
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+DELETE FROM dbms_stats.relation_stats_backup
+ WHERE id = 2
+ AND relname = 's0.sc0';
+
+-- No.9-1-21
+DELETE FROM dbms_stats._relation_stats_locked;
+INSERT INTO dbms_stats.relation_stats_backup(
+ id, relid, relname, relpages, reltuples,
+ relallvisible,
+ curpages)
+ VALUES (3, 's0.sft0'::regclass, 's0.sft0', 1, 1,
+ 1,
+ 1);
+SELECT * FROM relations_backup_v
+ WHERE id = 3
+ AND relname = 's0.sft0';
+SELECT dbms_stats.restore(2, 's0.sft0', NULL);
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+DELETE FROM dbms_stats.relation_stats_backup
+ WHERE id = 3
+ AND relname = 's0.sft0';
+
+-- No.9-1-22
+DELETE FROM dbms_stats._relation_stats_locked;
+INSERT INTO dbms_stats.relation_stats_backup(
+ id, relid, relname, relpages, reltuples,
+ relallvisible,
+ curpages)
+ VALUES (2, 'pg_catalog.pg_class'::regclass, 'pg_catalog.pg_class', 1, 1,
+ 1,
+ 1);
+SELECT * FROM relations_backup_v
+ WHERE id = 2
+ AND relname = 'pg_catalog.pg_class';
+SELECT dbms_stats.restore(2, 'pg_catalog.pg_class', NULL);
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+SELECT count(*) FROM dbms_stats.relation_stats_locked;
+DELETE FROM dbms_stats.relation_stats_backup
+ WHERE id = 2
+ AND relname = 'pg_catalog.pg_class';
+
+-- No.9-1-23
+DELETE FROM dbms_stats._relation_stats_locked;
+INSERT INTO dbms_stats._relation_stats_locked(relid, relname)
+ VALUES ('s0.st0'::regclass, 's0.st0');
+INSERT INTO dbms_stats._column_stats_locked(starelid, staattnum, stainherit)
+ SELECT starelid::regclass, staattnum, stainherit
+ FROM dbms_stats.column_stats_effective
+ WHERE starelid = 's0.st0'::regclass;
+SELECT id, unit, comment FROM dbms_stats.backup_history
+ WHERE id = 2;
+SELECT * FROM columns_locked_v;
+SELECT * FROM relations_locked_v;
+SELECT dbms_stats.restore(2, 's0.st0', NULL);
+SELECT * FROM relations_locked_v;
+SELECT * FROM columns_locked_v;
+
+-- No.9-1-24
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT id, unit, comment FROM dbms_stats.backup_history
+ WHERE id = 2;
+SELECT dbms_stats.restore(2, 's0.st0', NULL);
+SELECT * FROM relations_locked_v;
+SELECT * FROM columns_locked_v;
+
+/*
+ * Stab function dbms_stats.restore
+ */
+CREATE OR REPLACE FUNCTION dbms_stats.restore(
+ backup_id int8,
+ relid regclass DEFAULT NULL,
+ attname text DEFAULT NULL)
+RETURNS SETOF regclass AS
+$$
+BEGIN
+ RAISE NOTICE 'arguments are "%, %, %"', $1, $2, $3;
+ RETURN QUERY
+ SELECT c.oid::regclass
+ FROM pg_class c, dbms_stats.relation_stats_backup b
+ WHERE (c.oid = $2 OR $2 IS NULL)
+ AND c.oid = b.relid
+ AND c.relkind IN ('r', 'i')
+ AND (b.id <= $1 OR $1 IS NOT NULL)
+ GROUP BY c.oid
+ ORDER BY c.oid::regclass::text;
+END;
+$$
+LANGUAGE plpgsql;
+
+/*
+ * No.10-1 dbms_stats.restore_database_stats
+ */
+-- No.10-1-1
+SELECT dbms_stats.restore_database_stats('2012-02-29 23:59:57');
+-- No.10-1-2
+SELECT dbms_stats.restore_database_stats('2012-02-29 23:59:57.000002');
+-- No.10-1-3
+SELECT dbms_stats.restore_database_stats('2012-01-01 00:00:00');
+--#No.10-1-4 is skipped after lock tests
+--#No.10-1-5 is skipped after lock tests
+-- No.10-1-6
+SELECT dbms_stats.restore_database_stats('2012-02-29 23:59:57');
+
+/*
+ * No.10-2 dbms_stats.restore_schema_stats
+ */
+-- No.10-2-1
+SELECT dbms_stats.restore_schema_stats('s0', '2012-02-29 23:59:57');
+-- No.10-2-2
+SELECT dbms_stats.restore_schema_stats('s0', '2012-02-29 23:59:57.000002');
+-- No.10-2-3
+SELECT dbms_stats.restore_schema_stats('s0', '2012-01-01 00:00:00');
+--#No.10-2-4 is skipped after lock tests
+--#No.10-2-5 is skipped after lock tests
+-- No.10-2-6
+SELECT dbms_stats.restore_schema_stats('s0', '2012-02-29 23:59:57');
+-- No.10-2-7
+SELECT dbms_stats.restore_schema_stats('s0', '2012-02-29 23:59:57');
+--#No.10-2-8 is skipped after lock tests
+-- No.10-2-9
+SELECT dbms_stats.restore_schema_stats('s00', '2012-02-29 23:59:57');
+-- No.10-2-10
+SELECT dbms_stats.restore_schema_stats('pg_catalog', '2012-02-29 23:59:57');
+
+/*
+ * No.10-7 dbms_stats.restore_stats
+ */
+-- No.10-7-1
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore_stats(NULL);
+
+-- No.10-7-2
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.restore_stats(0);
+
+-- No.10-7-3
+DELETE FROM dbms_stats._relation_stats_locked;
+BEGIN;
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+SELECT dbms_stats.restore_stats(2);
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+COMMIT;
+SELECT relid::regclass FROM dbms_stats.relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+
+-- No.10-7-4
+DELETE FROM dbms_stats._relation_stats_locked;
+INSERT INTO dbms_stats._relation_stats_locked(relid, relname)
+ SELECT relid::regclass, relname
+ FROM dbms_stats.relation_stats_effective;
+INSERT INTO dbms_stats._column_stats_locked(starelid, staattnum, stainherit)
+ SELECT starelid::regclass, staattnum, stainherit
+ FROM dbms_stats.column_stats_effective;
+SELECT id, unit, comment FROM dbms_stats.backup_history
+ WHERE id = 8;
+SELECT * FROM columns_locked_v;
+SELECT * FROM relations_locked_v;
+SELECT dbms_stats.restore_stats(8);
+SELECT * FROM relations_locked_v;
+SELECT * FROM columns_locked_v;
+
+-- No.10-7-5
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT id, unit, comment FROM dbms_stats.backup_history
+ WHERE id = 8;
+SELECT dbms_stats.restore_stats(8);
+SELECT * FROM relations_locked_v;
+SELECT * FROM columns_locked_v;
+
+/*
+ * No.11-1 dbms_stats.lock(relid, attname)
+ */
+-- No.11-1-1
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock(NULL, NULL);
+-- No.11-1-2
+ALTER FUNCTION dbms_stats.lock(relid regclass)
+ RENAME TO truth_lock;
+CREATE FUNCTION dbms_stats.lock(relid regclass)
+RETURNS regclass AS
+$$
+BEGIN
+ RAISE NOTICE 'arguments are %', $1;
+ RETURN $1;
+END
+$$
+LANGUAGE plpgsql;
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.st0', NULL);
+DROP FUNCTION dbms_stats.lock(relid regclass);
+ALTER FUNCTION dbms_stats.truth_lock(relid regclass)
+ RENAME TO lock;
+-- No.11-1-3
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock(NULL, 'id');
+-- No.11-1-4
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.st0', 'id');
+SELECT * FROM relations_locked_v;
+SELECT * FROM columns_locked_v c;
+-- No.11-1-5
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock(0, 'id');
+-- No.11-1-6
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.st0', 'id');
+SELECT * FROM relations_locked_v;
+SELECT * FROM columns_locked_v c;
+-- No.11-1-7
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('pg_toast.pg_toast_2618', 'id');
+-- No.11-1-8
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.st0_idx', 'id');
+-- No.11-1-9
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('st1_exp', 'lower');
+SELECT * FROM relations_locked_v;
+SELECT * FROM columns_locked_v c;
+DELETE FROM dbms_stats._relation_stats_locked;
+
+-- No.11-1-10
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.ss0', 'id');
+-- No.11-1-11
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.sc0', 'id');
+-- No.11-1-12
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.sft0', 'id');
+-- No.11-1-13
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('pg_catalog.pg_class', 'id');
+-- No.11-1-14
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.st0', 'dummy');
+-- No.11-1-15
+DELETE FROM dbms_stats._relation_stats_locked;
+DELETE FROM pg_statistic
+ WHERE starelid = 's0.st0'::regclass;
+SELECT dbms_stats.lock('s0.st0', 'id');
+VACUUM ANALYZE;
+-- No.11-1-16
+DELETE FROM dbms_stats._relation_stats_locked;
+INSERT INTO dbms_stats._relation_stats_locked(
+ relid, relname, relpages, reltuples,
+ relallvisible,
+ curpages)
+ VALUES('s0.st0'::regclass, 's0.st0', 1, 1640,
+ 1,
+ 1);
+SELECT dbms_stats.lock_column_stats('s0.st0','id');
+UPDATE dbms_stats._column_stats_locked
+ SET (stanullfrac, stawidth, stadistinct,
+ stakind1, stakind2, stakind3, stakind4,
+ stakind5,
+ staop1, staop2, staop3, staop4,
+ staop5,
+ stanumbers1, stanumbers2, stanumbers3, stanumbers4,
+ stanumbers5,
+ stavalues1, stavalues2, stavalues3, stavalues4
+ ,stavalues5
+ ) = (
+ NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL)
+ WHERE starelid = 's0.st0'::regclass;
+SELECT dbms_stats.lock('s0.st0', 'id');
+SELECT * FROM relations_locked_v;
+SELECT * FROM columns_locked_v c;
+-- No.11-1-17
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.st0', 'id');
+SELECT * FROM relations_locked_v
+ WHERE relid = 's0.st0'::regclass;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+
+/*
+ * No.11-2 dbms_stats.lock(relid)
+ */
+-- No.11-2-1
+DELETE FROM dbms_stats._relation_stats_locked;
+BEGIN;
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+SELECT dbms_stats.lock('s0.st0');
+SELECT * FROM relations_locked_v;
+SELECT * FROM columns_locked_v c;
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+COMMIT;
+
+-- No.11-2-2
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock(NULL);
+-- No.11-2-3
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('0');
+-- No.11-2-4
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.st0');
+SELECT * FROM relations_locked_v;
+SELECT * FROM columns_locked_v c;
+-- No.11-2-5
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('pg_toast.pg_toast_2618');
+-- No.11-2-6
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.st0_idx');
+SELECT * FROM relations_locked_v;
+SELECT * FROM columns_locked_v c;
+-- No.11-2-7
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.ss0');
+-- No.11-2-8
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.sc0');
+-- No.11-2-9
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.sft0');
+-- No.11-2-10
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('pg_catalog.pg_class');
+-- No.11-2-11
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_table_stats('s0.st0');
+UPDATE dbms_stats._relation_stats_locked
+ SET (relpages, reltuples,
+ relallvisible,
+ curpages)
+ = (NULL, NULL, NULL
+ ,NULL
+ )
+ WHERE relid = 's0.st0'::regclass;
+SELECT dbms_stats.lock('s0.st0');
+SELECT * FROM relations_locked_v;
+SELECT * FROM columns_locked_v c;
+-- No.11-2-12
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock('s0.st0');
+SELECT * FROM relations_locked_v;
+SELECT * FROM columns_locked_v c;
+
+/*
+ * Stab function dbms_stats.lock
+ */
+ALTER FUNCTION dbms_stats.lock(relid regclass)
+ RENAME TO truth_lock;
+CREATE FUNCTION dbms_stats.lock(relid regclass)
+RETURNS regclass AS
+$$
+BEGIN
+ RAISE NOTICE 'arguments are %', $1;
+ RETURN $1;
+END
+$$
+LANGUAGE plpgsql;
+
+ALTER FUNCTION dbms_stats.lock(relid regclass, attname text)
+ RENAME TO truth_lock;
+CREATE FUNCTION dbms_stats.lock(
+ relid regclass,
+ attname text)
+RETURNS regclass AS
+$$
+BEGIN
+ RAISE NOTICE 'arguments are %, %', $1, $2;
+ RETURN $1;
+END
+$$
+LANGUAGE plpgsql;
+
+/*
+ * No.12-1 dbms_stats.lock_database_stats
+ */
+-- No.12-1-1
+SELECT dbms_stats.lock_database_stats();
+
+/*
+ * No.12-2 dbms_stats.lock_schema_stats
+ */
+-- No.12-2-1
+SELECT dbms_stats.lock_schema_stats('s0');
+-- No.12-2-2
+SELECT dbms_stats.lock_schema_stats('s00');
+-- No.12-2-3
+SELECT dbms_stats.lock_schema_stats('pg_catalog');
+
+/*
+ * No.12-3 dbms_stats.lock_table_stats(regclass)
+ */
+-- No.12-3-1
+SELECT dbms_stats.lock_table_stats('s0.st0');
+-- No.12-3-2
+SELECT dbms_stats.lock_table_stats('st0');
+-- No.12-3-3
+SELECT dbms_stats.lock_table_stats('s00.s0');
+
+/*
+ * No.12-4 dbms_stats.lock_table_stats(schemaname, tablename)
+ */
+-- No.12-4-1
+SELECT dbms_stats.lock_table_stats('s0', 'st0');
+
+/*
+ * No.12-5 dbms_stats.lock_column_stats(regclass, attname)
+ */
+-- No.12-5-1
+SELECT dbms_stats.lock_column_stats('s0.st0', 'id');
+-- No.12-5-2
+SELECT dbms_stats.lock_column_stats('st0', 'id');
+-- No.12-5-3
+SELECT dbms_stats.lock_column_stats('s00.s0', 'id');
+
+/*
+ * No.12-6 dbms_stats.lock_column_stats(schemaname, tablename, int2)
+ */
+-- No.12-6-1
+SELECT dbms_stats.lock_column_stats('s0', 'st0', 'id');
+
+/*
+ * Delete Stab function lock
+ */
+DROP FUNCTION dbms_stats.lock(relid regclass);
+ALTER FUNCTION dbms_stats.truth_lock(relid regclass)
+ RENAME TO lock;
+DROP FUNCTION dbms_stats.lock(relid regclass, attname text);
+ALTER FUNCTION dbms_stats.truth_lock(relid regclass, attname text)
+ RENAME TO lock;
+
+/*
+ * No.13-1 dbms_stats.unlock
+ */
+-- No.13-1-1
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+SELECT dbms_stats.unlock();
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+
+-- No.13-1-2
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT dbms_stats.unlock();
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+
+-- No.13-1-3
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+DELETE FROM dbms_stats._column_stats_locked;
+SELECT dbms_stats.unlock();
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+
+-- No.13-1-4
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.unlock();
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+
+-- No.13-1-5
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT dbms_stats.unlock('s0.st0');
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+
+-- No.13-1-6
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT dbms_stats.unlock('st0');
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+
+-- No.13-1-7
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+SELECT dbms_stats.unlock('s00.s0');
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+
+-- No.13-1-8
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT dbms_stats.unlock('s0.st0', 'id');
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+
+-- No.13-1-9
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT dbms_stats.unlock('s0.st0', 'dummy');
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+
+-- No.13-1-10
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+DELETE FROM dbms_stats._column_stats_locked;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT dbms_stats.unlock('s0.st0', 'id');
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, staattnum FROM dbms_stats._column_stats_locked
+ GROUP BY starelid, staattnum
+ ORDER BY starelid;
+
+-- No.13-1-11
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, staattnum FROM dbms_stats._column_stats_locked
+ GROUP BY starelid, staattnum
+ ORDER BY starelid;
+SELECT dbms_stats.unlock(NULL, 'id');
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, staattnum FROM dbms_stats._column_stats_locked
+ GROUP BY starelid, staattnum
+ ORDER BY starelid;
+
+-- No.13-1-12
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, staattnum FROM dbms_stats._column_stats_locked
+ GROUP BY starelid, staattnum
+ ORDER BY starelid;
+SELECT dbms_stats.unlock('s0.st0', NULL);
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, staattnum FROM dbms_stats._column_stats_locked
+ GROUP BY starelid, staattnum
+ ORDER BY starelid;
+
+-- No.13-1-13
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+BEGIN;
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+SELECT dbms_stats.unlock();
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+COMMIT;
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+
+/*
+ * No.14-1 dbms_stats.unlock_database_stats
+ */
+-- No.14-1-1
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+SELECT dbms_stats.unlock_database_stats();
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+
+-- No.14-1-2
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+DELETE FROM dbms_stats._column_stats_locked;
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.unlock_database_stats();
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+
+-- No.14-1-3
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.unlock_database_stats();
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+
+-- No.14-1-4
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+BEGIN;
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+SELECT dbms_stats.unlock_database_stats();
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+COMMIT;
+SELECT count(*) FROM dbms_stats._relation_stats_locked;
+SELECT count(*) FROM dbms_stats._column_stats_locked;
+
+/*
+ * No.14-2 dbms_stats.unlock_schema_stats
+ */
+-- No.14-2-1
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT dbms_stats.unlock_schema_stats('s0');
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+
+-- No.14-2-2
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+DELETE FROM dbms_stats._column_stats_locked;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT dbms_stats.unlock_schema_stats('s0');
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+
+-- No.14-2-3
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT dbms_stats.unlock_schema_stats('s0');
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+
+-- No.14-2-4
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT dbms_stats.unlock_schema_stats('s0');
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+
+-- No.14-2-5
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT dbms_stats.unlock_schema_stats('s00');
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+
+-- No.14-2-6
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT dbms_stats.unlock_schema_stats('pg_catalog');
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+
+-- No.14-2-7
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT dbms_stats.unlock_schema_stats(NULL);
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+
+-- No.14-2-8
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+BEGIN;
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+SELECT dbms_stats.unlock_schema_stats('s0');
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+COMMIT;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+
+/*
+ * No.14-3 dbms_stats.unlock_table_stats(regclass)
+ */
+-- No.14-3-1
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT dbms_stats.unlock_table_stats('s0.st0');
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+
+-- No.14-3-2
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+DELETE FROM dbms_stats._column_stats_locked;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT dbms_stats.unlock_table_stats('s0.st0');
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+
+-- No.14-3-3
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT dbms_stats.unlock_table_stats('s0.st0');
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+
+-- No.14-3-4
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT dbms_stats.unlock_table_stats('s0.st0');
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+
+-- No.14-3-5
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT dbms_stats.unlock_table_stats('st0');
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+
+-- No.14-3-6
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT dbms_stats.unlock_table_stats('s00.s0');
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+
+-- No.14-3-7
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT dbms_stats.unlock_table_stats(NULL);
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+
+-- No.14-3-8
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+BEGIN;
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+SELECT dbms_stats.unlock_table_stats('s0.st0');
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+COMMIT;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+
+/*
+ * No.14-4 dbms_stats.unlock_table_stats(schemaname, tablename)
+ */
+-- No.14-4-1
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT dbms_stats.unlock_table_stats('s0','st0');
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+
+-- No.14-4-2
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+DELETE FROM dbms_stats._column_stats_locked;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT dbms_stats.unlock_table_stats('s0', 'st0');
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+
+-- No.14-4-3
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT dbms_stats.unlock_table_stats('s0', 'st0');
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+
+-- No.14-4-4
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT dbms_stats.unlock_table_stats('s0', 'st0');
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+
+-- No.14-4-5
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT dbms_stats.unlock_table_stats('s00', 's0');
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+
+-- No.14-4-6
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT dbms_stats.unlock_table_stats(NULL, 'st0');
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+
+-- No.14-4-7
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+SELECT dbms_stats.unlock_table_stats('s0', NULL);
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+
+-- No.14-4-8
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+BEGIN;
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+SELECT dbms_stats.unlock_table_stats('s0', 'st0');
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+COMMIT;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, count(*) FROM dbms_stats._column_stats_locked
+ GROUP BY starelid
+ ORDER BY starelid;
+
+/*
+ * No.14-5 dbms_stats.unlock_column_stats(regclass, attname)
+ */
+-- No.14-5-1
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT dbms_stats.unlock_column_stats('s0.st0', 'id');
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+
+-- No.14-5-2
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+DELETE FROM dbms_stats._column_stats_locked;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT dbms_stats.unlock_column_stats('s0.st0', 'id');
+SELECT count(*) FROM dbms_stats.column_stats_locked;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+
+-- No.14-5-3
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT dbms_stats.unlock_column_stats('s0.st0', 'id');
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+
+-- No.14-5-4
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT dbms_stats.unlock_column_stats('st0', 'id');
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+
+-- No.14-5-5
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT dbms_stats.unlock_column_stats('s0.st0', 'dummy');
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+
+-- No.14-5-6
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT dbms_stats.unlock_column_stats('s00.s0', 'id');
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+
+-- No.14-5-7
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT dbms_stats.unlock_column_stats(NULL, 'id');
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+
+-- No.14-5-8
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT dbms_stats.unlock_column_stats('s0.st0', NULL);
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+
+-- No.14-5-9
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+BEGIN;
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+SELECT dbms_stats.unlock_column_stats('s0.st0', 'id');
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+COMMIT;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+
+/*
+ * No.14-6 dbms_stats.unlock_column_stats(schemaname, tablename, attname)
+ */
+-- No.14-6-1
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT dbms_stats.unlock_column_stats('s0', 'st0', 'id');
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+
+-- No.14-6-2
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+DELETE FROM dbms_stats._column_stats_locked;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT dbms_stats.unlock_column_stats('s0', 'st0', 'id');
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+
+-- No.14-6-3
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT dbms_stats.unlock_column_stats('s0', 'st0', 'id');
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+
+-- No.14-6-4
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT dbms_stats.unlock_column_stats('s0', 'st0', 'dummy');
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+
+-- No.14-6-5
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT dbms_stats.unlock_column_stats(NULL, 'st0', 'id');
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+
+-- No.14-6-6
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT dbms_stats.unlock_column_stats('s0', NULL, 'id');
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+
+-- No.14-6-7
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT dbms_stats.unlock_column_stats('s0', 'st0', NULL);
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+
+-- No.14-6-8
+DELETE FROM dbms_stats._relation_stats_locked;
+SELECT dbms_stats.lock_database_stats();
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+BEGIN;
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+SELECT dbms_stats.unlock_column_stats('s0', 'st0', 'id');
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+COMMIT;
+SELECT starelid, attname, stainherit FROM columns_locked_v c;
+SELECT relid::regclass FROM dbms_stats._relation_stats_locked
+ GROUP BY relid
+ ORDER BY relid;
diff --git a/sql/ut-common.sql b/sql/ut-common.sql
new file mode 100644
index 0000000..74da45e
--- /dev/null
+++ b/sql/ut-common.sql
@@ -0,0 +1,1027 @@
+\pset null '(null)'
+LOAD 'pg_dbms_stats';
+/*
+ * No.2-3 dbms_stats.backup_history_id_seq
+ */
+-- No.2-3-1
+SELECT setval('dbms_stats.backup_history_id_seq', 0, false);
+-- No.2-3-2
+SELECT setval('dbms_stats.backup_history_id_seq', 1, false);
+INSERT INTO dbms_stats.backup_history(time, unit)
+ VALUES ('2011-01-01', 't');
+SELECT id, time, unit FROM dbms_stats.backup_history
+ ORDER BY id;
+-- No.2-3-3
+INSERT INTO dbms_stats.backup_history(time, unit)
+ VALUES ('2011-01-02', 'c'), ('2011-01-03', 'd');
+SELECT id, time, unit FROM dbms_stats.backup_history
+ ORDER BY id;
+-- clean up
+SELECT setval('dbms_stats.backup_history_id_seq', 1, false);
+DELETE FROM dbms_stats.backup_history;
+
+/*
+ * No.3-1 dbms_stats.use_locked_stats
+ */
+DELETE FROM dbms_stats._relation_stats_locked;
+EXPLAIN (costs false) SELECT * FROM s0.st2 WHERE id < 1;
+SELECT dbms_stats.lock_table_stats('s0.st2'::regclass);
+UPDATE dbms_stats._relation_stats_locked SET curpages = 10000;
+-- No.3-1-1
+SET pg_dbms_stats.use_locked_stats TO on;
+EXPLAIN (costs false) SELECT * FROM s0.st2 WHERE id < 1;
+-- No.3-1-2
+SET pg_dbms_stats.use_locked_stats TO off;
+EXPLAIN (costs false) SELECT * FROM s0.st2 WHERE id < 1;
+-- No.3-1-3
+\c - regular_user
+LOAD '$libdir/plugins/pg_dbms_stats';
+SHOW pg_dbms_stats.use_locked_stats;
+SET pg_dbms_stats.use_locked_stats TO OFF;
+SHOW pg_dbms_stats.use_locked_stats;
+EXPLAIN (costs false) SELECT * FROM s0.st2 WHERE id < 1;
+RESET pg_dbms_stats.use_locked_stats;
+EXPLAIN (costs false) SELECT * FROM s0.st2 WHERE id < 1;
+-- clean up
+\c - postgres
+LOAD 'pg_dbms_stats';
+DELETE FROM dbms_stats._relation_stats_locked;
+
+/*
+ * No.4-1 DATA TYPE dbms_stats.anyarray
+ */
+CREATE TABLE st3(id integer, name char(1000), num_arr char(5)[]);
+INSERT INTO st3 SELECT i, i , ARRAY[i::char, 'a'] FROM generate_series(1,10) g(i);
+ANALYZE st3;
+SELECT stavalues1 FROM pg_statistic
+ WHERE starelid = 'public.st3'::regclass;
+\copy (SELECT stavalues1::dbms_stats.anyarray FROM dbms_stats.column_stats_effective WHERE starelid = 'st3'::regclass) TO 'results/anyarray_test.cp' binary
+CREATE TABLE st4 (arr dbms_stats.anyarray);
+
+SELECT t.typname, n.nspname,
+ t.typlen, t.typbyval, t.typtype,
+ t.typcategory, t.typispreferred, t.typispreferred,
+ t.typdelim, t.typrelid, t.typmodin,
+ t.typmodout, t.typanalyze, t.typalign,
+ t.typstorage, t.typnotnull, t.typbasetype, t.typtypmod,
+ t.typndims, t.typcollation, t.typdefaultbin, t.typdefault
+ FROM pg_type t, pg_namespace n
+ WHERE t.typname = 'anyarray'
+ AND t.typnamespace = n.oid
+ ORDER BY t.typname;
+-- No.4-1-1
+INSERT INTO st4 VALUES(NULL);
+SELECT * FROM st4;
+-- No.4-1-2
+DELETE FROM st4;
+SELECT stavalues1::dbms_stats.anyarray
+ FROM dbms_stats.column_stats_effective
+ WHERE starelid = 'st3'::regclass
+ AND staattnum = 1;
+SELECT count(*) FROM st4;
+INSERT INTO st4
+ SELECT stavalues1::dbms_stats.anyarray
+ FROM dbms_stats.column_stats_effective
+ WHERE starelid = 'st3'::regclass
+ AND staattnum = 1;
+SELECT * FROM st4;
+-- No.4-1-3
+DELETE FROM st4;
+SELECT stavalues1::dbms_stats.anyarray
+ FROM dbms_stats.column_stats_effective
+ WHERE starelid = 'st3'::regclass
+ AND staattnum = 2;
+SELECT count(*) FROM st4;
+INSERT INTO st4
+ SELECT stavalues1::dbms_stats.anyarray
+ FROM dbms_stats.column_stats_effective
+ WHERE starelid = 'st3'::regclass
+ AND staattnum = 2;
+SELECT * FROM st4;
+-- No.4-1-4
+DELETE FROM st4;
+SELECT stavalues1::dbms_stats.anyarray
+ FROM dbms_stats.column_stats_effective
+ WHERE starelid = 'st3'::regclass
+ AND staattnum = 1;
+SELECT count(*) FROM st4;
+INSERT INTO st4
+ SELECT stavalues1::dbms_stats.anyarray
+ FROM dbms_stats.column_stats_effective
+ WHERE starelid = 'st3'::regclass
+ AND staattnum = 1;
+SELECT * FROM st4;
+-- No.4-1-5
+DELETE FROM st4;
+SELECT stavalues1::dbms_stats.anyarray
+ FROM dbms_stats.column_stats_effective
+ WHERE starelid = 'st3'::regclass
+ AND staattnum = 3;
+SELECT count(*) FROM st4;
+INSERT INTO st4
+ SELECT stavalues1::dbms_stats.anyarray
+ FROM dbms_stats.column_stats_effective
+ WHERE starelid = 'st3'::regclass
+ AND staattnum = 3;
+SELECT * FROM st4;
+-- No.4-1-6
+DELETE FROM st4;
+SELECT stavalues1::dbms_stats.anyarray
+ FROM dbms_stats.column_stats_effective
+ WHERE starelid = 'st3'::regclass;
+\copy st4(arr) FROM 'results/anyarray_test.cp' binary
+SELECT * FROM st4;
+-- clean up
+DROP TABLE st3;
+DROP TABLE st4;
+
+SELECT dbms_stats.unlock_database_stats();
+SELECT dbms_stats.lock_table_stats('st1');
+
+/*
+ * No.5-2 dbms_stats.invalidate_column_cache
+ */
+-- No.5-2-1
+SELECT dbms_stats.invalidate_column_cache();
+
+-- No.5-2-2
+/*
+ * Driver function dbms_stats.invalidate_cache1
+ */
+CREATE TRIGGER invalidate_cache1
+ AFTER INSERT OR DELETE OR UPDATE
+ ON pt0
+ FOR EACH ROW EXECUTE PROCEDURE dbms_stats.invalidate_column_cache();
+INSERT INTO pt0 VALUES (1,'2012/12/12');
+DROP TRIGGER invalidate_cache1 ON pt0;
+
+-- No.5-2-3
+/*
+ * Driver function dbms_stats.invalidate_cache2
+ */
+CREATE TRIGGER invalidate_cache2
+BEFORE INSERT OR DELETE OR UPDATE
+ ON pt0
+ FOR EACH STATEMENT EXECUTE PROCEDURE dbms_stats.invalidate_column_cache();
+INSERT INTO pt0 VALUES (1,'2012/12/12');
+DROP TRIGGER invalidate_cache2 ON pt0;
+
+-- No.5-2-4
+/*
+ * Driver function dbms_stats.invalidate_cache3
+ */
+CREATE TRIGGER invalidate_cache3
+BEFORE TRUNCATE
+ ON pt0
+ FOR EACH STATEMENT EXECUTE PROCEDURE dbms_stats.invalidate_column_cache();
+TRUNCATE TABLE pt0;
+DROP TRIGGER invalidate_cache3 ON pt0;
+
+-- No.5-2-5
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+INSERT INTO dbms_stats._relation_stats_locked (relid, relname) VALUES (0, 'dummy');
+INSERT INTO dbms_stats._column_stats_locked (starelid, staattnum, stainherit)
+ VALUES (0, 1, true);
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+
+-- No.5-2-6
+INSERT INTO dbms_stats._column_stats_locked (starelid, staattnum, stainherit)
+ VALUES ('st1_idx'::regclass, 1, true);
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+
+-- No.5-2-7
+INSERT INTO dbms_stats._column_stats_locked (starelid, staattnum, stainherit)
+ VALUES ('complex'::regclass, 1, true);
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+
+-- No.5-2-9
+UPDATE dbms_stats._column_stats_locked SET stanullfrac = 1
+ WHERE starelid = 'st1'::regclass
+ AND staattnum = 1
+ AND stainherit = false;
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+
+-- No.5-2-10
+DELETE FROM dbms_stats._column_stats_locked
+ WHERE starelid = 'st1'::regclass
+ AND staattnum = 1
+ AND stainherit = false;
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+
+-- No.5-2-8
+INSERT INTO dbms_stats._column_stats_locked
+ (starelid, staattnum, stainherit, stanullfrac)
+ VALUES ('st1'::regclass, 1, false, 1);
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+
+-- No.5-2-11
+PREPARE p2 AS SELECT str FROM st1 WHERE lower(str) IS NULL;
+EXPLAIN (costs false) SELECT str FROM st1 WHERE lower(str) IS NULL;
+EXPLAIN (costs false) EXECUTE p2;
+INSERT INTO dbms_stats._relation_stats_locked (relid, relname)
+ VALUES ('st1_exp'::regclass, 'dummy');
+INSERT INTO dbms_stats._column_stats_locked
+ (starelid, staattnum, stainherit, stanullfrac)
+ VALUES ('st1_exp'::regclass, 1, false, 1);
+EXPLAIN (costs false) SELECT str FROM st1 WHERE lower(str) IS NULL;
+EXPLAIN (costs false) EXECUTE p2;
+
+DEALLOCATE p2;
+
+SELECT dbms_stats.unlock_database_stats();
+
+
+/*
+ * No.5-3 dbms_stats.invalidate_relation_cache
+ */
+-- No.5-3-1
+SELECT dbms_stats.invalidate_relation_cache();
+
+-- No.5-3-2
+/*
+ * Driver function dbms_stats.invalidate_cache1
+ */
+CREATE TRIGGER invalidate_cache1
+ AFTER INSERT OR DELETE OR UPDATE
+ ON pt0
+ FOR EACH ROW EXECUTE PROCEDURE dbms_stats.invalidate_relation_cache();
+INSERT INTO pt0 VALUES (1,'2012/12/12');
+DROP TRIGGER invalidate_cache1 ON pt0;
+
+-- No.5-3-3
+/*
+ * Driver function dbms_stats.invalidate_cache2
+ */
+CREATE TRIGGER invalidate_cache2
+BEFORE INSERT OR DELETE OR UPDATE
+ ON pt0
+ FOR EACH STATEMENT EXECUTE PROCEDURE dbms_stats.invalidate_relation_cache();
+INSERT INTO pt0 VALUES (1,'2012/12/12');
+DROP TRIGGER invalidate_cache2 ON pt0;
+
+-- No.5-3-4
+/*
+ * Driver function dbms_stats.invalidate_cache3
+ */
+CREATE TRIGGER invalidate_cache3
+BEFORE TRUNCATE
+ ON pt0
+ FOR EACH STATEMENT EXECUTE PROCEDURE dbms_stats.invalidate_relation_cache();
+TRUNCATE TABLE pt0;
+DROP TRIGGER invalidate_cache3 ON pt0;
+
+-- No.5-3-5
+SELECT dbms_stats.unlock_database_stats();
+SELECT dbms_stats.lock_table_stats('st1');
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+INSERT INTO dbms_stats._relation_stats_locked (relid, relname) VALUES (0, 'dummy');
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+
+-- No.5-3-6
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+INSERT INTO dbms_stats._relation_stats_locked (relid, relname)
+ VALUES ('st1_idx'::regclass, 'st1_idx');
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+
+-- No.5-3-7
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+INSERT INTO dbms_stats._relation_stats_locked (relid, relname)
+ VALUES ('complex'::regclass, 'complex');
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+
+-- No.5-3-9
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+UPDATE dbms_stats._relation_stats_locked SET curpages = 1
+ WHERE relid = 'st1'::regclass;
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+
+-- No.5-3-10
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+DELETE FROM dbms_stats._relation_stats_locked
+ WHERE relid = 'st1'::regclass;
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+
+-- No.5-3-8
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+INSERT INTO dbms_stats._relation_stats_locked (relid, relname, curpages)
+ VALUES ('st1'::regclass, 'st1', 1);
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+
+-- No.5-3-11
+SELECT dbms_stats.unlock_database_stats();
+SELECT dbms_stats.lock_table_stats('st1');
+SELECT relname, curpages FROM dbms_stats.relation_stats_locked
+ WHERE relid = 'st1'::regclass;
+SELECT pg_sleep(0.5);
+SELECT pg_stat_reset();
+UPDATE dbms_stats._relation_stats_locked SET curpages = 1000
+ WHERE relid = 'st1_exp'::regclass;
+SELECT pg_sleep(0.5);
+SELECT * FROM lockd_io;
+SELECT relname, curpages FROM dbms_stats.relation_stats_locked
+ WHERE relid = 'st1'::regclass;
+SELECT pg_sleep(0.5);
+SELECT * FROM lockd_io;
+
+/*
+ * No.5-4 StatsCacheRelCallback
+ */
+-- No.5-4-1
+UPDATE dbms_stats._relation_stats_locked SET curpages = 1
+ WHERE relid = 'st1'::regclass;
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+\c
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+LOAD 'pg_dbms_stats';
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+
+SELECT dbms_stats.unlock_database_stats();
+SELECT dbms_stats.lock_table_stats('st1');
+-- No.5-4-3
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+\! psql contrib_regression -c "UPDATE dbms_stats._column_stats_locked SET stanullfrac = 1 WHERE starelid = 'st1'::regclass"
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+
+-- No.5-4-4
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+\! psql contrib_regression -c "DELETE FROM dbms_stats._column_stats_locked WHERE starelid = 'st1'::regclass"
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+
+-- No.5-4-2
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+\! psql contrib_regression -c "INSERT INTO dbms_stats._column_stats_locked (starelid, staattnum, stainherit, stanullfrac) VALUES ('st1'::regclass, 1, false, 1)"
+EXPLAIN (costs false) SELECT * FROM st1 WHERE val IS NULL;
+
+SELECT dbms_stats.unlock_database_stats();
+
+-- No.5-4-5
+CREATE TABLE s0.droptest(id integer);
+INSERT INTO s0.droptest VALUES (1),(2),(3);
+VACUUM ANALYZE;
+SELECT * FROM s0.droptest
+ WHERE id = 1;
+SELECT pg_sleep(0.5);
+SELECT pg_stat_reset();
+ALTER TABLE s0.droptest RENAME TO test;
+SELECT pg_sleep(0.5);
+SELECT * FROM lockd_io;
+SELECT * FROM s0.test
+ WHERE id = 1;
+SELECT pg_sleep(0.5);
+SELECT * FROM lockd_io;
+ALTER TABLE s0.test RENAME TO droptest;
+
+-- No.5-4-6
+SELECT * FROM s0.droptest
+ WHERE id = 1;
+SELECT pg_sleep(0.5);
+SELECT pg_stat_reset();
+ALTER TABLE s0.droptest RENAME id TO test;
+SELECT pg_sleep(0.5);
+SELECT * FROM lockd_io;
+SELECT * FROM s0.droptest
+ WHERE test = 1;
+SELECT pg_sleep(0.5);
+SELECT * FROM lockd_io;
+ALTER TABLE s0.droptest RENAME test TO id;
+
+-- No.5-4-8
+INSERT INTO s0.droptest VALUES (4);
+SELECT * FROM s0.droptest
+ WHERE id = 1;
+SELECT pg_sleep(0.5);
+SELECT pg_stat_reset();
+ANALYZE;
+SELECT pg_sleep(0.5);
+SELECT * FROM lockd_io;
+SELECT * FROM s0.droptest
+ WHERE id = 1;
+SELECT pg_sleep(1.0);
+SELECT * FROM lockd_io;
+
+-- No.5-4-9
+DELETE FROM s0.droptest;
+INSERT INTO s0.droptest VALUES (4),(5);
+SELECT * FROM s0.droptest
+ WHERE id = 4;
+SELECT pg_sleep(0.5);
+SELECT pg_stat_reset();
+VACUUM;
+SELECT pg_sleep(0.5);
+SELECT * FROM lockd_io;
+SELECT * FROM s0.droptest
+ WHERE id = 4;
+SELECT pg_sleep(0.5);
+SELECT * FROM lockd_io;
+
+-- clean up
+DROP TABLE s0.droptest;
+
+/*
+ * No.6-1 dbms_stats.relname
+ */
+-- No.6-1-1
+SELECT dbms_stats.relname('aaa', 'bbb');
+-- No.6-1-2
+SELECT dbms_stats.relname(NULL, 'bbb');
+-- No.6-1-3
+SELECT dbms_stats.relname('aaa', NULL);
+-- No.6-1-4
+SELECT dbms_stats.relname(NULL, NULL);
+-- No.6-1-5
+SELECT dbms_stats.relname('', '');
+-- No.6-1-6
+SELECT dbms_stats.relname('aAa', 'bBb');
+-- No.6-1-7
+SELECT dbms_stats.relname('a a', 'b b');
+-- No.6-1-8
+SELECT dbms_stats.relname('a.a', 'b.b');
+-- No.6-1-9
+SELECT dbms_stats.relname(E'a\na', E'b\nb');
+-- No.6-1-10
+SELECT dbms_stats.relname('a"a', 'b"b');
+-- No.6-1-11
+SELECT dbms_stats.relname('ããã', 'äºä¼å¯');
+
+/*
+ * No.6-2 dbms_stats.is_system_schema
+ */
+-- No.6-2-1
+SELECT dbms_stats.is_system_schema('pg_catalog');
+-- No.6-2-2
+SELECT dbms_stats.is_system_schema('pg_toast');
+-- No.6-2-3
+SELECT dbms_stats.is_system_schema('information_schema');
+-- No.6-2-4
+SELECT dbms_stats.is_system_schema('dbms_stats');
+-- No.6-2-5
+SELECT dbms_stats.is_system_schema(NULL);
+-- No.6-2-6
+SELECT dbms_stats.is_system_schema('');
+-- No.6-2-7
+SELECT dbms_stats.is_system_schema('s0');
+-- No.6-2-8
+/*
+ * Driver function dbms_stats.is_system_schema1
+ */
+CREATE FUNCTION dbms_stats.is_system_schema1(schemaname text)
+ RETURNS integer AS
+ '$libdir/pg_dbms_stats', 'dbms_stats_is_system_schema'
+ LANGUAGE C IMMUTABLE STRICT;
+SELECT dbms_stats.is_system_schema1('s0');
+DROP FUNCTION dbms_stats.is_system_schema1(schemaname text);
+
+/*
+ * No.6-3 dbms_stats.is_system_catalog
+ */
+-- No.6-3-1
+SELECT dbms_stats.is_system_catalog('s0.st0');
+-- No.6-3-2
+SELECT dbms_stats.is_system_catalog('st0');
+-- No.6-3-3
+SELECT dbms_stats.is_system_catalog('s00.s0');
+-- No.6-3-4
+SELECT dbms_stats.is_system_catalog(NULL);
+-- No.6-3-5
+/*
+ * Driver function dbms_stats.is_system_catalog1
+ */
+CREATE FUNCTION dbms_stats.is_system_catalog1(relid regclass)
+RETURNS integer AS
+'$libdir/pg_dbms_stats', 'dbms_stats_is_system_catalog'
+LANGUAGE C STABLE;
+SELECT dbms_stats.is_system_catalog1('s0.st0');
+DROP FUNCTION dbms_stats.is_system_catalog1(relid regclass);
+
+
+/*
+ * No.6-4 dbms_stats.is_target_relkind
+ */
+-- No.6-4-1
+SELECT dbms_stats.is_target_relkind('r');
+-- No.6-4-2
+SELECT dbms_stats.is_target_relkind('i');
+-- No.6-4-3
+SELECT dbms_stats.is_target_relkind('S');
+-- No.6-4-4
+SELECT dbms_stats.is_target_relkind('v');
+-- No.6-4-5
+SELECT dbms_stats.is_target_relkind('c');
+-- No.6-4-6
+SELECT dbms_stats.is_target_relkind('t');
+-- No.6-4-7
+SELECT dbms_stats.is_target_relkind('a');
+-- No.6-4-8
+SELECT dbms_stats.is_target_relkind('');
+-- No.6-4-9
+SELECT dbms_stats.is_target_relkind(NULL);
+--#No.6-4-10 result varies according to a version
+
+/*
+ * No.7-1 dbms_stats.backup
+ */
+INSERT INTO dbms_stats.backup_history(id, time, unit) values(1, '2012-01-01', 'd');
+-- No.7-1-1
+DELETE FROM dbms_stats.relation_stats_backup;
+SELECT dbms_stats.backup(1, 's0.st0'::regclass, NULL);
+SELECT relid::regclass FROM dbms_stats.relation_stats_backup
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, staattnum FROM dbms_stats.column_stats_backup
+ GROUP BY starelid, staattnum
+ ORDER BY starelid, staattnum;
+
+-- No.7-1-2
+DELETE FROM dbms_stats.relation_stats_backup;
+SELECT dbms_stats.backup(1, 'st0'::regclass, NULL);
+SELECT relid::regclass FROM dbms_stats.relation_stats_backup
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, staattnum FROM dbms_stats.column_stats_backup
+ GROUP BY starelid, staattnum
+ ORDER BY starelid, staattnum;
+
+-- No.7-1-3
+DELETE FROM dbms_stats.relation_stats_backup;
+SELECT dbms_stats.backup(1, 'public.notfound'::regclass, NULL);
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+
+-- No.7-1-4
+DELETE FROM dbms_stats.relation_stats_backup;
+SELECT dbms_stats.backup(1, 's0.st0'::regclass, NULL);
+SELECT relid::regclass FROM dbms_stats.relation_stats_backup
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, staattnum FROM dbms_stats.column_stats_backup
+ GROUP BY starelid, staattnum
+ ORDER BY starelid, staattnum;
+
+-- No.7-1-5
+DELETE FROM dbms_stats.relation_stats_backup;
+SELECT dbms_stats.backup(1, 'pg_toast.pg_toast_2618'::regclass, NULL);
+SELECT relid::regclass FROM dbms_stats.relation_stats_backup
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, staattnum FROM dbms_stats.column_stats_backup
+ GROUP BY starelid, staattnum
+ ORDER BY starelid, staattnum;
+
+-- No.7-1-6
+DELETE FROM dbms_stats.relation_stats_backup;
+SELECT dbms_stats.backup(1, 's0.st0_idx'::regclass, NULL);
+SELECT relid::regclass FROM dbms_stats.relation_stats_backup
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, staattnum FROM dbms_stats.column_stats_backup
+ GROUP BY starelid, staattnum
+ ORDER BY starelid, staattnum;
+
+-- No.7-1-7
+DELETE FROM dbms_stats.relation_stats_backup;
+SELECT dbms_stats.backup(1, 's0.ss0'::regclass, NULL);
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+
+-- No.7-1-8
+DELETE FROM dbms_stats.relation_stats_backup;
+SELECT dbms_stats.backup(1, 's0.sc0'::regclass, NULL);
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+
+--#No.7-1-9 ut-
+
+-- No.7-1-10
+DELETE FROM dbms_stats.relation_stats_backup;
+SELECT dbms_stats.backup(1, 's0.st0'::regclass, 1::int2);
+SELECT relid::regclass FROM dbms_stats.relation_stats_backup
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, staattnum FROM dbms_stats.column_stats_backup
+ GROUP BY starelid, staattnum
+ ORDER BY starelid, staattnum;
+
+--#No.7-1-11 ut-
+
+-- No.7-1-12
+DELETE FROM dbms_stats.relation_stats_backup;
+SELECT dbms_stats.backup(1, 's0.st0'::regclass, NULL);
+SELECT relid::regclass FROM dbms_stats.relation_stats_backup
+ GROUP BY relid
+ ORDER BY relid;
+SELECT starelid::regclass, staattnum FROM dbms_stats.column_stats_backup
+ GROUP BY starelid, staattnum
+ ORDER BY starelid, staattnum;
+
+--#No.7-1-13 ut-
+
+-- No.7-1-14
+DELETE FROM dbms_stats.relation_stats_backup;
+SELECT dbms_stats.backup(1, 'pg_catalog.pg_class'::regclass, NULL);
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+
+-- No.7-1-15
+SELECT dbms_stats.backup(1, 's0.st0'::regclass, NULL);
+DELETE FROM dbms_stats.column_stats_backup;
+SELECT starelid::regclass, staattnum FROM dbms_stats.column_stats_backup
+ GROUP BY starelid, staattnum
+ ORDER BY starelid, staattnum;
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+SET client_min_messages TO FATAL;
+SELECT dbms_stats.backup(1, 's0.st0'::regclass, NULL);
+RESET client_min_messages;
+\! tail ${PGDATA}/pg_log/postgresql.log > results/ut_no2_1_15.out
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+
+--#No.7-1-17 ut-
+
+/*
+ * Stab function dbms_stats.backup
+ */
+ALTER FUNCTION dbms_stats.backup(
+ backup_id int8,
+ relid regclass,
+ attnum int2)
+ RENAME TO truth_func_backup;
+
+CREATE OR REPLACE FUNCTION dbms_stats.backup(
+ backup_id int8,
+ regclass,
+ attnum int2)
+RETURNS int8 AS
+$$
+BEGIN
+ RAISE NOTICE 'arguments are %, %, %', $1, $2, $3;
+ RETURN 1;
+END;
+$$
+LANGUAGE plpgsql;
+
+ALTER FUNCTION dbms_stats.backup(
+ relid regclass,
+ attname text,
+ comment text)
+ RENAME TO truth_func_backup;
+CREATE OR REPLACE FUNCTION dbms_stats.backup(
+ relid regclass DEFAULT NULL,
+ attname text DEFAULT NULL,
+ comment text DEFAULT NULL)
+RETURNS int8 AS
+$$
+BEGIN
+ IF $3 = '' THEN
+ RAISE NOTICE 'third argument is not NULL but string ""';
+ END IF;
+ RAISE NOTICE 'arguments are %, %, %', $1, $2, $3;
+ RETURN 1;
+END;
+$$
+LANGUAGE plpgsql;
+
+/*
+ * No.8-2 dbms_stats.backup_database_stats
+ */
+SELECT setval('dbms_stats.backup_history_id_seq',8);
+-- No.8-2-1
+SELECT dbms_stats.backup_database_stats('comment');
+
+/*
+ * No.8-4 dbms_stats.backup_table_stats(regclass,comment)
+ */
+-- No.8-4-1
+SELECT dbms_stats.backup_table_stats('s0.st0', 'comment');
+-- No.8-4-2
+SELECT dbms_stats.backup_table_stats('st0', 'comment');
+-- No.8-4-3
+SELECT dbms_stats.backup_table_stats('s00.s0', 'comment');
+
+/*
+ * No.8-5 dbms_stats.backup_table_stats(schemaname, tablename, comment)
+ */
+-- No.8-5-1
+SELECT dbms_stats.backup_table_stats('s0', 'st0', 'comment');
+-- No.8-5-2
+SELECT dbms_stats.backup_table_stats('s00', 's0', 'comment');
+
+/*
+ * No.8-6 dbms_stats.backup_column_stats(regclass, attname, comment)
+ */
+-- No.8-6-1
+SELECT dbms_stats.backup_column_stats('s0.st0', 'id', 'comment');
+-- No.8-6-2
+SELECT dbms_stats.backup_column_stats('st0', 'id', 'comment');
+-- No.8-6-3
+SELECT dbms_stats.backup_column_stats('s00.s0', 'id', 'comment');
+
+/*
+ * No.8-7 dbms_stats.backup_column_stats(schemaname, tablename, attname, comment)
+ */
+-- No.8-7-1
+SELECT dbms_stats.backup_column_stats('s0', 'st0', 'id', 'comment');
+-- No.8-7-2
+SELECT dbms_stats.backup_column_stats('s00', 's0', 'id', 'comment');
+
+/*
+ * Delete stab function dbms_stats.backup
+ */
+DROP FUNCTION dbms_stats.backup(
+ backup_id int8,
+ regclass,
+ attnum int2);
+ALTER FUNCTION dbms_stats.truth_func_backup(
+ backup_id int8,
+ regclass,
+ attnum int2)
+ RENAME TO backup;
+DROP FUNCTION dbms_stats.backup(
+ regclass,
+ attname text,
+ comment text);
+ALTER FUNCTION dbms_stats.truth_func_backup(
+ regclass,
+ attname text,
+ comment text)
+ RENAME TO backup;
+VACUUM ANALYZE;
+
+/*
+ * create backup statistics state A
+ */
+DELETE FROM dbms_stats.backup_history;
+
+INSERT INTO dbms_stats.backup_history(id, time, unit)
+ VALUES (1, '2012-02-29 23:59:56.999999', 'd');
+
+SELECT setval('dbms_stats.backup_history_id_seq',1);
+SELECT dbms_stats.backup();
+UPDATE dbms_stats.backup_history
+ SET time = '2012-02-29 23:59:57'
+ WHERE id = 2;
+SELECT dbms_stats.backup('s0.st0');
+UPDATE dbms_stats.backup_history
+ SET time = '2012-02-29 23:59:57.000001'
+ WHERE id = 3;
+SELECT dbms_stats.backup();
+UPDATE dbms_stats.backup_history
+ SET time = '2012-02-29 23:59:58'
+ WHERE id = 4;
+DELETE FROM dbms_stats.relation_stats_backup
+ WHERE id = 4;
+SELECT dbms_stats.backup('s0.st0', 'id');
+UPDATE dbms_stats.backup_history
+ SET time = '2012-03-01 00:00:00'
+ WHERE id = 5;
+SELECT dbms_stats.backup('s0.st0');
+UPDATE dbms_stats.backup_history
+ SET time = '2012-03-01 00:00:02'
+ WHERE id = 6;
+SELECT dbms_stats.backup('public.st0');
+UPDATE dbms_stats.backup_history
+ SET time = '2012-03-01 00:00:04'
+ WHERE id = 7;
+INSERT INTO dbms_stats.backup_history(time, unit)
+ VALUES ('2012-03-01 00:00:06', 's');
+SELECT dbms_stats.backup(8, c.oid, NULL)
+ FROM pg_catalog.pg_class c,
+ pg_catalog.pg_namespace n
+ WHERE n.nspname = 's0'
+ AND c.relnamespace = n.oid
+ AND c.relkind IN ('r', 'i');
+
+SELECT * FROM dbms_stats.backup_history
+ ORDER BY id;
+
+VACUUM ANALYZE;
+
+/*
+ * Stab function dbms_stats.restore
+ */
+ALTER FUNCTION dbms_stats.restore(int8, regclass, text)
+ RENAME TO truth_func_restore;
+CREATE FUNCTION dbms_stats.restore(int8, regclass DEFAULT NULL, text DEFAULT NULL)
+RETURNS SETOF regclass AS
+$$
+BEGIN
+ RAISE NOTICE 'arguments are "%, %, %"', $1, $2, $3;
+ RETURN QUERY
+ SELECT c.oid::regclass
+ FROM pg_class c, dbms_stats.relation_stats_backup b
+ WHERE (c.oid = $2 OR $2 IS NULL)
+ AND c.oid = b.relid
+ AND c.relkind IN ('r', 'i')
+ AND (b.id <= $1 OR $1 IS NOT NULL)
+ GROUP BY c.oid
+ ORDER BY c.oid::regclass::text;
+END;
+$$
+LANGUAGE plpgsql;
+
+/*
+ * No.10-3 dbms_stats.restore_table_stats(regclass, as_of_timestamp)
+ */
+-- No.10-3-1
+SELECT dbms_stats.restore_table_stats('s0.st0', '2012-02-29 23:59:57');
+-- No.10-3-2
+SELECT dbms_stats.restore_table_stats('s0.st0', '2012-02-29 23:59:57.000002');
+-- No.10-3-3
+SELECT dbms_stats.restore_table_stats('s0.st0', '2012-01-01 00:00:00');
+--#No.10-3-4 is skipped after lock tests
+-- No.10-3-5
+SELECT dbms_stats.restore_table_stats('s0.st0', '2012-02-29 23:59:57');
+-- No.10-3-6
+SELECT dbms_stats.restore_table_stats('st0', '2012-02-29 23:59:57');
+-- No.10-3-7
+SELECT dbms_stats.restore_table_stats('s00.s0', '2012-02-29 23:59:57');
+/*
+ * Stab dbms_stats.restore_table_stats(regclass, as_of_timestamp)
+ */
+CREATE OR REPLACE FUNCTION dbms_stats.restore_table_stats(
+ relid regclass,
+ as_of_timestamp timestamp with time zone)
+RETURNS SETOF regclass AS
+$$
+BEGIN
+ RAISE NOTICE 'arguments are %, %', $1, $2;
+ RETURN QUERY
+ SELECT $1;
+END
+$$
+LANGUAGE plpgsql;
+
+/*
+ * No.10-4 dbms_stats.restore_table_stats(schemaname, tablename, as_of_timestamp)
+ */
+-- No.10-4-1
+SELECT dbms_stats.restore_table_stats('s0', 'st0', '2012-02-29 23:59:57');
+
+/*
+ * No.10-5 dbms_stats.restore_column_stats(regclass, attname, as_of_timestamp)
+ */
+-- No.10-5-1
+SELECT dbms_stats.restore_column_stats('s0.st0', 'id', '2012-02-29 23:59:57');
+-- No.10-5-2
+SELECT dbms_stats.restore_column_stats('s0.st0', 'id', '2012-02-29 23:59:57.000002');
+-- No.10-5-3
+SELECT dbms_stats.restore_column_stats('s0.st0', 'id', '2012-01-01 00:00:00');
+--#No.10-5-4 is skipped after lock tests
+-- No.10-5-5
+SELECT dbms_stats.restore_column_stats('s0.st0', 'id', '2012-02-29 23:59:57');
+-- No.10-5-6
+SELECT dbms_stats.restore_column_stats('st0', 'id', '2012-02-29 23:59:57');
+-- No.10-5-7
+SELECT dbms_stats.restore_column_stats('s00.s0', 'id', '2012-02-29 23:59:57');
+
+/*
+ * No.10-6 dbms_stats.restore_column_stats(
+ * schemaname, tablename, attname, as_of_timestamp)
+ */
+-- No.10-6-1
+SELECT dbms_stats.restore_column_stats('s0', 'st0', 'id', '2012-02-29 23:59:57');
+
+/*
+ * No.15-1 dbms_stats.purge_stats
+ */
+-- No.15-1-1
+SELECT * FROM dbms_stats.backup_history;
+BEGIN;
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+SELECT id, unit, comment FROM dbms_stats.purge_stats(2);
+SELECT relation::regclass, mode
+ FROM pg_locks
+ WHERE mode LIKE '%ExclusiveLock%'
+ ORDER BY relation::regclass::text, mode;
+COMMIT;
+SELECT * FROM dbms_stats.backup_history;
+-- No.15-1-6
+SELECT id, unit, comment FROM dbms_stats.purge_stats(NULL);
+-- No.15-1-7
+SELECT id, unit, comment FROM dbms_stats.purge_stats(-1);
+-- No.15-1-8
+SELECT id, unit, comment FROM dbms_stats.purge_stats(2, NULL);
+-- No.15-1-4
+SELECT * FROM dbms_stats.backup_history;
+SELECT id, unit, comment FROM dbms_stats.purge_stats(3);
+SELECT * FROM dbms_stats.backup_history;
+-- No.15-1-5
+SELECT * FROM dbms_stats.backup_history;
+SELECT id, unit, comment FROM dbms_stats.purge_stats(6);
+SELECT * FROM dbms_stats.backup_history;
+-- No.15-1-2
+SELECT * FROM dbms_stats.backup_history;
+SELECT id, unit, comment FROM dbms_stats.purge_stats(8);
+SELECT * FROM dbms_stats.backup_history;
+-- No.15-1-3
+SELECT * FROM dbms_stats.backup_history;
+SELECT id, unit, comment FROM dbms_stats.purge_stats(8, true);
+SELECT * FROM dbms_stats.backup_history;
+
+/*
+ * create backup statistics state A
+ */
+DELETE FROM dbms_stats.backup_history;
+
+INSERT INTO dbms_stats.backup_history(id, time, unit)
+ VALUES (1, '2012-02-29 23:59:56.999999', 'd');
+
+SELECT setval('dbms_stats.backup_history_id_seq',1);
+SELECT dbms_stats.backup();
+UPDATE dbms_stats.backup_history
+ SET time = '2012-02-29 23:59:57'
+ WHERE id = 2;
+SELECT dbms_stats.backup('s0.st0');
+UPDATE dbms_stats.backup_history
+ SET time = '2012-02-29 23:59:57.000001'
+ WHERE id = 3;
+SELECT dbms_stats.backup();
+UPDATE dbms_stats.backup_history
+ SET time = '2012-02-29 23:59:58'
+ WHERE id = 4;
+DELETE FROM dbms_stats.relation_stats_backup
+ WHERE id = 4;
+SELECT dbms_stats.backup('s0.st0', 'id');
+UPDATE dbms_stats.backup_history
+ SET time = '2012-03-01 00:00:00'
+ WHERE id = 5;
+SELECT dbms_stats.backup('s0.st0');
+UPDATE dbms_stats.backup_history
+ SET time = '2012-03-01 00:00:02'
+ WHERE id = 6;
+SELECT dbms_stats.backup('public.st0');
+UPDATE dbms_stats.backup_history
+ SET time = '2012-03-01 00:00:04'
+ WHERE id = 7;
+INSERT INTO dbms_stats.backup_history(time, unit)
+ VALUES ('2012-03-01 00:00:06', 's');
+SELECT dbms_stats.backup(8, c.oid, NULL)
+ FROM pg_catalog.pg_class c,
+ pg_catalog.pg_namespace n
+ WHERE n.nspname = 's0'
+ AND c.relnamespace = n.oid
+ AND c.relkind IN ('r', 'i');
+
+/*
+ * restore test when only backup data does not exist 's0' schema
+ */
+DELETE FROM dbms_stats.column_stats_backup;
+DELETE FROM dbms_stats.relation_stats_backup
+ WHERE relname LIKE 's0.%';
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+-- No.10-2-8
+SELECT dbms_stats.restore_schema_stats('s0', '2012-03-01 00:00:04');
+
+/*
+ * restore test when there are only backup hisotory
+ */
+DELETE FROM dbms_stats.relation_stats_backup;
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+-- No.10-1-5
+SELECT dbms_stats.restore_database_stats('2012-02-29 23:59:58');
+-- No.10-2-5
+SELECT dbms_stats.restore_schema_stats('s0', '2012-02-29 23:59:58');
+/*
+ * restore when Backup does not exist
+ */
+DELETE FROM dbms_stats.backup_history;
+SELECT count(*) FROM dbms_stats.backup_history;
+SELECT count(*) FROM dbms_stats.relation_stats_backup;
+SELECT count(*) FROM dbms_stats.column_stats_backup;
+
+-- No.10-1-4
+SELECT dbms_stats.restore_database_stats('2012-02-29 23:59:57');
+-- No.10-2-4
+SELECT dbms_stats.restore_schema_stats('s0', '2012-02-29 23:59:57');
+-- No.10-3-4
+SELECT dbms_stats.restore_table_stats('s0.st0', '2012-02-29 23:59:57');
+-- No.10-5-4
+SELECT dbms_stats.restore_column_stats('s0.st0', 'id', '2012-02-29 23:59:57');
+
+/*
+ * Delete stab function dbms_stats.restore
+ */
+DROP FUNCTION dbms_stats.restore(int8, regclass, text);
+ALTER FUNCTION dbms_stats.truth_func_restore(int8, regclass, text)
+ RENAME TO restore;
+
+/*
+ * No.18-1 dummy statistics view for general users privileges.
+ */
+\c - regular_user
+-- No.18-1-1
+SELECT count(*) FROM dbms_stats.relation_stats_locked WHERE false;
+-- No.18-1-2
+SELECT count(*) FROM dbms_stats.column_stats_locked WHERE false;
+-- No.18-1-3
+SELECT count(*) FROM dbms_stats.stats WHERE false;
+-- No.18-1-4
+SELECT count(*) FROM dbms_stats._relation_stats_locked WHERE false;
+-- No.18-1-5
+SELECT count(*) FROM dbms_stats._columnns_user WHERE false;
+\c - postgres
+LOAD 'pg_dbms_stats';