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

Commit0b0f281

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 parent4be69e2 commit0b0f281

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3757,14 +3757,19 @@ estimate_multivariate_ndistinct(PlannerInfo *root, RelOptInfo *rel,
37573757
foreach(lc,*varinfos)
37583758
{
37593759
GroupVarInfo*varinfo= (GroupVarInfo*)lfirst(lc);
3760+
AttrNumberattnum;
37603761

37613762
Assert(varinfo->rel==rel);
37623763

3763-
if (IsA(varinfo->var,Var))
3764-
{
3765-
attnums=bms_add_member(attnums,
3766-
((Var*)varinfo->var)->varattno);
3767-
}
3764+
if (!IsA(varinfo->var,Var))
3765+
continue;
3766+
3767+
attnum= ((Var*)varinfo->var)->varattno;
3768+
3769+
if (!AttrNumberIsForUserDefinedAttr(attnum))
3770+
continue;
3771+
3772+
attnums=bms_add_member(attnums,attnum);
37683773
}
37693774

37703775
/* look for the ndistinct statistics matching the most vars */
@@ -3844,6 +3849,10 @@ estimate_multivariate_ndistinct(PlannerInfo *root, RelOptInfo *rel,
38443849
}
38453850

38463851
attnum= ((Var*)varinfo->var)->varattno;
3852+
3853+
if (!AttrNumberIsForUserDefinedAttr(attnum))
3854+
continue;
3855+
38473856
if (!bms_is_member(attnum,matched))
38483857
newlist=lappend(newlist,varinfo);
38493858
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,18 @@ SELECT stxkind, stxndistinct
217217
{d,f} | {"3, 4": 301, "3, 6": 301, "4, 6": 301, "3, 4, 6": 301}
218218
(1 row)
219219

220+
-- minor improvement, make sure the ctid does not break the matching
221+
EXPLAIN (COSTS off)
222+
SELECT COUNT(*) FROM ndistinct GROUP BY ctid, a, b;
223+
QUERY PLAN
224+
-----------------------------------
225+
GroupAggregate
226+
Group Key: ctid, a, b
227+
-> Sort
228+
Sort Key: ctid, a, b
229+
-> Seq Scan on ndistinct
230+
(5 rows)
231+
220232
-- Hash Aggregate, thanks to estimates improved by the statistic
221233
EXPLAIN (COSTS off)
222234
SELECT COUNT(*) FROM ndistinct GROUP BY a, b;

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ ANALYZE ndistinct;
144144
SELECT stxkind, stxndistinct
145145
FROM pg_statistic_extWHERE stxrelid='ndistinct'::regclass;
146146

147+
-- minor improvement, make sure the ctid does not break the matching
148+
EXPLAIN (COSTS off)
149+
SELECTCOUNT(*)FROM ndistinctGROUP BY ctid, a, b;
150+
147151
-- Hash Aggregate, thanks to estimates improved by the statistic
148152
EXPLAIN (COSTS off)
149153
SELECTCOUNT(*)FROM ndistinctGROUP BY a, b;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp