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

Commit14ef15a

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 parent04cf0bf commit14ef15a

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
@@ -574,9 +574,15 @@ do_analyze_rel(Relation onerel, VacuumParams *params,
574574
thisdata->attr_cnt,thisdata->vacattrstats);
575575
}
576576

577-
/* Build extended statistics (if there are any). */
578-
BuildRelationExtStatistics(onerel,totalrows,numrows,rows,attr_cnt,
579-
vacattrstats);
577+
/*
578+
* Build extended statistics (if there are any).
579+
*
580+
* For now we only build extended statistics on individual relations,
581+
* not for relations representing inheritance trees.
582+
*/
583+
if (!inh)
584+
BuildRelationExtStatistics(onerel,totalrows,numrows,rows,
585+
attr_cnt,vacattrstats);
580586
}
581587

582588
/*

‎src/test/regress/expected/stats_ext.out

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,14 @@ ANALYZE ab1 (a);
103103
WARNING: statistics object "public.ab1_a_b_stats" could not be computed for relation "public.ab1"
104104
ANALYZE ab1;
105105
DROP TABLE ab1;
106+
-- Ensure we can build statistics for tables with inheritance.
107+
CREATE TABLE ab1 (a INTEGER, b INTEGER);
108+
CREATE TABLE ab1c () INHERITS (ab1);
109+
INSERT INTO ab1 VALUES (1,1);
110+
CREATE STATISTICS ab1_a_b_stats ON a, b FROM ab1;
111+
ANALYZE ab1;
112+
DROP TABLE ab1 CASCADE;
113+
NOTICE: drop cascades to table ab1c
106114
-- Verify supported object types for extended statistics
107115
CREATE schema tststats;
108116
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
@@ -73,6 +73,14 @@ ANALYZE ab1 (a);
7373
ANALYZE ab1;
7474
DROPTABLE ab1;
7575

76+
-- Ensure we can build statistics for tables with inheritance.
77+
CREATETABLEab1 (aINTEGER, bINTEGER);
78+
CREATETABLEab1c () INHERITS (ab1);
79+
INSERT INTO ab1VALUES (1,1);
80+
CREATE STATISTICS ab1_a_b_statsON a, bFROM ab1;
81+
ANALYZE ab1;
82+
DROPTABLE ab1 CASCADE;
83+
7684
-- Verify supported object types for extended statistics
7785
CREATEschematststats;
7886

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp