1996-07-09 08:22:35 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* relnode.c
|
1997-09-07 07:04:48 +02:00
|
|
|
* Relation 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-01-26 06:58:53 +01:00
|
|
|
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/relnode.c,v 1.21 2000/01/26 05:56:40 momjian Exp $
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#include "postgres.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include "optimizer/internal.h"
|
1999-07-16 05:14:30 +02:00
|
|
|
#include "optimizer/pathnode.h"
|
1996-07-09 08:22:35 +02:00
|
|
|
#include "optimizer/plancat.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
/*
|
1999-02-14 00:22:53 +01:00
|
|
|
* get_base_rel
|
1997-09-07 07:04:48 +02:00
|
|
|
* Returns relation entry corresponding to 'relid', creating a new one if
|
|
|
|
* necessary. This is for base relations.
|
|
|
|
*
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1998-07-18 06:22:52 +02:00
|
|
|
RelOptInfo *
|
1997-09-08 23:56:23 +02:00
|
|
|
get_base_rel(Query *root, int relid)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1999-08-16 04:17:58 +02:00
|
|
|
Relids relids = lconsi(relid, NIL);
|
1998-09-01 06:40:42 +02:00
|
|
|
RelOptInfo *rel;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1998-08-10 04:26:40 +02:00
|
|
|
rel = rel_member(relids, root->base_rel_list);
|
1997-09-07 07:04:48 +02:00
|
|
|
if (rel == NULL)
|
|
|
|
{
|
1998-07-18 06:22:52 +02:00
|
|
|
rel = makeNode(RelOptInfo);
|
1997-09-07 07:04:48 +02:00
|
|
|
rel->relids = relids;
|
2000-01-09 01:26:47 +01:00
|
|
|
rel->rows = 0;
|
1997-09-07 07:04:48 +02:00
|
|
|
rel->width = 0;
|
|
|
|
rel->targetlist = NIL;
|
|
|
|
rel->pathlist = NIL;
|
|
|
|
rel->cheapestpath = (Path *) NULL;
|
|
|
|
rel->pruneable = true;
|
2000-01-09 01:26:47 +01:00
|
|
|
rel->indexed = false;
|
|
|
|
rel->pages = 0;
|
|
|
|
rel->tuples = 0;
|
1999-02-03 21:15:53 +01:00
|
|
|
rel->restrictinfo = NIL;
|
1997-09-07 07:04:48 +02:00
|
|
|
rel->joininfo = NIL;
|
|
|
|
rel->innerjoin = NIL;
|
|
|
|
|
1998-08-10 04:26:40 +02:00
|
|
|
root->base_rel_list = lcons(rel, root->base_rel_list);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
if (relid < 0)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* If the relation is a materialized relation, assume
|
|
|
|
* constants for sizes.
|
|
|
|
*/
|
1999-02-09 18:03:14 +01:00
|
|
|
rel->pages = _NONAME_RELATION_PAGES_;
|
|
|
|
rel->tuples = _NONAME_RELATION_TUPLES_;
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/*
|
1999-08-16 04:17:58 +02:00
|
|
|
* Otherwise, retrieve relation statistics from the
|
1997-09-07 07:04:48 +02:00
|
|
|
* system catalogs.
|
|
|
|
*/
|
1999-08-16 04:17:58 +02:00
|
|
|
relation_info(root, relid,
|
|
|
|
&rel->indexed, &rel->pages, &rel->tuples);
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return rel;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
/*
|
1999-02-14 00:22:53 +01:00
|
|
|
* get_join_rel
|
1997-09-07 07:04:48 +02:00
|
|
|
* Returns relation entry corresponding to 'relid' (a list of relids),
|
1999-02-18 01:49:48 +01:00
|
|
|
* or NULL.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1998-07-18 06:22:52 +02:00
|
|
|
RelOptInfo *
|
1999-02-18 01:49:48 +01:00
|
|
|
get_join_rel(Query *root, Relids relid)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1998-08-10 04:26:40 +02:00
|
|
|
return rel_member(relid, root->join_rel_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
|
|
|
* rel_member
|
1997-09-07 07:04:48 +02:00
|
|
|
* Determines whether a relation of id 'relid' is contained within a list
|
|
|
|
* 'rels'.
|
|
|
|
*
|
1996-07-09 08:22:35 +02:00
|
|
|
* Returns the corresponding entry in 'rels' if it is there.
|
1997-09-07 07:04:48 +02:00
|
|
|
*
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1998-07-18 06:22:52 +02:00
|
|
|
RelOptInfo *
|
1999-02-18 01:49:48 +01:00
|
|
|
rel_member(Relids relids, List *rels)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1999-02-18 01:49:48 +01:00
|
|
|
if (relids != NIL && rels != NIL)
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
1999-08-16 04:17:58 +02:00
|
|
|
List *temp;
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
foreach(temp, rels)
|
|
|
|
{
|
1999-08-16 04:17:58 +02:00
|
|
|
RelOptInfo *rel = (RelOptInfo *) lfirst(temp);
|
|
|
|
|
|
|
|
if (same(rel->relids, relids))
|
|
|
|
return rel;
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
1998-09-01 05:29:17 +02:00
|
|
|
return NULL;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|