1996-07-09 08:22:35 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* pathnode.c
|
1997-09-07 07:04:48 +02:00
|
|
|
* Routines to manipulate pathlists and create path nodes
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
2000-01-23 00:50:30 +01:00
|
|
|
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/pathnode.c,v 1.57 2000/01/22 23:50:17 tgl Exp $
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#include "postgres.h"
|
|
|
|
|
|
|
|
#include "optimizer/cost.h"
|
1999-07-16 07:00:38 +02:00
|
|
|
#include "optimizer/pathnode.h"
|
1999-07-27 05:51:11 +02:00
|
|
|
#include "optimizer/paths.h"
|
1999-07-16 07:00:38 +02:00
|
|
|
#include "optimizer/plancat.h"
|
|
|
|
#include "optimizer/restrictinfo.h"
|
1999-07-16 05:14:30 +02:00
|
|
|
#include "parser/parsetree.h"
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
1997-09-07 07:04:48 +02:00
|
|
|
* MISC. PATH UTILITIES
|
1996-07-09 08:22:35 +02:00
|
|
|
*****************************************************************************/
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
/*
|
1999-02-14 00:22:53 +01:00
|
|
|
* path_is_cheaper
|
1997-09-07 07:04:48 +02:00
|
|
|
* Returns t iff 'path1' is cheaper than 'path2'.
|
|
|
|
*
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
|
|
|
bool
|
1997-09-08 23:56:23 +02:00
|
|
|
path_is_cheaper(Path *path1, Path *path2)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2000-01-09 01:26:47 +01:00
|
|
|
return (bool) (path1->path_cost < path2->path_cost);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
/*
|
1999-02-14 00:22:53 +01:00
|
|
|
* set_cheapest
|
1997-09-07 07:04:48 +02:00
|
|
|
* Finds the minimum cost path from among a relation's paths.
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* 'parent_rel' is the parent relation
|
|
|
|
* 'pathlist' is a list of path nodes corresponding to 'parent_rel'
|
1997-09-07 07:04:48 +02:00
|
|
|
*
|
|
|
|
* Returns and sets the relation entry field with the pathnode that
|
1996-07-09 08:22:35 +02:00
|
|
|
* is minimum.
|
1997-09-07 07:04:48 +02:00
|
|
|
*
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1998-02-26 05:46:47 +01:00
|
|
|
Path *
|
1999-05-26 00:43:53 +02:00
|
|
|
set_cheapest(RelOptInfo *parent_rel, List *pathlist)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
List *p;
|
|
|
|
Path *cheapest_so_far;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1998-07-18 06:22:52 +02:00
|
|
|
Assert(IsA(parent_rel, RelOptInfo));
|
2000-01-09 01:26:47 +01:00
|
|
|
Assert(pathlist != NIL);
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
cheapest_so_far = (Path *) lfirst(pathlist);
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
foreach(p, lnext(pathlist))
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
Path *path = (Path *) lfirst(p);
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
if (path_is_cheaper(path, cheapest_so_far))
|
|
|
|
cheapest_so_far = path;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
parent_rel->cheapestpath = cheapest_so_far;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1998-09-01 05:29:17 +02:00
|
|
|
return cheapest_so_far;
|
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_pathlist
|
1999-08-16 04:17:58 +02:00
|
|
|
* Construct an output path list by adding to old_paths each path in
|
|
|
|
* new_paths that is worth considering --- that is, it has either a
|
|
|
|
* better sort order (better pathkeys) or cheaper cost than any of the
|
|
|
|
* existing old paths.
|
1997-09-07 07:04:48 +02:00
|
|
|
*
|
1999-08-16 04:17:58 +02:00
|
|
|
* Unless parent_rel->pruneable is false, we also remove from the output
|
|
|
|
* pathlist any old paths that are dominated by added path(s) --- that is,
|
|
|
|
* some new path is both cheaper and at least as well ordered.
|
1997-09-07 07:04:48 +02:00
|
|
|
*
|
1999-08-16 04:17:58 +02:00
|
|
|
* Note: the list old_paths is destructively modified, and in fact is
|
|
|
|
* turned into the output list.
|
1997-09-07 07:04:48 +02:00
|
|
|
*
|
1999-08-16 04:17:58 +02:00
|
|
|
* 'parent_rel' is the relation entry to which these paths correspond.
|
|
|
|
* 'old_paths' is the list of previously accepted paths for parent_rel.
|
|
|
|
* 'new_paths' is a list of potential new paths.
|
|
|
|
*
|
|
|
|
* Returns the updated list of interesting pathnodes.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1998-02-26 05:46:47 +01:00
|
|
|
List *
|
1999-08-16 04:17:58 +02:00
|
|
|
add_pathlist(RelOptInfo *parent_rel, List *old_paths, List *new_paths)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1999-02-04 20:20:12 +01:00
|
|
|
List *p1;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1999-02-04 20:20:12 +01:00
|
|
|
foreach(p1, new_paths)
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
1999-02-04 20:20:12 +01:00
|
|
|
Path *new_path = (Path *) lfirst(p1);
|
1999-08-16 04:17:58 +02:00
|
|
|
bool accept_new = true; /* unless we find a superior old path */
|
|
|
|
List *p2_prev = NIL;
|
|
|
|
List *p2;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1999-08-16 04:17:58 +02:00
|
|
|
/*
|
|
|
|
* Loop to check proposed new path against old paths. Note it is
|
|
|
|
* possible for more than one old path to be tossed out because
|
|
|
|
* new_path dominates it.
|
|
|
|
*/
|
|
|
|
foreach(p2, old_paths)
|
1999-02-09 04:51:42 +01:00
|
|
|
{
|
1999-08-16 04:17:58 +02:00
|
|
|
Path *old_path = (Path *) lfirst(p2);
|
|
|
|
bool remove_old = false; /* unless new proves superior */
|
1999-02-11 05:08:44 +01:00
|
|
|
|
1999-08-16 04:17:58 +02:00
|
|
|
switch (compare_pathkeys(new_path->pathkeys, old_path->pathkeys))
|
|
|
|
{
|
|
|
|
case PATHKEYS_EQUAL:
|
|
|
|
if (new_path->path_cost < old_path->path_cost)
|
|
|
|
remove_old = true; /* new dominates old */
|
|
|
|
else
|
|
|
|
accept_new = false; /* old equals or dominates new */
|
|
|
|
break;
|
|
|
|
case PATHKEYS_BETTER1:
|
|
|
|
if (new_path->path_cost <= old_path->path_cost)
|
|
|
|
remove_old = true; /* new dominates old */
|
|
|
|
break;
|
|
|
|
case PATHKEYS_BETTER2:
|
|
|
|
if (new_path->path_cost >= old_path->path_cost)
|
|
|
|
accept_new = false; /* old dominates new */
|
|
|
|
break;
|
|
|
|
case PATHKEYS_DIFFERENT:
|
|
|
|
/* keep both paths, since they have different ordering */
|
|
|
|
break;
|
|
|
|
}
|
1999-05-25 18:15:34 +02:00
|
|
|
|
1999-02-11 22:05:28 +01:00
|
|
|
/*
|
1999-08-16 04:17:58 +02:00
|
|
|
* Remove current element from old_list if dominated by new,
|
|
|
|
* unless xfunc told us not to remove any paths.
|
1999-02-11 22:05:28 +01:00
|
|
|
*/
|
1999-08-16 04:17:58 +02:00
|
|
|
if (remove_old && parent_rel->pruneable)
|
1999-02-11 05:08:44 +01:00
|
|
|
{
|
1999-08-16 04:17:58 +02:00
|
|
|
if (p2_prev)
|
|
|
|
lnext(p2_prev) = lnext(p2);
|
|
|
|
else
|
|
|
|
old_paths = lnext(p2);
|
1999-02-11 22:05:28 +01:00
|
|
|
}
|
1999-08-16 04:17:58 +02:00
|
|
|
else
|
|
|
|
p2_prev = p2;
|
1999-02-11 22:05:28 +01:00
|
|
|
|
1999-08-16 04:17:58 +02:00
|
|
|
/*
|
|
|
|
* If we found an old path that dominates new_path, we can quit
|
|
|
|
* scanning old_paths; we will not add new_path, and we assume
|
|
|
|
* new_path cannot dominate any other elements of old_paths.
|
|
|
|
*/
|
|
|
|
if (! accept_new)
|
|
|
|
break;
|
|
|
|
}
|
1999-02-11 22:05:28 +01:00
|
|
|
|
1999-08-16 04:17:58 +02:00
|
|
|
if (accept_new)
|
|
|
|
{
|
|
|
|
/* Accept the path. Note that it will now be eligible to be
|
|
|
|
* compared against the additional elements of new_paths...
|
|
|
|
*/
|
|
|
|
new_path->parent = parent_rel; /* not redundant, see prune.c */
|
|
|
|
old_paths = lcons(new_path, old_paths);
|
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
|
|
|
return old_paths;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
1997-09-07 07:04:48 +02:00
|
|
|
* PATH NODE CREATION ROUTINES
|
1996-07-09 08:22:35 +02:00
|
|
|
*****************************************************************************/
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
/*
|
1999-02-14 00:22:53 +01:00
|
|
|
* create_seqscan_path
|
1997-09-07 07:04:48 +02:00
|
|
|
* Creates a path corresponding to a sequential scan, returning the
|
|
|
|
* pathnode.
|
|
|
|
*
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1998-02-26 05:46:47 +01:00
|
|
|
Path *
|
1999-05-26 00:43:53 +02:00
|
|
|
create_seqscan_path(RelOptInfo *rel)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
Path *pathnode = makeNode(Path);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
pathnode->pathtype = T_SeqScan;
|
|
|
|
pathnode->parent = rel;
|
1999-08-16 04:17:58 +02:00
|
|
|
pathnode->pathkeys = NIL; /* seqscan has unordered result */
|
2000-01-09 01:26:47 +01:00
|
|
|
pathnode->path_cost = cost_seqscan(rel);
|
1999-07-27 05:51:11 +02:00
|
|
|
|
1998-09-01 05:29:17 +02:00
|
|
|
return pathnode;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
/*
|
1999-02-14 00:22:53 +01:00
|
|
|
* create_index_path
|
1999-07-30 06:07:25 +02:00
|
|
|
* Creates a path node for an index scan.
|
1997-09-07 07:04:48 +02:00
|
|
|
*
|
1996-07-09 08:22:35 +02:00
|
|
|
* 'rel' is the parent rel
|
1999-07-30 06:07:25 +02:00
|
|
|
* 'index' is an index on 'rel'
|
|
|
|
* 'restriction_clauses' is a list of RestrictInfo nodes
|
|
|
|
* to be used as index qual conditions in the scan.
|
1997-09-07 07:04:48 +02:00
|
|
|
*
|
1996-07-09 08:22:35 +02:00
|
|
|
* Returns the new path node.
|
|
|
|
*/
|
1997-09-08 04:41:22 +02:00
|
|
|
IndexPath *
|
1997-09-08 23:56:23 +02:00
|
|
|
create_index_path(Query *root,
|
1999-05-26 00:43:53 +02:00
|
|
|
RelOptInfo *rel,
|
2000-01-09 01:26:47 +01:00
|
|
|
IndexOptInfo *index,
|
1999-07-30 06:07:25 +02:00
|
|
|
List *restriction_clauses)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
IndexPath *pathnode = makeNode(IndexPath);
|
2000-01-23 00:50:30 +01:00
|
|
|
List *indexquals;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
pathnode->path.pathtype = T_IndexScan;
|
|
|
|
pathnode->path.parent = rel;
|
1999-08-16 04:17:58 +02:00
|
|
|
pathnode->path.pathkeys = build_index_pathkeys(root, rel, index);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-01-23 00:50:30 +01:00
|
|
|
indexquals = get_actual_clauses(restriction_clauses);
|
|
|
|
/* expand special operators to indexquals the executor can handle */
|
|
|
|
indexquals = expand_indexqual_conditions(indexquals);
|
|
|
|
|
1999-08-16 04:17:58 +02:00
|
|
|
/*
|
2000-01-23 00:50:30 +01:00
|
|
|
* We are making a pathnode for a single-scan indexscan; therefore,
|
|
|
|
* both indexid and indexqual should be single-element lists.
|
1999-07-26 01:07:26 +02:00
|
|
|
*/
|
2000-01-09 01:26:47 +01:00
|
|
|
pathnode->indexid = lconsi(index->indexoid, NIL);
|
2000-01-23 00:50:30 +01:00
|
|
|
pathnode->indexqual = lcons(indexquals, NIL);
|
1999-08-16 04:17:58 +02:00
|
|
|
pathnode->joinrelids = NIL; /* no join clauses here */
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-01-23 00:50:30 +01:00
|
|
|
pathnode->path.path_cost = cost_index(root, rel, index, indexquals,
|
|
|
|
false);
|
1999-07-26 01:07:26 +02:00
|
|
|
|
1998-09-01 05:29:17 +02:00
|
|
|
return pathnode;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
1999-11-23 21:07:06 +01:00
|
|
|
/*
|
|
|
|
* create_tidscan_path
|
|
|
|
* Creates a path corresponding to a tid_direct scan, returning the
|
|
|
|
* pathnode.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
TidPath *
|
|
|
|
create_tidscan_path(RelOptInfo *rel, List *tideval)
|
|
|
|
{
|
|
|
|
TidPath *pathnode = makeNode(TidPath);
|
|
|
|
|
|
|
|
pathnode->path.pathtype = T_TidScan;
|
|
|
|
pathnode->path.parent = rel;
|
|
|
|
pathnode->path.pathkeys = NIL;
|
2000-01-09 01:26:47 +01:00
|
|
|
pathnode->path.path_cost = cost_tidscan(rel, tideval);
|
1999-11-23 21:07:06 +01:00
|
|
|
/* divide selectivity for each clause to get an equal selectivity
|
|
|
|
* as IndexScan does OK ?
|
|
|
|
*/
|
2000-01-09 01:26:47 +01:00
|
|
|
pathnode->tideval = copyObject(tideval); /* is copy really necessary? */
|
1999-11-23 21:07:06 +01:00
|
|
|
pathnode->unjoined_relids = NIL;
|
|
|
|
|
|
|
|
return pathnode;
|
|
|
|
}
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
/*
|
1999-02-14 00:22:53 +01:00
|
|
|
* create_nestloop_path
|
1997-09-07 07:04:48 +02:00
|
|
|
* Creates a pathnode corresponding to a nestloop join between two
|
|
|
|
* relations.
|
|
|
|
*
|
1996-07-09 08:22:35 +02:00
|
|
|
* 'joinrel' is the join relation.
|
1999-08-16 04:17:58 +02:00
|
|
|
* 'outer_path' is the outer path
|
|
|
|
* 'inner_path' is the inner path
|
|
|
|
* 'pathkeys' are the path keys of the new join path
|
1997-09-07 07:04:48 +02:00
|
|
|
*
|
1996-07-09 08:22:35 +02:00
|
|
|
* Returns the resulting path node.
|
1997-09-07 07:04:48 +02:00
|
|
|
*
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1999-02-12 07:43:53 +01:00
|
|
|
NestPath *
|
1999-05-26 00:43:53 +02:00
|
|
|
create_nestloop_path(RelOptInfo *joinrel,
|
1997-09-08 23:56:23 +02:00
|
|
|
Path *outer_path,
|
|
|
|
Path *inner_path,
|
1999-02-10 04:52:54 +01:00
|
|
|
List *pathkeys)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1999-02-12 07:43:53 +01:00
|
|
|
NestPath *pathnode = makeNode(NestPath);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
pathnode->path.pathtype = T_NestLoop;
|
|
|
|
pathnode->path.parent = joinrel;
|
|
|
|
pathnode->outerjoinpath = outer_path;
|
|
|
|
pathnode->innerjoinpath = inner_path;
|
1999-02-10 04:52:54 +01:00
|
|
|
pathnode->path.pathkeys = pathkeys;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-01-09 01:26:47 +01:00
|
|
|
pathnode->path.path_cost = cost_nestloop(outer_path,
|
|
|
|
inner_path,
|
1999-05-25 18:15:34 +02:00
|
|
|
IsA(inner_path, IndexPath));
|
1999-07-27 05:51:11 +02:00
|
|
|
|
1998-09-01 05:29:17 +02:00
|
|
|
return pathnode;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
/*
|
1999-02-14 00:22:53 +01:00
|
|
|
* create_mergejoin_path
|
1998-08-04 18:44:31 +02:00
|
|
|
* Creates a pathnode corresponding to a mergejoin join between
|
1997-09-07 07:04:48 +02:00
|
|
|
* two relations
|
|
|
|
*
|
1996-07-09 08:22:35 +02:00
|
|
|
* 'joinrel' is the join relation
|
|
|
|
* 'outer_path' is the outer path
|
|
|
|
* 'inner_path' is the inner path
|
1999-08-16 04:17:58 +02:00
|
|
|
* 'pathkeys' are the path keys of the new join path
|
1996-07-09 08:22:35 +02:00
|
|
|
* 'mergeclauses' are the applicable join/restriction clauses
|
|
|
|
* 'outersortkeys' are the sort varkeys for the outer relation
|
|
|
|
* 'innersortkeys' are the sort varkeys for the inner relation
|
1997-09-07 07:04:48 +02:00
|
|
|
*
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1997-09-08 04:41:22 +02:00
|
|
|
MergePath *
|
1999-05-26 00:43:53 +02:00
|
|
|
create_mergejoin_path(RelOptInfo *joinrel,
|
1997-09-08 23:56:23 +02:00
|
|
|
Path *outer_path,
|
|
|
|
Path *inner_path,
|
1999-02-10 04:52:54 +01:00
|
|
|
List *pathkeys,
|
1997-09-08 23:56:23 +02:00
|
|
|
List *mergeclauses,
|
|
|
|
List *outersortkeys,
|
|
|
|
List *innersortkeys)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
MergePath *pathnode = makeNode(MergePath);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1999-08-16 04:17:58 +02:00
|
|
|
/*
|
|
|
|
* If the given paths are already well enough ordered, we can skip
|
|
|
|
* doing an explicit sort.
|
|
|
|
*/
|
|
|
|
if (outersortkeys &&
|
|
|
|
pathkeys_contained_in(outersortkeys, outer_path->pathkeys))
|
|
|
|
outersortkeys = NIL;
|
|
|
|
if (innersortkeys &&
|
|
|
|
pathkeys_contained_in(innersortkeys, inner_path->pathkeys))
|
|
|
|
innersortkeys = NIL;
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
pathnode->jpath.path.pathtype = T_MergeJoin;
|
|
|
|
pathnode->jpath.path.parent = joinrel;
|
|
|
|
pathnode->jpath.outerjoinpath = outer_path;
|
|
|
|
pathnode->jpath.innerjoinpath = inner_path;
|
1999-02-10 04:52:54 +01:00
|
|
|
pathnode->jpath.path.pathkeys = pathkeys;
|
1997-09-07 07:04:48 +02:00
|
|
|
pathnode->path_mergeclauses = mergeclauses;
|
|
|
|
pathnode->outersortkeys = outersortkeys;
|
|
|
|
pathnode->innersortkeys = innersortkeys;
|
2000-01-09 01:26:47 +01:00
|
|
|
pathnode->jpath.path.path_cost = cost_mergejoin(outer_path,
|
|
|
|
inner_path,
|
1999-05-25 18:15:34 +02:00
|
|
|
outersortkeys,
|
2000-01-09 01:26:47 +01:00
|
|
|
innersortkeys);
|
1999-07-27 05:51:11 +02:00
|
|
|
|
1998-09-01 05:29:17 +02:00
|
|
|
return pathnode;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
/*
|
1999-08-06 06:00:17 +02:00
|
|
|
* create_hashjoin_path
|
1997-09-07 07:04:48 +02:00
|
|
|
* Creates a pathnode corresponding to a hash join between two relations.
|
|
|
|
*
|
1996-07-09 08:22:35 +02:00
|
|
|
* 'joinrel' is the join relation
|
1999-08-06 06:00:17 +02:00
|
|
|
* 'outer_path' is the cheapest outer path
|
|
|
|
* 'inner_path' is the cheapest inner path
|
|
|
|
* 'hashclauses' is a list of the hash join clause (always a 1-element list)
|
|
|
|
* 'innerdisbursion' is an estimate of the disbursion of the inner hash key
|
1997-09-07 07:04:48 +02:00
|
|
|
*
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1999-08-16 04:17:58 +02:00
|
|
|
HashPath *
|
1999-05-26 00:43:53 +02:00
|
|
|
create_hashjoin_path(RelOptInfo *joinrel,
|
1997-09-08 23:56:23 +02:00
|
|
|
Path *outer_path,
|
|
|
|
Path *inner_path,
|
|
|
|
List *hashclauses,
|
2000-01-09 01:26:47 +01:00
|
|
|
Selectivity innerdisbursion)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
HashPath *pathnode = makeNode(HashPath);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
pathnode->jpath.path.pathtype = T_HashJoin;
|
|
|
|
pathnode->jpath.path.parent = joinrel;
|
|
|
|
pathnode->jpath.outerjoinpath = outer_path;
|
|
|
|
pathnode->jpath.innerjoinpath = inner_path;
|
1999-08-16 04:17:58 +02:00
|
|
|
/* A hashjoin never has pathkeys, since its ordering is unpredictable */
|
|
|
|
pathnode->jpath.path.pathkeys = NIL;
|
1997-09-07 07:04:48 +02:00
|
|
|
pathnode->path_hashclauses = hashclauses;
|
2000-01-09 01:26:47 +01:00
|
|
|
pathnode->jpath.path.path_cost = cost_hashjoin(outer_path,
|
|
|
|
inner_path,
|
1999-08-06 06:00:17 +02:00
|
|
|
innerdisbursion);
|
1999-07-27 05:51:11 +02:00
|
|
|
|
1998-09-01 05:29:17 +02:00
|
|
|
return pathnode;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|