1996-07-09 08:22:35 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* initsplan.c
|
1997-09-07 07:04:48 +02:00
|
|
|
* Target list, qualification, joininfo initialization routines
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
2000-04-12 19:17:23 +02:00
|
|
|
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/initsplan.c,v 1.46 2000/04/12 17:15:21 momjian Exp $
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
1996-10-31 11:59:42 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
#include "postgres.h"
|
1998-08-10 04:26:40 +02:00
|
|
|
#include "catalog/pg_type.h"
|
1999-07-16 07:00:38 +02:00
|
|
|
#include "nodes/makefuncs.h"
|
|
|
|
#include "optimizer/clauses.h"
|
|
|
|
#include "optimizer/cost.h"
|
1996-07-09 08:22:35 +02:00
|
|
|
#include "optimizer/joininfo.h"
|
|
|
|
#include "optimizer/pathnode.h"
|
2000-02-15 21:49:31 +01:00
|
|
|
#include "optimizer/paths.h"
|
1999-07-16 07:00:38 +02:00
|
|
|
#include "optimizer/planmain.h"
|
1996-07-09 08:22:35 +02:00
|
|
|
#include "optimizer/tlist.h"
|
|
|
|
#include "optimizer/var.h"
|
1999-07-16 07:00:38 +02:00
|
|
|
#include "utils/lsyscache.h"
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
|
1999-07-25 01:21:14 +02:00
|
|
|
static void add_restrict_and_join_to_rel(Query *root, Node *clause);
|
1999-05-26 00:43:53 +02:00
|
|
|
static void add_join_info_to_rels(Query *root, RestrictInfo *restrictinfo,
|
2000-04-12 19:17:23 +02:00
|
|
|
Relids join_relids);
|
1999-07-25 01:21:14 +02:00
|
|
|
static void add_vars_to_targetlist(Query *root, List *vars);
|
1999-08-16 04:17:58 +02:00
|
|
|
static void check_mergejoinable(RestrictInfo *restrictinfo);
|
|
|
|
static void check_hashjoinable(RestrictInfo *restrictinfo);
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* TARGET LISTS
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
/*
|
1999-02-14 00:22:53 +01:00
|
|
|
* make_var_only_tlist
|
1997-09-07 07:04:48 +02:00
|
|
|
* Creates rel nodes for every relation mentioned in the target list
|
|
|
|
* 'tlist' (if a node hasn't already been created) and adds them to
|
1999-02-14 00:22:53 +01:00
|
|
|
* *query_relation_list*. Creates targetlist entries for each member of
|
1997-09-07 07:04:48 +02:00
|
|
|
* 'tlist' and adds them to the tlist field of the appropriate rel node.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
|
|
|
void
|
1999-02-14 00:22:53 +01:00
|
|
|
make_var_only_tlist(Query *root, List *tlist)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1999-08-26 07:09:06 +02:00
|
|
|
List *tlist_vars = pull_var_clause((Node *) tlist, false);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1999-08-10 05:00:15 +02:00
|
|
|
add_vars_to_targetlist(root, tlist_vars);
|
|
|
|
freeList(tlist_vars);
|
|
|
|
}
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1999-08-10 05:00:15 +02:00
|
|
|
/*
|
|
|
|
* add_vars_to_targetlist
|
|
|
|
* For each variable appearing in the list, add it to the relation's
|
|
|
|
* targetlist if not already present. Rel nodes will also be created
|
|
|
|
* if not already present.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
add_vars_to_targetlist(Query *root, List *vars)
|
|
|
|
{
|
|
|
|
List *temp;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1999-08-10 05:00:15 +02:00
|
|
|
foreach(temp, vars)
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
1999-08-10 05:00:15 +02:00
|
|
|
Var *var = (Var *) lfirst(temp);
|
|
|
|
RelOptInfo *rel = get_base_rel(root, var->varno);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1999-08-10 05:00:15 +02:00
|
|
|
add_var_to_tlist(rel, var);
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1999-10-07 06:23:24 +02:00
|
|
|
* add_missing_rels_to_query
|
|
|
|
*
|
|
|
|
* If we have a range variable in the FROM clause that does not appear
|
|
|
|
* in the target list nor qualifications, we must add it to the base
|
2000-04-12 19:17:23 +02:00
|
|
|
* relation list so that it will be joined. For instance, "select f.x
|
1999-10-07 06:23:24 +02:00
|
|
|
* from foo f, foo f2" is a join of f and f2. Note that if we have
|
|
|
|
* "select foo.x from foo f", it also gets turned into a join (between
|
|
|
|
* foo as foo and foo as f).
|
|
|
|
*
|
|
|
|
* To avoid putting useless entries into the per-relation targetlists,
|
|
|
|
* this should only be called after all the variables in the targetlist
|
|
|
|
* and quals have been processed by the routines above.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
|
|
|
void
|
1999-10-07 06:23:24 +02:00
|
|
|
add_missing_rels_to_query(Query *root)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1999-08-10 05:00:15 +02:00
|
|
|
int varno = 1;
|
1997-09-08 04:41:22 +02:00
|
|
|
List *l;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
foreach(l, root->rtable)
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
RangeTblEntry *rte = (RangeTblEntry *) lfirst(l);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1999-10-07 06:23:24 +02:00
|
|
|
if (rte->inJoinSet)
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
1999-10-07 06:23:24 +02:00
|
|
|
RelOptInfo *rel = get_base_rel(root, varno);
|
1999-08-10 05:00:15 +02:00
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
/*
|
|
|
|
* If the rel isn't otherwise referenced, give it a dummy
|
1999-10-07 06:23:24 +02:00
|
|
|
* targetlist consisting of its own OID.
|
|
|
|
*/
|
|
|
|
if (rel->targetlist == NIL)
|
|
|
|
{
|
|
|
|
Var *var = makeVar(varno, ObjectIdAttributeNumber,
|
|
|
|
OIDOID, -1, 0);
|
2000-04-12 19:17:23 +02:00
|
|
|
|
1999-10-07 06:23:24 +02:00
|
|
|
add_var_to_tlist(rel, var);
|
|
|
|
}
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
|
|
|
varno++;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* QUALIFICATIONS
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
/*
|
1999-08-16 04:17:58 +02:00
|
|
|
* add_restrict_and_join_to_rels
|
|
|
|
* Fill RestrictInfo and JoinInfo lists of relation entries for all
|
1997-09-07 07:04:48 +02:00
|
|
|
* relations appearing within clauses. Creates new relation entries if
|
1999-02-14 00:22:53 +01:00
|
|
|
* necessary, adding them to *query_relation_list*.
|
1997-09-07 07:04:48 +02:00
|
|
|
*
|
1999-07-25 01:21:14 +02:00
|
|
|
* 'clauses': the list of clauses in the cnfify'd query qualification.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
|
|
|
void
|
1999-02-14 00:22:53 +01:00
|
|
|
add_restrict_and_join_to_rels(Query *root, List *clauses)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
List *clause;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
foreach(clause, clauses)
|
2000-04-12 19:17:23 +02:00
|
|
|
add_restrict_and_join_to_rel(root, (Node *) lfirst(clause));
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
/*
|
1999-08-16 04:17:58 +02:00
|
|
|
* add_restrict_and_join_to_rel
|
1999-02-03 21:15:53 +01:00
|
|
|
* Add clause information to either the 'RestrictInfo' or 'JoinInfo' field
|
1999-08-16 04:17:58 +02:00
|
|
|
* (depending on whether the clause is a join) of each base relation
|
2000-04-12 19:17:23 +02:00
|
|
|
* mentioned in the clause. A RestrictInfo node is created and added to
|
2000-02-15 21:49:31 +01:00
|
|
|
* the appropriate list for each rel. Also, if the clause uses a
|
|
|
|
* mergejoinable operator, enter the left- and right-side expressions
|
|
|
|
* into the query's lists of equijoined vars.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
|
|
|
static void
|
1999-07-25 01:21:14 +02:00
|
|
|
add_restrict_and_join_to_rel(Query *root, Node *clause)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1999-07-25 01:21:14 +02:00
|
|
|
RestrictInfo *restrictinfo = makeNode(RestrictInfo);
|
1999-02-18 01:49:48 +01:00
|
|
|
Relids relids;
|
1997-09-08 04:41:22 +02:00
|
|
|
List *vars;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1999-02-03 21:15:53 +01:00
|
|
|
restrictinfo->clause = (Expr *) clause;
|
1999-08-16 04:17:58 +02:00
|
|
|
restrictinfo->subclauseindices = NIL;
|
|
|
|
restrictinfo->mergejoinoperator = InvalidOid;
|
|
|
|
restrictinfo->left_sortop = InvalidOid;
|
|
|
|
restrictinfo->right_sortop = InvalidOid;
|
|
|
|
restrictinfo->hashjoinoperator = InvalidOid;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1999-07-25 01:21:14 +02:00
|
|
|
/*
|
|
|
|
* Retrieve all relids and vars contained within the clause.
|
|
|
|
*/
|
|
|
|
clause_get_relids_vars(clause, &relids, &vars);
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
if (length(relids) == 1)
|
|
|
|
{
|
2000-04-12 19:17:23 +02:00
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
/*
|
1997-09-07 07:04:48 +02:00
|
|
|
* There is only one relation participating in 'clause', so
|
1999-07-25 01:21:14 +02:00
|
|
|
* 'clause' must be a restriction clause for that relation.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1999-02-14 00:22:53 +01:00
|
|
|
RelOptInfo *rel = get_base_rel(root, lfirsti(relids));
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-02-07 05:41:04 +01:00
|
|
|
rel->baserestrictinfo = lcons(restrictinfo,
|
|
|
|
rel->baserestrictinfo);
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2000-02-15 21:49:31 +01:00
|
|
|
/*
|
|
|
|
* Check for a "mergejoinable" clause even though it's not a join
|
2000-04-12 19:17:23 +02:00
|
|
|
* clause. This is so that we can recognize that "a.x = a.y"
|
|
|
|
* makes x and y eligible to be considered equal, even when they
|
|
|
|
* belong to the same rel. Without this, we would not recognize
|
|
|
|
* that "a.x = a.y AND a.x = b.z AND a.y = c.q" allows us to
|
|
|
|
* consider z and q equal after their rels are joined.
|
2000-02-15 21:49:31 +01:00
|
|
|
*/
|
|
|
|
check_mergejoinable(restrictinfo);
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
1996-07-09 08:22:35 +02:00
|
|
|
else
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
2000-04-12 19:17:23 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
/*
|
|
|
|
* 'clause' is a join clause, since there is more than one atom in
|
2000-04-12 19:17:23 +02:00
|
|
|
* the relid list. Set additional RestrictInfo fields for
|
|
|
|
* joining.
|
2000-02-15 21:49:31 +01:00
|
|
|
*
|
|
|
|
* We need the merge info whether or not mergejoin is enabled (for
|
|
|
|
* constructing equijoined-var lists), but we don't bother setting
|
|
|
|
* hash info if hashjoin is disabled.
|
2000-01-09 01:26:47 +01:00
|
|
|
*/
|
2000-02-15 21:49:31 +01:00
|
|
|
check_mergejoinable(restrictinfo);
|
|
|
|
if (enable_hashjoin)
|
|
|
|
check_hashjoinable(restrictinfo);
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2000-01-09 01:26:47 +01:00
|
|
|
/*
|
2000-04-12 19:17:23 +02:00
|
|
|
* Add clause to the join lists of all the relevant relations.
|
|
|
|
* (If, perchance, 'clause' contains NO vars, then nothing will
|
|
|
|
* happen...)
|
1997-09-07 07:04:48 +02:00
|
|
|
*/
|
1999-02-03 21:15:53 +01:00
|
|
|
add_join_info_to_rels(root, restrictinfo, relids);
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2000-01-09 01:26:47 +01:00
|
|
|
/*
|
2000-04-12 19:17:23 +02:00
|
|
|
* Add vars used in the join clause to targetlists of member
|
|
|
|
* 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!).
|
2000-01-09 01:26:47 +01:00
|
|
|
*/
|
1999-07-25 01:21:14 +02:00
|
|
|
add_vars_to_targetlist(root, vars);
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
2000-02-15 21:49:31 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the clause has a mergejoinable operator, then the two sides
|
|
|
|
* represent equivalent PathKeyItems for path keys: any path that is
|
|
|
|
* sorted by one side will also be sorted by the other (after joining,
|
|
|
|
* that is). Record the key equivalence for future use.
|
|
|
|
*/
|
|
|
|
if (restrictinfo->mergejoinoperator != InvalidOid)
|
|
|
|
add_equijoined_keys(root, restrictinfo);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
/*
|
1999-02-14 00:22:53 +01:00
|
|
|
* add_join_info_to_rels
|
1999-02-03 21:15:53 +01:00
|
|
|
* For every relation participating in a join clause, add 'restrictinfo' to
|
2000-01-09 01:26:47 +01:00
|
|
|
* the appropriate joininfo list (creating a new list and adding it to the
|
1997-09-07 07:04:48 +02:00
|
|
|
* appropriate rel node if necessary).
|
|
|
|
*
|
1999-02-03 21:15:53 +01:00
|
|
|
* 'restrictinfo' describes the join clause
|
1999-02-14 00:22:53 +01:00
|
|
|
* 'join_relids' is the list of relations participating in the join clause
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
|
|
|
static void
|
1999-05-26 00:43:53 +02:00
|
|
|
add_join_info_to_rels(Query *root, RestrictInfo *restrictinfo,
|
1999-05-25 18:15:34 +02:00
|
|
|
Relids join_relids)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
List *join_relid;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1999-07-25 01:21:14 +02:00
|
|
|
/* For every relid, find the joininfo, and add the proper join entries */
|
1997-09-07 07:04:48 +02:00
|
|
|
foreach(join_relid, join_relids)
|
|
|
|
{
|
1999-08-16 04:17:58 +02:00
|
|
|
int cur_relid = lfirsti(join_relid);
|
1999-02-18 01:49:48 +01:00
|
|
|
Relids unjoined_relids = NIL;
|
2000-01-09 01:26:47 +01:00
|
|
|
JoinInfo *joininfo;
|
1999-08-16 04:17:58 +02:00
|
|
|
List *otherrel;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1999-02-18 01:49:48 +01:00
|
|
|
/* Get the relids not equal to the current relid */
|
1999-08-16 04:17:58 +02:00
|
|
|
foreach(otherrel, join_relids)
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
1999-08-16 04:17:58 +02:00
|
|
|
if (lfirsti(otherrel) != cur_relid)
|
|
|
|
unjoined_relids = lappendi(unjoined_relids, lfirsti(otherrel));
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
|
|
|
|
1999-07-25 01:21:14 +02:00
|
|
|
/*
|
2000-01-09 01:26:47 +01:00
|
|
|
* Find or make the joininfo node for this combination of rels,
|
|
|
|
* and add the restrictinfo node to it.
|
1999-07-25 01:21:14 +02:00
|
|
|
*/
|
1999-08-16 04:17:58 +02:00
|
|
|
joininfo = find_joininfo_node(get_base_rel(root, cur_relid),
|
1999-02-18 01:49:48 +01:00
|
|
|
unjoined_relids);
|
2000-01-09 01:26:47 +01:00
|
|
|
joininfo->jinfo_restrictinfo = lcons(restrictinfo,
|
2000-04-12 19:17:23 +02:00
|
|
|
joininfo->jinfo_restrictinfo);
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
*
|
2000-02-15 21:49:31 +01:00
|
|
|
* CHECKS FOR MERGEJOINABLE AND HASHJOINABLE CLAUSES
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
/*
|
1999-08-16 04:17:58 +02:00
|
|
|
* check_mergejoinable
|
|
|
|
* If the restrictinfo's clause is mergejoinable, set the mergejoin
|
|
|
|
* info fields in the restrictinfo.
|
|
|
|
*
|
|
|
|
* Currently, we support mergejoin for binary opclauses where
|
|
|
|
* both operands are simple Vars and the operator is a mergejoinable
|
2000-02-15 21:49:31 +01:00
|
|
|
* operator.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1999-08-16 04:17:58 +02:00
|
|
|
static void
|
|
|
|
check_mergejoinable(RestrictInfo *restrictinfo)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1999-08-16 04:17:58 +02:00
|
|
|
Expr *clause = restrictinfo->clause;
|
1999-02-15 02:06:59 +01:00
|
|
|
Var *left,
|
|
|
|
*right;
|
|
|
|
Oid opno,
|
|
|
|
leftOp,
|
1997-09-08 04:41:22 +02:00
|
|
|
rightOp;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
if (!is_opclause((Node *) clause))
|
1999-08-16 04:17:58 +02:00
|
|
|
return;
|
1999-02-15 02:06:59 +01:00
|
|
|
|
|
|
|
left = get_leftop(clause);
|
|
|
|
right = get_rightop(clause);
|
|
|
|
|
|
|
|
/* caution: is_opclause accepts more than I do, so check it */
|
2000-04-12 19:17:23 +02:00
|
|
|
if (!right)
|
1999-08-16 04:17:58 +02:00
|
|
|
return; /* unary opclauses need not apply */
|
2000-04-12 19:17:23 +02:00
|
|
|
if (!IsA(left, Var) ||!IsA(right, Var))
|
1999-08-16 04:17:58 +02:00
|
|
|
return;
|
1999-02-15 02:06:59 +01:00
|
|
|
|
|
|
|
opno = ((Oper *) clause->oper)->opno;
|
|
|
|
|
1999-08-16 04:17:58 +02:00
|
|
|
if (op_mergejoinable(opno,
|
|
|
|
left->vartype,
|
|
|
|
right->vartype,
|
|
|
|
&leftOp,
|
|
|
|
&rightOp))
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
1999-08-16 04:17:58 +02:00
|
|
|
restrictinfo->mergejoinoperator = opno;
|
|
|
|
restrictinfo->left_sortop = leftOp;
|
|
|
|
restrictinfo->right_sortop = rightOp;
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
/*
|
1999-08-16 04:17:58 +02:00
|
|
|
* check_hashjoinable
|
|
|
|
* If the restrictinfo's clause is hashjoinable, set the hashjoin
|
|
|
|
* info fields in the restrictinfo.
|
|
|
|
*
|
|
|
|
* Currently, we support hashjoin for binary opclauses where
|
|
|
|
* both operands are simple Vars and the operator is a hashjoinable
|
2000-02-15 21:49:31 +01:00
|
|
|
* operator.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1999-08-16 04:17:58 +02:00
|
|
|
static void
|
|
|
|
check_hashjoinable(RestrictInfo *restrictinfo)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1999-08-16 04:17:58 +02:00
|
|
|
Expr *clause = restrictinfo->clause;
|
1999-02-15 02:06:59 +01:00
|
|
|
Var *left,
|
|
|
|
*right;
|
1999-08-16 04:17:58 +02:00
|
|
|
Oid opno;
|
1999-02-15 02:06:59 +01:00
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
if (!is_opclause((Node *) clause))
|
1999-08-16 04:17:58 +02:00
|
|
|
return;
|
1999-02-15 02:06:59 +01:00
|
|
|
|
|
|
|
left = get_leftop(clause);
|
|
|
|
right = get_rightop(clause);
|
|
|
|
|
|
|
|
/* caution: is_opclause accepts more than I do, so check it */
|
2000-04-12 19:17:23 +02:00
|
|
|
if (!right)
|
1999-08-16 04:17:58 +02:00
|
|
|
return; /* unary opclauses need not apply */
|
2000-04-12 19:17:23 +02:00
|
|
|
if (!IsA(left, Var) ||!IsA(right, Var))
|
1999-08-16 04:17:58 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
opno = ((Oper *) clause->oper)->opno;
|
1999-02-15 02:06:59 +01:00
|
|
|
|
1999-08-16 04:17:58 +02:00
|
|
|
if (op_hashjoinable(opno,
|
|
|
|
left->vartype,
|
|
|
|
right->vartype))
|
|
|
|
restrictinfo->hashjoinoperator = opno;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|