Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit859b300

Browse files
committed
Don't build extended statistics on inheritance trees
When performing ANALYZE on inheritance trees, we collect two samples foreach relation - one for the relation alone, and one for the inheritancesubtree (relation and its child relations). And then we build statisticson each sample, so for each relation we get two sets of statistics.For regular (per-column) statistics this works fine, because the catalogincludes a flag differentiating statistics built from those two samples.But we don't have such flag in the extended statistics catalogs, and weended up updating the same row twice, triggering this error: ERROR: tuple already updated by selfThe simplest solution is to disable extended statistics on inheritancetrees, which is what this commit is doing. In the future we may need todo something similar to per-column statistics, but that requires adding aflag to the catalog - and that's not backpatchable. Moreover, the currentselectivity estimation code only works with individual relations, sobuilding statistics on inheritance trees would be pointless anyway.Author: Tomas VondraBackpatch-to: 10-Discussion:https://postgr.es/m/20190618231233.GA27470@telsasoft.comReported-by: Justin Pryzby
1 parentaf41ab5 commit859b300

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

‎src/backend/commands/analyze.c

Lines changed: 9 additions & 3 deletions
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

Lines changed: 8 additions & 0 deletions
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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ ANALYZE ab1 (a);
5555
ANALYZE ab1;
5656
DROPTABLE ab1;
5757

58+
-- Ensure we can build statistics for tables with inheritance.
59+
CREATETABLEab1 (aINTEGER, bINTEGER);
60+
CREATETABLEab1c () INHERITS (ab1);
61+
INSERT INTO ab1VALUES (1,1);
62+
CREATE STATISTICS ab1_a_b_statsON a, bFROM ab1;
63+
ANALYZE ab1;
64+
DROPTABLE ab1 CASCADE;
65+
5866
-- Verify supported object types for extended statistics
5967
CREATEschematststats;
6068

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp