diff options
author | Tomas Vondra <tomas.vondra@postgresql.org> | 2019-07-30 19:17:12 +0200 |
---|---|---|
committer | Tomas Vondra <tomas.vondra@postgresql.org> | 2019-07-30 19:48:13 +0200 |
commit | e1947f6c3ed8bda397295f555fa9e3fe39d50143 (patch) | |
tree | a1019ebd9333ab6798a312ee87527de7e65ade9a | |
parent | d933816c04c64326419bbcd89dc17a4e310f950b (diff) | |
download | postgresql-e1947f6c3ed8bda397295f555fa9e3fe39d50143.tar.gz postgresql-e1947f6c3ed8bda397295f555fa9e3fe39d50143.zip |
Don't build extended statistics on inheritance trees
When performing ANALYZE on inheritance trees, we collect two samples for
each relation - one for the relation alone, and one for the inheritance
subtree (relation and its child relations). And then we build statistics
on each sample, so for each relation we get two sets of statistics.
For regular (per-column) statistics this works fine, because the catalog
includes a flag differentiating statistics built from those two samples.
But we don't have such flag in the extended statistics catalogs, and we
ended up updating the same row twice, triggering this error:
ERROR: tuple already updated by self
The simplest solution is to disable extended statistics on inheritance
trees, which is what this commit is doing. In the future we may need to
do something similar to per-column statistics, but that requires adding a
flag to the catalog - and that's not backpatchable. Moreover, the current
selectivity estimation code only works with individual relations, so
building statistics on inheritance trees would be pointless anyway.
Author: Tomas Vondra
Backpatch-to: 10-
Discussion: https://postgr.es/m/20190618231233.GA27470@telsasoft.com
Reported-by: Justin Pryzby
-rw-r--r-- | src/backend/commands/analyze.c | 12 | ||||
-rw-r--r-- | src/test/regress/expected/stats_ext.out | 8 | ||||
-rw-r--r-- | src/test/regress/sql/stats_ext.sql | 8 |
3 files changed, 25 insertions, 3 deletions
diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c index d7004e53138..faabbeb002d 100644 --- a/src/backend/commands/analyze.c +++ b/src/backend/commands/analyze.c @@ -573,9 +573,15 @@ do_analyze_rel(Relation onerel, VacuumParams *params, thisdata->attr_cnt, thisdata->vacattrstats); } - /* Build extended statistics (if there are any). */ - BuildRelationExtStatistics(onerel, totalrows, numrows, rows, attr_cnt, - vacattrstats); + /* + * Build extended statistics (if there are any). + * + * For now we only build extended statistics on individual relations, + * not for relations representing inheritance trees. + */ + if (!inh) + BuildRelationExtStatistics(onerel, totalrows, numrows, rows, + attr_cnt, vacattrstats); } /* diff --git a/src/test/regress/expected/stats_ext.out b/src/test/regress/expected/stats_ext.out index 94b8a8f8b85..d782ebcfeaa 100644 --- a/src/test/regress/expected/stats_ext.out +++ b/src/test/regress/expected/stats_ext.out @@ -103,6 +103,14 @@ ANALYZE ab1 (a); WARNING: statistics object "public.ab1_a_b_stats" could not be computed for relation "public.ab1" ANALYZE ab1; DROP TABLE ab1; +-- Ensure we can build statistics for tables with inheritance. +CREATE TABLE ab1 (a INTEGER, b INTEGER); +CREATE TABLE ab1c () INHERITS (ab1); +INSERT INTO ab1 VALUES (1,1); +CREATE STATISTICS ab1_a_b_stats ON a, b FROM ab1; +ANALYZE ab1; +DROP TABLE ab1 CASCADE; +NOTICE: drop cascades to table ab1c -- Verify supported object types for extended statistics CREATE schema tststats; CREATE TABLE tststats.t (a int, b int, c text); diff --git a/src/test/regress/sql/stats_ext.sql b/src/test/regress/sql/stats_ext.sql index 4bc1536727b..d506e8238c3 100644 --- a/src/test/regress/sql/stats_ext.sql +++ b/src/test/regress/sql/stats_ext.sql @@ -73,6 +73,14 @@ ANALYZE ab1 (a); ANALYZE ab1; DROP TABLE ab1; +-- Ensure we can build statistics for tables with inheritance. +CREATE TABLE ab1 (a INTEGER, b INTEGER); +CREATE TABLE ab1c () INHERITS (ab1); +INSERT INTO ab1 VALUES (1,1); +CREATE STATISTICS ab1_a_b_stats ON a, b FROM ab1; +ANALYZE ab1; +DROP TABLE ab1 CASCADE; + -- Verify supported object types for extended statistics CREATE schema tststats; |