Commit 4e91824b authored by Tom Lane's avatar Tom Lane

Make some adjustments to reduce platform dependencies in plan selection.

In particular, there was a mathematical tie between the two possible
nestloop-with-materialized-inner-scan plans for a join (ie, we computed
the same cost with either input on the inside), resulting in a roundoff
error driven choice, if the relations were both small enough to fit in
sort_mem.  Add a small cost factor to ensure we prefer materializing the
smaller input.  This changes several regression test plans, but with any
luck we will now have more stability across platforms.
parent ee9007a2
......@@ -49,7 +49,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/path/costsize.c,v 1.135 2004/10/23 00:05:27 tgl Exp $
* $PostgreSQL: pgsql/src/backend/optimizer/path/costsize.c,v 1.136 2004/12/02 01:34:17 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -615,6 +615,15 @@ cost_material(Path *path,
run_cost += npages;
}
/*
* Charge a very small amount per inserted tuple, to reflect bookkeeping
* costs. We use cpu_tuple_cost/10 for this. This is needed to break
* the tie that would otherwise exist between nestloop with A outer,
* materialized B inner and nestloop with B outer, materialized A inner.
* The extra cost ensures we'll prefer materializing the smaller rel.
*/
startup_cost += cpu_tuple_cost * 0.1 * tuples;
/*
* Also charge a small amount per extracted tuple. We use
* cpu_tuple_cost so that it doesn't appear worthwhile to materialize
......
......@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/util/plancat.c,v 1.98 2004/12/01 19:00:43 tgl Exp $
* $PostgreSQL: pgsql/src/backend/optimizer/util/plancat.c,v 1.99 2004/12/02 01:34:17 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -268,6 +268,12 @@ estimate_rel_size(Relation rel, int32 *attr_widths,
* but is probably an overestimate for indexes. Fortunately
* get_relation_info() can clamp the overestimate to the
* parent table's size.
*
* Note: this code intentionally disregards alignment
* considerations, because (a) that would be gilding the
* lily considering how crude the estimate is, and (b)
* it creates platform dependencies in the default plans
* which are kind of a headache for regression testing.
*/
int32 tuple_width = 0;
int i;
......@@ -291,8 +297,7 @@ estimate_rel_size(Relation rel, int32 *attr_widths,
attr_widths[i] = item_width;
tuple_width += item_width;
}
tuple_width = MAXALIGN(tuple_width);
tuple_width += MAXALIGN(sizeof(HeapTupleHeaderData));
tuple_width += sizeof(HeapTupleHeaderData);
tuple_width += sizeof(ItemPointerData);
/* note: integer division is intentional here */
density = (BLCKSZ - sizeof(PageHeaderData)) / tuple_width;
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -557,17 +557,18 @@ insert into bar2 values(2,2,2);
insert into bar2 values(3,3,3);
insert into bar2 values(4,4,4);
update bar set f2 = f2 + 100 where f1 in (select f1 from foo);
SELECT relname, bar.* FROM bar, pg_class where bar.tableoid = pg_class.oid;
SELECT relname, bar.* FROM bar, pg_class where bar.tableoid = pg_class.oid
order by 1,2;
relname | f1 | f2
---------+----+-----
bar | 4 | 4
bar | 3 | 103
bar | 2 | 102
bar | 1 | 101
bar2 | 4 | 4
bar2 | 3 | 103
bar2 | 2 | 102
bar | 2 | 102
bar | 3 | 103
bar | 4 | 4
bar2 | 1 | 101
bar2 | 2 | 102
bar2 | 3 | 103
bar2 | 4 | 4
(8 rows)
/* Test inheritance of structure (LIKE) */
......
This diff is collapsed.
......@@ -118,7 +118,8 @@ insert into bar2 values(4,4,4);
update bar set f2 = f2 + 100 where f1 in (select f1 from foo);
SELECT relname, bar.* FROM bar, pg_class where bar.tableoid = pg_class.oid;
SELECT relname, bar.* FROM bar, pg_class where bar.tableoid = pg_class.oid
order by 1,2;
/* Test inheritance of structure (LIKE) */
......
......@@ -167,11 +167,11 @@ SELECT '' AS "xxx", *
SELECT '' AS "xxx", *
FROM J1_TBL LEFT OUTER JOIN J2_TBL USING (i)
ORDER BY i;
ORDER BY i, k;
SELECT '' AS "xxx", *
FROM J1_TBL LEFT JOIN J2_TBL USING (i)
ORDER BY i;
ORDER BY i, k;
SELECT '' AS "xxx", *
FROM J1_TBL RIGHT OUTER JOIN J2_TBL USING (i);
......@@ -181,11 +181,11 @@ SELECT '' AS "xxx", *
SELECT '' AS "xxx", *
FROM J1_TBL FULL OUTER JOIN J2_TBL USING (i)
ORDER BY i, t;
ORDER BY i, k;
SELECT '' AS "xxx", *
FROM J1_TBL FULL JOIN J2_TBL USING (i)
ORDER BY i, t;
ORDER BY i, k;
SELECT '' AS "xxx", *
FROM J1_TBL LEFT JOIN J2_TBL USING (i) WHERE (k = 1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment