OSDN Git Service

Rename same() to sameseti() to have a slightly less generic name. Move
[pg-rex/syncrep.git] / src / backend / optimizer / util / joininfo.c
1 /*-------------------------------------------------------------------------
2  *
3  * joininfo.c
4  *        JoinInfo node manipulation routines
5  *
6  * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  *
10  * IDENTIFICATION
11  *        $Header: /cvsroot/pgsql/src/backend/optimizer/util/joininfo.c,v 1.26 2000/02/06 03:27:33 tgl Exp $
12  *
13  *-------------------------------------------------------------------------
14  */
15 #include "postgres.h"
16
17
18 #include "optimizer/joininfo.h"
19
20
21 /*
22  * joininfo_member
23  *        Determines whether a node has already been created for a join
24  *        between a set of join relations and the relation described by
25  *        'joininfo_list'.
26  *
27  * 'join_relids' is a list of relids corresponding to the join relation
28  * 'joininfo_list' is the list of joininfo nodes against which this is
29  *                              checked
30  *
31  * Returns the corresponding node in 'joininfo_list' if such a node
32  * exists.
33  *
34  */
35 JoinInfo   *
36 joininfo_member(List *join_relids, List *joininfo_list)
37 {
38         List       *i;
39
40         foreach(i, joininfo_list)
41         {
42                 JoinInfo   *joininfo = (JoinInfo *) lfirst(i);
43
44                 if (sameseti(join_relids, joininfo->unjoined_relids))
45                         return joininfo;
46         }
47         return NULL;
48 }
49
50
51 /*
52  * find_joininfo_node
53  *        Find the joininfo node within a relation entry corresponding
54  *        to a join between 'this_rel' and the relations in 'join_relids'.
55  *        A new node is created and added to the relation entry's joininfo
56  *        field if the desired one can't be found.
57  *
58  * Returns a joininfo node.
59  *
60  */
61 JoinInfo   *
62 find_joininfo_node(RelOptInfo *this_rel, Relids join_relids)
63 {
64         JoinInfo   *joininfo = joininfo_member(join_relids,
65                                                                                    this_rel->joininfo);
66
67         if (joininfo == NULL)
68         {
69                 joininfo = makeNode(JoinInfo);
70                 joininfo->unjoined_relids = join_relids;
71                 joininfo->jinfo_restrictinfo = NIL;
72                 this_rel->joininfo = lcons(joininfo, this_rel->joininfo);
73         }
74         return joininfo;
75 }