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

« back to all changes in this revision

Viewing changes to src/backend/optimizer/path/allpaths.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/path/allpaths.c,v 1.182 2009/04/19 19:46:33 tgl Exp $
 
11
 *        $PostgreSQL: pgsql/src/backend/optimizer/path/allpaths.c,v 1.183 2009/06/11 14:48:58 momjian Exp $
12
12
 *
13
13
 *-------------------------------------------------------------------------
14
14
 */
58
58
static void set_values_pathlist(PlannerInfo *root, RelOptInfo *rel,
59
59
                                        RangeTblEntry *rte);
60
60
static void set_cte_pathlist(PlannerInfo *root, RelOptInfo *rel,
61
 
                                                         RangeTblEntry *rte);
 
61
                                 RangeTblEntry *rte);
62
62
static void set_worktable_pathlist(PlannerInfo *root, RelOptInfo *rel,
63
 
                                                                   RangeTblEntry *rte);
 
63
                                           RangeTblEntry *rte);
64
64
static RelOptInfo *make_rel_from_joinlist(PlannerInfo *root, List *joinlist);
65
65
static bool subquery_is_pushdown_safe(Query *subquery, Query *topquery,
66
66
                                                  bool *differentTypes);
292
292
        /*
293
293
         * Initialize to compute size estimates for whole append relation.
294
294
         *
295
 
         * We handle width estimates by weighting the widths of different
296
 
         * child rels proportionally to their number of rows.  This is sensible
297
 
         * because the use of width estimates is mainly to compute the total
298
 
         * relation "footprint" if we have to sort or hash it.  To do this,
299
 
         * we sum the total equivalent size (in "double" arithmetic) and then
300
 
         * divide by the total rowcount estimate.  This is done separately for
301
 
         * the total rel width and each attribute.
 
295
         * We handle width estimates by weighting the widths of different child
 
296
         * rels proportionally to their number of rows.  This is sensible because
 
297
         * the use of width estimates is mainly to compute the total relation
 
298
         * "footprint" if we have to sort or hash it.  To do this, we sum the
 
299
         * total equivalent size (in "double" arithmetic) and then divide by the
 
300
         * total rowcount estimate.  This is done separately for the total rel
 
301
         * width and each attribute.
302
302
         *
303
303
         * Note: if you consider changing this logic, beware that child rels could
304
304
         * have zero rows and/or width, if they were excluded by constraints.
377
377
                }
378
378
 
379
379
                /*
380
 
                 * Note: we could compute appropriate attr_needed data for the
381
 
                 * child's variables, by transforming the parent's attr_needed
382
 
                 * through the translated_vars mapping.  However, currently there's
383
 
                 * no need because attr_needed is only examined for base relations
384
 
                 * not otherrels.  So we just leave the child's attr_needed empty.
 
380
                 * Note: we could compute appropriate attr_needed data for the child's
 
381
                 * variables, by transforming the parent's attr_needed through the
 
382
                 * translated_vars mapping.  However, currently there's no need
 
383
                 * because attr_needed is only examined for base relations not
 
384
                 * otherrels.  So we just leave the child's attr_needed empty.
385
385
                 */
386
386
 
387
387
                /*
438
438
        rel->rows = parent_rows;
439
439
        if (parent_rows > 0)
440
440
        {
441
 
                int             i;
 
441
                int                     i;
442
442
 
443
443
                rel->width = rint(parent_size / parent_rows);
444
444
                for (i = 0; i < nattrs; i++)
681
681
                if (!cteroot)                   /* shouldn't happen */
682
682
                        elog(ERROR, "bad levelsup for CTE \"%s\"", rte->ctename);
683
683
        }
 
684
 
684
685
        /*
685
686
         * Note: cte_plan_ids can be shorter than cteList, if we are still working
686
687
         * on planning the CTEs (ie, this is a side-reference from another CTE).
726
727
 
727
728
        /*
728
729
         * We need to find the non-recursive term's plan, which is in the plan
729
 
         * level that's processing the recursive UNION, which is one level
730
 
         * *below* where the CTE comes from.
 
730
         * level that's processing the recursive UNION, which is one level *below*
 
731
         * where the CTE comes from.
731
732
         */
732
733
        levelsup = rte->ctelevelsup;
733
734
        if (levelsup == 0)                      /* shouldn't happen */
1087
1088
 * of rows returned.  (This condition is vacuous for DISTINCT, because then
1088
1089
 * there are no non-DISTINCT output columns, so we needn't check.  But note
1089
1090
 * we are assuming that the qual can't distinguish values that the DISTINCT
1090
 
 * operator sees as equal.  This is a bit shaky but we have no way to test
 
1091
 * operator sees as equal.      This is a bit shaky but we have no way to test
1091
1092
 * for the case, and it's unlikely enough that we shouldn't refuse the
1092
1093
 * optimization just because it could theoretically happen.)
1093
1094
 *
1113
1114
                return false;
1114
1115
 
1115
1116
        /*
1116
 
         * It would be unsafe to push down window function calls, but at least
1117
 
         * for the moment we could never see any in a qual anyhow.
 
1117
         * It would be unsafe to push down window function calls, but at least for
 
1118
         * the moment we could never see any in a qual anyhow.
1118
1119
         */
1119
1120
        Assert(!contain_window_function(qual));
1120
1121