1 /*-------------------------------------------------------------------------
4 * Relation manipulation routines
6 * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
7 * Portions Copyright (c) 1994, Regents of the University of California
11 * $Header: /cvsroot/pgsql/src/backend/optimizer/util/relnode.c,v 1.21 2000/01/26 05:56:40 momjian Exp $
13 *-------------------------------------------------------------------------
18 #include "optimizer/internal.h"
19 #include "optimizer/pathnode.h"
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)
33 Relids relids = lconsi(relid, NIL);
36 rel = rel_member(relids, root->base_rel_list);
39 rel = makeNode(RelOptInfo);
43 rel->targetlist = NIL;
45 rel->cheapestpath = (Path *) NULL;
46 rel->pruneable = true;
50 rel->restrictinfo = NIL;
54 root->base_rel_list = lcons(rel, root->base_rel_list);
59 * If the relation is a materialized relation, assume
60 * constants for sizes.
62 rel->pages = _NONAME_RELATION_PAGES_;
63 rel->tuples = _NONAME_RELATION_TUPLES_;
68 * Otherwise, retrieve relation statistics from the
71 relation_info(root, relid,
72 &rel->indexed, &rel->pages, &rel->tuples);
80 * Returns relation entry corresponding to 'relid' (a list of relids),
84 get_join_rel(Query *root, Relids relid)
86 return rel_member(relid, root->join_rel_list);
91 * Determines whether a relation of id 'relid' is contained within a list
94 * Returns the corresponding entry in 'rels' if it is there.
98 rel_member(Relids relids, List *rels)
100 if (relids != NIL && rels != NIL)
106 RelOptInfo *rel = (RelOptInfo *) lfirst(temp);
108 if (same(rel->relids, relids))