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

Commit33e52ad

Browse files
committed
Fix ndistinct estimates with system attributes
When estimating the number of groups using extended statistics, the codewas discarding information about system attributes. This led to strangesituation that SELECT 1 FROM t GROUP BY ctid;could have produced higher estimate (equal to pg_class.reltuples) than SELECT 1 FROM t GROUP BY a, b, ctid;with extended statistics on (a,b). Fixed by retaining information aboutthe system attribute.Backpatch all the way to 10, where extended statistics were introduced.Author: Tomas VondraBackpatch-through: 10
1 parenta14a011 commit33e52ad

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

‎src/backend/utils/adt/selfuncs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3987,11 +3987,11 @@ estimate_multivariate_ndistinct(PlannerInfo *root, RelOptInfo *rel,
39873987

39883988
attnum= ((Var*)varinfo->var)->varattno;
39893989

3990-
if (!AttrNumberIsForUserDefinedAttr(attnum))
3990+
if (AttrNumberIsForUserDefinedAttr(attnum)&&
3991+
bms_is_member(attnum,matched))
39913992
continue;
39923993

3993-
if (!bms_is_member(attnum,matched))
3994-
newlist=lappend(newlist,varinfo);
3994+
newlist=lappend(newlist,varinfo);
39953995
}
39963996

39973997
*varinfos=newlist;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ SELECT s.stxkind, d.stxdndistinct
260260
SELECT * FROM check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY ctid, a, b');
261261
estimated | actual
262262
-----------+--------
263-
11 | 1000
263+
1000 | 1000
264264
(1 row)
265265

266266
-- Hash Aggregate, thanks to estimates improved by the statistic

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp