1 /*-------------------------------------------------------------------------
4 * Relation manipulation routines
6 * Copyright (c) 1994, Regents of the University of California
10 * $Header: /cvsroot/pgsql/src/backend/optimizer/util/relnode.c,v 1.3 1997/09/08 02:25:02 momjian Exp $
12 *-------------------------------------------------------------------------
16 #include "nodes/relation.h"
18 #include "optimizer/internal.h"
19 #include "optimizer/pathnode.h" /* where the decls go */
20 #include "optimizer/plancat.h"
26 * Returns relation entry corresponding to 'relid', creating a new one if
27 * necessary. This is for base relations.
31 get_base_rel(Query * root, int relid)
36 relids = lconsi(relid, NIL);
37 rel = rel_member(relids, root->base_relation_list_);
46 rel->targetlist = NIL;
48 rel->unorderedpath = (Path *) NULL;
49 rel->cheapestpath = (Path *) NULL;
50 rel->pruneable = true;
51 rel->classlist = NULL;
53 rel->relam = InvalidOid;
54 rel->clauseinfo = NIL;
59 root->base_relation_list_ = lcons(rel,
60 root->base_relation_list_);
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
71 * If the relation is a materialized relation, assume
72 * constants for sizes.
74 rel->pages = _TEMP_RELATION_PAGES_;
75 rel->tuples = _TEMP_RELATION_TUPLES_;
85 * Otherwise, retrieve relation characteristics from the
88 relation_info(root, relid, &hasindex, &pages, &tuples);
89 rel->indexed = hasindex;
99 * Returns relation entry corresponding to 'relid' (a list of relids),
100 * creating a new one if necessary. This is for join relations.
104 get_join_rel(Query * root, List * relid)
106 return rel_member(relid, root->join_relation_list_);
111 * Determines whether a relation of id 'relid' is contained within a list
114 * Returns the corresponding entry in 'rels' if it is there.
118 rel_member(List * relid, List * rels)
121 List *temprelid = NIL;
123 if (relid != NIL && rels != NIL)
127 temprelid = ((Rel *) lfirst(temp))->relids;
128 if (same(temprelid, relid))
129 return ((Rel *) (lfirst(temp)));