Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 859b300

Browse files
committed
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
1 parent af41ab5 commit 859b300

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

src/backend/commands/analyze.c

+9-3
Original file line numberDiff line numberDiff line change
@@ -589,9 +589,15 @@ do_analyze_rel(Relation onerel, int options, VacuumParams *params,
589589
thisdata->attr_cnt, thisdata->vacattrstats);
590590
}
591591

592-
/* Build extended statistics (if there are any). */
593-
BuildRelationExtStatistics(onerel, totalrows, numrows, rows, attr_cnt,
594-
vacattrstats);
592+
/*
593+
* Build extended statistics (if there are any).
594+
*
595+
* For now we only build extended statistics on individual relations,
596+
* not for relations representing inheritance trees.
597+
*/
598+
if (!inh)
599+
BuildRelationExtStatistics(onerel, totalrows, numrows, rows,
600+
attr_cnt, vacattrstats);
595601
}
596602

597603
/*

src/test/regress/expected/stats_ext.out

+8
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ ANALYZE ab1 (a);
8686
WARNING: statistics object "public.ab1_a_b_stats" could not be computed for relation "public.ab1"
8787
ANALYZE ab1;
8888
DROP TABLE ab1;
89+
-- Ensure we can build statistics for tables with inheritance.
90+
CREATE TABLE ab1 (a INTEGER, b INTEGER);
91+
CREATE TABLE ab1c () INHERITS (ab1);
92+
INSERT INTO ab1 VALUES (1,1);
93+
CREATE STATISTICS ab1_a_b_stats ON a, b FROM ab1;
94+
ANALYZE ab1;
95+
DROP TABLE ab1 CASCADE;
96+
NOTICE: drop cascades to table ab1c
8997
-- Verify supported object types for extended statistics
9098
CREATE schema tststats;
9199
CREATE TABLE tststats.t (a int, b int, c text);

src/test/regress/sql/stats_ext.sql

+8
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ ANALYZE ab1 (a);
5555
ANALYZE ab1;
5656
DROP TABLE ab1;
5757

58+
-- Ensure we can build statistics for tables with inheritance.
59+
CREATE TABLE ab1 (a INTEGER, b INTEGER);
60+
CREATE TABLE ab1c () INHERITS (ab1);
61+
INSERT INTO ab1 VALUES (1,1);
62+
CREATE STATISTICS ab1_a_b_stats ON a, b FROM ab1;
63+
ANALYZE ab1;
64+
DROP TABLE ab1 CASCADE;
65+
5866
-- Verify supported object types for extended statistics
5967
CREATE schema tststats;
6068

0 commit comments

Comments
 (0)