42
42
* Portions Copyright (c) 1994, Regents of the University of California
43
43
*
44
44
* IDENTIFICATION
45
- * $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.94 2002/12/12 15:49:28 tgl Exp $
45
+ * $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.95 2002/12/13 17:29:25 tgl Exp $
46
46
*
47
47
*-------------------------------------------------------------------------
48
48
*/
@@ -672,12 +672,22 @@ cost_nestloop(Path *path, Query *root,
672
672
*/
673
673
startup_cost += outer_path -> startup_cost + inner_path -> startup_cost ;
674
674
run_cost += outer_path -> total_cost - outer_path -> startup_cost ;
675
- run_cost += outer_path -> parent -> rows *
676
- (inner_path -> total_cost - inner_path -> startup_cost );
677
- if (!(IsA (inner_path , MaterialPath ) ||
678
- IsA (inner_path , HashPath )) &&
679
- outer_path -> parent -> rows > 1 )
680
- run_cost += (outer_path -> parent -> rows - 1 ) * inner_path -> startup_cost ;
675
+ if (IsA (inner_path , MaterialPath ) ||
676
+ IsA (inner_path , HashPath ))
677
+ {
678
+ /* charge only run cost for each iteration of inner path */
679
+ run_cost += outer_path -> parent -> rows *
680
+ (inner_path -> total_cost - inner_path -> startup_cost );
681
+ }
682
+ else
683
+ {
684
+ /*
685
+ * charge total cost for each iteration of inner path, except we
686
+ * already charged the first startup_cost in our own startup
687
+ */
688
+ run_cost += outer_path -> parent -> rows * inner_path -> total_cost
689
+ - inner_path -> startup_cost ;
690
+ }
681
691
682
692
/*
683
693
* Number of tuples processed (not number emitted!). If inner path is
@@ -768,8 +778,8 @@ cost_mergejoin(Path *path, Query *root,
768
778
innerscansel = firstclause -> left_mergescansel ;
769
779
}
770
780
771
- outer_rows = outer_path -> parent -> rows * outerscansel ;
772
- inner_rows = inner_path -> parent -> rows * innerscansel ;
781
+ outer_rows = ceil ( outer_path -> parent -> rows * outerscansel ) ;
782
+ inner_rows = ceil ( inner_path -> parent -> rows * innerscansel ) ;
773
783
774
784
/* cost of source data */
775
785
@@ -1343,21 +1353,27 @@ approx_selectivity(Query *root, List *quals)
1343
1353
void
1344
1354
set_baserel_size_estimates (Query * root , RelOptInfo * rel )
1345
1355
{
1356
+ double temp ;
1357
+
1346
1358
/* Should only be applied to base relations */
1347
1359
Assert (length (rel -> relids ) == 1 );
1348
1360
1349
- rel -> rows = rel -> tuples *
1361
+ temp = rel -> tuples *
1350
1362
restrictlist_selectivity (root ,
1351
1363
rel -> baserestrictinfo ,
1352
1364
lfirsti (rel -> relids ));
1353
1365
1354
1366
/*
1355
1367
* Force estimate to be at least one row, to make explain output look
1356
1368
* better and to avoid possible divide-by-zero when interpolating
1357
- * cost.
1369
+ * cost. Make it an integer, too.
1358
1370
*/
1359
- if (rel -> rows < 1.0 )
1360
- rel -> rows = 1.0 ;
1371
+ if (temp < 1.0 )
1372
+ temp = 1.0 ;
1373
+ else
1374
+ temp = ceil (temp );
1375
+
1376
+ rel -> rows = temp ;
1361
1377
1362
1378
rel -> baserestrictcost = cost_qual_eval (rel -> baserestrictinfo );
1363
1379
@@ -1437,10 +1453,12 @@ set_joinrel_size_estimates(Query *root, RelOptInfo *rel,
1437
1453
/*
1438
1454
* Force estimate to be at least one row, to make explain output look
1439
1455
* better and to avoid possible divide-by-zero when interpolating
1440
- * cost.
1456
+ * cost. Make it an integer, too.
1441
1457
*/
1442
1458
if (temp < 1.0 )
1443
1459
temp = 1.0 ;
1460
+ else
1461
+ temp = ceil (temp );
1444
1462
1445
1463
rel -> rows = temp ;
1446
1464
@@ -1470,6 +1488,8 @@ set_joinrel_size_estimates(Query *root, RelOptInfo *rel,
1470
1488
void
1471
1489
set_function_size_estimates (Query * root , RelOptInfo * rel )
1472
1490
{
1491
+ double temp ;
1492
+
1473
1493
/* Should only be applied to base relations that are functions */
1474
1494
Assert (length (rel -> relids ) == 1 );
1475
1495
Assert (rel -> rtekind == RTE_FUNCTION );
@@ -1483,18 +1503,22 @@ set_function_size_estimates(Query *root, RelOptInfo *rel)
1483
1503
rel -> tuples = 1000 ;
1484
1504
1485
1505
/* Now estimate number of output rows */
1486
- rel -> rows = rel -> tuples *
1506
+ temp = rel -> tuples *
1487
1507
restrictlist_selectivity (root ,
1488
1508
rel -> baserestrictinfo ,
1489
1509
lfirsti (rel -> relids ));
1490
1510
1491
1511
/*
1492
1512
* Force estimate to be at least one row, to make explain output look
1493
1513
* better and to avoid possible divide-by-zero when interpolating
1494
- * cost.
1514
+ * cost. Make it an integer, too.
1495
1515
*/
1496
- if (rel -> rows < 1.0 )
1497
- rel -> rows = 1.0 ;
1516
+ if (temp < 1.0 )
1517
+ temp = 1.0 ;
1518
+ else
1519
+ temp = ceil (temp );
1520
+
1521
+ rel -> rows = temp ;
1498
1522
1499
1523
rel -> baserestrictcost = cost_qual_eval (rel -> baserestrictinfo );
1500
1524
0 commit comments