diff options
author | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2017-04-17 17:55:17 -0300 |
---|---|---|
committer | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2017-04-17 17:55:55 -0300 |
commit | 8c5cdb7f4f6e1d6a6104cb58ce4f23453891651b (patch) | |
tree | 25a5dfbae4b5d274b17cdb592ad120e36469c06e /src/test | |
parent | 76799fc89d2ca6f357c188daa4e1b38f0a59e360 (diff) | |
download | postgresql-8c5cdb7f4f6e1d6a6104cb58ce4f23453891651b.tar.gz postgresql-8c5cdb7f4f6e1d6a6104cb58ce4f23453891651b.zip |
Tighten up relation kind checks for extended statistics
We were accepting creation of extended statistics only for regular
tables, but they can usefully be created for foreign tables, partitioned
tables, and materialized views, too. Allow those cases.
While at it, make sure all the rejected cases throw a consistent error
message, and add regression tests for the whole thing.
Author: David Rowley, Álvaro Herrera
Discussion: https://postgr.es/m/CAKJS1f-BmGo410bh5RSPZUvOO0LhmHL2NYmdrC_Jm8pk_FfyCA@mail.gmail.com
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/regress/expected/stats_ext.out | 40 | ||||
-rw-r--r-- | src/test/regress/sql/stats_ext.sql | 38 |
2 files changed, 78 insertions, 0 deletions
diff --git a/src/test/regress/expected/stats_ext.out b/src/test/regress/expected/stats_ext.out index 6a3345548a2..658d2857695 100644 --- a/src/test/regress/expected/stats_ext.out +++ b/src/test/regress/expected/stats_ext.out @@ -47,6 +47,46 @@ ANALYZE ab1 (a); WARNING: extended statistics "public.ab1_a_b_stats" could not be collected for relation public.ab1 ANALYZE ab1; DROP TABLE ab1; +-- Verify supported object types for extended statistics +CREATE schema tststats; +CREATE TABLE tststats.t (a int, b int, c text); +CREATE INDEX ti ON tststats.t (a, b); +CREATE SEQUENCE tststats.s; +CREATE VIEW tststats.v AS SELECT * FROM tststats.t; +CREATE MATERIALIZED VIEW tststats.mv AS SELECT * FROM tststats.t; +CREATE TYPE tststats.ty AS (a int, b int, c text); +CREATE FOREIGN DATA WRAPPER extstats_dummy_fdw; +CREATE SERVER extstats_dummy_srv FOREIGN DATA WRAPPER extstats_dummy_fdw; +CREATE FOREIGN TABLE tststats.f (a int, b int, c text) SERVER extstats_dummy_srv; +CREATE TABLE tststats.pt (a int, b int, c text) PARTITION BY RANGE (a, b); +CREATE TABLE tststats.pt1 PARTITION OF tststats.pt FOR VALUES FROM (-10, -10) TO (10, 10); +CREATE STATISTICS tststats.s1 ON (a, b) FROM tststats.t; +CREATE STATISTICS tststats.s2 ON (a, b) FROM tststats.ti; +ERROR: relation "ti" is not a table, foreign table, or materialized view +CREATE STATISTICS tststats.s3 ON (a, b) FROM tststats.s; +ERROR: relation "s" is not a table, foreign table, or materialized view +CREATE STATISTICS tststats.s4 ON (a, b) FROM tststats.v; +ERROR: relation "v" is not a table, foreign table, or materialized view +CREATE STATISTICS tststats.s5 ON (a, b) FROM tststats.mv; +CREATE STATISTICS tststats.s6 ON (a, b) FROM tststats.ty; +ERROR: relation "ty" is not a table, foreign table, or materialized view +CREATE STATISTICS tststats.s7 ON (a, b) FROM tststats.f; +CREATE STATISTICS tststats.s8 ON (a, b) FROM tststats.pt; +CREATE STATISTICS tststats.s9 ON (a, b) FROM tststats.pt1; +DO $$ +DECLARE + relname text := reltoastrelid::regclass FROM pg_class WHERE oid = 'tststats.t'::regclass; +BEGIN + EXECUTE 'CREATE STATISTICS tststats.s10 ON (a, b) FROM ' || relname; +EXCEPTION WHEN wrong_object_type THEN + RAISE NOTICE 'stats on toast table not created'; +END; +$$; +NOTICE: stats on toast table not created +SET client_min_messages TO warning; +DROP SCHEMA tststats CASCADE; +DROP FOREIGN DATA WRAPPER extstats_dummy_fdw CASCADE; +RESET client_min_messages; -- n-distinct tests CREATE TABLE ndistinct ( filler1 TEXT, diff --git a/src/test/regress/sql/stats_ext.sql b/src/test/regress/sql/stats_ext.sql index ebb6a78383e..3c7e0684d3e 100644 --- a/src/test/regress/sql/stats_ext.sql +++ b/src/test/regress/sql/stats_ext.sql @@ -40,6 +40,44 @@ ANALYZE ab1 (a); ANALYZE ab1; DROP TABLE ab1; +-- Verify supported object types for extended statistics +CREATE schema tststats; + +CREATE TABLE tststats.t (a int, b int, c text); +CREATE INDEX ti ON tststats.t (a, b); +CREATE SEQUENCE tststats.s; +CREATE VIEW tststats.v AS SELECT * FROM tststats.t; +CREATE MATERIALIZED VIEW tststats.mv AS SELECT * FROM tststats.t; +CREATE TYPE tststats.ty AS (a int, b int, c text); +CREATE FOREIGN DATA WRAPPER extstats_dummy_fdw; +CREATE SERVER extstats_dummy_srv FOREIGN DATA WRAPPER extstats_dummy_fdw; +CREATE FOREIGN TABLE tststats.f (a int, b int, c text) SERVER extstats_dummy_srv; +CREATE TABLE tststats.pt (a int, b int, c text) PARTITION BY RANGE (a, b); +CREATE TABLE tststats.pt1 PARTITION OF tststats.pt FOR VALUES FROM (-10, -10) TO (10, 10); + +CREATE STATISTICS tststats.s1 ON (a, b) FROM tststats.t; +CREATE STATISTICS tststats.s2 ON (a, b) FROM tststats.ti; +CREATE STATISTICS tststats.s3 ON (a, b) FROM tststats.s; +CREATE STATISTICS tststats.s4 ON (a, b) FROM tststats.v; +CREATE STATISTICS tststats.s5 ON (a, b) FROM tststats.mv; +CREATE STATISTICS tststats.s6 ON (a, b) FROM tststats.ty; +CREATE STATISTICS tststats.s7 ON (a, b) FROM tststats.f; +CREATE STATISTICS tststats.s8 ON (a, b) FROM tststats.pt; +CREATE STATISTICS tststats.s9 ON (a, b) FROM tststats.pt1; +DO $$ +DECLARE + relname text := reltoastrelid::regclass FROM pg_class WHERE oid = 'tststats.t'::regclass; +BEGIN + EXECUTE 'CREATE STATISTICS tststats.s10 ON (a, b) FROM ' || relname; +EXCEPTION WHEN wrong_object_type THEN + RAISE NOTICE 'stats on toast table not created'; +END; +$$; + +SET client_min_messages TO warning; +DROP SCHEMA tststats CASCADE; +DROP FOREIGN DATA WRAPPER extstats_dummy_fdw CASCADE; +RESET client_min_messages; -- n-distinct tests CREATE TABLE ndistinct ( |