Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 610d0d0

Browse files
committed
1. Enable to have different _CPU_PAGE_WEIGHT_ for heap and index.
2. PageWeights are variables now. 3. Fixed using ceil((double)selec*indextuples) as estimation for expected heap pages: ceil((double)selec*relpages) now.
1 parent fa2629b commit 610d0d0

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

src/backend/optimizer/path/costsize.c

+20-16
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.13 1997/02/14 04:15:35 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.14 1997/04/09 02:13:41 vadim Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -52,6 +52,9 @@ bool _enable_nestloop_ = true;
5252
bool _enable_mergesort_ = true;
5353
bool _enable_hashjoin_ = true;
5454

55+
Cost _cpu_page_wight_ = _CPU_PAGE_WEIGHT_;
56+
Cost _cpu_index_page_wight_ = _CPU_INDEX_PAGE_WEIGHT_;
57+
5558
/*
5659
* cost_seqscan--
5760
* Determines and returns the cost of scanning a relation sequentially.
@@ -87,7 +90,7 @@ cost_seqscan(int relid, int relpages, int reltuples)
8790
temp += _TEMP_SCAN_COST_;
8891
} else {
8992
temp += relpages;
90-
temp += _CPU_PAGE_WEIGHT_ * reltuples;
93+
temp += _cpu_page_wight_ * reltuples;
9194
}
9295
Assert(temp >= 0);
9396
return(temp);
@@ -124,26 +127,27 @@ cost_index(Oid indexid,
124127
bool is_injoin)
125128
{
126129
Cost temp;
127-
Cost temp2;
130+
double temp2;
128131

129-
temp = temp2 = (Cost) 0;
132+
temp = (Cost) 0;
130133

131134
if (!_enable_indexscan_ && !is_injoin)
132135
temp += _disable_cost_;
133136

134137
/* expected index relation pages */
135138
temp += expected_indexpages;
136139

137-
/* about one base relation page */
138-
temp += Min(relpages,(int)ceil((double)selec*indextuples));
140+
/* expected base relation pages */
141+
temp2 = ( reltuples == 0 ) ? (double)0 : (double)relpages/reltuples;
142+
temp2 = temp2 * (double)selec * indextuples;
143+
temp += Min (relpages, (int)ceil (temp2));
139144

140-
/*
141-
* per index tuple
142-
*/
143-
temp2 += selec * indextuples;
144-
temp2 += selec * reltuples;
145+
/* per index tuples */
146+
temp = temp + (_cpu_index_page_wight_ * selec * indextuples);
147+
148+
/* per heap tuples */
149+
temp = temp + (_cpu_page_wight_ * selec * reltuples);
145150

146-
temp = temp + (_CPU_PAGE_WEIGHT_ * temp2);
147151
Assert(temp >= 0);
148152
return(temp);
149153
}
@@ -186,7 +190,7 @@ cost_sort(List *keys, int tuples, int width, bool noread)
186190
/*
187191
* could be base_log(pages, NBuffers), but we are only doing 2-way merges
188192
*/
189-
temp += _CPU_PAGE_WEIGHT_ *
193+
temp += _cpu_page_wight_ *
190194
numTuples * base_log((double)pages,(double)2.0);
191195

192196
if( !noread )
@@ -210,7 +214,7 @@ cost_result(int tuples, int width)
210214
{
211215
Cost temp =0;
212216
temp = temp + page_size(tuples,width);
213-
temp = temp + _CPU_PAGE_WEIGHT_ * tuples;
217+
temp = temp + _cpu_page_wight_ * tuples;
214218
Assert(temp >= 0);
215219
return(temp);
216220
}
@@ -279,7 +283,7 @@ cost_mergesort(Cost outercost,
279283
temp += innercost;
280284
temp += cost_sort(outersortkeys,outersize,outerwidth,false);
281285
temp += cost_sort(innersortkeys,innersize,innerwidth,false);
282-
temp += _CPU_PAGE_WEIGHT_ * (outersize + innersize);
286+
temp += _cpu_page_wight_ * (outersize + innersize);
283287
Assert(temp >= 0);
284288

285289
return(temp);
@@ -327,7 +331,7 @@ cost_hashjoin(Cost outercost,
327331
*/
328332
temp += outercost + (nrun + 1);
329333

330-
temp += _CPU_PAGE_WEIGHT_ * (outersize + nrun * innersize);
334+
temp += _cpu_page_wight_ * (outersize + nrun * innersize);
331335
Assert(temp >= 0);
332336

333337
return(temp);

0 commit comments

Comments
 (0)