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

Commit8c1144b

Browse files
committed
Avoid believing incomplete MCV-only stats in get_variable_range().
get_variable_range() would incautiously believe that statisticscontaining only an MCV list are sufficient to derive a range estimate.That's okay for an enum-like column that contains only MCVs, butotherwise the estimate could be pretty bad. Make it report that therange is indeterminate unless the MCVs plus nullfrac account forthe whole table.I don't think this needs a dedicated test case, since a quick codecoverage check verifies that the existing regression tests traverseall the alternatives. There is room to doubt that a future-prooftest case could be built anyway, given that the submitted exampleaccidentally doesn't fail before v11.Per bug #17207 from Simon Perepelitsa. Back-patch to v10.In principle this has been broken all along, but I'm hesitant tomake such changes in 9.6, since if anyone is unhappy with 9.6.24'sbehavior there will be no second chance to fix it.Discussion:https://postgr.es/m/17207-5265aefa79e333b4@postgresql.org
1 parent7b5d4c2 commit8c1144b

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

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

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5841,15 +5841,35 @@ get_variable_range(PlannerInfo *root, VariableStatData *vardata,
58415841
/*
58425842
* If we have most-common-values info, look for extreme MCVs. This is
58435843
* needed even if we also have a histogram, since the histogram excludes
5844-
* the MCVs.
5844+
* the MCVs. However, if we *only* have MCVs and no histogram, we should
5845+
* be pretty wary of deciding that that is a full representation of the
5846+
* data. Proceed only if the MCVs represent the whole table (to within
5847+
* roundoff error).
58455848
*/
58465849
if (get_attstatsslot(&sslot,vardata->statsTuple,
58475850
STATISTIC_KIND_MCV,InvalidOid,
5848-
ATTSTATSSLOT_VALUES))
5851+
have_data ?ATTSTATSSLOT_VALUES :
5852+
(ATTSTATSSLOT_VALUES |ATTSTATSSLOT_NUMBERS)))
58495853
{
5850-
get_stats_slot_range(&sslot,opfuncoid,&opproc,
5851-
collation,typLen,typByVal,
5852-
&tmin,&tmax,&have_data);
5854+
booluse_mcvs=have_data;
5855+
5856+
if (!have_data)
5857+
{
5858+
doublesumcommon=0.0;
5859+
doublenullfrac;
5860+
inti;
5861+
5862+
for (i=0;i<sslot.nnumbers;i++)
5863+
sumcommon+=sslot.numbers[i];
5864+
nullfrac= ((Form_pg_statistic)GETSTRUCT(vardata->statsTuple))->stanullfrac;
5865+
if (sumcommon+nullfrac>0.99999)
5866+
use_mcvs= true;
5867+
}
5868+
5869+
if (use_mcvs)
5870+
get_stats_slot_range(&sslot,opfuncoid,&opproc,
5871+
collation,typLen,typByVal,
5872+
&tmin,&tmax,&have_data);
58535873
free_attstatsslot(&sslot);
58545874
}
58555875

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp