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
2ef99ee7
Commit
2ef99ee7
authored
Apr 01, 2001
by
Tom Lane
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Planner wasn't correctly handling adjustment of tuple_fraction for the
case of LIMIT in a sub-select.
parent
7db692ce
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
102 additions
and
58 deletions
+102
-58
src/backend/optimizer/plan/planner.c
src/backend/optimizer/plan/planner.c
+102
-58
No files found.
src/backend/optimizer/plan/planner.c
View file @
2ef99ee7
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.10
2 2001/03/22 03:59:37 momjian
Exp $
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.10
3 2001/04/01 22:37:19 tgl
Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -874,9 +874,9 @@ grouping_planner(Query *parse, double tuple_fraction)
...
@@ -874,9 +874,9 @@ grouping_planner(Query *parse, double tuple_fraction)
/*
/*
* Figure out whether we expect to retrieve all the tuples that
* Figure out whether we expect to retrieve all the tuples that
* the plan can generate, or to stop early due to
a LIMIT or other
* the plan can generate, or to stop early due to
outside factors
*
factors. If the caller passed a value >= 0, believe that
*
such as a cursor. If the caller passed a value >= 0, believe
* value, else do our own examination of the query context.
*
that
value, else do our own examination of the query context.
*/
*/
if
(
tuple_fraction
<
0
.
0
)
if
(
tuple_fraction
<
0
.
0
)
{
{
...
@@ -884,74 +884,118 @@ grouping_planner(Query *parse, double tuple_fraction)
...
@@ -884,74 +884,118 @@ grouping_planner(Query *parse, double tuple_fraction)
tuple_fraction
=
0
.
0
;
tuple_fraction
=
0
.
0
;
/*
/*
* Check for a LIMIT clause.
* Check for retrieve-into-portal, ie DECLARE CURSOR.
*
* We have no real idea how many tuples the user will ultimately
* FETCH from a cursor, but it seems a good bet that he
* doesn't want 'em all. Optimize for 10% retrieval (you
* gotta better number? Should this be a SETtable parameter?)
*/
if
(
parse
->
isPortal
)
tuple_fraction
=
0
.
10
;
}
/*
* Adjust tuple_fraction if we see that we are going to apply
* limiting/grouping/aggregation/etc. This is not overridable by
* the caller, since it reflects plan actions that this routine
* will certainly take, not assumptions about context.
*/
if
(
parse
->
limitCount
!=
NULL
)
{
/*
* A LIMIT clause limits the absolute number of tuples returned.
* However, if it's not a constant LIMIT then we have to punt;
* for lack of a better idea, assume 10% of the plan's result
* is wanted.
*/
*/
if
(
parse
->
limitCount
!=
NULL
)
double
limit_fraction
=
0
.
0
;
if
(
IsA
(
parse
->
limitCount
,
Const
))
{
{
if
(
IsA
(
parse
->
limitCount
,
Const
))
Const
*
limitc
=
(
Const
*
)
parse
->
limitCount
;
int32
count
=
DatumGetInt32
(
limitc
->
constvalue
);
/*
* A NULL-constant LIMIT represents "LIMIT ALL", which
* we treat the same as no limit (ie, expect to
* retrieve all the tuples).
*/
if
(
!
limitc
->
constisnull
&&
count
>
0
)
{
{
Const
*
limitc
=
(
Const
*
)
parse
->
limitCount
;
limit_fraction
=
(
double
)
count
;
int32
count
=
DatumGetInt32
(
limitc
->
constvalue
);
/* We must also consider the OFFSET, if present */
if
(
parse
->
limitOffset
!=
NULL
)
/*
* A NULL-constant LIMIT represents "LIMIT ALL", which
* we treat the same as no limit (ie, expect to
* retrieve all the tuples).
*/
if
(
!
limitc
->
constisnull
&&
count
>
0
)
{
{
tuple_fraction
=
(
double
)
count
;
if
(
IsA
(
parse
->
limitOffset
,
Const
))
/* We must also consider the OFFSET, if present */
{
if
(
parse
->
limitOffset
!=
NULL
)
int32
offset
;
limitc
=
(
Const
*
)
parse
->
limitOffset
;
offset
=
DatumGetInt32
(
limitc
->
constvalue
);
if
(
!
limitc
->
constisnull
&&
offset
>
0
)
limit_fraction
+=
(
double
)
offset
;
}
else
{
{
if
(
IsA
(
parse
->
limitOffset
,
Const
))
/* OFFSET is an expression ... punt ... */
{
limit_fraction
=
0
.
10
;
int32
offset
;
limitc
=
(
Const
*
)
parse
->
limitOffset
;
offset
=
DatumGetInt32
(
limitc
->
constvalue
);
if
(
!
limitc
->
constisnull
&&
offset
>
0
)
tuple_fraction
+=
(
double
)
offset
;
}
else
{
/* It's an expression ... punt ... */
tuple_fraction
=
0
.
10
;
}
}
}
}
}
}
}
}
else
{
/* LIMIT is an expression ... punt ... */
limit_fraction
=
0
.
10
;
}
if
(
limit_fraction
>
0
.
0
)
{
/*
* If we have absolute limits from both caller and LIMIT,
* use the smaller value; if one is fractional and the other
* absolute, treat the fraction as a fraction of the absolute
* value; else we can multiply the two fractions together.
*/
if
(
tuple_fraction
>=
1
.
0
)
{
if
(
limit_fraction
>=
1
.
0
)
{
/* both absolute */
tuple_fraction
=
Min
(
tuple_fraction
,
limit_fraction
);
}
else
{
/* caller absolute, limit fractional */
tuple_fraction
*=
limit_fraction
;
if
(
tuple_fraction
<
1
.
0
)
tuple_fraction
=
1
.
0
;
}
}
else
if
(
tuple_fraction
>
0
.
0
)
{
if
(
limit_fraction
>=
1
.
0
)
{
/* caller fractional, limit absolute */
tuple_fraction
*=
limit_fraction
;
if
(
tuple_fraction
<
1
.
0
)
tuple_fraction
=
1
.
0
;
}
else
{
/* both fractional */
tuple_fraction
*=
limit_fraction
;
}
}
else
else
{
{
/* no info from caller, just use limit */
/*
tuple_fraction
=
limit_fraction
;
* COUNT is an expression ... don't know exactly what
* the limit will be, but for lack of a better idea
* assume 10% of the plan's result is wanted.
*/
tuple_fraction
=
0
.
10
;
}
}
}
}
/*
* If no LIMIT, check for retrieve-into-portal, ie DECLARE
* CURSOR.
*
* We have no real idea how many tuples the user will ultimately
* FETCH from a cursor, but it seems a good bet that he
* doesn't want 'em all. Optimize for 10% retrieval (you
* gotta better number?)
*/
else
if
(
parse
->
isPortal
)
tuple_fraction
=
0
.
10
;
}
}
/*
* Adjust tuple_fraction if we see that we are going to apply
* grouping/aggregation/etc. This is not overridable by the
* caller, since it reflects plan actions that this routine will
* certainly take, not assumptions about context.
*/
if
(
parse
->
groupClause
)
if
(
parse
->
groupClause
)
{
{
...
...
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