~ubuntu-branches/ubuntu/natty/postgresql-8.4/natty-security

« back to all changes in this revision

Viewing changes to src/backend/optimizer/util/pathnode.c

Tags: upstream-8.4.0
ImportĀ upstreamĀ versionĀ 8.4.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 *
9
9
 *
10
10
 * IDENTIFICATION
11
 
 *        $PostgreSQL: pgsql/src/backend/optimizer/util/pathnode.c,v 1.151 2009/03/26 17:15:35 tgl Exp $
 
11
 *        $PostgreSQL: pgsql/src/backend/optimizer/util/pathnode.c,v 1.152 2009/06/11 14:48:59 momjian Exp $
12
12
 *
13
13
 *-------------------------------------------------------------------------
14
14
 */
797
797
        in_operators = NIL;
798
798
        uniq_exprs = NIL;
799
799
        all_btree = true;
800
 
        all_hash = enable_hashagg;              /* don't consider hash if not enabled */
 
800
        all_hash = enable_hashagg;      /* don't consider hash if not enabled */
801
801
        foreach(lc, sjinfo->join_quals)
802
802
        {
803
803
                OpExpr     *op = (OpExpr *) lfirst(lc);
904
904
                goto no_unique_path;
905
905
 
906
906
        /*
907
 
         * If we get here, we can unique-ify using at least one of sorting
908
 
         * and hashing.  Start building the result Path object.
 
907
         * If we get here, we can unique-ify using at least one of sorting and
 
908
         * hashing.  Start building the result Path object.
909
909
         */
910
910
        pathnode = makeNode(UniquePath);
911
911
 
972
972
                                  -1.0);
973
973
 
974
974
                /*
975
 
                 * Charge one cpu_operator_cost per comparison per input tuple.
976
 
                 * We assume all columns get compared at most of the tuples. (XXX
 
975
                 * Charge one cpu_operator_cost per comparison per input tuple. We
 
976
                 * assume all columns get compared at most of the tuples. (XXX
977
977
                 * probably this is an overestimate.)  This should agree with
978
978
                 * make_unique.
979
979
                 */
1030
1030
 
1031
1031
        return pathnode;
1032
1032
 
1033
 
no_unique_path:                                 /* failure exit */
 
1033
no_unique_path:                 /* failure exit */
1034
1034
 
1035
1035
        /* Mark the SpecialJoinInfo as not unique-able */
1036
1036
        sjinfo->join_quals = NIL;
1404
1404
         * selected as the input of a mergejoin, and they don't support
1405
1405
         * mark/restore at present.
1406
1406
         *
1407
 
         * Note: Sort supports mark/restore, so no materialize is really needed
1408
 
         * in that case; but one may be desirable anyway to optimize the sort.
1409
 
         * However, since we aren't representing the sort step separately in
1410
 
         * the Path tree, we can't explicitly represent the materialize either.
1411
 
         * So that case is not handled here.  Instead, cost_mergejoin has to
1412
 
         * factor in the cost and create_mergejoin_plan has to add the plan node.
 
1407
         * Note: Sort supports mark/restore, so no materialize is really needed in
 
1408
         * that case; but one may be desirable anyway to optimize the sort.
 
1409
         * However, since we aren't representing the sort step separately in the
 
1410
         * Path tree, we can't explicitly represent the materialize either. So
 
1411
         * that case is not handled here.  Instead, cost_mergejoin has to factor
 
1412
         * in the cost and create_mergejoin_plan has to add the plan node.
1413
1413
         */
1414
1414
        if (innersortkeys == NIL &&
1415
1415
                !ExecSupportsMarkRestore(inner_path->pathtype))
1416
1416
        {
1417
 
                Path   *mpath;
 
1417
                Path       *mpath;
1418
1418
 
1419
1419
                mpath = (Path *) create_material_path(inner_path->parent, inner_path);
1420
1420
 
1421
1421
                /*
1422
 
                 * We expect the materialize won't spill to disk (it could only do
1423
 
                 * so if there were a whole lot of duplicate tuples, which is a case
1424
 
                 * cost_mergejoin will avoid choosing anyway).  Therefore
1425
 
                 * cost_material's cost estimate is bogus and we should charge
1426
 
                 * just cpu_tuple_cost per tuple.  (Keep this estimate in sync with
1427
 
                 * similar ones in cost_mergejoin and create_mergejoin_plan.)
 
1422
                 * We expect the materialize won't spill to disk (it could only do so
 
1423
                 * if there were a whole lot of duplicate tuples, which is a case
 
1424
                 * cost_mergejoin will avoid choosing anyway).  Therefore
 
1425
                 * cost_material's cost estimate is bogus and we should charge just
 
1426
                 * cpu_tuple_cost per tuple.  (Keep this estimate in sync with similar
 
1427
                 * ones in cost_mergejoin and create_mergejoin_plan.)
1428
1428
                 */
1429
1429
                mpath->startup_cost = inner_path->startup_cost;
1430
1430
                mpath->total_cost = inner_path->total_cost;
1480
1480
        pathnode->jpath.outerjoinpath = outer_path;
1481
1481
        pathnode->jpath.innerjoinpath = inner_path;
1482
1482
        pathnode->jpath.joinrestrictinfo = restrict_clauses;
 
1483
 
1483
1484
        /*
1484
1485
         * A hashjoin never has pathkeys, since its output ordering is
1485
 
         * unpredictable due to possible batching.  XXX If the inner relation is
 
1486
         * unpredictable due to possible batching.      XXX If the inner relation is
1486
1487
         * small enough, we could instruct the executor that it must not batch,
1487
1488
         * and then we could assume that the output inherits the outer relation's
1488
 
         * ordering, which might save a sort step.  However there is considerable
1489
 
         * downside if our estimate of the inner relation size is badly off.
1490
 
         * For the moment we don't risk it.  (Note also that if we wanted to take
1491
 
         * this seriously, joinpath.c would have to consider many more paths for
1492
 
         * the outer rel than it does now.)
 
1489
         * ordering, which might save a sort step.      However there is considerable
 
1490
         * downside if our estimate of the inner relation size is badly off. For
 
1491
         * the moment we don't risk it.  (Note also that if we wanted to take this
 
1492
         * seriously, joinpath.c would have to consider many more paths for the
 
1493
         * outer rel than it does now.)
1493
1494
         */
1494
1495
        pathnode->jpath.path.pathkeys = NIL;
1495
1496
        pathnode->path_hashclauses = hashclauses;