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

Commita43f20c

Browse files
committed
Tweak nestloop costing to weight restart cost of inner path more heavily.
Without this, it was making some pretty silly decisions about whether anexpensive sub-SELECT should be the inner or outer side of a join...
1 parentcbeda84 commita43f20c

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
* Portions Copyright (c) 1994, Regents of the University of California
4242
*
4343
* IDENTIFICATION
44-
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.69 2001/03/22 03:59:34 momjian Exp $
44+
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.70 2001/04/25 22:04:37 tgl Exp $
4545
*
4646
*-------------------------------------------------------------------------
4747
*/
@@ -443,14 +443,22 @@ cost_nestloop(Path *path,
443443
/* cost of source data */
444444

445445
/*
446-
* NOTE: we assume that the inner path's startup_cost is paid once,
447-
* not over again on each restart.This is certainly correct if the
448-
* inner path is materialized.Are there any cases where it is wrong?
446+
* NOTE: clearly, we must pay both outer and inner paths' startup_cost
447+
* before we can start returning tuples, so the join's startup cost
448+
* is their sum. What's not so clear is whether the inner path's
449+
* startup_cost must be paid again on each rescan of the inner path.
450+
* This is not true if the inner path is materialized, but probably
451+
* is true otherwise. Since we don't yet have clean handling of the
452+
* decision whether to materialize a path, we can't tell here which
453+
* will happen. As a compromise, charge 50% of the inner startup cost
454+
* for each restart.
449455
*/
450456
startup_cost+=outer_path->startup_cost+inner_path->startup_cost;
451457
run_cost+=outer_path->total_cost-outer_path->startup_cost;
452458
run_cost+=outer_path->parent->rows*
453459
(inner_path->total_cost-inner_path->startup_cost);
460+
if (outer_path->parent->rows>1)
461+
run_cost+= (outer_path->parent->rows-1)*inner_path->startup_cost;
454462

455463
/*
456464
* Number of tuples processed (not number emitted!). If inner path is

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp