7
7
*
8
8
*
9
9
* 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 $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
@@ -52,6 +52,9 @@ bool _enable_nestloop_ = true;
52
52
bool _enable_mergesort_ = true;
53
53
bool _enable_hashjoin_ = true;
54
54
55
+ Cost _cpu_page_wight_ = _CPU_PAGE_WEIGHT_ ;
56
+ Cost _cpu_index_page_wight_ = _CPU_INDEX_PAGE_WEIGHT_ ;
57
+
55
58
/*
56
59
* cost_seqscan--
57
60
* Determines and returns the cost of scanning a relation sequentially.
@@ -87,7 +90,7 @@ cost_seqscan(int relid, int relpages, int reltuples)
87
90
temp += _TEMP_SCAN_COST_ ;
88
91
} else {
89
92
temp += relpages ;
90
- temp += _CPU_PAGE_WEIGHT_ * reltuples ;
93
+ temp += _cpu_page_wight_ * reltuples ;
91
94
}
92
95
Assert (temp >= 0 );
93
96
return (temp );
@@ -124,26 +127,27 @@ cost_index(Oid indexid,
124
127
bool is_injoin )
125
128
{
126
129
Cost temp ;
127
- Cost temp2 ;
130
+ double temp2 ;
128
131
129
- temp = temp2 = (Cost ) 0 ;
132
+ temp = (Cost ) 0 ;
130
133
131
134
if (!_enable_indexscan_ && !is_injoin )
132
135
temp += _disable_cost_ ;
133
136
134
137
/* expected index relation pages */
135
138
temp += expected_indexpages ;
136
139
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 ));
139
144
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 ) ;
145
150
146
- temp = temp + (_CPU_PAGE_WEIGHT_ * temp2 );
147
151
Assert (temp >= 0 );
148
152
return (temp );
149
153
}
@@ -186,7 +190,7 @@ cost_sort(List *keys, int tuples, int width, bool noread)
186
190
/*
187
191
* could be base_log(pages, NBuffers), but we are only doing 2-way merges
188
192
*/
189
- temp += _CPU_PAGE_WEIGHT_ *
193
+ temp += _cpu_page_wight_ *
190
194
numTuples * base_log ((double )pages ,(double )2.0 );
191
195
192
196
if ( !noread )
@@ -210,7 +214,7 @@ cost_result(int tuples, int width)
210
214
{
211
215
Cost temp = 0 ;
212
216
temp = temp + page_size (tuples ,width );
213
- temp = temp + _CPU_PAGE_WEIGHT_ * tuples ;
217
+ temp = temp + _cpu_page_wight_ * tuples ;
214
218
Assert (temp >= 0 );
215
219
return (temp );
216
220
}
@@ -279,7 +283,7 @@ cost_mergesort(Cost outercost,
279
283
temp += innercost ;
280
284
temp += cost_sort (outersortkeys ,outersize ,outerwidth ,false);
281
285
temp += cost_sort (innersortkeys ,innersize ,innerwidth ,false);
282
- temp += _CPU_PAGE_WEIGHT_ * (outersize + innersize );
286
+ temp += _cpu_page_wight_ * (outersize + innersize );
283
287
Assert (temp >= 0 );
284
288
285
289
return (temp );
@@ -327,7 +331,7 @@ cost_hashjoin(Cost outercost,
327
331
*/
328
332
temp += outercost + (nrun + 1 );
329
333
330
- temp += _CPU_PAGE_WEIGHT_ * (outersize + nrun * innersize );
334
+ temp += _cpu_page_wight_ * (outersize + nrun * innersize );
331
335
Assert (temp >= 0 );
332
336
333
337
return (temp );
0 commit comments