* initsplan.c
* Target list, qualification, joininfo initialization routines
*
- * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/plan/initsplan.c,v 1.99 2004/05/26 04:41:24 neilc Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/plan/initsplan.c,v 1.106 2005/06/05 22:32:55 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "utils/syscache.h"
-static void mark_baserels_for_outer_join(Query *root, Relids rels,
+static void mark_baserels_for_outer_join(PlannerInfo *root, Relids rels,
Relids outerrels);
-static void distribute_qual_to_rels(Query *root, Node *clause,
+static void distribute_qual_to_rels(PlannerInfo *root, Node *clause,
bool is_pushed_down,
bool isdeduced,
Relids outerjoin_nonnullable,
Relids qualscope);
-static void add_vars_to_targetlist(Query *root, List *vars,
+static void add_vars_to_targetlist(PlannerInfo *root, List *vars,
Relids where_needed);
-static bool qual_is_redundant(Query *root, RestrictInfo *restrictinfo,
+static bool qual_is_redundant(PlannerInfo *root, RestrictInfo *restrictinfo,
List *restrictlist);
static void check_mergejoinable(RestrictInfo *restrictinfo);
static void check_hashjoinable(RestrictInfo *restrictinfo);
* will be used later to build rels for inheritance children.
*/
void
-add_base_rels_to_query(Query *root, Node *jtnode)
+add_base_rels_to_query(PlannerInfo *root, Node *jtnode)
{
if (jtnode == NULL)
return;
* propagate up through all join plan steps.
*/
void
-build_base_rel_tlists(Query *root, List *final_tlist)
+build_base_rel_tlists(PlannerInfo *root, List *final_tlist)
{
List *tlist_vars = pull_var_clause((Node *) final_tlist, false);
if (tlist_vars != NIL)
{
add_vars_to_targetlist(root, tlist_vars, bms_make_singleton(0));
- freeList(tlist_vars);
+ list_free(tlist_vars);
}
}
* where_needed includes "relation 0").
*/
static void
-add_vars_to_targetlist(Query *root, List *vars, Relids where_needed)
+add_vars_to_targetlist(PlannerInfo *root, List *vars, Relids where_needed)
{
ListCell *temp;
{
/* Variable not yet requested, so add to reltargetlist */
/* XXX is copyObject necessary here? */
- FastAppend(&rel->reltargetlist, copyObject(var));
+ rel->reltargetlist = lappend(rel->reltargetlist, copyObject(var));
}
rel->attr_needed[attrno] = bms_add_members(rel->attr_needed[attrno],
where_needed);
* internal convenience; no outside callers pay attention to the result.
*/
Relids
-distribute_quals_to_rels(Query *root, Node *jtnode)
+distribute_quals_to_rels(PlannerInfo *root, Node *jtnode)
{
Relids result = NULL;
* Mark all base rels listed in 'rels' as having the given outerjoinset.
*/
static void
-mark_baserels_for_outer_join(Query *root, Relids rels, Relids outerrels)
+mark_baserels_for_outer_join(PlannerInfo *root, Relids rels, Relids outerrels)
{
Relids tmprelids;
int relno;
Assert(bms_is_subset(rel->outerjoinset, outerrels));
/*
- * Presently the executor cannot support FOR UPDATE marking of
+ * Presently the executor cannot support FOR UPDATE/SHARE marking of
* rels appearing on the nullable side of an outer join. (It's
* somewhat unclear what that would mean, anyway: what should we
* mark when a result row is generated from no element of the
- * nullable relation?) So, complain if target rel is FOR UPDATE.
+ * nullable relation?) So, complain if target rel is FOR UPDATE/SHARE.
* It's sufficient to make this check once per rel, so do it only
* if rel wasn't already known nullable.
*/
if (rel->outerjoinset == NULL)
{
- if (intMember(relno, root->rowMarks))
+ if (list_member_int(root->parse->rowMarks, relno))
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("SELECT FOR UPDATE cannot be applied to the nullable side of an outer join")));
+ errmsg("SELECT FOR UPDATE/SHARE cannot be applied to the nullable side of an outer join")));
}
rel->outerjoinset = outerrels;
* 'is_pushed_down' will be TRUE.
*/
static void
-distribute_qual_to_rels(Query *root, Node *clause,
+distribute_qual_to_rels(PlannerInfo *root, Node *clause,
bool is_pushed_down,
bool isdeduced,
Relids outerjoin_nonnullable,
* tree.
*
* We also need to determine whether the qual is "valid everywhere",
- * which is true if the qual mentions no variables that are involved
- * in lower-level outer joins (this may be an overly strong test).
+ * which is true if the qual mentions no variables that are
+ * involved in lower-level outer joins (this may be an overly
+ * strong test).
*/
Relids addrelids = NULL;
Relids tmprelids;
*/
vars = pull_var_clause(clause, false);
add_vars_to_targetlist(root, vars, relids);
- freeList(vars);
+ list_free(vars);
break;
default:
* for more details.
*/
void
-process_implied_equality(Query *root,
+process_implied_equality(PlannerInfo *root,
Node *item1, Node *item2,
Oid sortop1, Oid sortop2,
Relids item1_relids, Relids item2_relids,
if (membership == BMS_SINGLETON)
{
/* delete it from local restrictinfo list */
- rel1->baserestrictinfo = lremove(restrictinfo,
- rel1->baserestrictinfo);
+ rel1->baserestrictinfo = list_delete_ptr(rel1->baserestrictinfo,
+ restrictinfo);
}
else
{
*/
ltype = exprType(item1);
rtype = exprType(item2);
- eq_operator = compatible_oper(makeList1(makeString("=")),
+ eq_operator = compatible_oper(list_make1(makeString("=")),
ltype, rtype, true);
if (!HeapTupleIsValid(eq_operator))
{
* all the "var = const" quals.
*/
static bool
-qual_is_redundant(Query *root,
+qual_is_redundant(PlannerInfo *root,
RestrictInfo *restrictinfo,
List *restrictlist)
{
* done. We give up when we can't expand the equalexprs list any
* more.
*/
- equalexprs = makeList1(newleft);
+ equalexprs = list_make1(newleft);
do
{
someadded = false;
- /* cannot use foreach here because of possible lremove */
+ /* cannot use foreach here because of possible list_delete */
olditem = list_head(oldquals);
while (olditem)
{
Node *oldright = get_rightop(oldrinfo->clause);
Node *newguy = NULL;
- /* must advance olditem before lremove possibly pfree's it */
+ /* must advance olditem before list_delete possibly pfree's it */
olditem = lnext(olditem);
- if (member(oldleft, equalexprs))
+ if (list_member(equalexprs, oldleft))
newguy = oldright;
- else if (member(oldright, equalexprs))
+ else if (list_member(equalexprs, oldright))
newguy = oldleft;
else
continue;
/*
* Remove this qual from list, since we don't need it anymore.
*/
- oldquals = lremove(oldrinfo, oldquals);
+ oldquals = list_delete_ptr(oldquals, oldrinfo);
}
} while (someadded);
if (!is_opclause(clause))
return;
- if (length(((OpExpr *) clause)->args) != 2)
+ if (list_length(((OpExpr *) clause)->args) != 2)
return;
opno = ((OpExpr *) clause)->opno;
if (!is_opclause(clause))
return;
- if (length(((OpExpr *) clause)->args) != 2)
+ if (list_length(((OpExpr *) clause)->args) != 2)
return;
opno = ((OpExpr *) clause)->opno;