Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
e4dd0673
Commit
e4dd0673
authored
Feb 18, 2002
by
Tom Lane
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace number-of-distinct-values estimator equation, per recent
pghackers discussion.
parent
b4a5fa45
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
21 deletions
+45
-21
src/backend/commands/analyze.c
src/backend/commands/analyze.c
+45
-21
No files found.
src/backend/commands/analyze.c
View file @
e4dd0673
...
...
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/analyze.c,v 1.2
5 2002/01/06 00:37:4
4 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/analyze.c,v 1.2
6 2002/02/18 16:04:1
4 tgl Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -1009,10 +1009,15 @@ compute_minimal_stats(VacAttrStats *stats,
{
/*----------
* Estimate the number of distinct values using the estimator
* proposed by Chaudhuri et al (see citation above). This is
* sqrt(n/r) * max(f1,1) + f2 + f3 + ...
* where fk is the number of distinct values that occurred
* exactly k times in our sample of r rows (from a total of n).
* proposed by Haas and Stokes in IBM Research Report RJ 10025:
* n*d / (n - f1 + f1*n/N)
* where f1 is the number of distinct values that occurred
* exactly once in our sample of n rows (from a total of N),
* and d is the total number of distinct values in the sample.
* This is their Duj1 estimator; the other estimators they
* recommend are considerably more complex, and are numerically
* very unstable when n is much smaller than N.
*
* We assume (not very reliably!) that all the multiply-occurring
* values are reflected in the final track[] list, and the other
* nonnull values all appeared but once. (XXX this usually
...
...
@@ -1021,12 +1026,19 @@ compute_minimal_stats(VacAttrStats *stats,
*----------
*/
int
f1
=
nonnull_cnt
-
summultiple
;
double
term1
;
if
(
f1
<
1
)
f1
=
1
;
term1
=
sqrt
(
totalrows
/
(
double
)
numrows
)
*
f1
;
stats
->
stadistinct
=
floor
(
term1
+
nmultiple
+
0
.
5
);
int
d
=
f1
+
nmultiple
;
double
numer
,
denom
,
stadistinct
;
numer
=
(
double
)
numrows
*
(
double
)
d
;
denom
=
(
double
)
(
numrows
-
f1
)
+
(
double
)
f1
*
(
double
)
numrows
/
totalrows
;
stadistinct
=
numer
/
denom
;
/* Clamp to sane range in case of roundoff error */
if
(
stadistinct
<
(
double
)
d
)
stadistinct
=
(
double
)
d
;
if
(
stadistinct
>
totalrows
)
stadistinct
=
totalrows
;
stats
->
stadistinct
=
floor
(
stadistinct
+
0
.
5
);
}
/*
...
...
@@ -1313,20 +1325,32 @@ compute_scalar_stats(VacAttrStats *stats,
{
/*----------
* Estimate the number of distinct values using the estimator
* proposed by Chaudhuri et al (see citation above). This is
* sqrt(n/r) * max(f1,1) + f2 + f3 + ...
* where fk is the number of distinct values that occurred
* exactly k times in our sample of r rows (from a total of n).
* proposed by Haas and Stokes in IBM Research Report RJ 10025:
* n*d / (n - f1 + f1*n/N)
* where f1 is the number of distinct values that occurred
* exactly once in our sample of n rows (from a total of N),
* and d is the total number of distinct values in the sample.
* This is their Duj1 estimator; the other estimators they
* recommend are considerably more complex, and are numerically
* very unstable when n is much smaller than N.
*
* Overwidth values are assumed to have been distinct.
*----------
*/
int
f1
=
ndistinct
-
nmultiple
+
toowide_cnt
;
double
term1
;
if
(
f1
<
1
)
f1
=
1
;
term1
=
sqrt
(
totalrows
/
(
double
)
numrows
)
*
f1
;
stats
->
stadistinct
=
floor
(
term1
+
nmultiple
+
0
.
5
);
int
d
=
f1
+
nmultiple
;
double
numer
,
denom
,
stadistinct
;
numer
=
(
double
)
numrows
*
(
double
)
d
;
denom
=
(
double
)
(
numrows
-
f1
)
+
(
double
)
f1
*
(
double
)
numrows
/
totalrows
;
stadistinct
=
numer
/
denom
;
/* Clamp to sane range in case of roundoff error */
if
(
stadistinct
<
(
double
)
d
)
stadistinct
=
(
double
)
d
;
if
(
stadistinct
>
totalrows
)
stadistinct
=
totalrows
;
stats
->
stadistinct
=
floor
(
stadistinct
+
0
.
5
);
}
/*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment