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
c4d0ff32
Commit
c4d0ff32
authored
Jan 22, 2003
by
Tom Lane
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make estimation of mergejoin scan selectivities more robust, per recent
example from RaÇl GutiÅrrez.
parent
c7b40472
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
11 deletions
+41
-11
src/backend/optimizer/path/costsize.c
src/backend/optimizer/path/costsize.c
+15
-1
src/backend/utils/adt/selfuncs.c
src/backend/utils/adt/selfuncs.c
+26
-10
No files found.
src/backend/optimizer/path/costsize.c
View file @
c4d0ff32
...
@@ -42,7 +42,7 @@
...
@@ -42,7 +42,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.10
1 2003/01/20 18:54:49
tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.10
2 2003/01/22 20:16:40
tgl Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -791,8 +791,22 @@ cost_mergejoin(Path *path, Query *root,
...
@@ -791,8 +791,22 @@ cost_mergejoin(Path *path, Query *root,
innerscansel
=
firstclause
->
left_mergescansel
;
innerscansel
=
firstclause
->
left_mergescansel
;
}
}
/* convert selectivity to row count; must scan at least one row */
outer_rows
=
ceil
(
outer_path
->
parent
->
rows
*
outerscansel
);
outer_rows
=
ceil
(
outer_path
->
parent
->
rows
*
outerscansel
);
if
(
outer_rows
<
1
)
outer_rows
=
1
;
inner_rows
=
ceil
(
inner_path
->
parent
->
rows
*
innerscansel
);
inner_rows
=
ceil
(
inner_path
->
parent
->
rows
*
innerscansel
);
if
(
inner_rows
<
1
)
inner_rows
=
1
;
/*
* Readjust scan selectivities to account for above rounding. This is
* normally an insignificant effect, but when there are only a few rows
* in the inputs, failing to do this makes for a large percentage error.
*/
outerscansel
=
outer_rows
/
outer_path
->
parent
->
rows
;
innerscansel
=
inner_rows
/
inner_path
->
parent
->
rows
;
/* cost of source data */
/* cost of source data */
...
...
src/backend/utils/adt/selfuncs.c
View file @
c4d0ff32
...
@@ -15,7 +15,7 @@
...
@@ -15,7 +15,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.12
7 2003/01/20 18:54:59
tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.12
8 2003/01/22 20:16:42
tgl Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -1742,7 +1742,9 @@ mergejoinscansel(Query *root, Node *clause,
...
@@ -1742,7 +1742,9 @@ mergejoinscansel(Query *root, Node *clause,
rsortop
,
rsortop
,
ltop
,
ltop
,
gtop
,
gtop
,
revltop
;
leop
,
revgtop
,
revleop
;
Datum
leftmax
,
Datum
leftmax
,
rightmax
;
rightmax
;
double
selec
;
double
selec
;
...
@@ -1780,35 +1782,49 @@ mergejoinscansel(Query *root, Node *clause,
...
@@ -1780,35 +1782,49 @@ mergejoinscansel(Query *root, Node *clause,
/* Look up the "left < right" and "left > right" operators */
/* Look up the "left < right" and "left > right" operators */
op_mergejoin_crossops
(
opno
,
&
ltop
,
&
gtop
,
NULL
,
NULL
);
op_mergejoin_crossops
(
opno
,
&
ltop
,
&
gtop
,
NULL
,
NULL
);
/* Look up the "right < left" operator */
/* Look up the "left <= right" operator */
revltop
=
get_commutator
(
gtop
);
leop
=
get_negator
(
gtop
);
if
(
!
OidIsValid
(
revltop
))
if
(
!
OidIsValid
(
leop
))
return
;
/* shouldn't happen */
return
;
/* insufficient info in catalogs */
/* Look up the "right > left" operator */
revgtop
=
get_commutator
(
ltop
);
if
(
!
OidIsValid
(
revgtop
))
return
;
/* insufficient info in catalogs */
/* Look up the "right <= left" operator */
revleop
=
get_negator
(
revgtop
);
if
(
!
OidIsValid
(
revleop
))
return
;
/* insufficient info in catalogs */
/*
/*
* Now, the fraction of the left variable that will be scanned is the
* Now, the fraction of the left variable that will be scanned is the
* fraction that's <= the right-side maximum value. But only believe
* fraction that's <= the right-side maximum value. But only believe
* non-default estimates, else stick with our 1.0.
* non-default estimates, else stick with our 1.0.
*/
*/
selec
=
scalarineqsel
(
root
,
l
t
op
,
false
,
left
,
selec
=
scalarineqsel
(
root
,
l
e
op
,
false
,
left
,
rightmax
,
right
->
vartype
);
rightmax
,
right
->
vartype
);
if
(
selec
!=
DEFAULT_INEQ_SEL
)
if
(
selec
!=
DEFAULT_INEQ_SEL
)
*
leftscan
=
selec
;
*
leftscan
=
selec
;
/* And similarly for the right variable. */
/* And similarly for the right variable. */
selec
=
scalarineqsel
(
root
,
revl
t
op
,
false
,
right
,
selec
=
scalarineqsel
(
root
,
revl
e
op
,
false
,
right
,
leftmax
,
left
->
vartype
);
leftmax
,
left
->
vartype
);
if
(
selec
!=
DEFAULT_INEQ_SEL
)
if
(
selec
!=
DEFAULT_INEQ_SEL
)
*
rightscan
=
selec
;
*
rightscan
=
selec
;
/*
/*
* Only one of the two fractions can really be less than 1.0; believe
* Only one of the two fractions can really be less than 1.0; believe
* the smaller estimate and reset the other one to exactly 1.0.
* the smaller estimate and reset the other one to exactly 1.0. If we
* get exactly equal estimates (as can easily happen with self-joins),
* believe neither.
*/
*/
if
(
*
leftscan
>
*
rightscan
)
if
(
*
leftscan
>
*
rightscan
)
*
leftscan
=
1
.
0
;
*
leftscan
=
1
.
0
;
else
else
if
(
*
leftscan
<
*
rightscan
)
*
rightscan
=
1
.
0
;
*
rightscan
=
1
.
0
;
else
*
leftscan
=
*
rightscan
=
1
.
0
;
}
}
/*
/*
...
...
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