Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
postgres-lambda-diff
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jakob Huber
postgres-lambda-diff
Commits
e4dd0673
Commit
e4dd0673
authored
23 years ago
by
Tom Lane
Browse files
Options
Downloads
Patches
Plain Diff
Replace number-of-distinct-values estimator equation, per recent
pghackers discussion.
parent
b4a5fa45
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/backend/commands/analyze.c
+45
-21
45 additions, 21 deletions
src/backend/commands/analyze.c
with
45 additions
and
21 deletions
src/backend/commands/analyze.c
+
45
−
21
View file @
e4dd0673
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/analyze.c,v 1.2
5
2002/0
1/06 00:37:4
4 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/analyze.c,v 1.2
6
2002/0
2/18 16:04:1
4 tgl Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -1009,10 +1009,15 @@ compute_minimal_stats(VacAttrStats *stats,
...
@@ -1009,10 +1009,15 @@ compute_minimal_stats(VacAttrStats *stats,
{
{
/*----------
/*----------
* Estimate the number of distinct values using the estimator
* Estimate the number of distinct values using the estimator
* proposed by Chaudhuri et al (see citation above). This is
* proposed by Haas and Stokes in IBM Research Report RJ 10025:
* sqrt(n/r) * max(f1,1) + f2 + f3 + ...
* n*d / (n - f1 + f1*n/N)
* where fk is the number of distinct values that occurred
* where f1 is the number of distinct values that occurred
* exactly k times in our sample of r rows (from a total of n).
* 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
* We assume (not very reliably!) that all the multiply-occurring
* values are reflected in the final track[] list, and the other
* values are reflected in the final track[] list, and the other
* nonnull values all appeared but once. (XXX this usually
* nonnull values all appeared but once. (XXX this usually
...
@@ -1021,12 +1026,19 @@ compute_minimal_stats(VacAttrStats *stats,
...
@@ -1021,12 +1026,19 @@ compute_minimal_stats(VacAttrStats *stats,
*----------
*----------
*/
*/
int
f1
=
nonnull_cnt
-
summultiple
;
int
f1
=
nonnull_cnt
-
summultiple
;
double
term1
;
int
d
=
f1
+
nmultiple
;
double
numer
,
denom
,
stadistinct
;
if
(
f1
<
1
)
f1
=
1
;
numer
=
(
double
)
numrows
*
(
double
)
d
;
term1
=
sqrt
(
totalrows
/
(
double
)
numrows
)
*
f1
;
denom
=
(
double
)
(
numrows
-
f1
)
+
stats
->
stadistinct
=
floor
(
term1
+
nmultiple
+
0
.
5
);
(
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,
...
@@ -1313,20 +1325,32 @@ compute_scalar_stats(VacAttrStats *stats,
{
{
/*----------
/*----------
* Estimate the number of distinct values using the estimator
* Estimate the number of distinct values using the estimator
* proposed by Chaudhuri et al (see citation above). This is
* proposed by Haas and Stokes in IBM Research Report RJ 10025:
* sqrt(n/r) * max(f1,1) + f2 + f3 + ...
* n*d / (n - f1 + f1*n/N)
* where fk is the number of distinct values that occurred
* where f1 is the number of distinct values that occurred
* exactly k times in our sample of r rows (from a total of n).
* 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.
* Overwidth values are assumed to have been distinct.
*----------
*----------
*/
*/
int
f1
=
ndistinct
-
nmultiple
+
toowide_cnt
;
int
f1
=
ndistinct
-
nmultiple
+
toowide_cnt
;
double
term1
;
int
d
=
f1
+
nmultiple
;
double
numer
,
denom
,
stadistinct
;
if
(
f1
<
1
)
f1
=
1
;
numer
=
(
double
)
numrows
*
(
double
)
d
;
term1
=
sqrt
(
totalrows
/
(
double
)
numrows
)
*
f1
;
denom
=
(
double
)
(
numrows
-
f1
)
+
stats
->
stadistinct
=
floor
(
term1
+
nmultiple
+
0
.
5
);
(
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
);
}
}
/*
/*
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment