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
605d8494
Commit
605d8494
authored
May 01, 1999
by
Tom Lane
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up cost_sort some more: most callers were double-counting
the cost of reading the source data.
parent
87d95ca0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
26 deletions
+20
-26
src/backend/optimizer/path/costsize.c
src/backend/optimizer/path/costsize.c
+13
-18
src/backend/optimizer/path/joinpath.c
src/backend/optimizer/path/joinpath.c
+3
-4
src/backend/optimizer/plan/createplan.c
src/backend/optimizer/plan/createplan.c
+2
-2
src/include/optimizer/cost.h
src/include/optimizer/cost.h
+2
-2
No files found.
src/backend/optimizer/path/costsize.c
View file @
605d8494
...
...
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.3
5 1999/04/30 04:01:44
tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.3
6 1999/05/01 19:47:41
tgl Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -167,28 +167,23 @@ cost_index(Oid indexid,
/*
* cost_sort
* Determines and returns the cost of sorting a relation by considering
*
1.
the cost of doing an external sort: XXX this is probably too low
* the cost of doing an external sort: XXX this is probably too low
* disk = (p lg p)
* cpu = *CPU-PAGE-WEIGHT* * (t lg t)
* 2. the cost of reading the sort result into memory (another seqscan)
* unless 'noread' is set
*
* 'pathkeys' is a list of sort keys
* 'tuples' is the number of tuples in the relation
* 'width' is the average tuple width in bytes
* 'noread' is a flag indicating that the cost of reading the sort
* source data should not be included (i.e., the caller
* will account for it separately).
*
* NOTE: some callers currently pass NULL for pathkeys because they
* can't conveniently supply sort keys. Since this routine doesn't
* can't conveniently supply
the
sort keys. Since this routine doesn't
* currently do anything with pathkeys anyway, that doesn't matter...
* but if it ever does, it should react gracefully to lack of key data.
*
* Returns a flonum.
*
*/
Cost
cost_sort
(
List
*
pathkeys
,
int
tuples
,
int
width
,
bool
noread
)
cost_sort
(
List
*
pathkeys
,
int
tuples
,
int
width
)
{
Cost
temp
=
0
;
int
npages
=
page_size
(
tuples
,
width
);
...
...
@@ -200,6 +195,8 @@ cost_sort(List *pathkeys, int tuples, int width, bool noread)
/* We want to be sure the cost of a sort is never estimated as zero,
* even if passed-in tuple count is zero. Besides, mustn't do log(0)...
*/
if
(
tuples
<=
0
)
tuples
=
1
;
if
(
npages
<=
0
)
npages
=
1
;
...
...
@@ -210,13 +207,10 @@ cost_sort(List *pathkeys, int tuples, int width, bool noread)
temp
+=
npages
*
log_npages
;
/*
* could be base_log(
pag
es, NBuffers), but we are only doing 2-way
* could be base_log(
tupl
es, NBuffers), but we are only doing 2-way
* merges
*/
temp
+=
_cpu_page_wight_
*
tuples
*
log_npages
;
if
(
!
noread
)
temp
+=
cost_seqscan
(
_NONAME_RELATION_ID_
,
npages
,
tuples
);
temp
+=
_cpu_page_wight_
*
tuples
*
base_log
((
double
)
tuples
,
2
.
0
);
Assert
(
temp
>
0
);
...
...
@@ -282,7 +276,8 @@ cost_nestloop(Cost outercost,
* 'outercost' and 'innercost' are the (disk+cpu) costs of scanning the
* outer and inner relations
* 'outersortkeys' and 'innersortkeys' are lists of the keys to be used
* to sort the outer and inner relations
* to sort the outer and inner relations (or NIL if no explicit
* sort is needed because the source path is already ordered)
* 'outertuples' and 'innertuples' are the number of tuples in the outer
* and inner relations
* 'outerwidth' and 'innerwidth' are the (typical) widths (in bytes)
...
...
@@ -309,9 +304,9 @@ cost_mergejoin(Cost outercost,
temp
+=
outercost
;
temp
+=
innercost
;
if
(
outersortkeys
)
/* do we need to sort? */
temp
+=
cost_sort
(
outersortkeys
,
outersize
,
outerwidth
,
true
);
temp
+=
cost_sort
(
outersortkeys
,
outersize
,
outerwidth
);
if
(
innersortkeys
)
/* do we need to sort? */
temp
+=
cost_sort
(
innersortkeys
,
innersize
,
innerwidth
,
true
);
temp
+=
cost_sort
(
innersortkeys
,
innersize
,
innerwidth
);
temp
+=
_cpu_page_wight_
*
(
outersize
+
innersize
);
Assert
(
temp
>=
0
);
...
...
src/backend/optimizer/path/joinpath.c
View file @
605d8494
...
...
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/joinpath.c,v 1.3
3 1999/04/03 00:18:28
tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/joinpath.c,v 1.3
4 1999/05/01 19:47:42
tgl Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -348,7 +348,7 @@ match_unsorted_outer(RelOptInfo *joinrel,
(
mergeinnerpath
->
path_cost
<
(
cheapest_inner
->
path_cost
+
cost_sort
(
matchedJoinKeys
,
innerrel
->
size
,
innerrel
->
width
,
false
))));
innerrel
->
width
))));
if
(
!
path_is_cheaper_than_sort
)
{
varkeys
=
make_pathkeys_from_joinkeys
(
matchedJoinKeys
,
...
...
@@ -464,8 +464,7 @@ match_unsorted_inner(RelOptInfo *joinrel,
if
(
clauses
&&
matchedJoinKeys
)
{
temp1
=
outerrel
->
cheapestpath
->
path_cost
+
cost_sort
(
matchedJoinKeys
,
outerrel
->
size
,
outerrel
->
width
,
false
);
cost_sort
(
matchedJoinKeys
,
outerrel
->
size
,
outerrel
->
width
);
temp2
=
(
bool
)
(
FLOAT_IS_ZERO
(
innerpath
->
outerjoincost
)
||
(
innerpath
->
outerjoincost
>
temp1
));
...
...
src/backend/optimizer/plan/createplan.c
View file @
605d8494
...
...
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.5
1 1999/04/30 04:04:27
tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.5
2 1999/05/01 19:47:40
tgl Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -1106,7 +1106,7 @@ make_sort(List *tlist, Oid nonameid, Plan *lefttree, int keycount)
Plan
*
plan
=
&
node
->
plan
;
copy_costsize
(
plan
,
lefttree
);
plan
->
cost
+=
cost_sort
(
NULL
,
plan
->
plan_size
,
plan
->
plan_width
,
true
);
plan
->
cost
+=
cost_sort
(
NULL
,
plan
->
plan_size
,
plan
->
plan_width
);
plan
->
state
=
(
EState
*
)
NULL
;
plan
->
targetlist
=
tlist
;
plan
->
qual
=
NIL
;
...
...
src/include/optimizer/cost.h
View file @
605d8494
...
...
@@ -6,7 +6,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: cost.h,v 1.1
7 1999/02/13 23:21:43 momjian
Exp $
* $Id: cost.h,v 1.1
8 1999/05/01 19:47:39 tgl
Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -34,7 +34,7 @@ extern Cost cost_seqscan(int relid, int relpages, int reltuples);
extern
Cost
cost_index
(
Oid
indexid
,
int
expected_indexpages
,
Cost
selec
,
int
relpages
,
int
reltuples
,
int
indexpages
,
int
indextuples
,
bool
is_injoin
);
extern
Cost
cost_sort
(
List
*
pathkeys
,
int
tuples
,
int
width
,
bool
noread
);
extern
Cost
cost_sort
(
List
*
pathkeys
,
int
tuples
,
int
width
);
extern
Cost
cost_nestloop
(
Cost
outercost
,
Cost
innercost
,
int
outertuples
,
int
innertuples
,
int
outerpages
,
bool
is_indexjoin
);
extern
Cost
cost_mergejoin
(
Cost
outercost
,
Cost
innercost
,
...
...
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