mirror of
https://github.com/postgres/postgres.git
synced 2025-08-19 23:22:23 +03:00
pgindent run for 8.3.
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/geqo/geqo_eval.c,v 1.85 2007/02/16 00:14:01 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/geqo/geqo_eval.c,v 1.86 2007/11/15 21:14:35 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -254,8 +254,8 @@ desirable_join(PlannerInfo *root,
|
||||
RelOptInfo *outer_rel, RelOptInfo *inner_rel)
|
||||
{
|
||||
/*
|
||||
* Join if there is an applicable join clause, or if there is a join
|
||||
* order restriction forcing these rels to be joined.
|
||||
* Join if there is an applicable join clause, or if there is a join order
|
||||
* restriction forcing these rels to be joined.
|
||||
*/
|
||||
if (have_relevant_joinclause(root, outer_rel, inner_rel) ||
|
||||
have_join_order_restriction(root, outer_rel, inner_rel))
|
||||
|
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/path/allpaths.c,v 1.165 2007/09/26 18:51:50 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/path/allpaths.c,v 1.166 2007/11/15 21:14:35 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -43,7 +43,7 @@ join_search_hook_type join_search_hook = NULL;
|
||||
|
||||
static void set_base_rel_pathlists(PlannerInfo *root);
|
||||
static void set_rel_pathlist(PlannerInfo *root, RelOptInfo *rel,
|
||||
Index rti, RangeTblEntry *rte);
|
||||
Index rti, RangeTblEntry *rte);
|
||||
static void set_plain_rel_pathlist(PlannerInfo *root, RelOptInfo *rel,
|
||||
RangeTblEntry *rte);
|
||||
static void set_append_rel_pathlist(PlannerInfo *root, RelOptInfo *rel,
|
||||
@@ -312,10 +312,10 @@ set_append_rel_pathlist(PlannerInfo *root, RelOptInfo *rel,
|
||||
|
||||
/*
|
||||
* We have to copy the parent's targetlist and quals to the child,
|
||||
* with appropriate substitution of variables. However, only the
|
||||
* with appropriate substitution of variables. However, only the
|
||||
* baserestrictinfo quals are needed before we can check for
|
||||
* constraint exclusion; so do that first and then check to see
|
||||
* if we can disregard this child.
|
||||
* constraint exclusion; so do that first and then check to see if we
|
||||
* can disregard this child.
|
||||
*/
|
||||
childrel->baserestrictinfo = (List *)
|
||||
adjust_appendrel_attrs((Node *) rel->baserestrictinfo,
|
||||
@@ -325,8 +325,8 @@ set_append_rel_pathlist(PlannerInfo *root, RelOptInfo *rel,
|
||||
{
|
||||
/*
|
||||
* This child need not be scanned, so we can omit it from the
|
||||
* appendrel. Mark it with a dummy cheapest-path though, in
|
||||
* case best_appendrel_indexscan() looks at it later.
|
||||
* appendrel. Mark it with a dummy cheapest-path though, in case
|
||||
* best_appendrel_indexscan() looks at it later.
|
||||
*/
|
||||
set_dummy_rel_pathlist(childrel);
|
||||
continue;
|
||||
@@ -709,7 +709,7 @@ make_rel_from_joinlist(PlannerInfo *root, List *joinlist)
|
||||
* needed for these paths need have been instantiated.
|
||||
*
|
||||
* Note to plugin authors: the functions invoked during standard_join_search()
|
||||
* modify root->join_rel_list and root->join_rel_hash. If you want to do more
|
||||
* modify root->join_rel_list and root->join_rel_hash. If you want to do more
|
||||
* than one join-order search, you'll probably need to save and restore the
|
||||
* original states of those data structures. See geqo_eval() for an example.
|
||||
*/
|
||||
|
@@ -54,7 +54,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/path/costsize.c,v 1.187 2007/10/24 18:37:08 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/path/costsize.c,v 1.188 2007/11/15 21:14:35 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -112,12 +112,12 @@ typedef struct
|
||||
{
|
||||
PlannerInfo *root;
|
||||
QualCost total;
|
||||
} cost_qual_eval_context;
|
||||
} cost_qual_eval_context;
|
||||
|
||||
static MergeScanSelCache *cached_scansel(PlannerInfo *root,
|
||||
RestrictInfo *rinfo,
|
||||
PathKey *pathkey);
|
||||
static bool cost_qual_eval_walker(Node *node, cost_qual_eval_context *context);
|
||||
RestrictInfo *rinfo,
|
||||
PathKey * pathkey);
|
||||
static bool cost_qual_eval_walker(Node *node, cost_qual_eval_context * context);
|
||||
static Selectivity approx_selectivity(PlannerInfo *root, List *quals,
|
||||
JoinType jointype);
|
||||
static Selectivity join_in_selectivity(JoinPath *path, PlannerInfo *root);
|
||||
@@ -303,15 +303,14 @@ cost_index(IndexPath *path, PlannerInfo *root,
|
||||
max_IO_cost = (pages_fetched * random_page_cost) / num_scans;
|
||||
|
||||
/*
|
||||
* In the perfectly correlated case, the number of pages touched
|
||||
* by each scan is selectivity * table_size, and we can use the
|
||||
* Mackert and Lohman formula at the page level to estimate how
|
||||
* much work is saved by caching across scans. We still assume
|
||||
* all the fetches are random, though, which is an overestimate
|
||||
* that's hard to correct for without double-counting the cache
|
||||
* effects. (But in most cases where such a plan is actually
|
||||
* interesting, only one page would get fetched per scan anyway,
|
||||
* so it shouldn't matter much.)
|
||||
* In the perfectly correlated case, the number of pages touched by
|
||||
* each scan is selectivity * table_size, and we can use the Mackert
|
||||
* and Lohman formula at the page level to estimate how much work is
|
||||
* saved by caching across scans. We still assume all the fetches are
|
||||
* random, though, which is an overestimate that's hard to correct for
|
||||
* without double-counting the cache effects. (But in most cases
|
||||
* where such a plan is actually interesting, only one page would get
|
||||
* fetched per scan anyway, so it shouldn't matter much.)
|
||||
*/
|
||||
pages_fetched = ceil(indexSelectivity * (double) baserel->pages);
|
||||
|
||||
@@ -344,8 +343,8 @@ cost_index(IndexPath *path, PlannerInfo *root,
|
||||
}
|
||||
|
||||
/*
|
||||
* Now interpolate based on estimated index order correlation to get
|
||||
* total disk I/O cost for main table accesses.
|
||||
* Now interpolate based on estimated index order correlation to get total
|
||||
* disk I/O cost for main table accesses.
|
||||
*/
|
||||
csquared = indexCorrelation * indexCorrelation;
|
||||
|
||||
@@ -643,11 +642,12 @@ cost_bitmap_tree_node(Path *path, Cost *cost, Selectivity *selec)
|
||||
{
|
||||
*cost = ((IndexPath *) path)->indextotalcost;
|
||||
*selec = ((IndexPath *) path)->indexselectivity;
|
||||
|
||||
/*
|
||||
* Charge a small amount per retrieved tuple to reflect the costs of
|
||||
* manipulating the bitmap. This is mostly to make sure that a bitmap
|
||||
* scan doesn't look to be the same cost as an indexscan to retrieve
|
||||
* a single tuple.
|
||||
* scan doesn't look to be the same cost as an indexscan to retrieve a
|
||||
* single tuple.
|
||||
*/
|
||||
*cost += 0.1 * cpu_operator_cost * ((IndexPath *) path)->rows;
|
||||
}
|
||||
@@ -806,7 +806,7 @@ cost_tidscan(Path *path, PlannerInfo *root,
|
||||
|
||||
/*
|
||||
* We must force TID scan for WHERE CURRENT OF, because only nodeTidscan.c
|
||||
* understands how to do it correctly. Therefore, honor enable_tidscan
|
||||
* understands how to do it correctly. Therefore, honor enable_tidscan
|
||||
* only when CURRENT OF isn't present. Also note that cost_qual_eval
|
||||
* counts a CurrentOfExpr as having startup cost disable_cost, which we
|
||||
* subtract off here; that's to prevent other plan types such as seqscan
|
||||
@@ -1043,10 +1043,10 @@ cost_sort(Path *path, PlannerInfo *root,
|
||||
else if (tuples > 2 * output_tuples || input_bytes > work_mem_bytes)
|
||||
{
|
||||
/*
|
||||
* We'll use a bounded heap-sort keeping just K tuples in memory,
|
||||
* for a total number of tuple comparisons of N log2 K; but the
|
||||
* constant factor is a bit higher than for quicksort. Tweak it
|
||||
* so that the cost curve is continuous at the crossover point.
|
||||
* We'll use a bounded heap-sort keeping just K tuples in memory, for
|
||||
* a total number of tuple comparisons of N log2 K; but the constant
|
||||
* factor is a bit higher than for quicksort. Tweak it so that the
|
||||
* cost curve is continuous at the crossover point.
|
||||
*/
|
||||
startup_cost += 2.0 * cpu_operator_cost * tuples * LOG2(2.0 * output_tuples);
|
||||
}
|
||||
@@ -1454,8 +1454,8 @@ cost_mergejoin(MergePath *path, PlannerInfo *root)
|
||||
RestrictInfo *firstclause = (RestrictInfo *) linitial(mergeclauses);
|
||||
List *opathkeys;
|
||||
List *ipathkeys;
|
||||
PathKey *opathkey;
|
||||
PathKey *ipathkey;
|
||||
PathKey *opathkey;
|
||||
PathKey *ipathkey;
|
||||
MergeScanSelCache *cache;
|
||||
|
||||
/* Get the input pathkeys to determine the sort-order details */
|
||||
@@ -1593,7 +1593,7 @@ cost_mergejoin(MergePath *path, PlannerInfo *root)
|
||||
* run mergejoinscansel() with caching
|
||||
*/
|
||||
static MergeScanSelCache *
|
||||
cached_scansel(PlannerInfo *root, RestrictInfo *rinfo, PathKey *pathkey)
|
||||
cached_scansel(PlannerInfo *root, RestrictInfo *rinfo, PathKey * pathkey)
|
||||
{
|
||||
MergeScanSelCache *cache;
|
||||
ListCell *lc;
|
||||
@@ -1787,8 +1787,8 @@ cost_hashjoin(HashPath *path, PlannerInfo *root)
|
||||
* If inner relation is too big then we will need to "batch" the join,
|
||||
* which implies writing and reading most of the tuples to disk an extra
|
||||
* time. Charge seq_page_cost per page, since the I/O should be nice and
|
||||
* sequential. Writing the inner rel counts as startup cost,
|
||||
* all the rest as run cost.
|
||||
* sequential. Writing the inner rel counts as startup cost, all the rest
|
||||
* as run cost.
|
||||
*/
|
||||
if (numbatches > 1)
|
||||
{
|
||||
@@ -1891,16 +1891,16 @@ cost_qual_eval_node(QualCost *cost, Node *qual, PlannerInfo *root)
|
||||
}
|
||||
|
||||
static bool
|
||||
cost_qual_eval_walker(Node *node, cost_qual_eval_context *context)
|
||||
cost_qual_eval_walker(Node *node, cost_qual_eval_context * context)
|
||||
{
|
||||
if (node == NULL)
|
||||
return false;
|
||||
|
||||
/*
|
||||
* RestrictInfo nodes contain an eval_cost field reserved for this
|
||||
* routine's use, so that it's not necessary to evaluate the qual
|
||||
* clause's cost more than once. If the clause's cost hasn't been
|
||||
* computed yet, the field's startup value will contain -1.
|
||||
* routine's use, so that it's not necessary to evaluate the qual clause's
|
||||
* cost more than once. If the clause's cost hasn't been computed yet,
|
||||
* the field's startup value will contain -1.
|
||||
*/
|
||||
if (IsA(node, RestrictInfo))
|
||||
{
|
||||
@@ -1913,14 +1913,16 @@ cost_qual_eval_walker(Node *node, cost_qual_eval_context *context)
|
||||
locContext.root = context->root;
|
||||
locContext.total.startup = 0;
|
||||
locContext.total.per_tuple = 0;
|
||||
|
||||
/*
|
||||
* For an OR clause, recurse into the marked-up tree so that
|
||||
* we set the eval_cost for contained RestrictInfos too.
|
||||
* For an OR clause, recurse into the marked-up tree so that we
|
||||
* set the eval_cost for contained RestrictInfos too.
|
||||
*/
|
||||
if (rinfo->orclause)
|
||||
cost_qual_eval_walker((Node *) rinfo->orclause, &locContext);
|
||||
else
|
||||
cost_qual_eval_walker((Node *) rinfo->clause, &locContext);
|
||||
|
||||
/*
|
||||
* If the RestrictInfo is marked pseudoconstant, it will be tested
|
||||
* only once, so treat its cost as all startup cost.
|
||||
@@ -1941,8 +1943,8 @@ cost_qual_eval_walker(Node *node, cost_qual_eval_context *context)
|
||||
|
||||
/*
|
||||
* For each operator or function node in the given tree, we charge the
|
||||
* estimated execution cost given by pg_proc.procost (remember to
|
||||
* multiply this by cpu_operator_cost).
|
||||
* estimated execution cost given by pg_proc.procost (remember to multiply
|
||||
* this by cpu_operator_cost).
|
||||
*
|
||||
* Vars and Consts are charged zero, and so are boolean operators (AND,
|
||||
* OR, NOT). Simplistic, but a lot better than no model at all.
|
||||
@@ -1951,7 +1953,7 @@ cost_qual_eval_walker(Node *node, cost_qual_eval_context *context)
|
||||
* evaluation of AND/OR? Probably *not*, because that would make the
|
||||
* results depend on the clause ordering, and we are not in any position
|
||||
* to expect that the current ordering of the clauses is the one that's
|
||||
* going to end up being used. (Is it worth applying order_qual_clauses
|
||||
* going to end up being used. (Is it worth applying order_qual_clauses
|
||||
* much earlier in the planning process to fix this?)
|
||||
*/
|
||||
if (IsA(node, FuncExpr))
|
||||
@@ -1984,9 +1986,9 @@ cost_qual_eval_walker(Node *node, cost_qual_eval_context *context)
|
||||
else if (IsA(node, CoerceViaIO))
|
||||
{
|
||||
CoerceViaIO *iocoerce = (CoerceViaIO *) node;
|
||||
Oid iofunc;
|
||||
Oid typioparam;
|
||||
bool typisvarlena;
|
||||
Oid iofunc;
|
||||
Oid typioparam;
|
||||
bool typisvarlena;
|
||||
|
||||
/* check the result type's input function */
|
||||
getTypeInputInfo(iocoerce->resulttype,
|
||||
@@ -2014,7 +2016,7 @@ cost_qual_eval_walker(Node *node, cost_qual_eval_context *context)
|
||||
|
||||
foreach(lc, rcexpr->opnos)
|
||||
{
|
||||
Oid opid = lfirst_oid(lc);
|
||||
Oid opid = lfirst_oid(lc);
|
||||
|
||||
context->total.per_tuple += get_func_cost(get_opcode(opid)) *
|
||||
cpu_operator_cost;
|
||||
@@ -2069,7 +2071,7 @@ cost_qual_eval_walker(Node *node, cost_qual_eval_context *context)
|
||||
{
|
||||
/*
|
||||
* Otherwise we will be rescanning the subplan output on each
|
||||
* evaluation. We need to estimate how much of the output we will
|
||||
* evaluation. We need to estimate how much of the output we will
|
||||
* actually need to scan. NOTE: this logic should agree with
|
||||
* get_initplan_cost, below, and with the estimates used by
|
||||
* make_subplan() in plan/subselect.c.
|
||||
@@ -2266,9 +2268,9 @@ set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel,
|
||||
* double-counting them because they were not considered in estimating the
|
||||
* sizes of the component rels.
|
||||
*
|
||||
* For an outer join, we have to distinguish the selectivity of the
|
||||
* join's own clauses (JOIN/ON conditions) from any clauses that were
|
||||
* "pushed down". For inner joins we just count them all as joinclauses.
|
||||
* For an outer join, we have to distinguish the selectivity of the join's
|
||||
* own clauses (JOIN/ON conditions) from any clauses that were "pushed
|
||||
* down". For inner joins we just count them all as joinclauses.
|
||||
*/
|
||||
if (IS_OUTER_JOIN(jointype))
|
||||
{
|
||||
@@ -2316,7 +2318,7 @@ set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel,
|
||||
*
|
||||
* If we are doing an outer join, take that into account: the joinqual
|
||||
* selectivity has to be clamped using the knowledge that the output must
|
||||
* be at least as large as the non-nullable input. However, any
|
||||
* be at least as large as the non-nullable input. However, any
|
||||
* pushed-down quals are applied after the outer join, so their
|
||||
* selectivity applies fully.
|
||||
*
|
||||
@@ -2515,7 +2517,7 @@ set_rel_width(PlannerInfo *root, RelOptInfo *rel)
|
||||
if (rel->relid > 0)
|
||||
rel_reloid = getrelid(rel->relid, root->parse->rtable);
|
||||
else
|
||||
rel_reloid = InvalidOid; /* probably can't happen */
|
||||
rel_reloid = InvalidOid; /* probably can't happen */
|
||||
|
||||
foreach(tllist, rel->reltargetlist)
|
||||
{
|
||||
|
@@ -10,7 +10,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/path/equivclass.c,v 1.4 2007/11/08 21:49:47 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/path/equivclass.c,v 1.5 2007/11/15 21:14:35 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -26,37 +26,37 @@
|
||||
#include "utils/lsyscache.h"
|
||||
|
||||
|
||||
static EquivalenceMember *add_eq_member(EquivalenceClass *ec,
|
||||
Expr *expr, Relids relids,
|
||||
bool is_child, Oid datatype);
|
||||
static EquivalenceMember *add_eq_member(EquivalenceClass * ec,
|
||||
Expr *expr, Relids relids,
|
||||
bool is_child, Oid datatype);
|
||||
static void generate_base_implied_equalities_const(PlannerInfo *root,
|
||||
EquivalenceClass *ec);
|
||||
EquivalenceClass * ec);
|
||||
static void generate_base_implied_equalities_no_const(PlannerInfo *root,
|
||||
EquivalenceClass *ec);
|
||||
EquivalenceClass * ec);
|
||||
static void generate_base_implied_equalities_broken(PlannerInfo *root,
|
||||
EquivalenceClass *ec);
|
||||
EquivalenceClass * ec);
|
||||
static List *generate_join_implied_equalities_normal(PlannerInfo *root,
|
||||
EquivalenceClass *ec,
|
||||
EquivalenceClass * ec,
|
||||
RelOptInfo *joinrel,
|
||||
RelOptInfo *outer_rel,
|
||||
RelOptInfo *inner_rel);
|
||||
static List *generate_join_implied_equalities_broken(PlannerInfo *root,
|
||||
EquivalenceClass *ec,
|
||||
EquivalenceClass * ec,
|
||||
RelOptInfo *joinrel,
|
||||
RelOptInfo *outer_rel,
|
||||
RelOptInfo *inner_rel);
|
||||
static Oid select_equality_operator(EquivalenceClass *ec,
|
||||
Oid lefttype, Oid righttype);
|
||||
static Oid select_equality_operator(EquivalenceClass * ec,
|
||||
Oid lefttype, Oid righttype);
|
||||
static RestrictInfo *create_join_clause(PlannerInfo *root,
|
||||
EquivalenceClass *ec, Oid opno,
|
||||
EquivalenceMember *leftem,
|
||||
EquivalenceMember *rightem,
|
||||
EquivalenceClass *parent_ec);
|
||||
EquivalenceClass * ec, Oid opno,
|
||||
EquivalenceMember * leftem,
|
||||
EquivalenceMember * rightem,
|
||||
EquivalenceClass * parent_ec);
|
||||
static void reconsider_outer_join_clause(PlannerInfo *root,
|
||||
RestrictInfo *rinfo,
|
||||
bool outer_on_left);
|
||||
RestrictInfo *rinfo,
|
||||
bool outer_on_left);
|
||||
static void reconsider_full_join_clause(PlannerInfo *root,
|
||||
RestrictInfo *rinfo);
|
||||
RestrictInfo *rinfo);
|
||||
|
||||
|
||||
/*
|
||||
@@ -70,7 +70,7 @@ static void reconsider_full_join_clause(PlannerInfo *root,
|
||||
*
|
||||
* If below_outer_join is true, then the clause was found below the nullable
|
||||
* side of an outer join, so its sides might validly be both NULL rather than
|
||||
* strictly equal. We can still deduce equalities in such cases, but we take
|
||||
* strictly equal. We can still deduce equalities in such cases, but we take
|
||||
* care to mark an EquivalenceClass if it came from any such clauses. Also,
|
||||
* we have to check that both sides are either pseudo-constants or strict
|
||||
* functions of Vars, else they might not both go to NULL above the outer
|
||||
@@ -127,37 +127,37 @@ process_equivalence(PlannerInfo *root, RestrictInfo *restrictinfo,
|
||||
}
|
||||
|
||||
/*
|
||||
* We use the declared input types of the operator, not exprType() of
|
||||
* the inputs, as the nominal datatypes for opfamily lookup. This
|
||||
* presumes that btree operators are always registered with amoplefttype
|
||||
* and amoprighttype equal to their declared input types. We will need
|
||||
* this info anyway to build EquivalenceMember nodes, and by extracting
|
||||
* it now we can use type comparisons to short-circuit some equal() tests.
|
||||
* We use the declared input types of the operator, not exprType() of the
|
||||
* inputs, as the nominal datatypes for opfamily lookup. This presumes
|
||||
* that btree operators are always registered with amoplefttype and
|
||||
* amoprighttype equal to their declared input types. We will need this
|
||||
* info anyway to build EquivalenceMember nodes, and by extracting it now
|
||||
* we can use type comparisons to short-circuit some equal() tests.
|
||||
*/
|
||||
op_input_types(opno, &item1_type, &item2_type);
|
||||
|
||||
opfamilies = restrictinfo->mergeopfamilies;
|
||||
|
||||
/*
|
||||
* Sweep through the existing EquivalenceClasses looking for matches
|
||||
* to item1 and item2. These are the possible outcomes:
|
||||
* Sweep through the existing EquivalenceClasses looking for matches to
|
||||
* item1 and item2. These are the possible outcomes:
|
||||
*
|
||||
* 1. We find both in the same EC. The equivalence is already known,
|
||||
* so there's nothing to do.
|
||||
* 1. We find both in the same EC. The equivalence is already known, so
|
||||
* there's nothing to do.
|
||||
*
|
||||
* 2. We find both in different ECs. Merge the two ECs together.
|
||||
*
|
||||
* 3. We find just one. Add the other to its EC.
|
||||
*
|
||||
* 4. We find neither. Make a new, two-entry EC.
|
||||
* 4. We find neither. Make a new, two-entry EC.
|
||||
*
|
||||
* Note: since all ECs are built through this process, it's impossible
|
||||
* that we'd match an item in more than one existing EC. It is possible
|
||||
* to match more than once within an EC, if someone fed us something silly
|
||||
* like "WHERE X=X". (However, we can't simply discard such clauses,
|
||||
* since they should fail when X is null; so we will build a 2-member
|
||||
* EC to ensure the correct restriction clause gets generated. Hence
|
||||
* there is no shortcut here for item1 and item2 equal.)
|
||||
* since they should fail when X is null; so we will build a 2-member EC
|
||||
* to ensure the correct restriction clause gets generated. Hence there
|
||||
* is no shortcut here for item1 and item2 equal.)
|
||||
*/
|
||||
ec1 = ec2 = NULL;
|
||||
em1 = em2 = NULL;
|
||||
@@ -182,11 +182,11 @@ process_equivalence(PlannerInfo *root, RestrictInfo *restrictinfo,
|
||||
{
|
||||
EquivalenceMember *cur_em = (EquivalenceMember *) lfirst(lc2);
|
||||
|
||||
Assert(!cur_em->em_is_child); /* no children yet */
|
||||
Assert(!cur_em->em_is_child); /* no children yet */
|
||||
|
||||
/*
|
||||
* If below an outer join, don't match constants: they're not
|
||||
* as constant as they look.
|
||||
* If below an outer join, don't match constants: they're not as
|
||||
* constant as they look.
|
||||
*/
|
||||
if ((below_outer_join || cur_ec->ec_below_outer_join) &&
|
||||
cur_em->em_is_const)
|
||||
@@ -234,11 +234,11 @@ process_equivalence(PlannerInfo *root, RestrictInfo *restrictinfo,
|
||||
}
|
||||
|
||||
/*
|
||||
* Case 2: need to merge ec1 and ec2. We add ec2's items to ec1,
|
||||
* then set ec2's ec_merged link to point to ec1 and remove ec2
|
||||
* from the eq_classes list. We cannot simply delete ec2 because
|
||||
* that could leave dangling pointers in existing PathKeys. We
|
||||
* leave it behind with a link so that the merged EC can be found.
|
||||
* Case 2: need to merge ec1 and ec2. We add ec2's items to ec1, then
|
||||
* set ec2's ec_merged link to point to ec1 and remove ec2 from the
|
||||
* eq_classes list. We cannot simply delete ec2 because that could
|
||||
* leave dangling pointers in existing PathKeys. We leave it behind
|
||||
* with a link so that the merged EC can be found.
|
||||
*/
|
||||
ec1->ec_members = list_concat(ec1->ec_members, ec2->ec_members);
|
||||
ec1->ec_sources = list_concat(ec1->ec_sources, ec2->ec_sources);
|
||||
@@ -313,7 +313,7 @@ process_equivalence(PlannerInfo *root, RestrictInfo *restrictinfo,
|
||||
* add_eq_member - build a new EquivalenceMember and add it to an EC
|
||||
*/
|
||||
static EquivalenceMember *
|
||||
add_eq_member(EquivalenceClass *ec, Expr *expr, Relids relids,
|
||||
add_eq_member(EquivalenceClass * ec, Expr *expr, Relids relids,
|
||||
bool is_child, Oid datatype)
|
||||
{
|
||||
EquivalenceMember *em = makeNode(EquivalenceMember);
|
||||
@@ -327,10 +327,10 @@ add_eq_member(EquivalenceClass *ec, Expr *expr, Relids relids,
|
||||
if (bms_is_empty(relids))
|
||||
{
|
||||
/*
|
||||
* No Vars, assume it's a pseudoconstant. This is correct for
|
||||
* entries generated from process_equivalence(), because a WHERE
|
||||
* clause can't contain aggregates or SRFs, and non-volatility was
|
||||
* checked before process_equivalence() ever got called. But
|
||||
* No Vars, assume it's a pseudoconstant. This is correct for entries
|
||||
* generated from process_equivalence(), because a WHERE clause can't
|
||||
* contain aggregates or SRFs, and non-volatility was checked before
|
||||
* process_equivalence() ever got called. But
|
||||
* get_eclass_for_sort_expr() has to work harder. We put the tests
|
||||
* there not here to save cycles in the equivalence case.
|
||||
*/
|
||||
@@ -399,8 +399,8 @@ get_eclass_for_sort_expr(PlannerInfo *root,
|
||||
EquivalenceMember *cur_em = (EquivalenceMember *) lfirst(lc2);
|
||||
|
||||
/*
|
||||
* If below an outer join, don't match constants: they're not
|
||||
* as constant as they look.
|
||||
* If below an outer join, don't match constants: they're not as
|
||||
* constant as they look.
|
||||
*/
|
||||
if (cur_ec->ec_below_outer_join &&
|
||||
cur_em->em_is_const)
|
||||
@@ -408,15 +408,15 @@ get_eclass_for_sort_expr(PlannerInfo *root,
|
||||
|
||||
if (expr_datatype == cur_em->em_datatype &&
|
||||
equal(expr, cur_em->em_expr))
|
||||
return cur_ec; /* Match! */
|
||||
return cur_ec; /* Match! */
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* No match, so build a new single-member EC
|
||||
*
|
||||
* Here, we must be sure that we construct the EC in the right context.
|
||||
* We can assume, however, that the passed expr is long-lived.
|
||||
* Here, we must be sure that we construct the EC in the right context. We
|
||||
* can assume, however, that the passed expr is long-lived.
|
||||
*/
|
||||
oldcontext = MemoryContextSwitchTo(root->planner_cxt);
|
||||
|
||||
@@ -437,8 +437,8 @@ get_eclass_for_sort_expr(PlannerInfo *root,
|
||||
|
||||
/*
|
||||
* add_eq_member doesn't check for volatile functions, set-returning
|
||||
* functions, or aggregates, but such could appear in sort expressions;
|
||||
* so we have to check whether its const-marking was correct.
|
||||
* functions, or aggregates, but such could appear in sort expressions; so
|
||||
* we have to check whether its const-marking was correct.
|
||||
*/
|
||||
if (newec->ec_has_const)
|
||||
{
|
||||
@@ -466,7 +466,7 @@ get_eclass_for_sort_expr(PlannerInfo *root,
|
||||
*
|
||||
* When an EC contains pseudoconstants, our strategy is to generate
|
||||
* "member = const1" clauses where const1 is the first constant member, for
|
||||
* every other member (including other constants). If we are able to do this
|
||||
* every other member (including other constants). If we are able to do this
|
||||
* then we don't need any "var = var" comparisons because we've successfully
|
||||
* constrained all the vars at their points of creation. If we fail to
|
||||
* generate any of these clauses due to lack of cross-type operators, we fall
|
||||
@@ -491,7 +491,7 @@ get_eclass_for_sort_expr(PlannerInfo *root,
|
||||
* "WHERE a.x = b.y AND b.y = a.z", the scheme breaks down if we cannot
|
||||
* generate "a.x = a.z" as a restriction clause for A.) In this case we mark
|
||||
* the EC "ec_broken" and fall back to regurgitating its original source
|
||||
* RestrictInfos at appropriate times. We do not try to retract any derived
|
||||
* RestrictInfos at appropriate times. We do not try to retract any derived
|
||||
* clauses already generated from the broken EC, so the resulting plan could
|
||||
* be poor due to bad selectivity estimates caused by redundant clauses. But
|
||||
* the correct solution to that is to fix the opfamilies ...
|
||||
@@ -517,8 +517,8 @@ generate_base_implied_equalities(PlannerInfo *root)
|
||||
{
|
||||
EquivalenceClass *ec = (EquivalenceClass *) lfirst(lc);
|
||||
|
||||
Assert(ec->ec_merged == NULL); /* else shouldn't be in list */
|
||||
Assert(!ec->ec_broken); /* not yet anyway... */
|
||||
Assert(ec->ec_merged == NULL); /* else shouldn't be in list */
|
||||
Assert(!ec->ec_broken); /* not yet anyway... */
|
||||
|
||||
/* Single-member ECs won't generate any deductions */
|
||||
if (list_length(ec->ec_members) <= 1)
|
||||
@@ -535,9 +535,8 @@ generate_base_implied_equalities(PlannerInfo *root)
|
||||
}
|
||||
|
||||
/*
|
||||
* This is also a handy place to mark base rels (which should all
|
||||
* exist by now) with flags showing whether they have pending eclass
|
||||
* joins.
|
||||
* This is also a handy place to mark base rels (which should all exist by
|
||||
* now) with flags showing whether they have pending eclass joins.
|
||||
*/
|
||||
for (rti = 1; rti < root->simple_rel_array_size; rti++)
|
||||
{
|
||||
@@ -555,7 +554,7 @@ generate_base_implied_equalities(PlannerInfo *root)
|
||||
*/
|
||||
static void
|
||||
generate_base_implied_equalities_const(PlannerInfo *root,
|
||||
EquivalenceClass *ec)
|
||||
EquivalenceClass * ec)
|
||||
{
|
||||
EquivalenceMember *const_em = NULL;
|
||||
ListCell *lc;
|
||||
@@ -579,7 +578,7 @@ generate_base_implied_equalities_const(PlannerInfo *root,
|
||||
EquivalenceMember *cur_em = (EquivalenceMember *) lfirst(lc);
|
||||
Oid eq_op;
|
||||
|
||||
Assert(!cur_em->em_is_child); /* no children yet */
|
||||
Assert(!cur_em->em_is_child); /* no children yet */
|
||||
if (cur_em == const_em)
|
||||
continue;
|
||||
eq_op = select_equality_operator(ec,
|
||||
@@ -604,7 +603,7 @@ generate_base_implied_equalities_const(PlannerInfo *root,
|
||||
*/
|
||||
static void
|
||||
generate_base_implied_equalities_no_const(PlannerInfo *root,
|
||||
EquivalenceClass *ec)
|
||||
EquivalenceClass * ec)
|
||||
{
|
||||
EquivalenceMember **prev_ems;
|
||||
ListCell *lc;
|
||||
@@ -613,9 +612,10 @@ generate_base_implied_equalities_no_const(PlannerInfo *root,
|
||||
* We scan the EC members once and track the last-seen member for each
|
||||
* base relation. When we see another member of the same base relation,
|
||||
* we generate "prev_mem = cur_mem". This results in the minimum number
|
||||
* of derived clauses, but it's possible that it will fail when a different
|
||||
* ordering would succeed. XXX FIXME: use a UNION-FIND algorithm similar
|
||||
* to the way we build merged ECs. (Use a list-of-lists for each rel.)
|
||||
* of derived clauses, but it's possible that it will fail when a
|
||||
* different ordering would succeed. XXX FIXME: use a UNION-FIND
|
||||
* algorithm similar to the way we build merged ECs. (Use a list-of-lists
|
||||
* for each rel.)
|
||||
*/
|
||||
prev_ems = (EquivalenceMember **)
|
||||
palloc0(root->simple_rel_array_size * sizeof(EquivalenceMember *));
|
||||
@@ -625,7 +625,7 @@ generate_base_implied_equalities_no_const(PlannerInfo *root,
|
||||
EquivalenceMember *cur_em = (EquivalenceMember *) lfirst(lc);
|
||||
int relid;
|
||||
|
||||
Assert(!cur_em->em_is_child); /* no children yet */
|
||||
Assert(!cur_em->em_is_child); /* no children yet */
|
||||
if (bms_membership(cur_em->em_relids) != BMS_SINGLETON)
|
||||
continue;
|
||||
relid = bms_singleton_member(cur_em->em_relids);
|
||||
@@ -657,12 +657,12 @@ generate_base_implied_equalities_no_const(PlannerInfo *root,
|
||||
pfree(prev_ems);
|
||||
|
||||
/*
|
||||
* We also have to make sure that all the Vars used in the member
|
||||
* clauses will be available at any join node we might try to reference
|
||||
* them at. For the moment we force all the Vars to be available at
|
||||
* all join nodes for this eclass. Perhaps this could be improved by
|
||||
* doing some pre-analysis of which members we prefer to join, but it's
|
||||
* no worse than what happened in the pre-8.3 code.
|
||||
* We also have to make sure that all the Vars used in the member clauses
|
||||
* will be available at any join node we might try to reference them at.
|
||||
* For the moment we force all the Vars to be available at all join nodes
|
||||
* for this eclass. Perhaps this could be improved by doing some
|
||||
* pre-analysis of which members we prefer to join, but it's no worse than
|
||||
* what happened in the pre-8.3 code.
|
||||
*/
|
||||
foreach(lc, ec->ec_members)
|
||||
{
|
||||
@@ -685,7 +685,7 @@ generate_base_implied_equalities_no_const(PlannerInfo *root,
|
||||
*/
|
||||
static void
|
||||
generate_base_implied_equalities_broken(PlannerInfo *root,
|
||||
EquivalenceClass *ec)
|
||||
EquivalenceClass * ec)
|
||||
{
|
||||
ListCell *lc;
|
||||
|
||||
@@ -720,7 +720,7 @@ generate_base_implied_equalities_broken(PlannerInfo *root,
|
||||
* we consider different join paths, we avoid generating multiple copies:
|
||||
* whenever we select a particular pair of EquivalenceMembers to join,
|
||||
* we check to see if the pair matches any original clause (in ec_sources)
|
||||
* or previously-built clause (in ec_derives). This saves memory and allows
|
||||
* or previously-built clause (in ec_derives). This saves memory and allows
|
||||
* re-use of information cached in RestrictInfos.
|
||||
*/
|
||||
List *
|
||||
@@ -735,7 +735,7 @@ generate_join_implied_equalities(PlannerInfo *root,
|
||||
foreach(lc, root->eq_classes)
|
||||
{
|
||||
EquivalenceClass *ec = (EquivalenceClass *) lfirst(lc);
|
||||
List *sublist = NIL;
|
||||
List *sublist = NIL;
|
||||
|
||||
/* ECs containing consts do not need any further enforcement */
|
||||
if (ec->ec_has_const)
|
||||
@@ -775,7 +775,7 @@ generate_join_implied_equalities(PlannerInfo *root,
|
||||
*/
|
||||
static List *
|
||||
generate_join_implied_equalities_normal(PlannerInfo *root,
|
||||
EquivalenceClass *ec,
|
||||
EquivalenceClass * ec,
|
||||
RelOptInfo *joinrel,
|
||||
RelOptInfo *outer_rel,
|
||||
RelOptInfo *inner_rel)
|
||||
@@ -787,13 +787,13 @@ generate_join_implied_equalities_normal(PlannerInfo *root,
|
||||
ListCell *lc1;
|
||||
|
||||
/*
|
||||
* First, scan the EC to identify member values that are computable
|
||||
* at the outer rel, at the inner rel, or at this relation but not in
|
||||
* either input rel. The outer-rel members should already be enforced
|
||||
* equal, likewise for the inner-rel members. We'll need to create
|
||||
* clauses to enforce that any newly computable members are all equal
|
||||
* to each other as well as to at least one input member, plus enforce
|
||||
* at least one outer-rel member equal to at least one inner-rel member.
|
||||
* First, scan the EC to identify member values that are computable at the
|
||||
* outer rel, at the inner rel, or at this relation but not in either
|
||||
* input rel. The outer-rel members should already be enforced equal,
|
||||
* likewise for the inner-rel members. We'll need to create clauses to
|
||||
* enforce that any newly computable members are all equal to each other
|
||||
* as well as to at least one input member, plus enforce at least one
|
||||
* outer-rel member equal to at least one inner-rel member.
|
||||
*/
|
||||
foreach(lc1, ec->ec_members)
|
||||
{
|
||||
@@ -813,20 +813,20 @@ generate_join_implied_equalities_normal(PlannerInfo *root,
|
||||
}
|
||||
|
||||
/*
|
||||
* First, select the joinclause if needed. We can equate any one outer
|
||||
* First, select the joinclause if needed. We can equate any one outer
|
||||
* member to any one inner member, but we have to find a datatype
|
||||
* combination for which an opfamily member operator exists. If we
|
||||
* have choices, we prefer simple Var members (possibly with RelabelType)
|
||||
* since these are (a) cheapest to compute at runtime and (b) most likely
|
||||
* to have useful statistics. Also, if enable_hashjoin is on, we prefer
|
||||
* combination for which an opfamily member operator exists. If we have
|
||||
* choices, we prefer simple Var members (possibly with RelabelType) since
|
||||
* these are (a) cheapest to compute at runtime and (b) most likely to
|
||||
* have useful statistics. Also, if enable_hashjoin is on, we prefer
|
||||
* operators that are also hashjoinable.
|
||||
*/
|
||||
if (outer_members && inner_members)
|
||||
{
|
||||
EquivalenceMember *best_outer_em = NULL;
|
||||
EquivalenceMember *best_inner_em = NULL;
|
||||
Oid best_eq_op = InvalidOid;
|
||||
int best_score = -1;
|
||||
Oid best_eq_op = InvalidOid;
|
||||
int best_score = -1;
|
||||
RestrictInfo *rinfo;
|
||||
|
||||
foreach(lc1, outer_members)
|
||||
@@ -837,8 +837,8 @@ generate_join_implied_equalities_normal(PlannerInfo *root,
|
||||
foreach(lc2, inner_members)
|
||||
{
|
||||
EquivalenceMember *inner_em = (EquivalenceMember *) lfirst(lc2);
|
||||
Oid eq_op;
|
||||
int score;
|
||||
Oid eq_op;
|
||||
int score;
|
||||
|
||||
eq_op = select_equality_operator(ec,
|
||||
outer_em->em_datatype,
|
||||
@@ -863,11 +863,11 @@ generate_join_implied_equalities_normal(PlannerInfo *root,
|
||||
best_eq_op = eq_op;
|
||||
best_score = score;
|
||||
if (best_score == 3)
|
||||
break; /* no need to look further */
|
||||
break; /* no need to look further */
|
||||
}
|
||||
}
|
||||
if (best_score == 3)
|
||||
break; /* no need to look further */
|
||||
break; /* no need to look further */
|
||||
}
|
||||
if (best_score < 0)
|
||||
{
|
||||
@@ -892,8 +892,8 @@ generate_join_implied_equalities_normal(PlannerInfo *root,
|
||||
* Vars from both sides of the join. We have to equate all of these to
|
||||
* each other as well as to at least one old member (if any).
|
||||
*
|
||||
* XXX as in generate_base_implied_equalities_no_const, we could be a
|
||||
* lot smarter here to avoid unnecessary failures in cross-type situations.
|
||||
* XXX as in generate_base_implied_equalities_no_const, we could be a lot
|
||||
* smarter here to avoid unnecessary failures in cross-type situations.
|
||||
* For now, use the same left-to-right method used there.
|
||||
*/
|
||||
if (new_members)
|
||||
@@ -944,7 +944,7 @@ generate_join_implied_equalities_normal(PlannerInfo *root,
|
||||
*/
|
||||
static List *
|
||||
generate_join_implied_equalities_broken(PlannerInfo *root,
|
||||
EquivalenceClass *ec,
|
||||
EquivalenceClass * ec,
|
||||
RelOptInfo *joinrel,
|
||||
RelOptInfo *outer_rel,
|
||||
RelOptInfo *inner_rel)
|
||||
@@ -957,7 +957,7 @@ generate_join_implied_equalities_broken(PlannerInfo *root,
|
||||
RestrictInfo *restrictinfo = (RestrictInfo *) lfirst(lc);
|
||||
|
||||
if (bms_is_subset(restrictinfo->required_relids, joinrel->relids) &&
|
||||
!bms_is_subset(restrictinfo->required_relids, outer_rel->relids) &&
|
||||
!bms_is_subset(restrictinfo->required_relids, outer_rel->relids) &&
|
||||
!bms_is_subset(restrictinfo->required_relids, inner_rel->relids))
|
||||
result = lappend(result, restrictinfo);
|
||||
}
|
||||
@@ -973,14 +973,14 @@ generate_join_implied_equalities_broken(PlannerInfo *root,
|
||||
* Returns InvalidOid if no operator can be found for this datatype combination
|
||||
*/
|
||||
static Oid
|
||||
select_equality_operator(EquivalenceClass *ec, Oid lefttype, Oid righttype)
|
||||
select_equality_operator(EquivalenceClass * ec, Oid lefttype, Oid righttype)
|
||||
{
|
||||
ListCell *lc;
|
||||
|
||||
foreach(lc, ec->ec_opfamilies)
|
||||
{
|
||||
Oid opfamily = lfirst_oid(lc);
|
||||
Oid opno;
|
||||
Oid opfamily = lfirst_oid(lc);
|
||||
Oid opno;
|
||||
|
||||
opno = get_opfamily_member(opfamily, lefttype, righttype,
|
||||
BTEqualStrategyNumber);
|
||||
@@ -1003,10 +1003,10 @@ select_equality_operator(EquivalenceClass *ec, Oid lefttype, Oid righttype)
|
||||
*/
|
||||
static RestrictInfo *
|
||||
create_join_clause(PlannerInfo *root,
|
||||
EquivalenceClass *ec, Oid opno,
|
||||
EquivalenceMember *leftem,
|
||||
EquivalenceMember *rightem,
|
||||
EquivalenceClass *parent_ec)
|
||||
EquivalenceClass * ec, Oid opno,
|
||||
EquivalenceMember * leftem,
|
||||
EquivalenceMember * rightem,
|
||||
EquivalenceClass * parent_ec)
|
||||
{
|
||||
RestrictInfo *rinfo;
|
||||
ListCell *lc;
|
||||
@@ -1014,8 +1014,8 @@ create_join_clause(PlannerInfo *root,
|
||||
|
||||
/*
|
||||
* Search to see if we already built a RestrictInfo for this pair of
|
||||
* EquivalenceMembers. We can use either original source clauses or
|
||||
* previously-derived clauses. The check on opno is probably redundant,
|
||||
* EquivalenceMembers. We can use either original source clauses or
|
||||
* previously-derived clauses. The check on opno is probably redundant,
|
||||
* but be safe ...
|
||||
*/
|
||||
foreach(lc, ec->ec_sources)
|
||||
@@ -1039,8 +1039,8 @@ create_join_clause(PlannerInfo *root,
|
||||
}
|
||||
|
||||
/*
|
||||
* Not there, so build it, in planner context so we can re-use it.
|
||||
* (Not important in normal planning, but definitely so in GEQO.)
|
||||
* Not there, so build it, in planner context so we can re-use it. (Not
|
||||
* important in normal planning, but definitely so in GEQO.)
|
||||
*/
|
||||
oldcontext = MemoryContextSwitchTo(root->planner_cxt);
|
||||
|
||||
@@ -1216,10 +1216,9 @@ reconsider_outer_join_clause(PlannerInfo *root, RestrictInfo *rinfo,
|
||||
continue; /* no match, so ignore this EC */
|
||||
|
||||
/*
|
||||
* Yes it does! Try to generate a clause INNERVAR = CONSTANT for
|
||||
* each CONSTANT in the EC. Note that we must succeed with at
|
||||
* least one constant before we can decide to throw away the
|
||||
* outer-join clause.
|
||||
* Yes it does! Try to generate a clause INNERVAR = CONSTANT for each
|
||||
* CONSTANT in the EC. Note that we must succeed with at least one
|
||||
* constant before we can decide to throw away the outer-join clause.
|
||||
*/
|
||||
match = false;
|
||||
foreach(lc2, cur_ec->ec_members)
|
||||
@@ -1300,15 +1299,15 @@ reconsider_full_join_clause(PlannerInfo *root, RestrictInfo *rinfo)
|
||||
/*
|
||||
* Does it contain a COALESCE(leftvar, rightvar) construct?
|
||||
*
|
||||
* We can assume the COALESCE() inputs are in the same order as
|
||||
* the join clause, since both were automatically generated in the
|
||||
* cases we care about.
|
||||
* We can assume the COALESCE() inputs are in the same order as the
|
||||
* join clause, since both were automatically generated in the cases
|
||||
* we care about.
|
||||
*
|
||||
* XXX currently this may fail to match in cross-type cases
|
||||
* because the COALESCE will contain typecast operations while the
|
||||
* join clause may not (if there is a cross-type mergejoin
|
||||
* operator available for the two column types). Is it OK to strip
|
||||
* implicit coercions from the COALESCE arguments?
|
||||
* XXX currently this may fail to match in cross-type cases because
|
||||
* the COALESCE will contain typecast operations while the join clause
|
||||
* may not (if there is a cross-type mergejoin operator available for
|
||||
* the two column types). Is it OK to strip implicit coercions from
|
||||
* the COALESCE arguments?
|
||||
*/
|
||||
match = false;
|
||||
foreach(lc2, cur_ec->ec_members)
|
||||
@@ -1337,9 +1336,9 @@ reconsider_full_join_clause(PlannerInfo *root, RestrictInfo *rinfo)
|
||||
|
||||
/*
|
||||
* Yes it does! Try to generate clauses LEFTVAR = CONSTANT and
|
||||
* RIGHTVAR = CONSTANT for each CONSTANT in the EC. Note that we
|
||||
* must succeed with at least one constant for each var before
|
||||
* we can decide to throw away the outer-join clause.
|
||||
* RIGHTVAR = CONSTANT for each CONSTANT in the EC. Note that we must
|
||||
* succeed with at least one constant for each var before we can
|
||||
* decide to throw away the outer-join clause.
|
||||
*/
|
||||
matchleft = matchright = false;
|
||||
foreach(lc2, cur_ec->ec_members)
|
||||
@@ -1378,16 +1377,17 @@ reconsider_full_join_clause(PlannerInfo *root, RestrictInfo *rinfo)
|
||||
|
||||
/*
|
||||
* If we were able to equate both vars to constants, we're done, and
|
||||
* we can throw away the full-join clause as redundant. Moreover,
|
||||
* we can remove the COALESCE entry from the EC, since the added
|
||||
* restrictions ensure it will always have the expected value.
|
||||
* (We don't bother trying to update ec_relids or ec_sources.)
|
||||
* we can throw away the full-join clause as redundant. Moreover, we
|
||||
* can remove the COALESCE entry from the EC, since the added
|
||||
* restrictions ensure it will always have the expected value. (We
|
||||
* don't bother trying to update ec_relids or ec_sources.)
|
||||
*/
|
||||
if (matchleft && matchright)
|
||||
{
|
||||
cur_ec->ec_members = list_delete_ptr(cur_ec->ec_members, coal_em);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Otherwise, fall out of the search loop, since we know the COALESCE
|
||||
* appears in at most one EC (XXX might stop being true if we allow
|
||||
@@ -1489,8 +1489,8 @@ add_child_rel_equivalences(PlannerInfo *root,
|
||||
if (bms_equal(cur_em->em_relids, parent_rel->relids))
|
||||
{
|
||||
/* Yes, generate transformed child version */
|
||||
Expr *child_expr;
|
||||
|
||||
Expr *child_expr;
|
||||
|
||||
child_expr = (Expr *)
|
||||
adjust_appendrel_attrs((Node *) cur_em->em_expr,
|
||||
appinfo);
|
||||
@@ -1528,8 +1528,8 @@ find_eclass_clauses_for_index_join(PlannerInfo *root, RelOptInfo *rel,
|
||||
continue;
|
||||
|
||||
/*
|
||||
* No point in searching if rel not mentioned in eclass (but we
|
||||
* can't tell that for a child rel).
|
||||
* No point in searching if rel not mentioned in eclass (but we can't
|
||||
* tell that for a child rel).
|
||||
*/
|
||||
if (!is_child_rel &&
|
||||
!bms_is_subset(rel->relids, cur_ec->ec_relids))
|
||||
@@ -1543,7 +1543,7 @@ find_eclass_clauses_for_index_join(PlannerInfo *root, RelOptInfo *rel,
|
||||
{
|
||||
EquivalenceMember *cur_em = (EquivalenceMember *) lfirst(lc2);
|
||||
EquivalenceMember *best_outer_em = NULL;
|
||||
Oid best_eq_op = InvalidOid;
|
||||
Oid best_eq_op = InvalidOid;
|
||||
ListCell *lc3;
|
||||
|
||||
if (!bms_equal(cur_em->em_relids, rel->relids) ||
|
||||
@@ -1552,14 +1552,14 @@ find_eclass_clauses_for_index_join(PlannerInfo *root, RelOptInfo *rel,
|
||||
|
||||
/*
|
||||
* Found one, so try to generate a join clause. This is like
|
||||
* generate_join_implied_equalities_normal, except simpler
|
||||
* since our only preference item is to pick a Var on the
|
||||
* outer side. We only need one join clause per index col.
|
||||
* generate_join_implied_equalities_normal, except simpler since
|
||||
* our only preference item is to pick a Var on the outer side.
|
||||
* We only need one join clause per index col.
|
||||
*/
|
||||
foreach(lc3, cur_ec->ec_members)
|
||||
{
|
||||
EquivalenceMember *outer_em = (EquivalenceMember *) lfirst(lc3);
|
||||
Oid eq_op;
|
||||
Oid eq_op;
|
||||
|
||||
if (!bms_is_subset(outer_em->em_relids, outer_relids))
|
||||
continue;
|
||||
@@ -1573,7 +1573,7 @@ find_eclass_clauses_for_index_join(PlannerInfo *root, RelOptInfo *rel,
|
||||
if (IsA(outer_em->em_expr, Var) ||
|
||||
(IsA(outer_em->em_expr, RelabelType) &&
|
||||
IsA(((RelabelType *) outer_em->em_expr)->arg, Var)))
|
||||
break; /* no need to look further */
|
||||
break; /* no need to look further */
|
||||
}
|
||||
|
||||
if (best_outer_em)
|
||||
@@ -1587,9 +1587,10 @@ find_eclass_clauses_for_index_join(PlannerInfo *root, RelOptInfo *rel,
|
||||
cur_ec);
|
||||
|
||||
result = lappend(result, rinfo);
|
||||
|
||||
/*
|
||||
* Note: we keep scanning here because we want to provide
|
||||
* a clause for every possible indexcol.
|
||||
* Note: we keep scanning here because we want to provide a
|
||||
* clause for every possible indexcol.
|
||||
*/
|
||||
}
|
||||
}
|
||||
@@ -1605,7 +1606,7 @@ find_eclass_clauses_for_index_join(PlannerInfo *root, RelOptInfo *rel,
|
||||
* a joinclause between the two given relations.
|
||||
*
|
||||
* This is essentially a very cut-down version of
|
||||
* generate_join_implied_equalities(). Note it's OK to occasionally say "yes"
|
||||
* generate_join_implied_equalities(). Note it's OK to occasionally say "yes"
|
||||
* incorrectly. Hence we don't bother with details like whether the lack of a
|
||||
* cross-type operator might prevent the clause from actually being generated.
|
||||
*/
|
||||
@@ -1647,7 +1648,7 @@ have_relevant_eclass_joinclause(PlannerInfo *root,
|
||||
EquivalenceMember *cur_em = (EquivalenceMember *) lfirst(lc2);
|
||||
|
||||
if (cur_em->em_is_child)
|
||||
continue; /* ignore children here */
|
||||
continue; /* ignore children here */
|
||||
if (bms_is_subset(cur_em->em_relids, rel1->relids))
|
||||
{
|
||||
has_rel1 = true;
|
||||
@@ -1715,7 +1716,7 @@ has_relevant_eclass_joinclause(PlannerInfo *root, RelOptInfo *rel1)
|
||||
EquivalenceMember *cur_em = (EquivalenceMember *) lfirst(lc2);
|
||||
|
||||
if (cur_em->em_is_child)
|
||||
continue; /* ignore children here */
|
||||
continue; /* ignore children here */
|
||||
if (bms_is_subset(cur_em->em_relids, rel1->relids))
|
||||
{
|
||||
has_rel1 = true;
|
||||
@@ -1744,12 +1745,12 @@ has_relevant_eclass_joinclause(PlannerInfo *root, RelOptInfo *rel1)
|
||||
* against the specified relation.
|
||||
*
|
||||
* This is just a heuristic test and doesn't have to be exact; it's better
|
||||
* to say "yes" incorrectly than "no". Hence we don't bother with details
|
||||
* to say "yes" incorrectly than "no". Hence we don't bother with details
|
||||
* like whether the lack of a cross-type operator might prevent the clause
|
||||
* from actually being generated.
|
||||
*/
|
||||
bool
|
||||
eclass_useful_for_merging(EquivalenceClass *eclass,
|
||||
eclass_useful_for_merging(EquivalenceClass * eclass,
|
||||
RelOptInfo *rel)
|
||||
{
|
||||
ListCell *lc;
|
||||
@@ -1757,16 +1758,16 @@ eclass_useful_for_merging(EquivalenceClass *eclass,
|
||||
Assert(!eclass->ec_merged);
|
||||
|
||||
/*
|
||||
* Won't generate joinclauses if const or single-member (the latter
|
||||
* test covers the volatile case too)
|
||||
* Won't generate joinclauses if const or single-member (the latter test
|
||||
* covers the volatile case too)
|
||||
*/
|
||||
if (eclass->ec_has_const || list_length(eclass->ec_members) <= 1)
|
||||
return false;
|
||||
|
||||
/*
|
||||
* Note we don't test ec_broken; if we did, we'd need a separate code
|
||||
* path to look through ec_sources. Checking the members anyway is OK
|
||||
* as a possibly-overoptimistic heuristic.
|
||||
* Note we don't test ec_broken; if we did, we'd need a separate code path
|
||||
* to look through ec_sources. Checking the members anyway is OK as a
|
||||
* possibly-overoptimistic heuristic.
|
||||
*/
|
||||
|
||||
/* If rel already includes all members of eclass, no point in searching */
|
||||
|
@@ -9,7 +9,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/path/indxpath.c,v 1.223 2007/11/07 22:37:24 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/path/indxpath.c,v 1.224 2007/11/15 21:14:35 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -39,7 +39,7 @@
|
||||
/*
|
||||
* DoneMatchingIndexKeys() - MACRO
|
||||
*/
|
||||
#define DoneMatchingIndexKeys(families) (families[0] == InvalidOid)
|
||||
#define DoneMatchingIndexKeys(families) (families[0] == InvalidOid)
|
||||
|
||||
#define IsBooleanOpfamily(opfamily) \
|
||||
((opfamily) == BOOL_BTREE_FAM_OID || (opfamily) == BOOL_HASH_FAM_OID)
|
||||
@@ -52,7 +52,7 @@ typedef struct
|
||||
List *quals; /* the WHERE clauses it uses */
|
||||
List *preds; /* predicates of its partial index(es) */
|
||||
Bitmapset *clauseids; /* quals+preds represented as a bitmapset */
|
||||
} PathClauseUsage;
|
||||
} PathClauseUsage;
|
||||
|
||||
|
||||
static List *find_usable_indexes(PlannerInfo *root, RelOptInfo *rel,
|
||||
@@ -70,7 +70,7 @@ static Cost bitmap_scan_cost_est(PlannerInfo *root, RelOptInfo *rel,
|
||||
static Cost bitmap_and_cost_est(PlannerInfo *root, RelOptInfo *rel,
|
||||
List *paths, RelOptInfo *outer_rel);
|
||||
static PathClauseUsage *classify_index_clause_usage(Path *path,
|
||||
List **clauselist);
|
||||
List **clauselist);
|
||||
static void find_indexpath_quals(Path *bitmapqual, List **quals, List **preds);
|
||||
static int find_list_position(Node *node, List **nodelist);
|
||||
static bool match_clause_to_indexcol(IndexOptInfo *index,
|
||||
@@ -382,8 +382,8 @@ find_usable_indexes(PlannerInfo *root, RelOptInfo *rel,
|
||||
}
|
||||
|
||||
/*
|
||||
* 4. If the index is ordered, a backwards scan might be
|
||||
* interesting. Again, this is only interesting at top level.
|
||||
* 4. If the index is ordered, a backwards scan might be interesting.
|
||||
* Again, this is only interesting at top level.
|
||||
*/
|
||||
if (index_is_ordered && possibly_useful_pathkeys &&
|
||||
istoplevel && outer_rel == NULL)
|
||||
@@ -581,7 +581,8 @@ choose_bitmap_and(PlannerInfo *root, RelOptInfo *rel,
|
||||
List *clauselist;
|
||||
List *bestpaths = NIL;
|
||||
Cost bestcost = 0;
|
||||
int i, j;
|
||||
int i,
|
||||
j;
|
||||
ListCell *l;
|
||||
|
||||
Assert(npaths > 0); /* else caller error */
|
||||
@@ -592,40 +593,39 @@ choose_bitmap_and(PlannerInfo *root, RelOptInfo *rel,
|
||||
* In theory we should consider every nonempty subset of the given paths.
|
||||
* In practice that seems like overkill, given the crude nature of the
|
||||
* estimates, not to mention the possible effects of higher-level AND and
|
||||
* OR clauses. Moreover, it's completely impractical if there are a large
|
||||
* OR clauses. Moreover, it's completely impractical if there are a large
|
||||
* number of paths, since the work would grow as O(2^N).
|
||||
*
|
||||
* As a heuristic, we first check for paths using exactly the same
|
||||
* sets of WHERE clauses + index predicate conditions, and reject all
|
||||
* but the cheapest-to-scan in any such group. This primarily gets rid
|
||||
* of indexes that include the interesting columns but also irrelevant
|
||||
* columns. (In situations where the DBA has gone overboard on creating
|
||||
* variant indexes, this can make for a very large reduction in the number
|
||||
* of paths considered further.)
|
||||
* As a heuristic, we first check for paths using exactly the same sets of
|
||||
* WHERE clauses + index predicate conditions, and reject all but the
|
||||
* cheapest-to-scan in any such group. This primarily gets rid of indexes
|
||||
* that include the interesting columns but also irrelevant columns. (In
|
||||
* situations where the DBA has gone overboard on creating variant
|
||||
* indexes, this can make for a very large reduction in the number of
|
||||
* paths considered further.)
|
||||
*
|
||||
* We then sort the surviving paths with the cheapest-to-scan first,
|
||||
* and for each path, consider using that path alone as the basis for
|
||||
* a bitmap scan. Then we consider bitmap AND scans formed from that
|
||||
* path plus each subsequent (higher-cost) path, adding on a subsequent
|
||||
* path if it results in a reduction in the estimated total scan cost.
|
||||
* This means we consider about O(N^2) rather than O(2^N) path
|
||||
* combinations, which is quite tolerable, especially given than N is
|
||||
* usually reasonably small because of the prefiltering step. The
|
||||
* cheapest of these is returned.
|
||||
* We then sort the surviving paths with the cheapest-to-scan first, and
|
||||
* for each path, consider using that path alone as the basis for a bitmap
|
||||
* scan. Then we consider bitmap AND scans formed from that path plus
|
||||
* each subsequent (higher-cost) path, adding on a subsequent path if it
|
||||
* results in a reduction in the estimated total scan cost. This means we
|
||||
* consider about O(N^2) rather than O(2^N) path combinations, which is
|
||||
* quite tolerable, especially given than N is usually reasonably small
|
||||
* because of the prefiltering step. The cheapest of these is returned.
|
||||
*
|
||||
* We will only consider AND combinations in which no two indexes use
|
||||
* the same WHERE clause. This is a bit of a kluge: it's needed because
|
||||
* We will only consider AND combinations in which no two indexes use the
|
||||
* same WHERE clause. This is a bit of a kluge: it's needed because
|
||||
* costsize.c and clausesel.c aren't very smart about redundant clauses.
|
||||
* They will usually double-count the redundant clauses, producing a
|
||||
* too-small selectivity that makes a redundant AND step look like it
|
||||
* reduces the total cost. Perhaps someday that code will be smarter and
|
||||
* reduces the total cost. Perhaps someday that code will be smarter and
|
||||
* we can remove this limitation. (But note that this also defends
|
||||
* against flat-out duplicate input paths, which can happen because
|
||||
* best_inner_indexscan will find the same OR join clauses that
|
||||
* create_or_index_quals has pulled OR restriction clauses out of.)
|
||||
*
|
||||
* For the same reason, we reject AND combinations in which an index
|
||||
* predicate clause duplicates another clause. Here we find it necessary
|
||||
* predicate clause duplicates another clause. Here we find it necessary
|
||||
* to be even stricter: we'll reject a partial index if any of its
|
||||
* predicate clauses are implied by the set of WHERE clauses and predicate
|
||||
* clauses used so far. This covers cases such as a condition "x = 42"
|
||||
@@ -639,9 +639,9 @@ choose_bitmap_and(PlannerInfo *root, RelOptInfo *rel,
|
||||
*/
|
||||
|
||||
/*
|
||||
* Extract clause usage info and detect any paths that use exactly
|
||||
* the same set of clauses; keep only the cheapest-to-scan of any such
|
||||
* groups. The surviving paths are put into an array for qsort'ing.
|
||||
* Extract clause usage info and detect any paths that use exactly the
|
||||
* same set of clauses; keep only the cheapest-to-scan of any such groups.
|
||||
* The surviving paths are put into an array for qsort'ing.
|
||||
*/
|
||||
pathinfoarray = (PathClauseUsage **)
|
||||
palloc(npaths * sizeof(PathClauseUsage *));
|
||||
@@ -649,7 +649,7 @@ choose_bitmap_and(PlannerInfo *root, RelOptInfo *rel,
|
||||
npaths = 0;
|
||||
foreach(l, paths)
|
||||
{
|
||||
Path *ipath = (Path *) lfirst(l);
|
||||
Path *ipath = (Path *) lfirst(l);
|
||||
|
||||
pathinfo = classify_index_clause_usage(ipath, &clauselist);
|
||||
for (i = 0; i < npaths; i++)
|
||||
@@ -686,9 +686,9 @@ choose_bitmap_and(PlannerInfo *root, RelOptInfo *rel,
|
||||
path_usage_comparator);
|
||||
|
||||
/*
|
||||
* For each surviving index, consider it as an "AND group leader", and
|
||||
* see whether adding on any of the later indexes results in an AND path
|
||||
* with cheaper total cost than before. Then take the cheapest AND group.
|
||||
* For each surviving index, consider it as an "AND group leader", and see
|
||||
* whether adding on any of the later indexes results in an AND path with
|
||||
* cheaper total cost than before. Then take the cheapest AND group.
|
||||
*/
|
||||
for (i = 0; i < npaths; i++)
|
||||
{
|
||||
@@ -705,17 +705,17 @@ choose_bitmap_and(PlannerInfo *root, RelOptInfo *rel,
|
||||
clauseidsofar = bms_copy(pathinfo->clauseids);
|
||||
lastcell = list_head(paths); /* for quick deletions */
|
||||
|
||||
for (j = i+1; j < npaths; j++)
|
||||
for (j = i + 1; j < npaths; j++)
|
||||
{
|
||||
Cost newcost;
|
||||
|
||||
pathinfo = pathinfoarray[j];
|
||||
/* Check for redundancy */
|
||||
if (bms_overlap(pathinfo->clauseids, clauseidsofar))
|
||||
continue; /* consider it redundant */
|
||||
continue; /* consider it redundant */
|
||||
if (pathinfo->preds)
|
||||
{
|
||||
bool redundant = false;
|
||||
bool redundant = false;
|
||||
|
||||
/* we check each predicate clause separately */
|
||||
foreach(l, pathinfo->preds)
|
||||
@@ -725,7 +725,7 @@ choose_bitmap_and(PlannerInfo *root, RelOptInfo *rel,
|
||||
if (predicate_implied_by(list_make1(np), qualsofar))
|
||||
{
|
||||
redundant = true;
|
||||
break; /* out of inner foreach loop */
|
||||
break; /* out of inner foreach loop */
|
||||
}
|
||||
}
|
||||
if (redundant)
|
||||
@@ -766,7 +766,7 @@ choose_bitmap_and(PlannerInfo *root, RelOptInfo *rel,
|
||||
}
|
||||
|
||||
if (list_length(bestpaths) == 1)
|
||||
return (Path *) linitial(bestpaths); /* no need for AND */
|
||||
return (Path *) linitial(bestpaths); /* no need for AND */
|
||||
return (Path *) create_bitmap_and_path(root, rel, bestpaths);
|
||||
}
|
||||
|
||||
@@ -774,8 +774,8 @@ choose_bitmap_and(PlannerInfo *root, RelOptInfo *rel,
|
||||
static int
|
||||
path_usage_comparator(const void *a, const void *b)
|
||||
{
|
||||
PathClauseUsage *pa = *(PathClauseUsage *const *) a;
|
||||
PathClauseUsage *pb = *(PathClauseUsage *const *) b;
|
||||
PathClauseUsage *pa = *(PathClauseUsage * const *) a;
|
||||
PathClauseUsage *pb = *(PathClauseUsage * const *) b;
|
||||
Cost acost;
|
||||
Cost bcost;
|
||||
Selectivity aselec;
|
||||
@@ -872,14 +872,14 @@ classify_index_clause_usage(Path *path, List **clauselist)
|
||||
clauseids = NULL;
|
||||
foreach(lc, result->quals)
|
||||
{
|
||||
Node *node = (Node *) lfirst(lc);
|
||||
Node *node = (Node *) lfirst(lc);
|
||||
|
||||
clauseids = bms_add_member(clauseids,
|
||||
find_list_position(node, clauselist));
|
||||
}
|
||||
foreach(lc, result->preds)
|
||||
{
|
||||
Node *node = (Node *) lfirst(lc);
|
||||
Node *node = (Node *) lfirst(lc);
|
||||
|
||||
clauseids = bms_add_member(clauseids,
|
||||
find_list_position(node, clauselist));
|
||||
@@ -944,7 +944,7 @@ find_indexpath_quals(Path *bitmapqual, List **quals, List **preds)
|
||||
/*
|
||||
* find_list_position
|
||||
* Return the given node's position (counting from 0) in the given
|
||||
* list of nodes. If it's not equal() to any existing list member,
|
||||
* list of nodes. If it's not equal() to any existing list member,
|
||||
* add it at the end, and return that position.
|
||||
*/
|
||||
static int
|
||||
@@ -956,7 +956,7 @@ find_list_position(Node *node, List **nodelist)
|
||||
i = 0;
|
||||
foreach(lc, *nodelist)
|
||||
{
|
||||
Node *oldnode = (Node *) lfirst(lc);
|
||||
Node *oldnode = (Node *) lfirst(lc);
|
||||
|
||||
if (equal(node, oldnode))
|
||||
return i;
|
||||
@@ -1218,7 +1218,7 @@ match_clause_to_indexcol(IndexOptInfo *index,
|
||||
}
|
||||
else if (index->amsearchnulls && IsA(clause, NullTest))
|
||||
{
|
||||
NullTest *nt = (NullTest *) clause;
|
||||
NullTest *nt = (NullTest *) clause;
|
||||
|
||||
if (nt->nulltesttype == IS_NULL &&
|
||||
match_index_to_operand((Node *) nt->arg, indexcol, index))
|
||||
@@ -1315,12 +1315,12 @@ match_rowcompare_to_indexcol(IndexOptInfo *index,
|
||||
/*
|
||||
* We could do the matching on the basis of insisting that the opfamily
|
||||
* shown in the RowCompareExpr be the same as the index column's opfamily,
|
||||
* but that could fail in the presence of reverse-sort opfamilies: it'd
|
||||
* be a matter of chance whether RowCompareExpr had picked the forward
|
||||
* or reverse-sort family. So look only at the operator, and match
|
||||
* if it is a member of the index's opfamily (after commutation, if the
|
||||
* indexkey is on the right). We'll worry later about whether any
|
||||
* additional operators are matchable to the index.
|
||||
* but that could fail in the presence of reverse-sort opfamilies: it'd be
|
||||
* a matter of chance whether RowCompareExpr had picked the forward or
|
||||
* reverse-sort family. So look only at the operator, and match if it is
|
||||
* a member of the index's opfamily (after commutation, if the indexkey is
|
||||
* on the right). We'll worry later about whether any additional
|
||||
* operators are matchable to the index.
|
||||
*/
|
||||
leftop = (Node *) linitial(clause->largs);
|
||||
rightop = (Node *) linitial(clause->rargs);
|
||||
@@ -1421,8 +1421,8 @@ indexable_outerrelids(PlannerInfo *root, RelOptInfo *rel)
|
||||
}
|
||||
|
||||
/*
|
||||
* We also have to look through the query's EquivalenceClasses to see
|
||||
* if any of them could generate indexable join conditions for this rel.
|
||||
* We also have to look through the query's EquivalenceClasses to see if
|
||||
* any of them could generate indexable join conditions for this rel.
|
||||
*/
|
||||
if (rel->has_eclass_joins)
|
||||
{
|
||||
@@ -1434,8 +1434,8 @@ indexable_outerrelids(PlannerInfo *root, RelOptInfo *rel)
|
||||
ListCell *lc2;
|
||||
|
||||
/*
|
||||
* Won't generate joinclauses if const or single-member (the latter
|
||||
* test covers the volatile case too)
|
||||
* Won't generate joinclauses if const or single-member (the
|
||||
* latter test covers the volatile case too)
|
||||
*/
|
||||
if (cur_ec->ec_has_const || list_length(cur_ec->ec_members) <= 1)
|
||||
continue;
|
||||
@@ -1569,7 +1569,7 @@ matches_any_index(RestrictInfo *rinfo, RelOptInfo *rel, Relids outer_relids)
|
||||
* This is also exported for use by find_eclass_clauses_for_index_join.
|
||||
*/
|
||||
bool
|
||||
eclass_matches_any_index(EquivalenceClass *ec, EquivalenceMember *em,
|
||||
eclass_matches_any_index(EquivalenceClass * ec, EquivalenceMember * em,
|
||||
RelOptInfo *rel)
|
||||
{
|
||||
ListCell *l;
|
||||
@@ -1831,14 +1831,14 @@ find_clauses_for_join(PlannerInfo *root, RelOptInfo *rel,
|
||||
|
||||
/*
|
||||
* Also check to see if any EquivalenceClasses can produce a relevant
|
||||
* joinclause. Since all such clauses are effectively pushed-down,
|
||||
* this doesn't apply to outer joins.
|
||||
* joinclause. Since all such clauses are effectively pushed-down, this
|
||||
* doesn't apply to outer joins.
|
||||
*/
|
||||
if (!isouterjoin && rel->has_eclass_joins)
|
||||
clause_list = list_concat(clause_list,
|
||||
find_eclass_clauses_for_index_join(root,
|
||||
rel,
|
||||
outer_relids));
|
||||
outer_relids));
|
||||
|
||||
/* If no join clause was matched then forget it, per comments above */
|
||||
if (clause_list == NIL)
|
||||
@@ -2150,9 +2150,9 @@ match_special_index_operator(Expr *clause, Oid opfamily,
|
||||
* want to apply. (A hash index, for example, will not support ">=".)
|
||||
* Currently, only btree supports the operators we need.
|
||||
*
|
||||
* We insist on the opfamily being the specific one we expect, else we'd do
|
||||
* the wrong thing if someone were to make a reverse-sort opfamily with the
|
||||
* same operators.
|
||||
* We insist on the opfamily being the specific one we expect, else we'd
|
||||
* do the wrong thing if someone were to make a reverse-sort opfamily with
|
||||
* the same operators.
|
||||
*/
|
||||
switch (expr_op)
|
||||
{
|
||||
@@ -2260,7 +2260,7 @@ expand_indexqual_conditions(IndexOptInfo *index, List *clausegroups)
|
||||
{
|
||||
resultquals = list_concat(resultquals,
|
||||
expand_indexqual_opclause(rinfo,
|
||||
curFamily));
|
||||
curFamily));
|
||||
}
|
||||
else if (IsA(clause, ScalarArrayOpExpr))
|
||||
{
|
||||
@@ -2602,9 +2602,9 @@ expand_indexqual_rowcompare(RestrictInfo *rinfo,
|
||||
righttypes_cell = list_head(righttypes);
|
||||
foreach(opfamilies_cell, opfamilies)
|
||||
{
|
||||
Oid opfam = lfirst_oid(opfamilies_cell);
|
||||
Oid lefttype = lfirst_oid(lefttypes_cell);
|
||||
Oid righttype = lfirst_oid(righttypes_cell);
|
||||
Oid opfam = lfirst_oid(opfamilies_cell);
|
||||
Oid lefttype = lfirst_oid(lefttypes_cell);
|
||||
Oid righttype = lfirst_oid(righttypes_cell);
|
||||
|
||||
expr_op = get_opfamily_member(opfam, lefttype, righttype,
|
||||
op_strategy);
|
||||
|
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/path/joinpath.c,v 1.112 2007/05/22 01:40:33 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/path/joinpath.c,v 1.113 2007/11/15 21:14:35 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -200,7 +200,7 @@ sort_inner_and_outer(PlannerInfo *root,
|
||||
*
|
||||
* Actually, it's not quite true that every mergeclause ordering will
|
||||
* generate a different path order, because some of the clauses may be
|
||||
* partially redundant (refer to the same EquivalenceClasses). Therefore,
|
||||
* partially redundant (refer to the same EquivalenceClasses). Therefore,
|
||||
* what we do is convert the mergeclause list to a list of canonical
|
||||
* pathkeys, and then consider different orderings of the pathkeys.
|
||||
*
|
||||
@@ -237,7 +237,7 @@ sort_inner_and_outer(PlannerInfo *root,
|
||||
list_delete_ptr(list_copy(all_pathkeys),
|
||||
front_pathkey));
|
||||
else
|
||||
outerkeys = all_pathkeys; /* no work at first one... */
|
||||
outerkeys = all_pathkeys; /* no work at first one... */
|
||||
|
||||
/* Sort the mergeclauses into the corresponding ordering */
|
||||
cur_mergeclauses = find_mergeclauses_for_pathkeys(root,
|
||||
|
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/path/joinrels.c,v 1.88 2007/10/26 18:10:50 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/path/joinrels.c,v 1.89 2007/11/15 21:14:36 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -346,8 +346,8 @@ join_is_legal(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2,
|
||||
ListCell *l;
|
||||
|
||||
/*
|
||||
* Ensure *jointype_p is set on failure return. This is just to
|
||||
* suppress uninitialized-variable warnings from overly anal compilers.
|
||||
* Ensure *jointype_p is set on failure return. This is just to suppress
|
||||
* uninitialized-variable warnings from overly anal compilers.
|
||||
*/
|
||||
*jointype_p = JOIN_INNER;
|
||||
|
||||
@@ -398,14 +398,14 @@ join_is_legal(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2,
|
||||
bms_is_subset(ojinfo->min_righthand, rel2->relids))
|
||||
{
|
||||
if (jointype != JOIN_INNER)
|
||||
return false; /* invalid join path */
|
||||
return false; /* invalid join path */
|
||||
jointype = ojinfo->is_full_join ? JOIN_FULL : JOIN_LEFT;
|
||||
}
|
||||
else if (bms_is_subset(ojinfo->min_lefthand, rel2->relids) &&
|
||||
bms_is_subset(ojinfo->min_righthand, rel1->relids))
|
||||
{
|
||||
if (jointype != JOIN_INNER)
|
||||
return false; /* invalid join path */
|
||||
return false; /* invalid join path */
|
||||
jointype = ojinfo->is_full_join ? JOIN_FULL : JOIN_RIGHT;
|
||||
}
|
||||
else
|
||||
@@ -520,7 +520,7 @@ join_is_legal(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2,
|
||||
else if (bms_equal(ininfo->righthand, rel2->relids))
|
||||
jointype = JOIN_UNIQUE_INNER;
|
||||
else
|
||||
return false; /* invalid join path */
|
||||
return false; /* invalid join path */
|
||||
}
|
||||
|
||||
/* Join is valid */
|
||||
@@ -666,9 +666,9 @@ have_join_order_restriction(PlannerInfo *root,
|
||||
ListCell *l;
|
||||
|
||||
/*
|
||||
* It's possible that the rels correspond to the left and right sides
|
||||
* of a degenerate outer join, that is, one with no joinclause mentioning
|
||||
* the non-nullable side; in which case we should force the join to occur.
|
||||
* It's possible that the rels correspond to the left and right sides of a
|
||||
* degenerate outer join, that is, one with no joinclause mentioning the
|
||||
* non-nullable side; in which case we should force the join to occur.
|
||||
*
|
||||
* Also, the two rels could represent a clauseless join that has to be
|
||||
* completed to build up the LHS or RHS of an outer join.
|
||||
@@ -696,9 +696,9 @@ have_join_order_restriction(PlannerInfo *root,
|
||||
}
|
||||
|
||||
/*
|
||||
* Might we need to join these rels to complete the RHS? We have
|
||||
* to use "overlap" tests since either rel might include a lower OJ
|
||||
* that has been proven to commute with this one.
|
||||
* Might we need to join these rels to complete the RHS? We have to
|
||||
* use "overlap" tests since either rel might include a lower OJ that
|
||||
* has been proven to commute with this one.
|
||||
*/
|
||||
if (bms_overlap(ojinfo->min_righthand, rel1->relids) &&
|
||||
bms_overlap(ojinfo->min_righthand, rel2->relids))
|
||||
@@ -761,13 +761,13 @@ have_join_order_restriction(PlannerInfo *root,
|
||||
}
|
||||
|
||||
/*
|
||||
* We do not force the join to occur if either input rel can legally
|
||||
* be joined to anything else using joinclauses. This essentially
|
||||
* means that clauseless bushy joins are put off as long as possible.
|
||||
* The reason is that when there is a join order restriction high up
|
||||
* in the join tree (that is, with many rels inside the LHS or RHS),
|
||||
* we would otherwise expend lots of effort considering very stupid
|
||||
* join combinations within its LHS or RHS.
|
||||
* We do not force the join to occur if either input rel can legally be
|
||||
* joined to anything else using joinclauses. This essentially means that
|
||||
* clauseless bushy joins are put off as long as possible. The reason is
|
||||
* that when there is a join order restriction high up in the join tree
|
||||
* (that is, with many rels inside the LHS or RHS), we would otherwise
|
||||
* expend lots of effort considering very stupid join combinations within
|
||||
* its LHS or RHS.
|
||||
*/
|
||||
if (result)
|
||||
{
|
||||
@@ -787,7 +787,7 @@ have_join_order_restriction(PlannerInfo *root,
|
||||
*
|
||||
* Essentially, this tests whether have_join_order_restriction() could
|
||||
* succeed with this rel and some other one. It's OK if we sometimes
|
||||
* say "true" incorrectly. (Therefore, we don't bother with the relatively
|
||||
* say "true" incorrectly. (Therefore, we don't bother with the relatively
|
||||
* expensive has_legal_joinclause test.)
|
||||
*/
|
||||
static bool
|
||||
|
@@ -11,7 +11,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/path/pathkeys.c,v 1.89 2007/11/08 21:49:47 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/path/pathkeys.c,v 1.90 2007/11/15 21:14:36 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -37,12 +37,12 @@
|
||||
#define MUST_BE_REDUNDANT(eclass) \
|
||||
((eclass)->ec_has_const && !(eclass)->ec_below_outer_join)
|
||||
|
||||
static PathKey *makePathKey(EquivalenceClass *eclass, Oid opfamily,
|
||||
int strategy, bool nulls_first);
|
||||
static PathKey *makePathKey(EquivalenceClass * eclass, Oid opfamily,
|
||||
int strategy, bool nulls_first);
|
||||
static PathKey *make_canonical_pathkey(PlannerInfo *root,
|
||||
EquivalenceClass *eclass, Oid opfamily,
|
||||
EquivalenceClass * eclass, Oid opfamily,
|
||||
int strategy, bool nulls_first);
|
||||
static bool pathkey_is_redundant(PathKey *new_pathkey, List *pathkeys);
|
||||
static bool pathkey_is_redundant(PathKey * new_pathkey, List *pathkeys);
|
||||
static PathKey *make_pathkey_from_sortinfo(PlannerInfo *root,
|
||||
Expr *expr, Oid ordering_op,
|
||||
bool nulls_first,
|
||||
@@ -50,7 +50,7 @@ static PathKey *make_pathkey_from_sortinfo(PlannerInfo *root,
|
||||
bool canonicalize);
|
||||
static Var *find_indexkey_var(PlannerInfo *root, RelOptInfo *rel,
|
||||
AttrNumber varattno);
|
||||
static bool right_merge_direction(PlannerInfo *root, PathKey *pathkey);
|
||||
static bool right_merge_direction(PlannerInfo *root, PathKey * pathkey);
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
@@ -65,10 +65,10 @@ static bool right_merge_direction(PlannerInfo *root, PathKey *pathkey);
|
||||
* convenience routine to build the specified node.
|
||||
*/
|
||||
static PathKey *
|
||||
makePathKey(EquivalenceClass *eclass, Oid opfamily,
|
||||
makePathKey(EquivalenceClass * eclass, Oid opfamily,
|
||||
int strategy, bool nulls_first)
|
||||
{
|
||||
PathKey *pk = makeNode(PathKey);
|
||||
PathKey *pk = makeNode(PathKey);
|
||||
|
||||
pk->pk_eclass = eclass;
|
||||
pk->pk_opfamily = opfamily;
|
||||
@@ -89,10 +89,10 @@ makePathKey(EquivalenceClass *eclass, Oid opfamily,
|
||||
*/
|
||||
static PathKey *
|
||||
make_canonical_pathkey(PlannerInfo *root,
|
||||
EquivalenceClass *eclass, Oid opfamily,
|
||||
EquivalenceClass * eclass, Oid opfamily,
|
||||
int strategy, bool nulls_first)
|
||||
{
|
||||
PathKey *pk;
|
||||
PathKey *pk;
|
||||
ListCell *lc;
|
||||
MemoryContext oldcontext;
|
||||
|
||||
@@ -155,7 +155,7 @@ make_canonical_pathkey(PlannerInfo *root,
|
||||
* pointer comparison is enough to decide whether canonical ECs are the same.
|
||||
*/
|
||||
static bool
|
||||
pathkey_is_redundant(PathKey *new_pathkey, List *pathkeys)
|
||||
pathkey_is_redundant(PathKey * new_pathkey, List *pathkeys)
|
||||
{
|
||||
EquivalenceClass *new_ec = new_pathkey->pk_eclass;
|
||||
ListCell *lc;
|
||||
@@ -170,7 +170,7 @@ pathkey_is_redundant(PathKey *new_pathkey, List *pathkeys)
|
||||
/* If same EC already used in list, then redundant */
|
||||
foreach(lc, pathkeys)
|
||||
{
|
||||
PathKey *old_pathkey = (PathKey *) lfirst(lc);
|
||||
PathKey *old_pathkey = (PathKey *) lfirst(lc);
|
||||
|
||||
/* Assert we've been given canonical pathkeys */
|
||||
Assert(!old_pathkey->pk_eclass->ec_merged);
|
||||
@@ -197,9 +197,9 @@ canonicalize_pathkeys(PlannerInfo *root, List *pathkeys)
|
||||
|
||||
foreach(l, pathkeys)
|
||||
{
|
||||
PathKey *pathkey = (PathKey *) lfirst(l);
|
||||
PathKey *pathkey = (PathKey *) lfirst(l);
|
||||
EquivalenceClass *eclass;
|
||||
PathKey *cpathkey;
|
||||
PathKey *cpathkey;
|
||||
|
||||
/* Find the canonical (merged) EquivalenceClass */
|
||||
eclass = pathkey->pk_eclass;
|
||||
@@ -255,13 +255,13 @@ make_pathkey_from_sortinfo(PlannerInfo *root,
|
||||
EquivalenceClass *eclass;
|
||||
|
||||
/*
|
||||
* An ordering operator fully determines the behavior of its opfamily,
|
||||
* so could only meaningfully appear in one family --- or perhaps two
|
||||
* if one builds a reverse-sort opfamily, but there's not much point in
|
||||
* that anymore. But EquivalenceClasses need to contain opfamily lists
|
||||
* based on the family membership of equality operators, which could
|
||||
* easily be bigger. So, look up the equality operator that goes with
|
||||
* the ordering operator (this should be unique) and get its membership.
|
||||
* An ordering operator fully determines the behavior of its opfamily, so
|
||||
* could only meaningfully appear in one family --- or perhaps two if one
|
||||
* builds a reverse-sort opfamily, but there's not much point in that
|
||||
* anymore. But EquivalenceClasses need to contain opfamily lists based
|
||||
* on the family membership of equality operators, which could easily be
|
||||
* bigger. So, look up the equality operator that goes with the ordering
|
||||
* operator (this should be unique) and get its membership.
|
||||
*/
|
||||
|
||||
/* Find the operator in pg_amop --- failure shouldn't happen */
|
||||
@@ -284,15 +284,15 @@ make_pathkey_from_sortinfo(PlannerInfo *root,
|
||||
|
||||
/*
|
||||
* When dealing with binary-compatible opclasses, we have to ensure that
|
||||
* the exposed type of the expression tree matches the declared input
|
||||
* type of the opclass, except when that is a polymorphic type
|
||||
* (compare the behavior of parse_coerce.c). This ensures that we can
|
||||
* correctly match the indexkey or sortclause expression to other
|
||||
* expressions we find in the query, because arguments of ordinary
|
||||
* operator expressions will be cast that way. (We have to do this
|
||||
* for indexkeys because they are represented without any explicit
|
||||
* relabel in pg_index, and for sort clauses because the parser is
|
||||
* likewise cavalier about putting relabels on them.)
|
||||
* the exposed type of the expression tree matches the declared input type
|
||||
* of the opclass, except when that is a polymorphic type (compare the
|
||||
* behavior of parse_coerce.c). This ensures that we can correctly match
|
||||
* the indexkey or sortclause expression to other expressions we find in
|
||||
* the query, because arguments of ordinary operator expressions will be
|
||||
* cast that way. (We have to do this for indexkeys because they are
|
||||
* represented without any explicit relabel in pg_index, and for sort
|
||||
* clauses because the parser is likewise cavalier about putting relabels
|
||||
* on them.)
|
||||
*/
|
||||
if (exprType((Node *) expr) != opcintype &&
|
||||
!IsPolymorphicType(opcintype))
|
||||
@@ -341,8 +341,8 @@ compare_pathkeys(List *keys1, List *keys2)
|
||||
|
||||
forboth(key1, keys1, key2, keys2)
|
||||
{
|
||||
PathKey *pathkey1 = (PathKey *) lfirst(key1);
|
||||
PathKey *pathkey2 = (PathKey *) lfirst(key2);
|
||||
PathKey *pathkey1 = (PathKey *) lfirst(key1);
|
||||
PathKey *pathkey2 = (PathKey *) lfirst(key2);
|
||||
|
||||
/*
|
||||
* XXX would like to check that we've been given canonicalized input,
|
||||
@@ -495,7 +495,7 @@ build_index_pathkeys(PlannerInfo *root,
|
||||
bool nulls_first;
|
||||
int ikey;
|
||||
Expr *indexkey;
|
||||
PathKey *cpathkey;
|
||||
PathKey *cpathkey;
|
||||
|
||||
if (ScanDirectionIsBackward(scandir))
|
||||
{
|
||||
@@ -601,9 +601,9 @@ convert_subquery_pathkeys(PlannerInfo *root, RelOptInfo *rel,
|
||||
|
||||
foreach(i, subquery_pathkeys)
|
||||
{
|
||||
PathKey *sub_pathkey = (PathKey *) lfirst(i);
|
||||
PathKey *sub_pathkey = (PathKey *) lfirst(i);
|
||||
EquivalenceClass *sub_eclass = sub_pathkey->pk_eclass;
|
||||
PathKey *best_pathkey = NULL;
|
||||
PathKey *best_pathkey = NULL;
|
||||
|
||||
if (sub_eclass->ec_has_volatile)
|
||||
{
|
||||
@@ -614,7 +614,7 @@ convert_subquery_pathkeys(PlannerInfo *root, RelOptInfo *rel,
|
||||
*/
|
||||
TargetEntry *tle;
|
||||
|
||||
if (sub_eclass->ec_sortref == 0) /* can't happen */
|
||||
if (sub_eclass->ec_sortref == 0) /* can't happen */
|
||||
elog(ERROR, "volatile EquivalenceClass has no sortref");
|
||||
tle = get_sortgroupref_tle(sub_eclass->ec_sortref, sub_tlist);
|
||||
Assert(tle);
|
||||
@@ -653,11 +653,11 @@ convert_subquery_pathkeys(PlannerInfo *root, RelOptInfo *rel,
|
||||
/*
|
||||
* Otherwise, the sub_pathkey's EquivalenceClass could contain
|
||||
* multiple elements (representing knowledge that multiple items
|
||||
* are effectively equal). Each element might match none, one, or
|
||||
* more of the output columns that are visible to the outer
|
||||
* query. This means we may have multiple possible representations
|
||||
* of the sub_pathkey in the context of the outer query. Ideally
|
||||
* we would generate them all and put them all into an EC of the
|
||||
* are effectively equal). Each element might match none, one, or
|
||||
* more of the output columns that are visible to the outer query.
|
||||
* This means we may have multiple possible representations of the
|
||||
* sub_pathkey in the context of the outer query. Ideally we
|
||||
* would generate them all and put them all into an EC of the
|
||||
* outer query, thereby propagating equality knowledge up to the
|
||||
* outer query. Right now we cannot do so, because the outer
|
||||
* query's EquivalenceClasses are already frozen when this is
|
||||
@@ -680,7 +680,8 @@ convert_subquery_pathkeys(PlannerInfo *root, RelOptInfo *rel,
|
||||
* We handle two cases: the sub_pathkey key can be either an
|
||||
* exact match for a targetlist entry, or it could match after
|
||||
* stripping RelabelType nodes. (We need that case since
|
||||
* make_pathkey_from_sortinfo could add or remove RelabelType.)
|
||||
* make_pathkey_from_sortinfo could add or remove
|
||||
* RelabelType.)
|
||||
*/
|
||||
sub_stripped = sub_expr;
|
||||
while (sub_stripped && IsA(sub_stripped, RelabelType))
|
||||
@@ -691,7 +692,7 @@ convert_subquery_pathkeys(PlannerInfo *root, RelOptInfo *rel,
|
||||
TargetEntry *tle = (TargetEntry *) lfirst(k);
|
||||
Expr *outer_expr;
|
||||
EquivalenceClass *outer_ec;
|
||||
PathKey *outer_pk;
|
||||
PathKey *outer_pk;
|
||||
int score;
|
||||
|
||||
/* resjunk items aren't visible to outer query */
|
||||
@@ -729,7 +730,7 @@ convert_subquery_pathkeys(PlannerInfo *root, RelOptInfo *rel,
|
||||
exprType((Node *) sub_expr))
|
||||
outer_expr = (Expr *)
|
||||
makeRelabelType(outer_expr,
|
||||
exprType((Node *) sub_expr),
|
||||
exprType((Node *) sub_expr),
|
||||
-1,
|
||||
COERCE_DONTCARE);
|
||||
}
|
||||
@@ -740,14 +741,14 @@ convert_subquery_pathkeys(PlannerInfo *root, RelOptInfo *rel,
|
||||
/* Found a representation for this sub_pathkey */
|
||||
outer_ec = get_eclass_for_sort_expr(root,
|
||||
outer_expr,
|
||||
sub_member->em_datatype,
|
||||
sub_eclass->ec_opfamilies,
|
||||
sub_member->em_datatype,
|
||||
sub_eclass->ec_opfamilies,
|
||||
0);
|
||||
outer_pk = make_canonical_pathkey(root,
|
||||
outer_ec,
|
||||
sub_pathkey->pk_opfamily,
|
||||
sub_pathkey->pk_strategy,
|
||||
sub_pathkey->pk_nulls_first);
|
||||
sub_pathkey->pk_opfamily,
|
||||
sub_pathkey->pk_strategy,
|
||||
sub_pathkey->pk_nulls_first);
|
||||
/* score = # of equivalence peers */
|
||||
score = list_length(outer_ec->ec_members) - 1;
|
||||
/* +1 if it matches the proper query_pathkeys item */
|
||||
@@ -854,7 +855,7 @@ make_pathkeys_for_sortclauses(PlannerInfo *root,
|
||||
{
|
||||
SortClause *sortcl = (SortClause *) lfirst(l);
|
||||
Expr *sortkey;
|
||||
PathKey *pathkey;
|
||||
PathKey *pathkey;
|
||||
|
||||
sortkey = (Expr *) get_sortgroupclause_expr(sortcl, tlist);
|
||||
pathkey = make_pathkey_from_sortinfo(root,
|
||||
@@ -961,7 +962,7 @@ find_mergeclauses_for_pathkeys(PlannerInfo *root,
|
||||
|
||||
foreach(i, pathkeys)
|
||||
{
|
||||
PathKey *pathkey = (PathKey *) lfirst(i);
|
||||
PathKey *pathkey = (PathKey *) lfirst(i);
|
||||
EquivalenceClass *pathkey_ec = pathkey->pk_eclass;
|
||||
List *matched_restrictinfos = NIL;
|
||||
ListCell *j;
|
||||
@@ -1042,7 +1043,7 @@ find_mergeclauses_for_pathkeys(PlannerInfo *root,
|
||||
* Returns a pathkeys list that can be applied to the outer relation.
|
||||
*
|
||||
* Since we assume here that a sort is required, there is no particular use
|
||||
* in matching any available ordering of the outerrel. (joinpath.c has an
|
||||
* in matching any available ordering of the outerrel. (joinpath.c has an
|
||||
* entirely separate code path for considering sort-free mergejoins.) Rather,
|
||||
* it's interesting to try to match the requested query_pathkeys so that a
|
||||
* second output sort may be avoided; and failing that, we try to list "more
|
||||
@@ -1117,16 +1118,15 @@ select_outer_pathkeys_for_merge(PlannerInfo *root,
|
||||
}
|
||||
|
||||
/*
|
||||
* Find out if we have all the ECs mentioned in query_pathkeys; if so
|
||||
* we can generate a sort order that's also useful for final output.
|
||||
* There is no percentage in a partial match, though, so we have to
|
||||
* have 'em all.
|
||||
* Find out if we have all the ECs mentioned in query_pathkeys; if so we
|
||||
* can generate a sort order that's also useful for final output. There is
|
||||
* no percentage in a partial match, though, so we have to have 'em all.
|
||||
*/
|
||||
if (root->query_pathkeys)
|
||||
{
|
||||
foreach(lc, root->query_pathkeys)
|
||||
{
|
||||
PathKey *query_pathkey = (PathKey *) lfirst(lc);
|
||||
PathKey *query_pathkey = (PathKey *) lfirst(lc);
|
||||
EquivalenceClass *query_ec = query_pathkey->pk_eclass;
|
||||
|
||||
for (j = 0; j < necs; j++)
|
||||
@@ -1145,7 +1145,7 @@ select_outer_pathkeys_for_merge(PlannerInfo *root,
|
||||
/* mark their ECs as already-emitted */
|
||||
foreach(lc, root->query_pathkeys)
|
||||
{
|
||||
PathKey *query_pathkey = (PathKey *) lfirst(lc);
|
||||
PathKey *query_pathkey = (PathKey *) lfirst(lc);
|
||||
EquivalenceClass *query_ec = query_pathkey->pk_eclass;
|
||||
|
||||
for (j = 0; j < necs; j++)
|
||||
@@ -1161,16 +1161,16 @@ select_outer_pathkeys_for_merge(PlannerInfo *root,
|
||||
}
|
||||
|
||||
/*
|
||||
* Add remaining ECs to the list in popularity order, using a default
|
||||
* sort ordering. (We could use qsort() here, but the list length is
|
||||
* usually so small it's not worth it.)
|
||||
* Add remaining ECs to the list in popularity order, using a default sort
|
||||
* ordering. (We could use qsort() here, but the list length is usually
|
||||
* so small it's not worth it.)
|
||||
*/
|
||||
for (;;)
|
||||
{
|
||||
int best_j;
|
||||
int best_score;
|
||||
int best_j;
|
||||
int best_score;
|
||||
EquivalenceClass *ec;
|
||||
PathKey *pathkey;
|
||||
PathKey *pathkey;
|
||||
|
||||
best_j = 0;
|
||||
best_score = scores[0];
|
||||
@@ -1230,7 +1230,7 @@ make_inner_pathkeys_for_merge(PlannerInfo *root,
|
||||
{
|
||||
List *pathkeys = NIL;
|
||||
EquivalenceClass *lastoeclass;
|
||||
PathKey *opathkey;
|
||||
PathKey *opathkey;
|
||||
ListCell *lc;
|
||||
ListCell *lop;
|
||||
|
||||
@@ -1243,7 +1243,7 @@ make_inner_pathkeys_for_merge(PlannerInfo *root,
|
||||
RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
|
||||
EquivalenceClass *oeclass;
|
||||
EquivalenceClass *ieclass;
|
||||
PathKey *pathkey;
|
||||
PathKey *pathkey;
|
||||
|
||||
cache_mergeclause_eclasses(root, rinfo);
|
||||
|
||||
@@ -1332,7 +1332,7 @@ pathkeys_useful_for_merging(PlannerInfo *root, RelOptInfo *rel, List *pathkeys)
|
||||
|
||||
foreach(i, pathkeys)
|
||||
{
|
||||
PathKey *pathkey = (PathKey *) lfirst(i);
|
||||
PathKey *pathkey = (PathKey *) lfirst(i);
|
||||
bool matched = false;
|
||||
ListCell *j;
|
||||
|
||||
@@ -1392,23 +1392,23 @@ pathkeys_useful_for_merging(PlannerInfo *root, RelOptInfo *rel, List *pathkeys)
|
||||
* for merging its target column.
|
||||
*/
|
||||
static bool
|
||||
right_merge_direction(PlannerInfo *root, PathKey *pathkey)
|
||||
right_merge_direction(PlannerInfo *root, PathKey * pathkey)
|
||||
{
|
||||
ListCell *l;
|
||||
|
||||
foreach(l, root->query_pathkeys)
|
||||
{
|
||||
PathKey *query_pathkey = (PathKey *) lfirst(l);
|
||||
PathKey *query_pathkey = (PathKey *) lfirst(l);
|
||||
|
||||
if (pathkey->pk_eclass == query_pathkey->pk_eclass &&
|
||||
pathkey->pk_opfamily == query_pathkey->pk_opfamily)
|
||||
{
|
||||
/*
|
||||
* Found a matching query sort column. Prefer this pathkey's
|
||||
* Found a matching query sort column. Prefer this pathkey's
|
||||
* direction iff it matches. Note that we ignore pk_nulls_first,
|
||||
* which means that a sort might be needed anyway ... but we
|
||||
* still want to prefer only one of the two possible directions,
|
||||
* and we might as well use this one.
|
||||
* which means that a sort might be needed anyway ... but we still
|
||||
* want to prefer only one of the two possible directions, and we
|
||||
* might as well use this one.
|
||||
*/
|
||||
return (pathkey->pk_strategy == query_pathkey->pk_strategy);
|
||||
}
|
||||
@@ -1480,13 +1480,13 @@ truncate_useless_pathkeys(PlannerInfo *root,
|
||||
* useful according to truncate_useless_pathkeys().
|
||||
*
|
||||
* This is a cheap test that lets us skip building pathkeys at all in very
|
||||
* simple queries. It's OK to err in the direction of returning "true" when
|
||||
* simple queries. It's OK to err in the direction of returning "true" when
|
||||
* there really aren't any usable pathkeys, but erring in the other direction
|
||||
* is bad --- so keep this in sync with the routines above!
|
||||
*
|
||||
* We could make the test more complex, for example checking to see if any of
|
||||
* the joinclauses are really mergejoinable, but that likely wouldn't win
|
||||
* often enough to repay the extra cycles. Queries with neither a join nor
|
||||
* often enough to repay the extra cycles. Queries with neither a join nor
|
||||
* a sort are reasonably common, though, so this much work seems worthwhile.
|
||||
*/
|
||||
bool
|
||||
|
@@ -10,7 +10,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/plan/createplan.c,v 1.234 2007/11/08 21:49:47 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/plan/createplan.c,v 1.235 2007/11/15 21:14:36 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -723,8 +723,8 @@ create_unique_plan(PlannerInfo *root, UniquePath *best_path)
|
||||
/*
|
||||
* Get the hashable equality operators for the Agg node to use.
|
||||
* Normally these are the same as the IN clause operators, but if
|
||||
* those are cross-type operators then the equality operators are
|
||||
* the ones for the IN clause operators' RHS datatype.
|
||||
* those are cross-type operators then the equality operators are the
|
||||
* ones for the IN clause operators' RHS datatype.
|
||||
*/
|
||||
groupOperators = (Oid *) palloc(numGroupCols * sizeof(Oid));
|
||||
groupColPos = 0;
|
||||
@@ -769,7 +769,7 @@ create_unique_plan(PlannerInfo *root, UniquePath *best_path)
|
||||
SortClause *sortcl;
|
||||
|
||||
sortop = get_ordering_op_for_equality_op(in_oper, false);
|
||||
if (!OidIsValid(sortop)) /* shouldn't happen */
|
||||
if (!OidIsValid(sortop)) /* shouldn't happen */
|
||||
elog(ERROR, "could not find ordering operator for equality operator %u",
|
||||
in_oper);
|
||||
tle = get_tle_by_resno(subplan->targetlist,
|
||||
@@ -1530,8 +1530,8 @@ create_mergejoin_plan(PlannerInfo *root,
|
||||
int i;
|
||||
EquivalenceClass *lastoeclass;
|
||||
EquivalenceClass *lastieclass;
|
||||
PathKey *opathkey;
|
||||
PathKey *ipathkey;
|
||||
PathKey *opathkey;
|
||||
PathKey *ipathkey;
|
||||
ListCell *lc;
|
||||
ListCell *lop;
|
||||
ListCell *lip;
|
||||
@@ -1603,8 +1603,8 @@ create_mergejoin_plan(PlannerInfo *root,
|
||||
/*
|
||||
* If inner plan is a sort that is expected to spill to disk, add a
|
||||
* materialize node to shield it from the need to handle mark/restore.
|
||||
* This will allow it to perform the last merge pass on-the-fly, while
|
||||
* in most cases not requiring the materialize to spill to disk.
|
||||
* This will allow it to perform the last merge pass on-the-fly, while in
|
||||
* most cases not requiring the materialize to spill to disk.
|
||||
*
|
||||
* XXX really, Sort oughta do this for itself, probably, to avoid the
|
||||
* overhead of a separate plan node.
|
||||
@@ -1645,7 +1645,7 @@ create_mergejoin_plan(PlannerInfo *root,
|
||||
i = 0;
|
||||
foreach(lc, best_path->path_mergeclauses)
|
||||
{
|
||||
RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
|
||||
RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
|
||||
EquivalenceClass *oeclass;
|
||||
EquivalenceClass *ieclass;
|
||||
|
||||
@@ -1938,7 +1938,7 @@ fix_indexqual_references(List *indexquals, IndexPath *index_path,
|
||||
}
|
||||
else if (IsA(clause, NullTest))
|
||||
{
|
||||
NullTest *nt = (NullTest *) clause;
|
||||
NullTest *nt = (NullTest *) clause;
|
||||
|
||||
Assert(nt->nulltesttype == IS_NULL);
|
||||
nt->arg = (Expr *) fix_indexqual_operand((Node *) nt->arg,
|
||||
@@ -2139,9 +2139,9 @@ order_qual_clauses(PlannerInfo *root, List *clauses)
|
||||
{
|
||||
typedef struct
|
||||
{
|
||||
Node *clause;
|
||||
Cost cost;
|
||||
} QualItem;
|
||||
Node *clause;
|
||||
Cost cost;
|
||||
} QualItem;
|
||||
int nitems = list_length(clauses);
|
||||
QualItem *items;
|
||||
ListCell *lc;
|
||||
@@ -2171,8 +2171,8 @@ order_qual_clauses(PlannerInfo *root, List *clauses)
|
||||
|
||||
/*
|
||||
* Sort. We don't use qsort() because it's not guaranteed stable for
|
||||
* equal keys. The expected number of entries is small enough that
|
||||
* a simple insertion sort should be good enough.
|
||||
* equal keys. The expected number of entries is small enough that a
|
||||
* simple insertion sort should be good enough.
|
||||
*/
|
||||
for (i = 1; i < nitems; i++)
|
||||
{
|
||||
@@ -2182,9 +2182,9 @@ order_qual_clauses(PlannerInfo *root, List *clauses)
|
||||
/* insert newitem into the already-sorted subarray */
|
||||
for (j = i; j > 0; j--)
|
||||
{
|
||||
if (newitem.cost >= items[j-1].cost)
|
||||
if (newitem.cost >= items[j - 1].cost)
|
||||
break;
|
||||
items[j] = items[j-1];
|
||||
items[j] = items[j - 1];
|
||||
}
|
||||
items[j] = newitem;
|
||||
}
|
||||
@@ -2616,7 +2616,7 @@ make_mergejoin(List *tlist,
|
||||
* make_sort --- basic routine to build a Sort plan node
|
||||
*
|
||||
* Caller must have built the sortColIdx, sortOperators, and nullsFirst
|
||||
* arrays already. limit_tuples is as for cost_sort (in particular, pass
|
||||
* arrays already. limit_tuples is as for cost_sort (in particular, pass
|
||||
* -1 if no limit)
|
||||
*/
|
||||
static Sort *
|
||||
@@ -2667,8 +2667,8 @@ add_sort_column(AttrNumber colIdx, Oid sortOp, bool nulls_first,
|
||||
for (i = 0; i < numCols; i++)
|
||||
{
|
||||
/*
|
||||
* Note: we check sortOp because it's conceivable that "ORDER BY
|
||||
* foo USING <, foo USING <<<" is not redundant, if <<< distinguishes
|
||||
* Note: we check sortOp because it's conceivable that "ORDER BY foo
|
||||
* USING <, foo USING <<<" is not redundant, if <<< distinguishes
|
||||
* values that < considers equal. We need not check nulls_first
|
||||
* however because a lower-order column with the same sortop but
|
||||
* opposite nulls direction is redundant.
|
||||
@@ -2729,7 +2729,7 @@ make_sort_from_pathkeys(PlannerInfo *root, Plan *lefttree, List *pathkeys,
|
||||
|
||||
foreach(i, pathkeys)
|
||||
{
|
||||
PathKey *pathkey = (PathKey *) lfirst(i);
|
||||
PathKey *pathkey = (PathKey *) lfirst(i);
|
||||
EquivalenceClass *ec = pathkey->pk_eclass;
|
||||
TargetEntry *tle = NULL;
|
||||
Oid pk_datatype = InvalidOid;
|
||||
@@ -2743,7 +2743,7 @@ make_sort_from_pathkeys(PlannerInfo *root, Plan *lefttree, List *pathkeys,
|
||||
* have come from an ORDER BY clause, and we have to match it to
|
||||
* that same targetlist entry.
|
||||
*/
|
||||
if (ec->ec_sortref == 0) /* can't happen */
|
||||
if (ec->ec_sortref == 0) /* can't happen */
|
||||
elog(ERROR, "volatile EquivalenceClass has no sortref");
|
||||
tle = get_sortgroupref_tle(ec->ec_sortref, tlist);
|
||||
Assert(tle);
|
||||
@@ -2755,7 +2755,7 @@ make_sort_from_pathkeys(PlannerInfo *root, Plan *lefttree, List *pathkeys,
|
||||
/*
|
||||
* Otherwise, we can sort by any non-constant expression listed in
|
||||
* the pathkey's EquivalenceClass. For now, we take the first one
|
||||
* that corresponds to an available item in the tlist. If there
|
||||
* that corresponds to an available item in the tlist. If there
|
||||
* isn't any, use the first one that is an expression in the
|
||||
* input's vars. (The non-const restriction only matters if the
|
||||
* EC is below_outer_join; but if it isn't, it won't contain
|
||||
@@ -2779,28 +2779,28 @@ make_sort_from_pathkeys(PlannerInfo *root, Plan *lefttree, List *pathkeys,
|
||||
if (tle)
|
||||
{
|
||||
pk_datatype = em->em_datatype;
|
||||
break; /* found expr already in tlist */
|
||||
break; /* found expr already in tlist */
|
||||
}
|
||||
|
||||
/*
|
||||
* We can also use it if the pathkey expression is a relabel
|
||||
* of the tlist entry, or vice versa. This is needed for
|
||||
* binary-compatible cases (cf. make_pathkey_from_sortinfo).
|
||||
* We prefer an exact match, though, so we do the basic
|
||||
* search first.
|
||||
* We prefer an exact match, though, so we do the basic search
|
||||
* first.
|
||||
*/
|
||||
tle = tlist_member_ignore_relabel((Node *) em->em_expr, tlist);
|
||||
if (tle)
|
||||
{
|
||||
pk_datatype = em->em_datatype;
|
||||
break; /* found expr already in tlist */
|
||||
break; /* found expr already in tlist */
|
||||
}
|
||||
}
|
||||
|
||||
if (!tle)
|
||||
{
|
||||
/* No matching tlist item; look for a computable expression */
|
||||
Expr *sortexpr = NULL;
|
||||
Expr *sortexpr = NULL;
|
||||
|
||||
foreach(j, ec->ec_members)
|
||||
{
|
||||
@@ -2821,7 +2821,7 @@ make_sort_from_pathkeys(PlannerInfo *root, Plan *lefttree, List *pathkeys,
|
||||
if (!k)
|
||||
{
|
||||
pk_datatype = em->em_datatype;
|
||||
break; /* found usable expression */
|
||||
break; /* found usable expression */
|
||||
}
|
||||
}
|
||||
if (!j)
|
||||
@@ -3172,7 +3172,7 @@ make_group(PlannerInfo *root,
|
||||
|
||||
/*
|
||||
* distinctList is a list of SortClauses, identifying the targetlist items
|
||||
* that should be considered by the Unique filter. The input path must
|
||||
* that should be considered by the Unique filter. The input path must
|
||||
* already be sorted accordingly.
|
||||
*/
|
||||
Unique *
|
||||
@@ -3221,7 +3221,7 @@ make_unique(Plan *lefttree, List *distinctList)
|
||||
|
||||
uniqColIdx[keyno] = tle->resno;
|
||||
uniqOperators[keyno] = get_equality_op_for_ordering_op(sortcl->sortop);
|
||||
if (!OidIsValid(uniqOperators[keyno])) /* shouldn't happen */
|
||||
if (!OidIsValid(uniqOperators[keyno])) /* shouldn't happen */
|
||||
elog(ERROR, "could not find equality operator for ordering operator %u",
|
||||
sortcl->sortop);
|
||||
keyno++;
|
||||
@@ -3287,7 +3287,7 @@ make_setop(SetOpCmd cmd, Plan *lefttree,
|
||||
|
||||
dupColIdx[keyno] = tle->resno;
|
||||
dupOperators[keyno] = get_equality_op_for_ordering_op(sortcl->sortop);
|
||||
if (!OidIsValid(dupOperators[keyno])) /* shouldn't happen */
|
||||
if (!OidIsValid(dupOperators[keyno])) /* shouldn't happen */
|
||||
elog(ERROR, "could not find equality operator for ordering operator %u",
|
||||
sortcl->sortop);
|
||||
keyno++;
|
||||
|
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/plan/initsplan.c,v 1.135 2007/10/24 20:54:27 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/plan/initsplan.c,v 1.136 2007/11/15 21:14:36 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -51,7 +51,7 @@ static void distribute_qual_to_rels(PlannerInfo *root, Node *clause,
|
||||
Relids ojscope,
|
||||
Relids outerjoin_nonnullable);
|
||||
static bool check_outerjoin_delay(PlannerInfo *root, Relids *relids_p,
|
||||
bool is_pushed_down);
|
||||
bool is_pushed_down);
|
||||
static void check_mergejoinable(RestrictInfo *restrictinfo);
|
||||
static void check_hashjoinable(RestrictInfo *restrictinfo);
|
||||
|
||||
@@ -329,10 +329,10 @@ deconstruct_recurse(PlannerInfo *root, Node *jtnode, bool below_outer_join,
|
||||
|
||||
/*
|
||||
* A FROM with more than one list element is an inner join subsuming
|
||||
* all below it, so we should report inner_join_rels = qualscope.
|
||||
* If there was exactly one element, we should (and already did) report
|
||||
* whatever its inner_join_rels were. If there were no elements
|
||||
* (is that possible?) the initialization before the loop fixed it.
|
||||
* all below it, so we should report inner_join_rels = qualscope. If
|
||||
* there was exactly one element, we should (and already did) report
|
||||
* whatever its inner_join_rels were. If there were no elements (is
|
||||
* that possible?) the initialization before the loop fixed it.
|
||||
*/
|
||||
if (list_length(f->fromlist) > 1)
|
||||
*inner_join_rels = *qualscope;
|
||||
@@ -478,8 +478,8 @@ deconstruct_recurse(PlannerInfo *root, Node *jtnode, bool below_outer_join,
|
||||
else
|
||||
{
|
||||
/* can't combine, but needn't force join order above here */
|
||||
Node *leftpart,
|
||||
*rightpart;
|
||||
Node *leftpart,
|
||||
*rightpart;
|
||||
|
||||
/* avoid creating useless 1-element sublists */
|
||||
if (list_length(leftjoinlist) == 1)
|
||||
@@ -590,13 +590,13 @@ make_outerjoininfo(PlannerInfo *root,
|
||||
ojinfo->lhs_strict = bms_overlap(strict_relids, left_rels);
|
||||
|
||||
/*
|
||||
* Required LHS always includes the LHS rels mentioned in the clause.
|
||||
* We may have to add more rels based on lower outer joins; see below.
|
||||
* Required LHS always includes the LHS rels mentioned in the clause. We
|
||||
* may have to add more rels based on lower outer joins; see below.
|
||||
*/
|
||||
min_lefthand = bms_intersect(clause_relids, left_rels);
|
||||
|
||||
/*
|
||||
* Similarly for required RHS. But here, we must also include any lower
|
||||
* Similarly for required RHS. But here, we must also include any lower
|
||||
* inner joins, to ensure we don't try to commute with any of them.
|
||||
*/
|
||||
min_righthand = bms_int_members(bms_union(clause_relids, inner_join_rels),
|
||||
@@ -614,10 +614,10 @@ make_outerjoininfo(PlannerInfo *root,
|
||||
* For a lower OJ in our LHS, if our join condition uses the lower
|
||||
* join's RHS and is not strict for that rel, we must preserve the
|
||||
* ordering of the two OJs, so add lower OJ's full syntactic relset to
|
||||
* min_lefthand. (We must use its full syntactic relset, not just
|
||||
* its min_lefthand + min_righthand. This is because there might
|
||||
* be other OJs below this one that this one can commute with,
|
||||
* but we cannot commute with them if we don't with this one.)
|
||||
* min_lefthand. (We must use its full syntactic relset, not just its
|
||||
* min_lefthand + min_righthand. This is because there might be other
|
||||
* OJs below this one that this one can commute with, but we cannot
|
||||
* commute with them if we don't with this one.)
|
||||
*
|
||||
* Note: I believe we have to insist on being strict for at least one
|
||||
* rel in the lower OJ's min_righthand, not its whole syn_righthand.
|
||||
@@ -635,19 +635,19 @@ make_outerjoininfo(PlannerInfo *root,
|
||||
/*
|
||||
* For a lower OJ in our RHS, if our join condition does not use the
|
||||
* lower join's RHS and the lower OJ's join condition is strict, we
|
||||
* can interchange the ordering of the two OJs; otherwise we must
|
||||
* add lower OJ's full syntactic relset to min_righthand.
|
||||
* can interchange the ordering of the two OJs; otherwise we must add
|
||||
* lower OJ's full syntactic relset to min_righthand.
|
||||
*
|
||||
* Here, we have to consider that "our join condition" includes
|
||||
* any clauses that syntactically appeared above the lower OJ and
|
||||
* below ours; those are equivalent to degenerate clauses in our
|
||||
* OJ and must be treated as such. Such clauses obviously can't
|
||||
* reference our LHS, and they must be non-strict for the lower OJ's
|
||||
* RHS (else reduce_outer_joins would have reduced the lower OJ to
|
||||
* a plain join). Hence the other ways in which we handle clauses
|
||||
* within our join condition are not affected by them. The net
|
||||
* effect is therefore sufficiently represented by the
|
||||
* delay_upper_joins flag saved for us by check_outerjoin_delay.
|
||||
* Here, we have to consider that "our join condition" includes any
|
||||
* clauses that syntactically appeared above the lower OJ and below
|
||||
* ours; those are equivalent to degenerate clauses in our OJ and must
|
||||
* be treated as such. Such clauses obviously can't reference our
|
||||
* LHS, and they must be non-strict for the lower OJ's RHS (else
|
||||
* reduce_outer_joins would have reduced the lower OJ to a plain
|
||||
* join). Hence the other ways in which we handle clauses within our
|
||||
* join condition are not affected by them. The net effect is
|
||||
* therefore sufficiently represented by the delay_upper_joins flag
|
||||
* saved for us by check_outerjoin_delay.
|
||||
*/
|
||||
if (bms_overlap(right_rels, otherinfo->syn_righthand))
|
||||
{
|
||||
@@ -817,7 +817,7 @@ distribute_qual_to_rels(PlannerInfo *root, Node *clause,
|
||||
* Note: it is not immediately obvious that a simple boolean is enough
|
||||
* for this: if for some reason we were to attach a degenerate qual to
|
||||
* its original join level, it would need to be treated as an outer join
|
||||
* qual there. However, this cannot happen, because all the rels the
|
||||
* qual there. However, this cannot happen, because all the rels the
|
||||
* clause mentions must be in the outer join's min_righthand, therefore
|
||||
* the join it needs must be formed before the outer join; and we always
|
||||
* attach quals to the lowest level where they can be evaluated. But
|
||||
@@ -828,10 +828,10 @@ distribute_qual_to_rels(PlannerInfo *root, Node *clause,
|
||||
if (is_deduced)
|
||||
{
|
||||
/*
|
||||
* If the qual came from implied-equality deduction, it should
|
||||
* not be outerjoin-delayed, else deducer blew it. But we can't
|
||||
* check this because the ojinfo list may now contain OJs above
|
||||
* where the qual belongs.
|
||||
* If the qual came from implied-equality deduction, it should not be
|
||||
* outerjoin-delayed, else deducer blew it. But we can't check this
|
||||
* because the ojinfo list may now contain OJs above where the qual
|
||||
* belongs.
|
||||
*/
|
||||
Assert(!ojscope);
|
||||
is_pushed_down = true;
|
||||
@@ -846,9 +846,9 @@ distribute_qual_to_rels(PlannerInfo *root, Node *clause,
|
||||
* The qual is attached to an outer join and mentions (some of the)
|
||||
* rels on the nonnullable side, so it's not degenerate.
|
||||
*
|
||||
* We can't use such a clause to deduce equivalence (the left and right
|
||||
* sides might be unequal above the join because one of them has gone
|
||||
* to NULL) ... but we might be able to use it for more limited
|
||||
* We can't use such a clause to deduce equivalence (the left and
|
||||
* right sides might be unequal above the join because one of them has
|
||||
* gone to NULL) ... but we might be able to use it for more limited
|
||||
* deductions, if there are no lower outer joins that delay its
|
||||
* application. If so, consider adding it to the lists of set-aside
|
||||
* clauses.
|
||||
@@ -875,8 +875,8 @@ distribute_qual_to_rels(PlannerInfo *root, Node *clause,
|
||||
else
|
||||
{
|
||||
/*
|
||||
* Normal qual clause or degenerate outer-join clause. Either way,
|
||||
* we can mark it as pushed-down.
|
||||
* Normal qual clause or degenerate outer-join clause. Either way, we
|
||||
* can mark it as pushed-down.
|
||||
*/
|
||||
is_pushed_down = true;
|
||||
|
||||
@@ -887,6 +887,7 @@ distribute_qual_to_rels(PlannerInfo *root, Node *clause,
|
||||
{
|
||||
/* Should still be a subset of current scope ... */
|
||||
Assert(bms_is_subset(relids, qualscope));
|
||||
|
||||
/*
|
||||
* Because application of the qual will be delayed by outer join,
|
||||
* we mustn't assume its vars are equal everywhere.
|
||||
@@ -896,12 +897,11 @@ distribute_qual_to_rels(PlannerInfo *root, Node *clause,
|
||||
else
|
||||
{
|
||||
/*
|
||||
* Qual is not delayed by any lower outer-join restriction, so
|
||||
* we can consider feeding it to the equivalence machinery.
|
||||
* However, if it's itself within an outer-join clause, treat it
|
||||
* as though it appeared below that outer join (note that we can
|
||||
* only get here when the clause references only nullable-side
|
||||
* rels).
|
||||
* Qual is not delayed by any lower outer-join restriction, so we
|
||||
* can consider feeding it to the equivalence machinery. However,
|
||||
* if it's itself within an outer-join clause, treat it as though
|
||||
* it appeared below that outer join (note that we can only get
|
||||
* here when the clause references only nullable-side rels).
|
||||
*/
|
||||
maybe_equivalence = true;
|
||||
if (outerjoin_nonnullable != NULL)
|
||||
@@ -926,9 +926,9 @@ distribute_qual_to_rels(PlannerInfo *root, Node *clause,
|
||||
|
||||
/*
|
||||
* If it's a join clause (either naturally, or because delayed by
|
||||
* outer-join rules), add vars used in the clause to targetlists of
|
||||
* their relations, so that they will be emitted by the plan nodes that
|
||||
* scan those relations (else they won't be available at the join node!).
|
||||
* outer-join rules), add vars used in the clause to targetlists of their
|
||||
* relations, so that they will be emitted by the plan nodes that scan
|
||||
* those relations (else they won't be available at the join node!).
|
||||
*
|
||||
* Note: if the clause gets absorbed into an EquivalenceClass then this
|
||||
* may be unnecessary, but for now we have to do it to cover the case
|
||||
@@ -955,23 +955,23 @@ distribute_qual_to_rels(PlannerInfo *root, Node *clause,
|
||||
* machinery. We do *not* attach it directly to any restriction or join
|
||||
* lists. The EC code will propagate it to the appropriate places later.
|
||||
*
|
||||
* If the clause has a mergejoinable operator and is not outerjoin-delayed,
|
||||
* yet isn't an equivalence because it is an outer-join clause, the EC
|
||||
* code may yet be able to do something with it. We add it to appropriate
|
||||
* lists for further consideration later. Specifically:
|
||||
* If the clause has a mergejoinable operator and is not
|
||||
* outerjoin-delayed, yet isn't an equivalence because it is an outer-join
|
||||
* clause, the EC code may yet be able to do something with it. We add it
|
||||
* to appropriate lists for further consideration later. Specifically:
|
||||
*
|
||||
* If it is a left or right outer-join qualification that relates the
|
||||
* two sides of the outer join (no funny business like leftvar1 =
|
||||
* leftvar2 + rightvar), we add it to root->left_join_clauses or
|
||||
* If it is a left or right outer-join qualification that relates the two
|
||||
* sides of the outer join (no funny business like leftvar1 = leftvar2 +
|
||||
* rightvar), we add it to root->left_join_clauses or
|
||||
* root->right_join_clauses according to which side the nonnullable
|
||||
* variable appears on.
|
||||
*
|
||||
* If it is a full outer-join qualification, we add it to
|
||||
* root->full_join_clauses. (Ideally we'd discard cases that aren't
|
||||
* leftvar = rightvar, as we do for left/right joins, but this routine
|
||||
* doesn't have the info needed to do that; and the current usage of
|
||||
* the full_join_clauses list doesn't require that, so it's not
|
||||
* currently worth complicating this routine's API to make it possible.)
|
||||
* doesn't have the info needed to do that; and the current usage of the
|
||||
* full_join_clauses list doesn't require that, so it's not currently
|
||||
* worth complicating this routine's API to make it possible.)
|
||||
*
|
||||
* If none of the above hold, pass it off to
|
||||
* distribute_restrictinfo_to_rels().
|
||||
@@ -997,9 +997,9 @@ distribute_qual_to_rels(PlannerInfo *root, Node *clause,
|
||||
return;
|
||||
}
|
||||
if (bms_is_subset(restrictinfo->right_relids,
|
||||
outerjoin_nonnullable) &&
|
||||
!bms_overlap(restrictinfo->left_relids,
|
||||
outerjoin_nonnullable))
|
||||
outerjoin_nonnullable) &&
|
||||
!bms_overlap(restrictinfo->left_relids,
|
||||
outerjoin_nonnullable))
|
||||
{
|
||||
/* we have innervar = outervar */
|
||||
root->right_join_clauses = lappend(root->right_join_clauses,
|
||||
@@ -1034,7 +1034,7 @@ distribute_qual_to_rels(PlannerInfo *root, Node *clause,
|
||||
* For an is_pushed_down qual, we can evaluate the qual as soon as (1) we have
|
||||
* all the rels it mentions, and (2) we are at or above any outer joins that
|
||||
* can null any of these rels and are below the syntactic location of the
|
||||
* given qual. We must enforce (2) because pushing down such a clause below
|
||||
* given qual. We must enforce (2) because pushing down such a clause below
|
||||
* the OJ might cause the OJ to emit null-extended rows that should not have
|
||||
* been formed, or that should have been rejected by the clause. (This is
|
||||
* only an issue for non-strict quals, since if we can prove a qual mentioning
|
||||
@@ -1043,7 +1043,7 @@ distribute_qual_to_rels(PlannerInfo *root, Node *clause,
|
||||
*
|
||||
* To enforce (2), scan the oj_info_list and merge the required-relid sets of
|
||||
* any such OJs into the clause's own reference list. At the time we are
|
||||
* called, the oj_info_list contains only outer joins below this qual. We
|
||||
* called, the oj_info_list contains only outer joins below this qual. We
|
||||
* have to repeat the scan until no new relids get added; this ensures that
|
||||
* the qual is suitably delayed regardless of the order in which OJs get
|
||||
* executed. As an example, if we have one OJ with LHS=A, RHS=B, and one with
|
||||
@@ -1060,7 +1060,7 @@ distribute_qual_to_rels(PlannerInfo *root, Node *clause,
|
||||
* required relids overlap the LHS too) causes that OJ's delay_upper_joins
|
||||
* flag to be set TRUE. This will prevent any higher-level OJs from
|
||||
* being interchanged with that OJ, which would result in not having any
|
||||
* correct place to evaluate the qual. (The case we care about here is a
|
||||
* correct place to evaluate the qual. (The case we care about here is a
|
||||
* sub-select WHERE clause within the RHS of some outer join. The WHERE
|
||||
* clause must effectively be treated as a degenerate clause of that outer
|
||||
* join's condition. Rather than trying to match such clauses with joins
|
||||
@@ -1077,7 +1077,8 @@ check_outerjoin_delay(PlannerInfo *root, Relids *relids_p,
|
||||
bool found_some;
|
||||
|
||||
outerjoin_delayed = false;
|
||||
do {
|
||||
do
|
||||
{
|
||||
ListCell *l;
|
||||
|
||||
found_some = false;
|
||||
@@ -1134,8 +1135,8 @@ distribute_restrictinfo_to_rels(PlannerInfo *root,
|
||||
case BMS_SINGLETON:
|
||||
|
||||
/*
|
||||
* There is only one relation participating in the clause, so
|
||||
* it is a restriction clause for that relation.
|
||||
* There is only one relation participating in the clause, so it
|
||||
* is a restriction clause for that relation.
|
||||
*/
|
||||
rel = find_base_rel(root, bms_singleton_member(relids));
|
||||
|
||||
@@ -1151,8 +1152,8 @@ distribute_restrictinfo_to_rels(PlannerInfo *root,
|
||||
*/
|
||||
|
||||
/*
|
||||
* Check for hashjoinable operators. (We don't bother setting
|
||||
* the hashjoin info if we're not going to need it.)
|
||||
* Check for hashjoinable operators. (We don't bother setting the
|
||||
* hashjoin info if we're not going to need it.)
|
||||
*/
|
||||
if (enable_hashjoin)
|
||||
check_hashjoinable(restrictinfo);
|
||||
@@ -1222,7 +1223,7 @@ process_implied_equality(PlannerInfo *root,
|
||||
/* If we produced const TRUE, just drop the clause */
|
||||
if (clause && IsA(clause, Const))
|
||||
{
|
||||
Const *cclause = (Const *) clause;
|
||||
Const *cclause = (Const *) clause;
|
||||
|
||||
Assert(cclause->consttype == BOOLOID);
|
||||
if (!cclause->constisnull && DatumGetBool(cclause->constvalue))
|
||||
@@ -1273,9 +1274,9 @@ build_implied_join_equality(Oid opno,
|
||||
* Build the RestrictInfo node itself.
|
||||
*/
|
||||
restrictinfo = make_restrictinfo(clause,
|
||||
true, /* is_pushed_down */
|
||||
false, /* outerjoin_delayed */
|
||||
false, /* pseudoconstant */
|
||||
true, /* is_pushed_down */
|
||||
false, /* outerjoin_delayed */
|
||||
false, /* pseudoconstant */
|
||||
qualscope);
|
||||
|
||||
/* Set mergejoinability info always, and hashjoinability if enabled */
|
||||
@@ -1322,9 +1323,9 @@ check_mergejoinable(RestrictInfo *restrictinfo)
|
||||
restrictinfo->mergeopfamilies = get_mergejoin_opfamilies(opno);
|
||||
|
||||
/*
|
||||
* Note: op_mergejoinable is just a hint; if we fail to find the
|
||||
* operator in any btree opfamilies, mergeopfamilies remains NIL
|
||||
* and so the clause is not treated as mergejoinable.
|
||||
* Note: op_mergejoinable is just a hint; if we fail to find the operator
|
||||
* in any btree opfamilies, mergeopfamilies remains NIL and so the clause
|
||||
* is not treated as mergejoinable.
|
||||
*/
|
||||
}
|
||||
|
||||
|
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/plan/planagg.c,v 1.33 2007/10/13 00:58:03 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/plan/planagg.c,v 1.34 2007/11/15 21:14:36 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -298,9 +298,9 @@ build_minmax_path(PlannerInfo *root, RelOptInfo *rel, MinMaxAggInfo *info)
|
||||
info->notnulltest = (Expr *) ntest;
|
||||
|
||||
/*
|
||||
* Build list of existing restriction clauses plus the notnull test.
|
||||
* We cheat a bit by not bothering with a RestrictInfo node for the
|
||||
* notnull test --- predicate_implied_by() won't care.
|
||||
* Build list of existing restriction clauses plus the notnull test. We
|
||||
* cheat a bit by not bothering with a RestrictInfo node for the notnull
|
||||
* test --- predicate_implied_by() won't care.
|
||||
*/
|
||||
allquals = list_concat(list_make1(ntest), rel->baserestrictinfo);
|
||||
|
||||
@@ -320,9 +320,9 @@ build_minmax_path(PlannerInfo *root, RelOptInfo *rel, MinMaxAggInfo *info)
|
||||
continue;
|
||||
|
||||
/*
|
||||
* Ignore partial indexes that do not match the query --- unless
|
||||
* their predicates can be proven from the baserestrict list plus
|
||||
* the IS NOT NULL test. In that case we can use them.
|
||||
* Ignore partial indexes that do not match the query --- unless their
|
||||
* predicates can be proven from the baserestrict list plus the IS NOT
|
||||
* NULL test. In that case we can use them.
|
||||
*/
|
||||
if (index->indpred != NIL && !index->predOK &&
|
||||
!predicate_implied_by(index->indpred, allquals))
|
||||
@@ -434,7 +434,7 @@ build_minmax_path(PlannerInfo *root, RelOptInfo *rel, MinMaxAggInfo *info)
|
||||
static ScanDirection
|
||||
match_agg_to_index_col(MinMaxAggInfo *info, IndexOptInfo *index, int indexcol)
|
||||
{
|
||||
ScanDirection result;
|
||||
ScanDirection result;
|
||||
|
||||
/* Check for operator match first (cheaper) */
|
||||
if (info->aggsortop == index->fwdsortop[indexcol])
|
||||
@@ -519,8 +519,8 @@ make_agg_subplan(PlannerInfo *root, MinMaxAggInfo *info)
|
||||
* have stuck a gating Result atop that, if there were any pseudoconstant
|
||||
* quals.
|
||||
*
|
||||
* We can skip adding the NOT NULL qual if it's redundant with either
|
||||
* an already-given WHERE condition, or a clause of the index predicate.
|
||||
* We can skip adding the NOT NULL qual if it's redundant with either an
|
||||
* already-given WHERE condition, or a clause of the index predicate.
|
||||
*/
|
||||
plan = create_plan(&subroot, (Path *) info->path);
|
||||
|
||||
|
@@ -14,7 +14,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/plan/planmain.c,v 1.103 2007/10/04 20:44:47 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/plan/planmain.c,v 1.104 2007/11/15 21:14:36 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -110,9 +110,10 @@ query_planner(PlannerInfo *root, List *tlist,
|
||||
*cheapest_path = (Path *)
|
||||
create_result_path((List *) parse->jointree->quals);
|
||||
*sorted_path = NULL;
|
||||
|
||||
/*
|
||||
* We still are required to canonicalize any pathkeys, in case
|
||||
* it's something like "SELECT 2+2 ORDER BY 1".
|
||||
* We still are required to canonicalize any pathkeys, in case it's
|
||||
* something like "SELECT 2+2 ORDER BY 1".
|
||||
*/
|
||||
root->canon_pathkeys = NIL;
|
||||
root->query_pathkeys = canonicalize_pathkeys(root,
|
||||
@@ -143,8 +144,8 @@ query_planner(PlannerInfo *root, List *tlist,
|
||||
root->oj_info_list = NIL;
|
||||
|
||||
/*
|
||||
* Make a flattened version of the rangetable for faster access (this
|
||||
* is OK because the rangetable won't change any more).
|
||||
* Make a flattened version of the rangetable for faster access (this is
|
||||
* OK because the rangetable won't change any more).
|
||||
*/
|
||||
root->simple_rte_array = (RangeTblEntry **)
|
||||
palloc0(root->simple_rel_array_size * sizeof(RangeTblEntry *));
|
||||
@@ -198,8 +199,8 @@ query_planner(PlannerInfo *root, List *tlist,
|
||||
* Examine the targetlist and qualifications, adding entries to baserel
|
||||
* targetlists for all referenced Vars. Restrict and join clauses are
|
||||
* added to appropriate lists belonging to the mentioned relations. We
|
||||
* also build EquivalenceClasses for provably equivalent expressions,
|
||||
* and form a target joinlist for make_one_rel() to work from.
|
||||
* also build EquivalenceClasses for provably equivalent expressions, and
|
||||
* form a target joinlist for make_one_rel() to work from.
|
||||
*
|
||||
* Note: all subplan nodes will have "flat" (var-only) tlists. This
|
||||
* implies that all expression evaluations are done at the root of the
|
||||
@@ -227,14 +228,14 @@ query_planner(PlannerInfo *root, List *tlist,
|
||||
|
||||
/*
|
||||
* If we formed any equivalence classes, generate additional restriction
|
||||
* clauses as appropriate. (Implied join clauses are formed on-the-fly
|
||||
* clauses as appropriate. (Implied join clauses are formed on-the-fly
|
||||
* later.)
|
||||
*/
|
||||
generate_base_implied_equalities(root);
|
||||
|
||||
/*
|
||||
* We have completed merging equivalence sets, so it's now possible to
|
||||
* convert the requested query_pathkeys to canonical form. Also
|
||||
* convert the requested query_pathkeys to canonical form. Also
|
||||
* canonicalize the groupClause and sortClause pathkeys for use later.
|
||||
*/
|
||||
root->query_pathkeys = canonicalize_pathkeys(root, root->query_pathkeys);
|
||||
|
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/plan/planner.c,v 1.223 2007/10/11 18:05:27 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/plan/planner.c,v 1.224 2007/11/15 21:14:36 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -174,8 +174,8 @@ standard_planner(Query *parse, int cursorOptions, ParamListInfo boundParams)
|
||||
Assert(list_length(glob->subplans) == list_length(glob->subrtables));
|
||||
forboth(lp, glob->subplans, lr, glob->subrtables)
|
||||
{
|
||||
Plan *subplan = (Plan *) lfirst(lp);
|
||||
List *subrtable = (List *) lfirst(lr);
|
||||
Plan *subplan = (Plan *) lfirst(lp);
|
||||
List *subrtable = (List *) lfirst(lr);
|
||||
|
||||
lfirst(lp) = set_plan_references(glob, subplan, subrtable);
|
||||
}
|
||||
@@ -229,7 +229,7 @@ standard_planner(Query *parse, int cursorOptions, ParamListInfo boundParams)
|
||||
*--------------------
|
||||
*/
|
||||
Plan *
|
||||
subquery_planner(PlannerGlobal *glob, Query *parse,
|
||||
subquery_planner(PlannerGlobal * glob, Query *parse,
|
||||
Index level, double tuple_fraction,
|
||||
PlannerInfo **subroot)
|
||||
{
|
||||
@@ -741,9 +741,10 @@ grouping_planner(PlannerInfo *root, double tuple_fraction)
|
||||
{
|
||||
tuple_fraction = preprocess_limit(root, tuple_fraction,
|
||||
&offset_est, &count_est);
|
||||
|
||||
/*
|
||||
* If we have a known LIMIT, and don't have an unknown OFFSET,
|
||||
* we can estimate the effects of using a bounded sort.
|
||||
* If we have a known LIMIT, and don't have an unknown OFFSET, we can
|
||||
* estimate the effects of using a bounded sort.
|
||||
*/
|
||||
if (count_est > 0 && offset_est >= 0)
|
||||
limit_tuples = (double) count_est + (double) offset_est;
|
||||
@@ -777,7 +778,7 @@ grouping_planner(PlannerInfo *root, double tuple_fraction)
|
||||
*/
|
||||
current_pathkeys = make_pathkeys_for_sortclauses(root,
|
||||
set_sortclauses,
|
||||
result_plan->targetlist,
|
||||
result_plan->targetlist,
|
||||
true);
|
||||
|
||||
/*
|
||||
@@ -1446,7 +1447,7 @@ extract_grouping_ops(List *groupClause)
|
||||
GroupClause *groupcl = (GroupClause *) lfirst(glitem);
|
||||
|
||||
groupOperators[colno] = get_equality_op_for_ordering_op(groupcl->sortop);
|
||||
if (!OidIsValid(groupOperators[colno])) /* shouldn't happen */
|
||||
if (!OidIsValid(groupOperators[colno])) /* shouldn't happen */
|
||||
elog(ERROR, "could not find equality operator for ordering operator %u",
|
||||
groupcl->sortop);
|
||||
colno++;
|
||||
@@ -1477,8 +1478,8 @@ choose_hashed_grouping(PlannerInfo *root,
|
||||
/*
|
||||
* Check can't-do-it conditions, including whether the grouping operators
|
||||
* are hashjoinable. (We assume hashing is OK if they are marked
|
||||
* oprcanhash. If there isn't actually a supporting hash function,
|
||||
* the executor will complain at runtime.)
|
||||
* oprcanhash. If there isn't actually a supporting hash function, the
|
||||
* executor will complain at runtime.)
|
||||
*
|
||||
* Executor doesn't support hashed aggregation with DISTINCT aggregates.
|
||||
* (Doing so would imply storing *all* the input values in the hash table,
|
||||
|
@@ -9,7 +9,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/plan/setrefs.c,v 1.137 2007/10/11 18:05:27 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/plan/setrefs.c,v 1.138 2007/11/15 21:14:36 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -45,7 +45,7 @@ typedef struct
|
||||
{
|
||||
PlannerGlobal *glob;
|
||||
int rtoffset;
|
||||
} fix_scan_expr_context;
|
||||
} fix_scan_expr_context;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@@ -54,29 +54,29 @@ typedef struct
|
||||
indexed_tlist *inner_itlist;
|
||||
Index acceptable_rel;
|
||||
int rtoffset;
|
||||
} fix_join_expr_context;
|
||||
} fix_join_expr_context;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
PlannerGlobal *glob;
|
||||
indexed_tlist *subplan_itlist;
|
||||
int rtoffset;
|
||||
} fix_upper_expr_context;
|
||||
} fix_upper_expr_context;
|
||||
|
||||
#define fix_scan_list(glob, lst, rtoffset) \
|
||||
((List *) fix_scan_expr(glob, (Node *) (lst), rtoffset))
|
||||
|
||||
static Plan *set_plan_refs(PlannerGlobal *glob, Plan *plan, int rtoffset);
|
||||
static Plan *set_subqueryscan_references(PlannerGlobal *glob,
|
||||
SubqueryScan *plan,
|
||||
int rtoffset);
|
||||
static Plan *set_plan_refs(PlannerGlobal * glob, Plan *plan, int rtoffset);
|
||||
static Plan *set_subqueryscan_references(PlannerGlobal * glob,
|
||||
SubqueryScan *plan,
|
||||
int rtoffset);
|
||||
static bool trivial_subqueryscan(SubqueryScan *plan);
|
||||
static Node *fix_scan_expr(PlannerGlobal *glob, Node *node, int rtoffset);
|
||||
static Node *fix_scan_expr_mutator(Node *node, fix_scan_expr_context *context);
|
||||
static void set_join_references(PlannerGlobal *glob, Join *join, int rtoffset);
|
||||
static void set_inner_join_references(PlannerGlobal *glob, Plan *inner_plan,
|
||||
static Node *fix_scan_expr(PlannerGlobal * glob, Node *node, int rtoffset);
|
||||
static Node *fix_scan_expr_mutator(Node *node, fix_scan_expr_context * context);
|
||||
static void set_join_references(PlannerGlobal * glob, Join *join, int rtoffset);
|
||||
static void set_inner_join_references(PlannerGlobal * glob, Plan *inner_plan,
|
||||
indexed_tlist *outer_itlist);
|
||||
static void set_upper_references(PlannerGlobal *glob, Plan *plan, int rtoffset);
|
||||
static void set_upper_references(PlannerGlobal * glob, Plan *plan, int rtoffset);
|
||||
static void set_dummy_tlist_references(Plan *plan, int rtoffset);
|
||||
static indexed_tlist *build_tlist_index(List *tlist);
|
||||
static Var *search_indexed_tlist_for_var(Var *var,
|
||||
@@ -86,19 +86,19 @@ static Var *search_indexed_tlist_for_var(Var *var,
|
||||
static Var *search_indexed_tlist_for_non_var(Node *node,
|
||||
indexed_tlist *itlist,
|
||||
Index newvarno);
|
||||
static List *fix_join_expr(PlannerGlobal *glob,
|
||||
List *clauses,
|
||||
indexed_tlist *outer_itlist,
|
||||
indexed_tlist *inner_itlist,
|
||||
Index acceptable_rel, int rtoffset);
|
||||
static List *fix_join_expr(PlannerGlobal * glob,
|
||||
List *clauses,
|
||||
indexed_tlist *outer_itlist,
|
||||
indexed_tlist *inner_itlist,
|
||||
Index acceptable_rel, int rtoffset);
|
||||
static Node *fix_join_expr_mutator(Node *node,
|
||||
fix_join_expr_context *context);
|
||||
static Node *fix_upper_expr(PlannerGlobal *glob,
|
||||
Node *node,
|
||||
indexed_tlist *subplan_itlist,
|
||||
int rtoffset);
|
||||
fix_join_expr_context * context);
|
||||
static Node *fix_upper_expr(PlannerGlobal * glob,
|
||||
Node *node,
|
||||
indexed_tlist *subplan_itlist,
|
||||
int rtoffset);
|
||||
static Node *fix_upper_expr_mutator(Node *node,
|
||||
fix_upper_expr_context *context);
|
||||
fix_upper_expr_context * context);
|
||||
static bool fix_opfuncids_walker(Node *node, void *context);
|
||||
|
||||
|
||||
@@ -155,26 +155,26 @@ static bool fix_opfuncids_walker(Node *node, void *context);
|
||||
* the list of relation OIDs is appended to glob->relationOids.
|
||||
*
|
||||
* Notice that we modify Plan nodes in-place, but use expression_tree_mutator
|
||||
* to process targetlist and qual expressions. We can assume that the Plan
|
||||
* to process targetlist and qual expressions. We can assume that the Plan
|
||||
* nodes were just built by the planner and are not multiply referenced, but
|
||||
* it's not so safe to assume that for expression tree nodes.
|
||||
*/
|
||||
Plan *
|
||||
set_plan_references(PlannerGlobal *glob, Plan *plan, List *rtable)
|
||||
set_plan_references(PlannerGlobal * glob, Plan *plan, List *rtable)
|
||||
{
|
||||
int rtoffset = list_length(glob->finalrtable);
|
||||
ListCell *lc;
|
||||
|
||||
/*
|
||||
* In the flat rangetable, we zero out substructure pointers that are
|
||||
* not needed by the executor; this reduces the storage space and
|
||||
* copying cost for cached plans. We keep only the alias and eref
|
||||
* Alias fields, which are needed by EXPLAIN.
|
||||
* In the flat rangetable, we zero out substructure pointers that are not
|
||||
* needed by the executor; this reduces the storage space and copying cost
|
||||
* for cached plans. We keep only the alias and eref Alias fields, which
|
||||
* are needed by EXPLAIN.
|
||||
*/
|
||||
foreach(lc, rtable)
|
||||
{
|
||||
RangeTblEntry *rte = (RangeTblEntry *) lfirst(lc);
|
||||
RangeTblEntry *newrte;
|
||||
RangeTblEntry *rte = (RangeTblEntry *) lfirst(lc);
|
||||
RangeTblEntry *newrte;
|
||||
|
||||
/* flat copy to duplicate all the scalar fields */
|
||||
newrte = (RangeTblEntry *) palloc(sizeof(RangeTblEntry));
|
||||
@@ -193,11 +193,11 @@ set_plan_references(PlannerGlobal *glob, Plan *plan, List *rtable)
|
||||
/*
|
||||
* If it's a plain relation RTE, add the table to relationOids.
|
||||
*
|
||||
* We do this even though the RTE might be unreferenced in the
|
||||
* plan tree; this would correspond to cases such as views that
|
||||
* were expanded, child tables that were eliminated by constraint
|
||||
* exclusion, etc. Schema invalidation on such a rel must still
|
||||
* force rebuilding of the plan.
|
||||
* We do this even though the RTE might be unreferenced in the plan
|
||||
* tree; this would correspond to cases such as views that were
|
||||
* expanded, child tables that were eliminated by constraint
|
||||
* exclusion, etc. Schema invalidation on such a rel must still force
|
||||
* rebuilding of the plan.
|
||||
*
|
||||
* Note we don't bother to avoid duplicate list entries. We could,
|
||||
* but it would probably cost more cycles than it would save.
|
||||
@@ -215,7 +215,7 @@ set_plan_references(PlannerGlobal *glob, Plan *plan, List *rtable)
|
||||
* set_plan_refs: recurse through the Plan nodes of a single subquery level
|
||||
*/
|
||||
static Plan *
|
||||
set_plan_refs(PlannerGlobal *glob, Plan *plan, int rtoffset)
|
||||
set_plan_refs(PlannerGlobal * glob, Plan *plan, int rtoffset)
|
||||
{
|
||||
ListCell *l;
|
||||
|
||||
@@ -229,7 +229,7 @@ set_plan_refs(PlannerGlobal *glob, Plan *plan, int rtoffset)
|
||||
{
|
||||
case T_SeqScan:
|
||||
{
|
||||
SeqScan *splan = (SeqScan *) plan;
|
||||
SeqScan *splan = (SeqScan *) plan;
|
||||
|
||||
splan->scanrelid += rtoffset;
|
||||
splan->plan.targetlist =
|
||||
@@ -240,7 +240,7 @@ set_plan_refs(PlannerGlobal *glob, Plan *plan, int rtoffset)
|
||||
break;
|
||||
case T_IndexScan:
|
||||
{
|
||||
IndexScan *splan = (IndexScan *) plan;
|
||||
IndexScan *splan = (IndexScan *) plan;
|
||||
|
||||
splan->scan.scanrelid += rtoffset;
|
||||
splan->scan.plan.targetlist =
|
||||
@@ -282,7 +282,7 @@ set_plan_refs(PlannerGlobal *glob, Plan *plan, int rtoffset)
|
||||
break;
|
||||
case T_TidScan:
|
||||
{
|
||||
TidScan *splan = (TidScan *) plan;
|
||||
TidScan *splan = (TidScan *) plan;
|
||||
|
||||
splan->scan.scanrelid += rtoffset;
|
||||
splan->scan.plan.targetlist =
|
||||
@@ -340,11 +340,12 @@ set_plan_refs(PlannerGlobal *glob, Plan *plan, int rtoffset)
|
||||
/*
|
||||
* These plan types don't actually bother to evaluate their
|
||||
* targetlists, because they just return their unmodified input
|
||||
* tuples. Even though the targetlist won't be used by the
|
||||
* tuples. Even though the targetlist won't be used by the
|
||||
* executor, we fix it up for possible use by EXPLAIN (not to
|
||||
* mention ease of debugging --- wrong varnos are very confusing).
|
||||
*/
|
||||
set_dummy_tlist_references(plan, rtoffset);
|
||||
|
||||
/*
|
||||
* Since these plan types don't check quals either, we should not
|
||||
* find any qual expression attached to them.
|
||||
@@ -353,13 +354,13 @@ set_plan_refs(PlannerGlobal *glob, Plan *plan, int rtoffset)
|
||||
break;
|
||||
case T_Limit:
|
||||
{
|
||||
Limit *splan = (Limit *) plan;
|
||||
Limit *splan = (Limit *) plan;
|
||||
|
||||
/*
|
||||
* Like the plan types above, Limit doesn't evaluate its tlist
|
||||
* or quals. It does have live expressions for limit/offset,
|
||||
* however; and those cannot contain subplan variable refs,
|
||||
* so fix_scan_expr works for them.
|
||||
* however; and those cannot contain subplan variable refs, so
|
||||
* fix_scan_expr works for them.
|
||||
*/
|
||||
set_dummy_tlist_references(plan, rtoffset);
|
||||
Assert(splan->plan.qual == NIL);
|
||||
@@ -376,7 +377,7 @@ set_plan_refs(PlannerGlobal *glob, Plan *plan, int rtoffset)
|
||||
break;
|
||||
case T_Result:
|
||||
{
|
||||
Result *splan = (Result *) plan;
|
||||
Result *splan = (Result *) plan;
|
||||
|
||||
/*
|
||||
* Result may or may not have a subplan; if not, it's more
|
||||
@@ -398,7 +399,7 @@ set_plan_refs(PlannerGlobal *glob, Plan *plan, int rtoffset)
|
||||
break;
|
||||
case T_Append:
|
||||
{
|
||||
Append *splan = (Append *) plan;
|
||||
Append *splan = (Append *) plan;
|
||||
|
||||
/*
|
||||
* Append, like Sort et al, doesn't actually evaluate its
|
||||
@@ -416,7 +417,7 @@ set_plan_refs(PlannerGlobal *glob, Plan *plan, int rtoffset)
|
||||
break;
|
||||
case T_BitmapAnd:
|
||||
{
|
||||
BitmapAnd *splan = (BitmapAnd *) plan;
|
||||
BitmapAnd *splan = (BitmapAnd *) plan;
|
||||
|
||||
/* BitmapAnd works like Append, but has no tlist */
|
||||
Assert(splan->plan.targetlist == NIL);
|
||||
@@ -431,7 +432,7 @@ set_plan_refs(PlannerGlobal *glob, Plan *plan, int rtoffset)
|
||||
break;
|
||||
case T_BitmapOr:
|
||||
{
|
||||
BitmapOr *splan = (BitmapOr *) plan;
|
||||
BitmapOr *splan = (BitmapOr *) plan;
|
||||
|
||||
/* BitmapOr works like Append, but has no tlist */
|
||||
Assert(splan->plan.targetlist == NIL);
|
||||
@@ -472,7 +473,7 @@ set_plan_refs(PlannerGlobal *glob, Plan *plan, int rtoffset)
|
||||
* to do the normal processing on it.
|
||||
*/
|
||||
static Plan *
|
||||
set_subqueryscan_references(PlannerGlobal *glob,
|
||||
set_subqueryscan_references(PlannerGlobal * glob,
|
||||
SubqueryScan *plan,
|
||||
int rtoffset)
|
||||
{
|
||||
@@ -618,7 +619,7 @@ copyVar(Var *var)
|
||||
* and adding OIDs from regclass Const nodes into glob->relationOids.
|
||||
*/
|
||||
static Node *
|
||||
fix_scan_expr(PlannerGlobal *glob, Node *node, int rtoffset)
|
||||
fix_scan_expr(PlannerGlobal * glob, Node *node, int rtoffset)
|
||||
{
|
||||
fix_scan_expr_context context;
|
||||
|
||||
@@ -628,7 +629,7 @@ fix_scan_expr(PlannerGlobal *glob, Node *node, int rtoffset)
|
||||
}
|
||||
|
||||
static Node *
|
||||
fix_scan_expr_mutator(Node *node, fix_scan_expr_context *context)
|
||||
fix_scan_expr_mutator(Node *node, fix_scan_expr_context * context)
|
||||
{
|
||||
if (node == NULL)
|
||||
return NULL;
|
||||
@@ -637,9 +638,10 @@ fix_scan_expr_mutator(Node *node, fix_scan_expr_context *context)
|
||||
Var *var = copyVar((Var *) node);
|
||||
|
||||
Assert(var->varlevelsup == 0);
|
||||
|
||||
/*
|
||||
* We should not see any Vars marked INNER, but in a nestloop inner
|
||||
* scan there could be OUTER Vars. Leave them alone.
|
||||
* scan there could be OUTER Vars. Leave them alone.
|
||||
*/
|
||||
Assert(var->varno != INNER);
|
||||
if (var->varno > 0 && var->varno != OUTER)
|
||||
@@ -657,9 +659,10 @@ fix_scan_expr_mutator(Node *node, fix_scan_expr_context *context)
|
||||
cexpr->cvarno += context->rtoffset;
|
||||
return (Node *) cexpr;
|
||||
}
|
||||
|
||||
/*
|
||||
* Since we update opcode info in-place, this part could possibly
|
||||
* scribble on the planner's input data structures, but it's OK.
|
||||
* Since we update opcode info in-place, this part could possibly scribble
|
||||
* on the planner's input data structures, but it's OK.
|
||||
*/
|
||||
if (IsA(node, OpExpr))
|
||||
set_opfuncid((OpExpr *) node);
|
||||
@@ -697,7 +700,7 @@ fix_scan_expr_mutator(Node *node, fix_scan_expr_context *context)
|
||||
* quals of the child indexscan. set_inner_join_references does that.
|
||||
*/
|
||||
static void
|
||||
set_join_references(PlannerGlobal *glob, Join *join, int rtoffset)
|
||||
set_join_references(PlannerGlobal * glob, Join *join, int rtoffset)
|
||||
{
|
||||
Plan *outer_plan = join->plan.lefttree;
|
||||
Plan *inner_plan = join->plan.righttree;
|
||||
@@ -774,7 +777,7 @@ set_join_references(PlannerGlobal *glob, Join *join, int rtoffset)
|
||||
* recursion reaches the inner indexscan, and so we'd have done it twice.
|
||||
*/
|
||||
static void
|
||||
set_inner_join_references(PlannerGlobal *glob, Plan *inner_plan,
|
||||
set_inner_join_references(PlannerGlobal * glob, Plan *inner_plan,
|
||||
indexed_tlist *outer_itlist)
|
||||
{
|
||||
if (IsA(inner_plan, IndexScan))
|
||||
@@ -966,7 +969,7 @@ set_inner_join_references(PlannerGlobal *glob, Plan *inner_plan,
|
||||
* the expression.
|
||||
*/
|
||||
static void
|
||||
set_upper_references(PlannerGlobal *glob, Plan *plan, int rtoffset)
|
||||
set_upper_references(PlannerGlobal * glob, Plan *plan, int rtoffset)
|
||||
{
|
||||
Plan *subplan = plan->lefttree;
|
||||
indexed_tlist *subplan_itlist;
|
||||
@@ -1038,7 +1041,7 @@ set_dummy_tlist_references(Plan *plan, int rtoffset)
|
||||
}
|
||||
else
|
||||
{
|
||||
newvar->varnoold = 0; /* wasn't ever a plain Var */
|
||||
newvar->varnoold = 0; /* wasn't ever a plain Var */
|
||||
newvar->varoattno = 0;
|
||||
}
|
||||
|
||||
@@ -1251,7 +1254,7 @@ search_indexed_tlist_for_non_var(Node *node,
|
||||
* not modified.
|
||||
*/
|
||||
static List *
|
||||
fix_join_expr(PlannerGlobal *glob,
|
||||
fix_join_expr(PlannerGlobal * glob,
|
||||
List *clauses,
|
||||
indexed_tlist *outer_itlist,
|
||||
indexed_tlist *inner_itlist,
|
||||
@@ -1269,7 +1272,7 @@ fix_join_expr(PlannerGlobal *glob,
|
||||
}
|
||||
|
||||
static Node *
|
||||
fix_join_expr_mutator(Node *node, fix_join_expr_context *context)
|
||||
fix_join_expr_mutator(Node *node, fix_join_expr_context * context)
|
||||
{
|
||||
Var *newvar;
|
||||
|
||||
@@ -1325,9 +1328,10 @@ fix_join_expr_mutator(Node *node, fix_join_expr_context *context)
|
||||
if (newvar)
|
||||
return (Node *) newvar;
|
||||
}
|
||||
|
||||
/*
|
||||
* Since we update opcode info in-place, this part could possibly
|
||||
* scribble on the planner's input data structures, but it's OK.
|
||||
* Since we update opcode info in-place, this part could possibly scribble
|
||||
* on the planner's input data structures, but it's OK.
|
||||
*/
|
||||
if (IsA(node, OpExpr))
|
||||
set_opfuncid((OpExpr *) node);
|
||||
@@ -1381,7 +1385,7 @@ fix_join_expr_mutator(Node *node, fix_join_expr_context *context)
|
||||
* The original tree is not modified.
|
||||
*/
|
||||
static Node *
|
||||
fix_upper_expr(PlannerGlobal *glob,
|
||||
fix_upper_expr(PlannerGlobal * glob,
|
||||
Node *node,
|
||||
indexed_tlist *subplan_itlist,
|
||||
int rtoffset)
|
||||
@@ -1395,7 +1399,7 @@ fix_upper_expr(PlannerGlobal *glob,
|
||||
}
|
||||
|
||||
static Node *
|
||||
fix_upper_expr_mutator(Node *node, fix_upper_expr_context *context)
|
||||
fix_upper_expr_mutator(Node *node, fix_upper_expr_context * context)
|
||||
{
|
||||
Var *newvar;
|
||||
|
||||
@@ -1422,9 +1426,10 @@ fix_upper_expr_mutator(Node *node, fix_upper_expr_context *context)
|
||||
if (newvar)
|
||||
return (Node *) newvar;
|
||||
}
|
||||
|
||||
/*
|
||||
* Since we update opcode info in-place, this part could possibly
|
||||
* scribble on the planner's input data structures, but it's OK.
|
||||
* Since we update opcode info in-place, this part could possibly scribble
|
||||
* on the planner's input data structures, but it's OK.
|
||||
*/
|
||||
if (IsA(node, OpExpr))
|
||||
set_opfuncid((OpExpr *) node);
|
||||
@@ -1474,7 +1479,7 @@ fix_upper_expr_mutator(Node *node, fix_upper_expr_context *context)
|
||||
* they are not coming from a subplan.
|
||||
*/
|
||||
List *
|
||||
set_returning_clause_references(PlannerGlobal *glob,
|
||||
set_returning_clause_references(PlannerGlobal * glob,
|
||||
List *rlist,
|
||||
Plan *topplan,
|
||||
Index resultRelation)
|
||||
@@ -1485,8 +1490,8 @@ set_returning_clause_references(PlannerGlobal *glob,
|
||||
* We can perform the desired Var fixup by abusing the fix_join_expr
|
||||
* machinery that normally handles inner indexscan fixup. We search the
|
||||
* top plan's targetlist for Vars of non-result relations, and use
|
||||
* fix_join_expr to convert RETURNING Vars into references to those
|
||||
* tlist entries, while leaving result-rel Vars as-is.
|
||||
* fix_join_expr to convert RETURNING Vars into references to those tlist
|
||||
* entries, while leaving result-rel Vars as-is.
|
||||
*/
|
||||
itlist = build_tlist_index_other_vars(topplan->targetlist, resultRelation);
|
||||
|
||||
|
@@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/plan/subselect.c,v 1.125 2007/09/22 21:36:40 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/plan/subselect.c,v 1.126 2007/11/15 21:14:36 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -43,7 +43,7 @@ typedef struct process_sublinks_context
|
||||
{
|
||||
PlannerInfo *root;
|
||||
bool isTopQual;
|
||||
} process_sublinks_context;
|
||||
} process_sublinks_context;
|
||||
|
||||
typedef struct finalize_primnode_context
|
||||
{
|
||||
@@ -54,16 +54,16 @@ typedef struct finalize_primnode_context
|
||||
|
||||
|
||||
static Node *convert_testexpr(PlannerInfo *root,
|
||||
Node *testexpr,
|
||||
int rtindex,
|
||||
List **righthandIds);
|
||||
Node *testexpr,
|
||||
int rtindex,
|
||||
List **righthandIds);
|
||||
static Node *convert_testexpr_mutator(Node *node,
|
||||
convert_testexpr_context *context);
|
||||
static bool subplan_is_hashable(SubLink *slink, SubPlan *node, Plan *plan);
|
||||
static bool hash_ok_operator(OpExpr *expr);
|
||||
static Node *replace_correlation_vars_mutator(Node *node, PlannerInfo *root);
|
||||
static Node *process_sublinks_mutator(Node *node,
|
||||
process_sublinks_context *context);
|
||||
process_sublinks_context * context);
|
||||
static Bitmapset *finalize_plan(PlannerInfo *root,
|
||||
Plan *plan,
|
||||
Bitmapset *outer_params,
|
||||
@@ -88,13 +88,13 @@ replace_outer_var(PlannerInfo *root, Var *var)
|
||||
abslevel = root->query_level - var->varlevelsup;
|
||||
|
||||
/*
|
||||
* If there's already a paramlist entry for this same Var, just use
|
||||
* it. NOTE: in sufficiently complex querytrees, it is possible for the
|
||||
* same varno/abslevel to refer to different RTEs in different parts of
|
||||
* the parsetree, so that different fields might end up sharing the same
|
||||
* Param number. As long as we check the vartype as well, I believe that
|
||||
* this sort of aliasing will cause no trouble. The correct field should
|
||||
* get stored into the Param slot at execution in each part of the tree.
|
||||
* If there's already a paramlist entry for this same Var, just use it.
|
||||
* NOTE: in sufficiently complex querytrees, it is possible for the same
|
||||
* varno/abslevel to refer to different RTEs in different parts of the
|
||||
* parsetree, so that different fields might end up sharing the same Param
|
||||
* number. As long as we check the vartype as well, I believe that this
|
||||
* sort of aliasing will cause no trouble. The correct field should get
|
||||
* stored into the Param slot at execution in each part of the tree.
|
||||
*
|
||||
* We also need to demand a match on vartypmod. This does not matter for
|
||||
* the Param itself, since those are not typmod-dependent, but it does
|
||||
@@ -470,11 +470,10 @@ make_subplan(PlannerInfo *root, SubLink *slink, Node *testexpr, bool isTopQual)
|
||||
|
||||
/*
|
||||
* A parameterless subplan (not initplan) should be prepared to handle
|
||||
* REWIND efficiently. If it has direct parameters then there's no point
|
||||
* since it'll be reset on each scan anyway; and if it's an initplan
|
||||
* then there's no point since it won't get re-run without parameter
|
||||
* changes anyway. The input of a hashed subplan doesn't need REWIND
|
||||
* either.
|
||||
* REWIND efficiently. If it has direct parameters then there's no point
|
||||
* since it'll be reset on each scan anyway; and if it's an initplan then
|
||||
* there's no point since it won't get re-run without parameter changes
|
||||
* anyway. The input of a hashed subplan doesn't need REWIND either.
|
||||
*/
|
||||
if (splan->parParam == NIL && !isInitPlan && !splan->useHashTable)
|
||||
root->glob->rewindPlanIDs = bms_add_member(root->glob->rewindPlanIDs,
|
||||
@@ -625,13 +624,12 @@ subplan_is_hashable(SubLink *slink, SubPlan *node, Plan *plan)
|
||||
return false;
|
||||
|
||||
/*
|
||||
* The combining operators must be hashable and strict.
|
||||
* The need for hashability is obvious, since we want to use hashing.
|
||||
* Without strictness, behavior in the presence of nulls is too
|
||||
* unpredictable. We actually must assume even more than plain
|
||||
* strictness: they can't yield NULL for non-null inputs, either
|
||||
* (see nodeSubplan.c). However, hash indexes and hash joins assume
|
||||
* that too.
|
||||
* The combining operators must be hashable and strict. The need for
|
||||
* hashability is obvious, since we want to use hashing. Without
|
||||
* strictness, behavior in the presence of nulls is too unpredictable. We
|
||||
* actually must assume even more than plain strictness: they can't yield
|
||||
* NULL for non-null inputs, either (see nodeSubplan.c). However, hash
|
||||
* indexes and hash joins assume that too.
|
||||
*/
|
||||
if (IsA(slink->testexpr, OpExpr))
|
||||
{
|
||||
@@ -730,7 +728,7 @@ convert_IN_to_join(PlannerInfo *root, SubLink *sublink)
|
||||
in_operators = NIL;
|
||||
foreach(lc, ((BoolExpr *) sublink->testexpr)->args)
|
||||
{
|
||||
OpExpr *op = (OpExpr *) lfirst(lc);
|
||||
OpExpr *op = (OpExpr *) lfirst(lc);
|
||||
|
||||
if (!IsA(op, OpExpr)) /* probably shouldn't happen */
|
||||
return NULL;
|
||||
@@ -867,7 +865,7 @@ SS_process_sublinks(PlannerInfo *root, Node *expr, bool isQual)
|
||||
}
|
||||
|
||||
static Node *
|
||||
process_sublinks_mutator(Node *node, process_sublinks_context *context)
|
||||
process_sublinks_mutator(Node *node, process_sublinks_context * context)
|
||||
{
|
||||
process_sublinks_context locContext;
|
||||
|
||||
|
@@ -22,7 +22,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/prep/prepunion.c,v 1.144 2007/10/22 17:04:35 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/prep/prepunion.c,v 1.145 2007/11/15 21:14:36 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -224,11 +224,11 @@ recurse_set_operations(Node *setOp, PlannerInfo *root,
|
||||
* output columns.
|
||||
*
|
||||
* XXX you don't really want to know about this: setrefs.c will apply
|
||||
* fix_upper_expr() to the Result node's tlist. This
|
||||
* would fail if the Vars generated by generate_setop_tlist() were not
|
||||
* exactly equal() to the corresponding tlist entries of the subplan.
|
||||
* However, since the subplan was generated by generate_union_plan()
|
||||
* or generate_nonunion_plan(), and hence its tlist was generated by
|
||||
* fix_upper_expr() to the Result node's tlist. This would fail if the
|
||||
* Vars generated by generate_setop_tlist() were not exactly equal()
|
||||
* to the corresponding tlist entries of the subplan. However, since
|
||||
* the subplan was generated by generate_union_plan() or
|
||||
* generate_nonunion_plan(), and hence its tlist was generated by
|
||||
* generate_append_tlist(), this will work. We just tell
|
||||
* generate_setop_tlist() to use varno 0.
|
||||
*/
|
||||
@@ -972,8 +972,8 @@ make_inh_translation_lists(Relation oldrelation, Relation newrelation,
|
||||
* Otherwise we have to search for the matching column by name.
|
||||
* There's no guarantee it'll have the same column position, because
|
||||
* of cases like ALTER TABLE ADD COLUMN and multiple inheritance.
|
||||
* However, in simple cases it will be the same column number, so
|
||||
* try that before we go groveling through all the columns.
|
||||
* However, in simple cases it will be the same column number, so try
|
||||
* that before we go groveling through all the columns.
|
||||
*
|
||||
* Note: the test for (att = ...) != NULL cannot fail, it's just a
|
||||
* notational device to include the assignment into the if-clause.
|
||||
|
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/util/clauses.c,v 1.250 2007/10/11 21:27:49 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/util/clauses.c,v 1.251 2007/11/15 21:14:36 momjian Exp $
|
||||
*
|
||||
* HISTORY
|
||||
* AUTHOR DATE MAJOR EVENT
|
||||
@@ -576,7 +576,7 @@ expression_returns_set_walker(Node *node, void *context)
|
||||
* Estimate the number of rows in a set result.
|
||||
*
|
||||
* We use the product of the rowcount estimates of all the functions in
|
||||
* the given tree. The result is 1 if there are no set-returning functions.
|
||||
* the given tree. The result is 1 if there are no set-returning functions.
|
||||
*/
|
||||
double
|
||||
expression_returns_set_rows(Node *clause)
|
||||
@@ -738,9 +738,9 @@ contain_mutable_functions_walker(Node *node, void *context)
|
||||
else if (IsA(node, CoerceViaIO))
|
||||
{
|
||||
CoerceViaIO *expr = (CoerceViaIO *) node;
|
||||
Oid iofunc;
|
||||
Oid typioparam;
|
||||
bool typisvarlena;
|
||||
Oid iofunc;
|
||||
Oid typioparam;
|
||||
bool typisvarlena;
|
||||
|
||||
/* check the result type's input function */
|
||||
getTypeInputInfo(expr->resulttype,
|
||||
@@ -849,9 +849,9 @@ contain_volatile_functions_walker(Node *node, void *context)
|
||||
else if (IsA(node, CoerceViaIO))
|
||||
{
|
||||
CoerceViaIO *expr = (CoerceViaIO *) node;
|
||||
Oid iofunc;
|
||||
Oid typioparam;
|
||||
bool typisvarlena;
|
||||
Oid iofunc;
|
||||
Oid typioparam;
|
||||
bool typisvarlena;
|
||||
|
||||
/* check the result type's input function */
|
||||
getTypeInputInfo(expr->resulttype,
|
||||
@@ -1065,13 +1065,13 @@ find_nonnullable_rels_walker(Node *node, bool top_level)
|
||||
else if (IsA(node, List))
|
||||
{
|
||||
/*
|
||||
* At top level, we are examining an implicit-AND list: if any of
|
||||
* the arms produces FALSE-or-NULL then the result is FALSE-or-NULL.
|
||||
* If not at top level, we are examining the arguments of a strict
|
||||
* At top level, we are examining an implicit-AND list: if any of the
|
||||
* arms produces FALSE-or-NULL then the result is FALSE-or-NULL. If
|
||||
* not at top level, we are examining the arguments of a strict
|
||||
* function: if any of them produce NULL then the result of the
|
||||
* function must be NULL. So in both cases, the set of nonnullable
|
||||
* rels is the union of those found in the arms, and we pass down
|
||||
* the top_level flag unmodified.
|
||||
* rels is the union of those found in the arms, and we pass down the
|
||||
* top_level flag unmodified.
|
||||
*/
|
||||
foreach(l, (List *) node)
|
||||
{
|
||||
@@ -1115,15 +1115,17 @@ find_nonnullable_rels_walker(Node *node, bool top_level)
|
||||
top_level);
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* Below top level, even if one arm produces NULL, the result
|
||||
* could be FALSE (hence not NULL). However, if *all* the
|
||||
* arms produce NULL then the result is NULL, so we can
|
||||
* take the intersection of the sets of nonnullable rels,
|
||||
* just as for OR. Fall through to share code.
|
||||
* arms produce NULL then the result is NULL, so we can take
|
||||
* the intersection of the sets of nonnullable rels, just as
|
||||
* for OR. Fall through to share code.
|
||||
*/
|
||||
/* FALL THRU */
|
||||
case OR_EXPR:
|
||||
|
||||
/*
|
||||
* OR is strict if all of its arms are, so we can take the
|
||||
* intersection of the sets of nonnullable rels for each arm.
|
||||
@@ -1135,13 +1137,14 @@ find_nonnullable_rels_walker(Node *node, bool top_level)
|
||||
|
||||
subresult = find_nonnullable_rels_walker(lfirst(l),
|
||||
top_level);
|
||||
if (result == NULL) /* first subresult? */
|
||||
if (result == NULL) /* first subresult? */
|
||||
result = subresult;
|
||||
else
|
||||
result = bms_int_members(result, subresult);
|
||||
|
||||
/*
|
||||
* If the intersection is empty, we can stop looking.
|
||||
* This also justifies the test for first-subresult above.
|
||||
* If the intersection is empty, we can stop looking. This
|
||||
* also justifies the test for first-subresult above.
|
||||
*/
|
||||
if (bms_is_empty(result))
|
||||
break;
|
||||
@@ -1669,7 +1672,7 @@ eval_const_expressions(Node *node)
|
||||
{
|
||||
eval_const_expressions_context context;
|
||||
|
||||
context.boundParams = NULL; /* don't use any bound params */
|
||||
context.boundParams = NULL; /* don't use any bound params */
|
||||
context.active_fns = NIL; /* nothing being recursively simplified */
|
||||
context.case_val = NULL; /* no CASE being examined */
|
||||
context.estimate = false; /* safe transformations only */
|
||||
@@ -1697,7 +1700,7 @@ estimate_expression_value(PlannerInfo *root, Node *node)
|
||||
{
|
||||
eval_const_expressions_context context;
|
||||
|
||||
context.boundParams = root->glob->boundParams; /* bound Params */
|
||||
context.boundParams = root->glob->boundParams; /* bound Params */
|
||||
context.active_fns = NIL; /* nothing being recursively simplified */
|
||||
context.case_val = NULL; /* no CASE being examined */
|
||||
context.estimate = true; /* unsafe transformations OK */
|
||||
@@ -3015,11 +3018,11 @@ inline_function(Oid funcid, Oid result_type, List *args,
|
||||
newexpr = (Node *) ((TargetEntry *) linitial(querytree->targetList))->expr;
|
||||
|
||||
/*
|
||||
* Make sure the function (still) returns what it's declared to. This will
|
||||
* raise an error if wrong, but that's okay since the function would fail
|
||||
* at runtime anyway. Note we do not try this until we have verified that
|
||||
* no rewriting was needed; that's probably not important, but let's be
|
||||
* careful.
|
||||
* Make sure the function (still) returns what it's declared to. This
|
||||
* will raise an error if wrong, but that's okay since the function would
|
||||
* fail at runtime anyway. Note we do not try this until we have verified
|
||||
* that no rewriting was needed; that's probably not important, but let's
|
||||
* be careful.
|
||||
*/
|
||||
if (check_sql_fn_retval(funcid, result_type, list_make1(querytree), NULL))
|
||||
goto fail; /* reject whole-tuple-result cases */
|
||||
@@ -3580,8 +3583,8 @@ expression_tree_walker(Node *node,
|
||||
return walker(((MinMaxExpr *) node)->args, context);
|
||||
case T_XmlExpr:
|
||||
{
|
||||
XmlExpr *xexpr = (XmlExpr *) node;
|
||||
|
||||
XmlExpr *xexpr = (XmlExpr *) node;
|
||||
|
||||
if (walker(xexpr->named_args, context))
|
||||
return true;
|
||||
/* we assume walker doesn't care about arg_names */
|
||||
@@ -3853,15 +3856,15 @@ expression_tree_mutator(Node *node,
|
||||
|
||||
switch (nodeTag(node))
|
||||
{
|
||||
/*
|
||||
* Primitive node types with no expression subnodes. Var and Const
|
||||
* are frequent enough to deserve special cases, the others we just
|
||||
* use copyObject for.
|
||||
*/
|
||||
/*
|
||||
* Primitive node types with no expression subnodes. Var and
|
||||
* Const are frequent enough to deserve special cases, the others
|
||||
* we just use copyObject for.
|
||||
*/
|
||||
case T_Var:
|
||||
{
|
||||
Var *var = (Var *) node;
|
||||
Var *newnode;
|
||||
Var *var = (Var *) node;
|
||||
Var *newnode;
|
||||
|
||||
FLATCOPY(newnode, var, Var);
|
||||
return (Node *) newnode;
|
||||
@@ -4130,8 +4133,8 @@ expression_tree_mutator(Node *node,
|
||||
break;
|
||||
case T_XmlExpr:
|
||||
{
|
||||
XmlExpr *xexpr = (XmlExpr *) node;
|
||||
XmlExpr *newnode;
|
||||
XmlExpr *xexpr = (XmlExpr *) node;
|
||||
XmlExpr *newnode;
|
||||
|
||||
FLATCOPY(newnode, xexpr, XmlExpr);
|
||||
MUTATE(newnode->named_args, xexpr->named_args, List *);
|
||||
|
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/util/joininfo.c,v 1.48 2007/02/16 00:14:01 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/util/joininfo.c,v 1.49 2007/11/15 21:14:36 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -56,8 +56,8 @@ have_relevant_joinclause(PlannerInfo *root,
|
||||
}
|
||||
|
||||
/*
|
||||
* We also need to check the EquivalenceClass data structure, which
|
||||
* might contain relationships not emitted into the joininfo lists.
|
||||
* We also need to check the EquivalenceClass data structure, which might
|
||||
* contain relationships not emitted into the joininfo lists.
|
||||
*/
|
||||
if (!result && rel1->has_eclass_joins && rel2->has_eclass_joins)
|
||||
result = have_relevant_eclass_joinclause(root, rel1, rel2);
|
||||
|
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/util/pathnode.c,v 1.140 2007/05/04 01:13:44 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/util/pathnode.c,v 1.141 2007/11/15 21:14:36 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -771,7 +771,7 @@ create_unique_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath)
|
||||
/*
|
||||
* Try to identify the targetlist that will actually be unique-ified. In
|
||||
* current usage, this routine is only used for sub-selects of IN clauses,
|
||||
* so we should be able to find the tlist in in_info_list. Get the IN
|
||||
* so we should be able to find the tlist in in_info_list. Get the IN
|
||||
* clause's operators, too, because they determine what "unique" means.
|
||||
*/
|
||||
sub_targetlist = NIL;
|
||||
@@ -931,7 +931,7 @@ translate_sub_tlist(List *tlist, int relid)
|
||||
*
|
||||
* colnos is an integer list of output column numbers (resno's). We are
|
||||
* interested in whether rows consisting of just these columns are certain
|
||||
* to be distinct. "Distinctness" is defined according to whether the
|
||||
* to be distinct. "Distinctness" is defined according to whether the
|
||||
* corresponding upper-level equality operators listed in opids would think
|
||||
* the values are distinct. (Note: the opids entries could be cross-type
|
||||
* operators, and thus not exactly the equality operators that the subquery
|
||||
@@ -948,8 +948,8 @@ query_is_distinct_for(Query *query, List *colnos, List *opids)
|
||||
|
||||
/*
|
||||
* DISTINCT (including DISTINCT ON) guarantees uniqueness if all the
|
||||
* columns in the DISTINCT clause appear in colnos and operator
|
||||
* semantics match.
|
||||
* columns in the DISTINCT clause appear in colnos and operator semantics
|
||||
* match.
|
||||
*/
|
||||
if (query->distinctClause)
|
||||
{
|
||||
@@ -1004,9 +1004,8 @@ query_is_distinct_for(Query *query, List *colnos, List *opids)
|
||||
*
|
||||
* XXX this code knows that prepunion.c will adopt the default ordering
|
||||
* operator for each column datatype as the sortop. It'd probably be
|
||||
* better if these operators were chosen at parse time and stored into
|
||||
* the parsetree, instead of leaving bits of the planner to decide
|
||||
* semantics.
|
||||
* better if these operators were chosen at parse time and stored into the
|
||||
* parsetree, instead of leaving bits of the planner to decide semantics.
|
||||
*/
|
||||
if (query->setOperations)
|
||||
{
|
||||
@@ -1028,7 +1027,7 @@ query_is_distinct_for(Query *query, List *colnos, List *opids)
|
||||
opid = distinct_col_search(tle->resno, colnos, opids);
|
||||
if (!OidIsValid(opid) ||
|
||||
!ops_in_same_btree_opfamily(opid,
|
||||
ordering_oper_opid(exprType((Node *) tle->expr))))
|
||||
ordering_oper_opid(exprType((Node *) tle->expr))))
|
||||
break; /* exit early if no match */
|
||||
}
|
||||
if (l == NULL) /* had matches for all? */
|
||||
@@ -1048,7 +1047,7 @@ query_is_distinct_for(Query *query, List *colnos, List *opids)
|
||||
* distinct_col_search - subroutine for query_is_distinct_for
|
||||
*
|
||||
* If colno is in colnos, return the corresponding element of opids,
|
||||
* else return InvalidOid. (We expect colnos does not contain duplicates,
|
||||
* else return InvalidOid. (We expect colnos does not contain duplicates,
|
||||
* so the result is well-defined.)
|
||||
*/
|
||||
static Oid
|
||||
|
@@ -9,7 +9,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/util/plancat.c,v 1.137 2007/09/20 17:56:31 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/util/plancat.c,v 1.138 2007/11/15 21:14:36 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -166,9 +166,9 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent,
|
||||
}
|
||||
|
||||
/*
|
||||
* If the index is valid, but cannot yet be used, ignore it;
|
||||
* but mark the plan we are generating as transient.
|
||||
* See src/backend/access/heap/README.HOT for discussion.
|
||||
* If the index is valid, but cannot yet be used, ignore it; but
|
||||
* mark the plan we are generating as transient. See
|
||||
* src/backend/access/heap/README.HOT for discussion.
|
||||
*/
|
||||
if (index->indcheckxmin &&
|
||||
!TransactionIdPrecedes(HeapTupleHeaderGetXmin(indexRelation->rd_indextuple->t_data),
|
||||
@@ -187,7 +187,7 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent,
|
||||
|
||||
/*
|
||||
* Allocate per-column info arrays. To save a few palloc cycles
|
||||
* we allocate all the Oid-type arrays in one request. Note that
|
||||
* we allocate all the Oid-type arrays in one request. Note that
|
||||
* the opfamily array needs an extra, terminating zero at the end.
|
||||
* We pre-zero the ordering info in case the index is unordered.
|
||||
*/
|
||||
@@ -221,9 +221,9 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent,
|
||||
|
||||
for (i = 0; i < ncolumns; i++)
|
||||
{
|
||||
int16 opt = indexRelation->rd_indoption[i];
|
||||
int fwdstrat;
|
||||
int revstrat;
|
||||
int16 opt = indexRelation->rd_indoption[i];
|
||||
int fwdstrat;
|
||||
int revstrat;
|
||||
|
||||
if (opt & INDOPTION_DESC)
|
||||
{
|
||||
@@ -235,10 +235,11 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent,
|
||||
fwdstrat = BTLessStrategyNumber;
|
||||
revstrat = BTGreaterStrategyNumber;
|
||||
}
|
||||
|
||||
/*
|
||||
* Index AM must have a fixed set of strategies for it
|
||||
* to make sense to specify amcanorder, so we
|
||||
* need not allow the case amstrategies == 0.
|
||||
* Index AM must have a fixed set of strategies for it to
|
||||
* make sense to specify amcanorder, so we need not allow
|
||||
* the case amstrategies == 0.
|
||||
*/
|
||||
if (fwdstrat > 0)
|
||||
{
|
||||
|
@@ -9,7 +9,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/util/predtest.c,v 1.16 2007/07/24 17:22:07 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/util/predtest.c,v 1.17 2007/11/15 21:14:36 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -1109,7 +1109,7 @@ list_member_strip(List *list, Expr *datum)
|
||||
|
||||
foreach(cell, list)
|
||||
{
|
||||
Expr *elem = (Expr *) lfirst(cell);
|
||||
Expr *elem = (Expr *) lfirst(cell);
|
||||
|
||||
if (elem && IsA(elem, RelabelType))
|
||||
elem = ((RelabelType *) elem)->arg;
|
||||
@@ -1342,7 +1342,8 @@ btree_predicate_proof(Expr *predicate, Node *clause, bool refute_it)
|
||||
*
|
||||
* We must find a btree opfamily that contains both operators, else the
|
||||
* implication can't be determined. Also, the opfamily must contain a
|
||||
* suitable test operator taking the pred_const and clause_const datatypes.
|
||||
* suitable test operator taking the pred_const and clause_const
|
||||
* datatypes.
|
||||
*
|
||||
* If there are multiple matching opfamilies, assume we can use any one to
|
||||
* determine the logical relationship of the two operators and the correct
|
||||
@@ -1354,8 +1355,8 @@ btree_predicate_proof(Expr *predicate, Node *clause, bool refute_it)
|
||||
0, 0, 0);
|
||||
|
||||
/*
|
||||
* If we couldn't find any opfamily containing the pred_op, perhaps it is a
|
||||
* <> operator. See if it has a negator that is in an opfamily.
|
||||
* If we couldn't find any opfamily containing the pred_op, perhaps it is
|
||||
* a <> operator. See if it has a negator that is in an opfamily.
|
||||
*/
|
||||
pred_op_negated = false;
|
||||
if (catlist->n_members == 0)
|
||||
|
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/util/relnode.c,v 1.87 2007/04/21 21:01:45 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/util/relnode.c,v 1.88 2007/11/15 21:14:36 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -32,9 +32,9 @@ typedef struct JoinHashEntry
|
||||
static void build_joinrel_tlist(PlannerInfo *root, RelOptInfo *joinrel,
|
||||
RelOptInfo *input_rel);
|
||||
static List *build_joinrel_restrictlist(PlannerInfo *root,
|
||||
RelOptInfo *joinrel,
|
||||
RelOptInfo *outer_rel,
|
||||
RelOptInfo *inner_rel);
|
||||
RelOptInfo *joinrel,
|
||||
RelOptInfo *outer_rel,
|
||||
RelOptInfo *inner_rel);
|
||||
static void build_joinrel_joinlist(RelOptInfo *joinrel,
|
||||
RelOptInfo *outer_rel,
|
||||
RelOptInfo *inner_rel);
|
||||
@@ -510,8 +510,9 @@ build_joinrel_restrictlist(PlannerInfo *root,
|
||||
*/
|
||||
result = subbuild_joinrel_restrictlist(joinrel, outer_rel->joininfo, NIL);
|
||||
result = subbuild_joinrel_restrictlist(joinrel, inner_rel->joininfo, result);
|
||||
|
||||
/*
|
||||
* Add on any clauses derived from EquivalenceClasses. These cannot be
|
||||
* Add on any clauses derived from EquivalenceClasses. These cannot be
|
||||
* redundant with the clauses in the joininfo lists, so don't bother
|
||||
* checking.
|
||||
*/
|
||||
@@ -599,10 +600,10 @@ subbuild_joinrel_joinlist(RelOptInfo *joinrel,
|
||||
{
|
||||
/*
|
||||
* This clause is still a join clause at this level, so add it to
|
||||
* the new joininfo list, being careful to eliminate
|
||||
* duplicates. (Since RestrictInfo nodes in different joinlists
|
||||
* will have been multiply-linked rather than copied, pointer
|
||||
* equality should be a sufficient test.)
|
||||
* the new joininfo list, being careful to eliminate duplicates.
|
||||
* (Since RestrictInfo nodes in different joinlists will have been
|
||||
* multiply-linked rather than copied, pointer equality should be
|
||||
* a sufficient test.)
|
||||
*/
|
||||
new_joininfo = list_append_unique_ptr(new_joininfo, rinfo);
|
||||
}
|
||||
|
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/util/restrictinfo.c,v 1.53 2007/01/22 20:00:39 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/util/restrictinfo.c,v 1.54 2007/11/15 21:14:36 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -534,7 +534,7 @@ extract_actual_join_clauses(List *restrictinfo_list,
|
||||
*
|
||||
* Given a list of RestrictInfo clauses that are to be applied in a join,
|
||||
* select the ones that are not redundant with any clause in the
|
||||
* reference_list. This is used only for nestloop-with-inner-indexscan
|
||||
* reference_list. This is used only for nestloop-with-inner-indexscan
|
||||
* joins: any clauses being checked by the index should be removed from
|
||||
* the qpquals list.
|
||||
*
|
||||
|
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/util/tlist.c,v 1.76 2007/11/08 21:49:47 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/util/tlist.c,v 1.77 2007/11/15 21:14:36 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -61,7 +61,7 @@ tlist_member_ignore_relabel(Node *node, List *targetlist)
|
||||
foreach(temp, targetlist)
|
||||
{
|
||||
TargetEntry *tlentry = (TargetEntry *) lfirst(temp);
|
||||
Expr *tlexpr = tlentry->expr;
|
||||
Expr *tlexpr = tlentry->expr;
|
||||
|
||||
while (tlexpr && IsA(tlexpr, RelabelType))
|
||||
tlexpr = ((RelabelType *) tlexpr)->arg;
|
||||
|
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/util/var.c,v 1.71 2007/09/20 17:56:31 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/util/var.c,v 1.72 2007/11/15 21:14:36 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -166,7 +166,7 @@ pull_varattnos_walker(Node *node, Bitmapset **varattnos)
|
||||
|
||||
Assert(var->varno == 1);
|
||||
*varattnos = bms_add_member(*varattnos,
|
||||
var->varattno - FirstLowInvalidHeapAttributeNumber);
|
||||
var->varattno - FirstLowInvalidHeapAttributeNumber);
|
||||
return false;
|
||||
}
|
||||
/* Should not find a subquery or subplan */
|
||||
|
Reference in New Issue
Block a user