1996-07-09 08:22:35 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* joininfo.c
|
1997-09-07 07:04:48 +02:00
|
|
|
* JoinInfo node manipulation 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-06-09 00:38:00 +02:00
|
|
|
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/joininfo.c,v 1.27 2000/06/08 22:37:16 momjian Exp $
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#include "postgres.h"
|
|
|
|
|
|
|
|
|
1999-07-16 07:00:38 +02:00
|
|
|
#include "optimizer/joininfo.h"
|
1996-07-09 08:22:35 +02:00
|
|
|
|
2000-06-09 00:38:00 +02:00
|
|
|
static JoinInfo *joininfo_member(List *join_relids, List *joininfo_list);
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
/*
|
1999-02-14 00:22:53 +01:00
|
|
|
* joininfo_member
|
1997-09-07 07:04:48 +02:00
|
|
|
* Determines whether a node has already been created for a join
|
|
|
|
* between a set of join relations and the relation described by
|
1999-02-14 00:22:53 +01:00
|
|
|
* 'joininfo_list'.
|
1997-09-07 07:04:48 +02:00
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* 'join_relids' is a list of relids corresponding to the join relation
|
|
|
|
* 'joininfo_list' is the list of joininfo nodes against which this is
|
1997-09-07 07:04:48 +02:00
|
|
|
* checked
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* Returns the corresponding node in 'joininfo_list' if such a node
|
1996-07-09 08:22:35 +02:00
|
|
|
* exists.
|
1997-09-07 07:04:48 +02:00
|
|
|
*
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
2000-06-09 00:38:00 +02:00
|
|
|
static JoinInfo *
|
1997-09-08 23:56:23 +02:00
|
|
|
joininfo_member(List *join_relids, List *joininfo_list)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1999-05-25 18:15:34 +02:00
|
|
|
List *i;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
foreach(i, joininfo_list)
|
|
|
|
{
|
1999-05-25 18:15:34 +02:00
|
|
|
JoinInfo *joininfo = (JoinInfo *) lfirst(i);
|
1999-02-18 01:49:48 +01:00
|
|
|
|
2000-02-06 04:27:35 +01:00
|
|
|
if (sameseti(join_relids, joininfo->unjoined_relids))
|
1999-02-18 01:49:48 +01:00
|
|
|
return joininfo;
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
1999-02-18 01:49:48 +01:00
|
|
|
return NULL;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
/*
|
1999-02-14 00:22:53 +01:00
|
|
|
* find_joininfo_node
|
1997-09-07 07:04:48 +02:00
|
|
|
* Find the joininfo node within a relation entry corresponding
|
1999-08-16 04:17:58 +02:00
|
|
|
* to a join between 'this_rel' and the relations in 'join_relids'.
|
|
|
|
* A new node is created and added to the relation entry's joininfo
|
1997-09-07 07:04:48 +02:00
|
|
|
* field if the desired one can't be found.
|
|
|
|
*
|
1996-07-09 08:22:35 +02:00
|
|
|
* Returns a joininfo node.
|
1997-09-07 07:04:48 +02:00
|
|
|
*
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1998-09-01 06:40:42 +02:00
|
|
|
JoinInfo *
|
1999-05-26 00:43:53 +02:00
|
|
|
find_joininfo_node(RelOptInfo *this_rel, Relids join_relids)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1998-09-01 06:40:42 +02:00
|
|
|
JoinInfo *joininfo = joininfo_member(join_relids,
|
1997-09-08 04:41:22 +02:00
|
|
|
this_rel->joininfo);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
if (joininfo == NULL)
|
|
|
|
{
|
1998-09-01 05:29:17 +02:00
|
|
|
joininfo = makeNode(JoinInfo);
|
1999-02-18 01:49:48 +01:00
|
|
|
joininfo->unjoined_relids = join_relids;
|
1999-02-03 21:15:53 +01:00
|
|
|
joininfo->jinfo_restrictinfo = NIL;
|
1997-09-07 07:04:48 +02:00
|
|
|
this_rel->joininfo = lcons(joininfo, this_rel->joininfo);
|
|
|
|
}
|
1998-09-01 05:29:17 +02:00
|
|
|
return joininfo;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|