]> granicus.if.org Git - postgresql/blob - src/backend/optimizer/util/relnode.c
Another PGINDENT run that changes variable indenting and case label indenting. Also...
[postgresql] / src / backend / optimizer / util / relnode.c
1 /*-------------------------------------------------------------------------
2  *
3  * relnode.c--
4  *        Relation manipulation routines
5  *
6  * Copyright (c) 1994, Regents of the University of California
7  *
8  *
9  * IDENTIFICATION
10  *        $Header: /cvsroot/pgsql/src/backend/optimizer/util/relnode.c,v 1.3 1997/09/08 02:25:02 momjian Exp $
11  *
12  *-------------------------------------------------------------------------
13  */
14 #include "postgres.h"
15
16 #include "nodes/relation.h"
17
18 #include "optimizer/internal.h"
19 #include "optimizer/pathnode.h" /* where the decls go */
20 #include "optimizer/plancat.h"
21
22
23
24 /*
25  * get_base_rel--
26  *        Returns relation entry corresponding to 'relid', creating a new one if
27  *        necessary. This is for base relations.
28  *
29  */
30 Rel                *
31 get_base_rel(Query * root, int relid)
32 {
33         List       *relids;
34         Rel                *rel;
35
36         relids = lconsi(relid, NIL);
37         rel = rel_member(relids, root->base_relation_list_);
38         if (rel == NULL)
39         {
40                 rel = makeNode(Rel);
41                 rel->relids = relids;
42                 rel->indexed = false;
43                 rel->pages = 0;
44                 rel->tuples = 0;
45                 rel->width = 0;
46                 rel->targetlist = NIL;
47                 rel->pathlist = NIL;
48                 rel->unorderedpath = (Path *) NULL;
49                 rel->cheapestpath = (Path *) NULL;
50                 rel->pruneable = true;
51                 rel->classlist = NULL;
52                 rel->ordering = NULL;
53                 rel->relam = InvalidOid;
54                 rel->clauseinfo = NIL;
55                 rel->joininfo = NIL;
56                 rel->innerjoin = NIL;
57                 rel->superrels = NIL;
58
59                 root->base_relation_list_ = lcons(rel,
60                                                                                   root->base_relation_list_);
61
62                 /*
63                  * ??? the old lispy C code (get_rel) do a listp(relid) here but
64                  * that can never happen since we already established relid is not
65                  * a list.                                                              -ay 10/94
66                  */
67                 if (relid < 0)
68                 {
69
70                         /*
71                          * If the relation is a materialized relation, assume
72                          * constants for sizes.
73                          */
74                         rel->pages = _TEMP_RELATION_PAGES_;
75                         rel->tuples = _TEMP_RELATION_TUPLES_;
76
77                 }
78                 else
79                 {
80                         bool            hasindex;
81                         int                     pages,
82                                                 tuples;
83
84                         /*
85                          * Otherwise, retrieve relation characteristics from the
86                          * system catalogs.
87                          */
88                         relation_info(root, relid, &hasindex, &pages, &tuples);
89                         rel->indexed = hasindex;
90                         rel->pages = pages;
91                         rel->tuples = tuples;
92                 }
93         }
94         return rel;
95 }
96
97 /*
98  * get_join_rel--
99  *        Returns relation entry corresponding to 'relid' (a list of relids),
100  *        creating a new one if necessary. This is for join relations.
101  *
102  */
103 Rel                *
104 get_join_rel(Query * root, List * relid)
105 {
106         return rel_member(relid, root->join_relation_list_);
107 }
108
109 /*
110  * rel-member--
111  *        Determines whether a relation of id 'relid' is contained within a list
112  *        'rels'.
113  *
114  * Returns the corresponding entry in 'rels' if it is there.
115  *
116  */
117 Rel                *
118 rel_member(List * relid, List * rels)
119 {
120         List       *temp = NIL;
121         List       *temprelid = NIL;
122
123         if (relid != NIL && rels != NIL)
124         {
125                 foreach(temp, rels)
126                 {
127                         temprelid = ((Rel *) lfirst(temp))->relids;
128                         if (same(temprelid, relid))
129                                 return ((Rel *) (lfirst(temp)));
130                 }
131         }
132         return (NULL);
133 }