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

Commitb32a25c

Browse files
committed
Fix booltestsel() for case where we have NULL stats but not MCV stats.
In a boolean column that contains mostly nulls, ANALYZE might not findenough non-null values to populate the most-common-values stats,but it would still create a pg_statistic entry with stanullfrac set.The logic in booltestsel() for this situation did the wrong thing for"col IS NOT TRUE" and "col IS NOT FALSE" tests, forgetting that nullvalues would satisfy these tests (so that the true selectivity wouldbe close to one, not close to zero). Per bug #8274.Fix by Andrew Gierth, some comment-smithing by me.
1 parent10a509d commitb32a25c

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,31 +1529,29 @@ booltestsel(PlannerInfo *root, BoolTestType booltesttype, Node *arg,
15291529
/*
15301530
* No most-common-value info available. Still have null fraction
15311531
* information, so use it for IS [NOT] UNKNOWN. Otherwise adjust
1532-
* for null fraction and assumean even splitfor boolean tests.
1532+
* for null fraction and assumea 50-50 splitof TRUE and FALSE.
15331533
*/
15341534
switch (booltesttype)
15351535
{
15361536
caseIS_UNKNOWN:
1537-
1538-
/*
1539-
* Use freq_null directly.
1540-
*/
1537+
/* select only NULL values */
15411538
selec=freq_null;
15421539
break;
15431540
caseIS_NOT_UNKNOWN:
1544-
1545-
/*
1546-
* Select not unknown (not null) values. Calculate from
1547-
* freq_null.
1548-
*/
1541+
/* select non-NULL values */
15491542
selec=1.0-freq_null;
15501543
break;
15511544
caseIS_TRUE:
1552-
caseIS_NOT_TRUE:
15531545
caseIS_FALSE:
1554-
caseIS_NOT_FALSE:
1546+
/* Assume we select half of the non-NULL values */
15551547
selec= (1.0-freq_null) /2.0;
15561548
break;
1549+
caseIS_NOT_TRUE:
1550+
caseIS_NOT_FALSE:
1551+
/* Assume we select NULLs plus half of the non-NULLs */
1552+
/* equiv. to freq_null + (1.0 - freq_null) / 2.0 */
1553+
selec= (freq_null+1.0) /2.0;
1554+
break;
15571555
default:
15581556
elog(ERROR,"unrecognized booltesttype: %d",
15591557
(int)booltesttype);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp