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
0d7abfe7
Commit
0d7abfe7
authored
Feb 15, 2003
by
Tom Lane
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Marginal tweaks to make sure that roundoff error won't cause us to make
a bad choice between sorted and hashed aggregation.
parent
056467ec
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
5 deletions
+16
-5
src/backend/optimizer/path/costsize.c
src/backend/optimizer/path/costsize.c
+14
-3
src/backend/optimizer/plan/planner.c
src/backend/optimizer/plan/planner.c
+2
-2
No files found.
src/backend/optimizer/path/costsize.c
View file @
0d7abfe7
...
...
@@ -49,7 +49,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.10
5 2003/02/08 20:20:54
tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.10
6 2003/02/15 21:39:58
tgl Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -601,6 +601,15 @@ cost_agg(Path *path, Query *root,
*
* We will produce a single output tuple if not grouping,
* and a tuple per group otherwise.
*
* Note: in this cost model, AGG_SORTED and AGG_HASHED have exactly the
* same total CPU cost, but AGG_SORTED has lower startup cost. If the
* input path is already sorted appropriately, AGG_SORTED should be
* preferred (since it has no risk of memory overflow). This will happen
* as long as the computed total costs are indeed exactly equal --- but
* if there's roundoff error we might do the wrong thing. So be sure
* that the computations below form the same intermediate values in the
* same order.
*/
if
(
aggstrategy
==
AGG_PLAIN
)
{
...
...
@@ -614,15 +623,17 @@ cost_agg(Path *path, Query *root,
/* Here we are able to deliver output on-the-fly */
startup_cost
=
input_startup_cost
;
total_cost
=
input_total_cost
;
total_cost
+=
cpu_operator_cost
*
(
input_tuples
+
numGroups
)
*
numAggs
;
/* calcs phrased this way to match HASHED case, see note above */
total_cost
+=
cpu_operator_cost
*
input_tuples
*
numGroupCols
;
total_cost
+=
cpu_operator_cost
*
input_tuples
*
numAggs
;
total_cost
+=
cpu_operator_cost
*
numGroups
*
numAggs
;
}
else
{
/* must be AGG_HASHED */
startup_cost
=
input_total_cost
;
startup_cost
+=
cpu_operator_cost
*
input_tuples
*
numAggs
;
startup_cost
+=
cpu_operator_cost
*
input_tuples
*
numGroupCols
;
startup_cost
+=
cpu_operator_cost
*
input_tuples
*
numAggs
;
total_cost
=
startup_cost
;
total_cost
+=
cpu_operator_cost
*
numGroups
*
numAggs
;
}
...
...
src/backend/optimizer/plan/planner.c
View file @
0d7abfe7
...
...
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.14
7 2003/02/15 20:12:40
tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.14
8 2003/02/15 21:39:58
tgl Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -1003,7 +1003,7 @@ grouping_planner(Query *parse, double tuple_fraction)
tuple_fraction
/=
dNumGroups
;
if
(
compare_fractional_path_costs
(
&
hashed_p
,
&
sorted_p
,
tuple_fraction
)
<
=
0
)
tuple_fraction
)
<
0
)
{
/* Hashed is cheaper, so use it */
use_hashed_grouping
=
true
;
...
...
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