Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite91f43a

Browse files
committed
Fix potential overflow problems when relation size exceeds
2gig. Fix failure to reliably put the smaller relation on the inside ofa hashjoin.
1 parent2e7ef74 commite91f43a

File tree

1 file changed

+39
-18
lines changed

1 file changed

+39
-18
lines changed

‎src/backend/optimizer/path/costsize.c

Lines changed: 39 additions & 18 deletions
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.33 1999/02/15 03:22:04 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.34 1999/04/05 02:07:07 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -37,6 +37,7 @@
3737
externintNBuffers;
3838

3939
staticintcompute_attribute_width(TargetEntry*tlistentry);
40+
staticdoublerelation_byte_size (inttuples,intwidth);
4041
staticdoublebase_log(doublex,doubleb);
4142
staticintcompute_targetlist_width(List*targetlist);
4243

@@ -323,27 +324,35 @@ cost_hashjoin(Cost outercost,
323324
Costtemp=0;
324325
intouterpages=page_size(outersize,outerwidth);
325326
intinnerpages=page_size(innersize,innerwidth);
326-
intnrun=ceil((double)outerpages / (double)NBuffers);
327327

328-
if (outerpages<innerpages)
329-
return_disable_cost_;
330328
if (!_enable_hashjoin_)
331329
temp+=_disable_cost_;
332330

333-
/*
334-
* temp += outercost + (nrun + 1) * innercost;
335-
*
336-
* the innercost shouldn't be used it. Instead the cost of hashing the
337-
* innerpath should be used
338-
*
339-
* ASSUME innercost is 1 for now -- a horrible hack - jolly temp +=
340-
* outercost + (nrun + 1);
331+
/* Bias against putting larger relation on inside.
341332
*
342-
* But we must add innercost to result.- vadim 04/24/97
333+
* Code used to use "outerpages < innerpages" but that has
334+
* poor resolution when both relations are small.
343335
*/
344-
temp+=outercost+innercost+ (nrun+1);
336+
if (relation_byte_size(outersize,outerwidth)<
337+
relation_byte_size(innersize,innerwidth))
338+
temp+=_disable_cost_;
339+
340+
/* cost of source data */
341+
temp+=outercost+innercost;
342+
343+
/* cost of computing hash function: must do it once per tuple */
344+
temp+=_cpu_page_wight_* (outersize+innersize);
345+
346+
/* cost of main-memory hashtable */
347+
temp+= (innerpages<NBuffers) ?innerpages :NBuffers;
348+
349+
/* if inner relation is too big then we will need to "batch" the join,
350+
* which implies writing and reading most of the tuples to disk an
351+
* extra time.
352+
*/
353+
if (innerpages>NBuffers)
354+
temp+=2* (outerpages+innerpages);
345355

346-
temp+=_cpu_page_wight_* (outersize+nrun*innersize);
347356
Assert(temp >=0);
348357

349358
returntemp;
@@ -458,6 +467,19 @@ compute_joinrel_size(JoinPath *joinpath)
458467
returntemp1;
459468
}
460469

470+
/*
471+
* relation_byte_size
472+
* Estimate the storage space in bytes for a given number of tuples
473+
* of a given width (size in bytes).
474+
* To avoid overflow with big relations, result is a double.
475+
*/
476+
477+
staticdouble
478+
relation_byte_size (inttuples,intwidth)
479+
{
480+
return ((double)tuples)* ((double) (width+sizeof(HeapTupleData)));
481+
}
482+
461483
/*
462484
* page_size
463485
* Returns an estimate of the number of pages covered by a given
@@ -466,10 +488,9 @@ compute_joinrel_size(JoinPath *joinpath)
466488
int
467489
page_size(inttuples,intwidth)
468490
{
469-
inttemp=0;
491+
inttemp;
470492

471-
temp=ceil((double) (tuples* (width+sizeof(HeapTupleData)))
472-
/BLCKSZ);
493+
temp= (int)ceil(relation_byte_size(tuples,width) /BLCKSZ);
473494
Assert(temp >=0);
474495
returntemp;
475496
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp