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

Commitd482f7f

Browse files
committed
Skip system attributes when applying mvdistinct stats
When estimating number of distinct groups, we failed to ignore systemattributes when matching the group expressions to mvdistinct stats,causing failures like ERROR: negative bitmapset member not allowedFix that by simply skipping anything that is not a regular attribute.Backpatch to PostgreSQL 10, where the extended stats were introduced.Bug: #16111Reported-by: Tuomas LeikolaAuthor: Tomas VondraBackpatch-through: 10Discussion:https://postgr.es/m/16111-687799584c3a7e73@postgresql.org
1 parent76cbfcd commitd482f7f

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3582,14 +3582,19 @@ estimate_multivariate_ndistinct(PlannerInfo *root, RelOptInfo *rel,
35823582
foreach(lc,*varinfos)
35833583
{
35843584
GroupVarInfo*varinfo= (GroupVarInfo*)lfirst(lc);
3585+
AttrNumberattnum;
35853586

35863587
Assert(varinfo->rel==rel);
35873588

3588-
if (IsA(varinfo->var,Var))
3589-
{
3590-
attnums=bms_add_member(attnums,
3591-
((Var*)varinfo->var)->varattno);
3592-
}
3589+
if (!IsA(varinfo->var,Var))
3590+
continue;
3591+
3592+
attnum= ((Var*)varinfo->var)->varattno;
3593+
3594+
if (!AttrNumberIsForUserDefinedAttr(attnum))
3595+
continue;
3596+
3597+
attnums=bms_add_member(attnums,attnum);
35933598
}
35943599

35953600
/* look for the ndistinct statistics matching the most vars */
@@ -3669,6 +3674,10 @@ estimate_multivariate_ndistinct(PlannerInfo *root, RelOptInfo *rel,
36693674
}
36703675

36713676
attnum= ((Var*)varinfo->var)->varattno;
3677+
3678+
if (!AttrNumberIsForUserDefinedAttr(attnum))
3679+
continue;
3680+
36723681
if (!bms_is_member(attnum,matched))
36733682
newlist=lappend(newlist,varinfo);
36743683
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,13 @@ SELECT s.stxkind, d.stxdndistinct
233233
{d,f,m} | {"3, 4": 11, "3, 6": 11, "4, 6": 11, "3, 4, 6": 11}
234234
(1 row)
235235

236+
-- minor improvement, make sure the ctid does not break the matching
237+
SELECT * FROM check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY ctid, a, b');
238+
estimated | actual
239+
-----------+--------
240+
11 | 1000
241+
(1 row)
242+
236243
-- Hash Aggregate, thanks to estimates improved by the statistic
237244
SELECT * FROM check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b');
238245
estimated | actual

‎src/test/regress/sql/stats_ext.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ SELECT s.stxkind, d.stxdndistinct
167167
WHEREs.stxrelid='ndistinct'::regclass
168168
ANDd.stxoid=s.oid;
169169

170+
-- minor improvement, make sure the ctid does not break the matching
171+
SELECT*FROM check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY ctid, a, b');
172+
170173
-- Hash Aggregate, thanks to estimates improved by the statistic
171174
SELECT*FROM check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b');
172175

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp