*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.62 1999/02/05 19:59:25 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.63 1999/02/08 04:29:03 momjian Exp $
*
*-------------------------------------------------------------------------
*/
newnode->path_cost = from->path_cost;
- newnode->p_ordering.ordtype = from->p_ordering.ordtype;
- if (from->p_ordering.ordtype == SORTOP_ORDER)
+ newnode->path_order.ordtype = from->path_order.ordtype;
+ if (from->path_order.ordtype == SORTOP_ORDER)
{
int len,
i;
- Oid *ordering = from->p_ordering.ord.sortop;
+ Oid *ordering = from->path_order.ord.sortop;
if (ordering)
{
for (len = 0; ordering[len] != 0; len++)
;
- newnode->p_ordering.ord.sortop = (Oid *) palloc(sizeof(Oid) * (len + 1));
+ newnode->path_order.ord.sortop = (Oid *) palloc(sizeof(Oid) * (len + 1));
for (i = 0; i < len; i++)
- newnode->p_ordering.ord.sortop[i] = ordering[i];
- newnode->p_ordering.ord.sortop[len] = 0;
+ newnode->path_order.ord.sortop[i] = ordering[i];
+ newnode->path_order.ord.sortop[len] = 0;
}
}
else
- Node_Copy(from, newnode, p_ordering.ord.merge);
+ Node_Copy(from, newnode, path_order.ord.merge);
Node_Copy(from, newnode, keys);
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.25 1999/02/07 00:52:12 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.26 1999/02/08 04:29:04 momjian Exp $
*
*-------------------------------------------------------------------------
*/
/*
* if (a->path_cost != b->path_cost) return(false);
*/
- if (a->p_ordering.ordtype == SORTOP_ORDER)
+ if (a->path_order.ordtype == SORTOP_ORDER)
{
int i = 0;
- if (a->p_ordering.ord.sortop == NULL ||
- b->p_ordering.ord.sortop == NULL)
+ if (a->path_order.ord.sortop == NULL ||
+ b->path_order.ord.sortop == NULL)
{
- if (a->p_ordering.ord.sortop != b->p_ordering.ord.sortop)
+ if (a->path_order.ord.sortop != b->path_order.ord.sortop)
return false;
}
else
{
- while (a->p_ordering.ord.sortop[i] != 0 &&
- b->p_ordering.ord.sortop[i] != 0)
+ while (a->path_order.ord.sortop[i] != 0 &&
+ b->path_order.ord.sortop[i] != 0)
{
- if (a->p_ordering.ord.sortop[i] != b->p_ordering.ord.sortop[i])
+ if (a->path_order.ord.sortop[i] != b->path_order.ord.sortop[i])
return false;
i++;
}
- if (a->p_ordering.ord.sortop[i] != 0 ||
- b->p_ordering.ord.sortop[i] != 0)
+ if (a->path_order.ord.sortop[i] != 0 ||
+ b->path_order.ord.sortop[i] != 0)
return false;
}
}
else
{
- if (!equal(a->p_ordering.ord.merge, b->p_ordering.ord.merge))
+ if (!equal(a->path_order.ord.merge, b->path_order.ord.merge))
return false;
}
if (!equal(a->keys, b->keys))
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/nodes/Attic/freefuncs.c,v 1.1 1999/02/06 16:50:25 wieck Exp $
+ * $Header: /cvsroot/pgsql/src/backend/nodes/Attic/freefuncs.c,v 1.2 1999/02/08 04:29:04 momjian Exp $
*
*-------------------------------------------------------------------------
*/
static void
FreePathFields(Path *node)
{
- if (node->p_ordering.ordtype == SORTOP_ORDER)
+ if (node->path_order.ordtype == SORTOP_ORDER)
{
- if (node->p_ordering.ord.sortop)
- pfree(node->p_ordering.ord.sortop);
+ if (node->path_order.ord.sortop)
+ pfree(node->path_order.ord.sortop);
}
else
- freeObject(node->p_ordering.ord.merge);
+ freeObject(node->path_order.ord.merge);
freeObject(node->keys);
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.49 1999/02/05 19:59:25 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.50 1999/02/08 04:29:04 momjian Exp $
*
* NOTES
* Most of the read functions for plan nodes are tested. (In fact, they
local_node->path_cost = (Cost) atof(token);
#if 0
- token = lsptok(NULL, &length); /* get :p_ordering */
- local_node->p_ordering = nodeRead(true); /* now read it */
+ token = lsptok(NULL, &length); /* get :path_order */
+ local_node->path_order = nodeRead(true); /* now read it */
#endif
token = lsptok(NULL, &length); /* get :keys */
local_node->path.path_cost = (Cost) atof(token);
#if 0
- token = lsptok(NULL, &length); /* get :p_ordering */
- local_node->path.p_ordering = nodeRead(true); /* now read it */
+ token = lsptok(NULL, &length); /* get :path_order */
+ local_node->path.path_order = nodeRead(true); /* now read it */
#endif
token = lsptok(NULL, &length); /* get :keys */
local_node->path.path_cost = (Cost) atof(token);
#if 0
- token = lsptok(NULL, &length); /* get :p_ordering */
- local_node->path.p_ordering = nodeRead(true); /* now read it */
+ token = lsptok(NULL, &length); /* get :path_order */
+ local_node->path.path_order = nodeRead(true); /* now read it */
#endif
token = lsptok(NULL, &length); /* get :keys */
local_node->jpath.path.path_cost = (Cost) atof(token);
#if 0
- token = lsptok(NULL, &length); /* get :p_ordering */
- local_node->jpath.path.p_ordering = nodeRead(true); /* now read it */
+ token = lsptok(NULL, &length); /* get :path_order */
+ local_node->jpath.path.path_order = nodeRead(true); /* now read it */
#endif
token = lsptok(NULL, &length); /* get :keys */
local_node->jpath.path.path_cost = (Cost) atof(token);
#if 0
- token = lsptok(NULL, &length); /* get :p_ordering */
- local_node->jpath.path.p_ordering = nodeRead(true); /* now read it */
+ token = lsptok(NULL, &length); /* get :path_order */
+ local_node->jpath.path.path_order = nodeRead(true); /* now read it */
#endif
token = lsptok(NULL, &length); /* get :keys */
+The optimizer generates optimial query plans by doing several steps:
+
+Take each relation in a query, and make a RelOptInfo structure for it.
+Find each way of accessing the relation, called a Path, including
+sequential and index scans, and add it to the RelOptInfo.path_order
+list.
+
+
Optimizer Functions
-------------------
*
* Copyright (c) 1994, Regents of the University of California
*
- * $Id: geqo_paths.c,v 1.12 1998/09/01 04:29:21 momjian Exp $
+ * $Id: geqo_paths.c,v 1.13 1999/02/08 04:29:06 momjian Exp $
*
*-------------------------------------------------------------------------
*/
{
path = (Path *) lfirst(y);
- if (!path->p_ordering.ord.sortop)
+ if (!path->path_order.ord.sortop)
break;
}
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/optimizer/path/indxpath.c,v 1.38 1999/02/05 19:59:26 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/optimizer/path/indxpath.c,v 1.39 1999/02/08 04:29:08 momjian Exp $
*
*-------------------------------------------------------------------------
*/
pathnode->path.pathtype = T_IndexScan;
pathnode->path.parent = rel;
- pathnode->path.p_ordering.ordtype = SORTOP_ORDER;
- pathnode->path.p_ordering.ord.sortop = index->ordering;
+ pathnode->path.path_order.ordtype = SORTOP_ORDER;
+ pathnode->path.path_order.ord.sortop = index->ordering;
pathnode->path.keys = NIL; /* not sure about this, bjm 1998/09/21 */
pathnode->indexid = index->relids;
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/optimizer/path/joinpath.c,v 1.14 1999/02/04 03:19:08 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/optimizer/path/joinpath.c,v 1.15 1999/02/08 04:29:11 momjian Exp $
*
*-------------------------------------------------------------------------
*/
outerpath = (Path *) lfirst(i);
- outerpath_ordering = &outerpath->p_ordering;
+ outerpath_ordering = &outerpath->path_order;
if (outerpath_ordering)
{
innerpath = (Path *) lfirst(i);
- innerpath_ordering = &innerpath->p_ordering;
+ innerpath_ordering = &innerpath->path_order;
if (innerpath_ordering)
{
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/joinutils.c,v 1.10 1999/02/06 17:29:26 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/joinutils.c,v 1.11 1999/02/08 04:29:12 momjian Exp $
*
*-------------------------------------------------------------------------
*/
key_match = every_func(joinkeys, path->keys, which_subkey);
if (equal_path_ordering(ordering,
- &path->p_ordering) &&
+ &path->path_order) &&
length(joinkeys) == length(path->keys) &&
key_match)
{
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/mergeutils.c,v 1.13 1999/02/06 17:29:26 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/mergeutils.c,v 1.14 1999/02/08 04:29:12 momjian Exp $
*
*-------------------------------------------------------------------------
*/
* Create a new mergeinfo node and add it to 'mergeinfo-list'
* if one does not yet exist for this merge ordering.
*/
- PathOrder p_ordering;
+ PathOrder path_order;
MergeInfo *xmergeinfo;
Expr *clause = restrictinfo->clause;
Var *leftop = get_leftop(clause);
Var *rightop = get_rightop(clause);
JoinKey *keys;
- p_ordering.ordtype = MERGE_ORDER;
- p_ordering.ord.merge = merge_ordering;
- xmergeinfo = match_order_mergeinfo(&p_ordering, mergeinfo_list);
+ path_order.ordtype = MERGE_ORDER;
+ path_order.ord.merge = merge_ordering;
+ xmergeinfo = match_order_mergeinfo(&path_order, mergeinfo_list);
if (inner_relid == leftop->varno)
{
keys = makeNode(JoinKey);
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/optimizer/path/orindxpath.c,v 1.14 1999/02/03 21:16:28 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/optimizer/path/orindxpath.c,v 1.15 1999/02/08 04:29:12 momjian Exp $
*
*-------------------------------------------------------------------------
*/
pathnode->path.pathtype = T_IndexScan;
pathnode->path.parent = rel;
- pathnode->path.p_ordering.ordtype = SORTOP_ORDER;
+ pathnode->path.path_order.ordtype = SORTOP_ORDER;
/*
* This is an IndexScan, but it does index lookups based
* on the order of the fields specified in the WHERE clause,
* not in any order, so the sortop is NULL.
*/
- pathnode->path.p_ordering.ord.sortop = NULL;
+ pathnode->path.path_order.ord.sortop = NULL;
pathnode->path.keys = NIL; /* not sure about this, bjm 1998/09/21 */
pathnode->indexqual = lcons(clausenode, NIL);
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/prune.c,v 1.23 1999/02/05 20:34:11 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/prune.c,v 1.24 1999/02/08 04:29:12 momjian Exp $
*
*-------------------------------------------------------------------------
*/
{
path = (Path *) lfirst(y);
- if (!path->p_ordering.ord.sortop)
+ if (!path->path_order.ord.sortop)
break;
}
cheapest = (JoinPath *) prune_rel_path(rel, path);
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.37 1999/02/05 19:59:27 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.38 1999/02/08 04:29:17 momjian Exp $
*
*-------------------------------------------------------------------------
*/
outer_tlist,
inner_tlist));
- opcode = get_opcode((best_path->jpath.path.p_ordering.ord.merge)->join_operator);
+ opcode = get_opcode((best_path->jpath.path.path_order.ord.merge)->join_operator);
outer_order = (Oid *) palloc(sizeof(Oid) * 2);
- outer_order[0] = (best_path->jpath.path.p_ordering.ord.merge)->left_operator;
+ outer_order[0] = (best_path->jpath.path.path_order.ord.merge)->left_operator;
outer_order[1] = 0;
inner_order = (Oid *) palloc(sizeof(Oid) * 2);
- inner_order[0] = (best_path->jpath.path.p_ordering.ord.merge)->right_operator;
+ inner_order[0] = (best_path->jpath.path.path_order.ord.merge)->right_operator;
inner_order[1] = 0;
/*
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/optimizer/util/pathnode.c,v 1.19 1999/02/06 17:29:27 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/optimizer/util/pathnode.c,v 1.20 1999/02/08 04:29:21 momjian Exp $
*
*-------------------------------------------------------------------------
*/
path = (Path *) lfirst(temp);
if (samekeys(path->keys, new_path->keys) &&
- equal_path_ordering(&path->p_ordering,
- &new_path->p_ordering))
+ equal_path_ordering(&path->path_order,
+ &new_path->path_order))
{
old_path = path;
break;
pathnode->pathtype = T_SeqScan;
pathnode->parent = rel;
pathnode->path_cost = 0.0;
- pathnode->p_ordering.ordtype = SORTOP_ORDER;
- pathnode->p_ordering.ord.sortop = NULL;
+ pathnode->path_order.ordtype = SORTOP_ORDER;
+ pathnode->path_order.ord.sortop = NULL;
pathnode->keys = NIL;
/*
pathnode->path.pathtype = T_IndexScan;
pathnode->path.parent = rel;
- pathnode->path.p_ordering.ordtype = SORTOP_ORDER;
- pathnode->path.p_ordering.ord.sortop = index->ordering;
+ pathnode->path.path_order.ordtype = SORTOP_ORDER;
+ pathnode->path.path_order.ord.sortop = index->ordering;
pathnode->indexid = index->relids;
pathnode->indexkeys = index->indexkeys;
* The index must have an ordering for the path to have (ordering)
* keys, and vice versa.
*/
- if (pathnode->path.p_ordering.ord.sortop)
+ if (pathnode->path.path_order.ord.sortop)
{
pathnode->path.keys = collect_index_pathkeys(index->indexkeys,
rel->targetlist);
* if no index keys were found, we can't order the path).
*/
if (pathnode->path.keys == NULL)
- pathnode->path.p_ordering.ord.sortop = NULL;
+ pathnode->path.path_order.ord.sortop = NULL;
}
else
pathnode->path.keys = NULL;
if (keys)
{
- pathnode->path.p_ordering.ordtype = outer_path->p_ordering.ordtype;
- if (outer_path->p_ordering.ordtype == SORTOP_ORDER)
+ pathnode->path.path_order.ordtype = outer_path->path_order.ordtype;
+ if (outer_path->path_order.ordtype == SORTOP_ORDER)
{
- pathnode->path.p_ordering.ord.sortop = outer_path->p_ordering.ord.sortop;
+ pathnode->path.path_order.ord.sortop = outer_path->path_order.ord.sortop;
}
else
{
- pathnode->path.p_ordering.ord.merge = outer_path->p_ordering.ord.merge;
+ pathnode->path.path_order.ord.merge = outer_path->path_order.ord.merge;
}
}
else
{
- pathnode->path.p_ordering.ordtype = SORTOP_ORDER;
- pathnode->path.p_ordering.ord.sortop = NULL;
+ pathnode->path.path_order.ordtype = SORTOP_ORDER;
+ pathnode->path.path_order.ord.sortop = NULL;
}
pathnode->path.path_cost = cost_nestloop(outer_path->path_cost,
pathnode->jpath.innerjoinpath = inner_path;
pathnode->jpath.pathinfo = joinrel->restrictinfo;
pathnode->jpath.path.keys = keys;
- pathnode->jpath.path.p_ordering.ordtype = MERGE_ORDER;
- pathnode->jpath.path.p_ordering.ord.merge = order;
+ pathnode->jpath.path.path_order.ordtype = MERGE_ORDER;
+ pathnode->jpath.path.path_order.ord.merge = order;
pathnode->path_mergeclauses = mergeclauses;
pathnode->jpath.path.loc_restrictinfo = NIL;
pathnode->outersortkeys = outersortkeys;
pathnode->jpath.pathinfo = joinrel->restrictinfo;
pathnode->jpath.path.loc_restrictinfo = NIL;
pathnode->jpath.path.keys = keys;
- pathnode->jpath.path.p_ordering.ordtype = SORTOP_ORDER;
- pathnode->jpath.path.p_ordering.ord.sortop = NULL;
+ pathnode->jpath.path.path_order.ordtype = SORTOP_ORDER;
+ pathnode->jpath.path.path_order.ord.sortop = NULL;
pathnode->jpath.path.outerjoincost = (Cost) 0.0;
pathnode->jpath.path.joinid = (Relid) NULL;
/* pathnode->hashjoinoperator = operator; */
*
* Copyright (c) 1994, Regents of the University of California
*
- * $Id: relation.h,v 1.15 1999/02/05 19:59:31 momjian Exp $
+ * $Id: relation.h,v 1.16 1999/02/08 04:29:25 momjian Exp $
*
*-------------------------------------------------------------------------
*/
NodeTag pathtype;
- PathOrder p_ordering;
+ PathOrder path_order;
List *keys;
Cost outerjoincost;