1996-08-28 03:59:28 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* relation.h--
|
1997-09-07 07:04:48 +02:00
|
|
|
* Definitions for internal planner nodes.
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
1999-02-12 06:57:08 +01:00
|
|
|
* $Id: relation.h,v 1.20 1999/02/12 05:57:01 momjian Exp $
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef RELATION_H
|
|
|
|
#define RELATION_H
|
|
|
|
|
1996-11-06 08:44:18 +01:00
|
|
|
#include <nodes/parsenodes.h>
|
|
|
|
#include <nodes/primnodes.h>
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Relid
|
1997-09-07 07:04:48 +02:00
|
|
|
* List of relation identifiers (indexes into the rangetable).
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
typedef List *Relid;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/*
|
1998-07-18 06:22:52 +02:00
|
|
|
* RelOptInfo
|
1997-09-07 07:04:48 +02:00
|
|
|
* Per-base-relation information
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* Parts of this data structure are specific to various scan and join
|
|
|
|
* mechanisms. It didn't seem worth creating new node types for them.
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* relids - List of relation indentifiers
|
|
|
|
* indexed - true if the relation has secondary indices
|
|
|
|
* pages - number of pages in the relation
|
|
|
|
* tuples - number of tuples in the relation
|
|
|
|
* size - number of tuples in the relation after restrictions clauses
|
|
|
|
* have been applied
|
|
|
|
* width - number of bytes per tuple in the relation after the
|
|
|
|
* appropriate projections have been done
|
|
|
|
* targetlist - List of TargetList nodes
|
|
|
|
* pathlist - List of Path nodes, one for each possible method of
|
|
|
|
* generating the relation
|
|
|
|
* cheapestpath - least expensive Path (regardless of final order)
|
|
|
|
* pruneable - flag to let the planner know whether it can prune the plan
|
1999-02-04 04:19:11 +01:00
|
|
|
* space of this RelOptInfo or not.
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* * If the relation is a (secondary) index it will have the following
|
|
|
|
* three fields:
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* classlist - List of PG_AMOPCLASS OIDs for the index
|
|
|
|
* indexkeys - List of base-relation attribute numbers that are index keys
|
|
|
|
* ordering - List of PG_OPERATOR OIDs which order the indexscan result
|
|
|
|
* relam - the OID of the pg_am of the index
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* * The presence of the remaining fields depends on the restrictions
|
|
|
|
* and joins which the relation participates in:
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
1999-02-03 21:15:53 +01:00
|
|
|
* restrictinfo - List of RestrictInfo nodes, containing info about each
|
1997-09-07 07:04:48 +02:00
|
|
|
* qualification clause in which this relation participates
|
|
|
|
* joininfo - List of JoinInfo nodes, containing info about each join
|
|
|
|
* clause in which this relation participates
|
|
|
|
* innerjoin - List of Path nodes that represent indices that may be used
|
|
|
|
* as inner paths of nestloop joins
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
* NB. the last element of the arrays classlist, indexkeys and ordering
|
1997-09-07 07:04:48 +02:00
|
|
|
* is always 0. 2/95 - ay
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
|
|
|
|
1998-07-18 06:22:52 +02:00
|
|
|
typedef struct RelOptInfo
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
NodeTag type;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
/* all relations: */
|
1997-09-08 04:41:22 +02:00
|
|
|
Relid relids;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
/* catalog statistics information */
|
1997-09-08 04:41:22 +02:00
|
|
|
bool indexed;
|
|
|
|
int pages;
|
|
|
|
int tuples;
|
|
|
|
int size;
|
|
|
|
int width;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
/* materialization information */
|
1997-09-08 04:41:22 +02:00
|
|
|
List *targetlist;
|
1999-02-04 02:47:02 +01:00
|
|
|
List *pathlist; /* Path structures */
|
1997-09-08 04:41:22 +02:00
|
|
|
struct Path *cheapestpath;
|
|
|
|
bool pruneable;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
/* used solely by indices: */
|
1997-09-08 04:41:22 +02:00
|
|
|
Oid *classlist; /* classes of AM operators */
|
|
|
|
int *indexkeys; /* keys over which we're indexing */
|
|
|
|
Oid relam; /* OID of the access method (in pg_am) */
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
Oid indproc;
|
|
|
|
List *indpred;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
/* used by various scans and joins: */
|
1997-09-08 04:41:22 +02:00
|
|
|
Oid *ordering; /* OID of operators in sort order */
|
1999-02-04 02:47:02 +01:00
|
|
|
List *restrictinfo; /* RestrictInfo structures */
|
|
|
|
List *joininfo; /* JoinInfo structures */
|
1997-09-08 04:41:22 +02:00
|
|
|
List *innerjoin;
|
|
|
|
List *superrels;
|
1999-02-04 02:47:02 +01:00
|
|
|
} RelOptInfo;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-09-08 23:56:23 +02:00
|
|
|
extern Var *get_expr(TargetEntry *foo);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
typedef struct MergeOrder
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
NodeTag type;
|
|
|
|
Oid join_operator;
|
|
|
|
Oid left_operator;
|
|
|
|
Oid right_operator;
|
|
|
|
Oid left_type;
|
|
|
|
Oid right_type;
|
1997-09-08 23:56:23 +02:00
|
|
|
} MergeOrder;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
typedef enum OrderType
|
|
|
|
{
|
|
|
|
MERGE_ORDER, SORTOP_ORDER
|
1997-09-08 23:56:23 +02:00
|
|
|
} OrderType;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
typedef struct PathOrder
|
|
|
|
{
|
1999-02-09 04:51:42 +01:00
|
|
|
NodeTag type;
|
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
OrderType ordtype;
|
1997-09-07 07:04:48 +02:00
|
|
|
union
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
Oid *sortop;
|
|
|
|
MergeOrder *merge;
|
1999-02-04 02:47:02 +01:00
|
|
|
} ord;
|
1997-09-08 23:56:23 +02:00
|
|
|
} PathOrder;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
typedef struct Path
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
NodeTag type;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1998-09-01 06:40:42 +02:00
|
|
|
RelOptInfo *parent;
|
1997-09-08 04:41:22 +02:00
|
|
|
Cost path_cost;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
NodeTag pathtype;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1999-02-11 15:59:09 +01:00
|
|
|
PathOrder *pathorder;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1999-02-10 04:52:54 +01:00
|
|
|
List *pathkeys; /* This is a List of List of Var nodes.
|
|
|
|
* It is a List of Lists because of multi-key
|
|
|
|
* indexes.
|
|
|
|
*/
|
1997-09-08 04:41:22 +02:00
|
|
|
Cost outerjoincost;
|
|
|
|
Relid joinid;
|
1999-02-03 21:15:53 +01:00
|
|
|
List *loc_restrictinfo;
|
1997-09-08 23:56:23 +02:00
|
|
|
} Path;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
typedef struct IndexPath
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
Path path;
|
|
|
|
List *indexid;
|
|
|
|
List *indexqual;
|
1999-02-04 04:19:11 +01:00
|
|
|
int *indexkeys; /* to transform heap attnos into index ones */
|
1997-09-08 23:56:23 +02:00
|
|
|
} IndexPath;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
typedef struct JoinPath
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
Path path;
|
1999-02-03 21:15:53 +01:00
|
|
|
List *pathinfo;
|
1997-09-08 04:41:22 +02:00
|
|
|
Path *outerjoinpath;
|
|
|
|
Path *innerjoinpath;
|
1997-09-08 23:56:23 +02:00
|
|
|
} JoinPath;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
typedef struct MergePath
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
JoinPath jpath;
|
|
|
|
List *path_mergeclauses;
|
|
|
|
List *outersortkeys;
|
|
|
|
List *innersortkeys;
|
1997-09-08 23:56:23 +02:00
|
|
|
} MergePath;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
typedef struct HashPath
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
JoinPath jpath;
|
|
|
|
List *path_hashclauses;
|
|
|
|
List *outerhashkeys;
|
|
|
|
List *innerhashkeys;
|
1997-09-08 23:56:23 +02:00
|
|
|
} HashPath;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/******
|
|
|
|
* Keys
|
|
|
|
******/
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct OrderKey
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
NodeTag type;
|
|
|
|
int attribute_number;
|
|
|
|
Index array_index;
|
1997-09-08 23:56:23 +02:00
|
|
|
} OrderKey;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct JoinKey
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
NodeTag type;
|
|
|
|
Var *outer;
|
|
|
|
Var *inner;
|
1997-09-08 23:56:23 +02:00
|
|
|
} JoinKey;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/*******
|
|
|
|
* clause info
|
|
|
|
*******/
|
|
|
|
|
1999-02-03 21:15:53 +01:00
|
|
|
typedef struct RestrictInfo
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
NodeTag type;
|
|
|
|
Expr *clause; /* should be an OP clause */
|
|
|
|
Cost selectivity;
|
|
|
|
bool notclause;
|
|
|
|
List *indexids;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1998-08-04 18:44:31 +02:00
|
|
|
/* mergejoin only */
|
|
|
|
MergeOrder *mergejoinorder;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
/* hashjoin only */
|
1997-09-08 04:41:22 +02:00
|
|
|
Oid hashjoinoperator;
|
1999-02-05 20:59:31 +01:00
|
|
|
Relid restrictinfojoinid;
|
1999-02-03 21:15:53 +01:00
|
|
|
} RestrictInfo;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
typedef struct JoinMethod
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
NodeTag type;
|
|
|
|
List *jmkeys;
|
|
|
|
List *clauses;
|
1997-09-08 23:56:23 +02:00
|
|
|
} JoinMethod;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1999-02-04 02:47:02 +01:00
|
|
|
typedef struct HashInfo
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
JoinMethod jmethod;
|
|
|
|
Oid hashop;
|
1999-02-04 02:47:02 +01:00
|
|
|
} HashInfo;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1999-02-04 04:19:11 +01:00
|
|
|
typedef struct MergeInfo
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
JoinMethod jmethod;
|
|
|
|
MergeOrder *m_ordering;
|
1999-02-04 04:19:11 +01:00
|
|
|
} MergeInfo;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1998-09-01 05:29:17 +02:00
|
|
|
typedef struct JoinInfo
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
NodeTag type;
|
|
|
|
List *otherrels;
|
1999-02-03 21:15:53 +01:00
|
|
|
List *jinfo_restrictinfo;
|
1998-08-04 18:44:31 +02:00
|
|
|
bool mergejoinable;
|
1997-09-08 04:41:22 +02:00
|
|
|
bool hashjoinable;
|
|
|
|
bool inactive;
|
1999-02-04 02:47:02 +01:00
|
|
|
} JoinInfo;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
typedef struct Iter
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
NodeTag type;
|
|
|
|
Node *iterexpr;
|
|
|
|
Oid itertype; /* type of the iter expr (use for type
|
1997-09-07 07:04:48 +02:00
|
|
|
* checking) */
|
1997-09-08 23:56:23 +02:00
|
|
|
} Iter;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Stream:
|
1997-09-07 07:04:48 +02:00
|
|
|
** A stream represents a root-to-leaf path in a plan tree (i.e. a tree of
|
1996-08-28 03:59:28 +02:00
|
|
|
** JoinPaths and Paths). The stream includes pointers to all Path nodes,
|
1997-09-07 07:04:48 +02:00
|
|
|
** as well as to any clauses that reside above Path nodes. This structure
|
1996-08-28 03:59:28 +02:00
|
|
|
** is used to make Path nodes and clauses look similar, so that Predicate
|
|
|
|
** Migration can run.
|
|
|
|
**
|
1997-09-07 07:04:48 +02:00
|
|
|
** pathptr -- pointer to the current path node
|
|
|
|
** cinfo -- if NULL, this stream node referes to the path node.
|
|
|
|
** Otherwise this is a pointer to the current clause.
|
1999-02-03 21:15:53 +01:00
|
|
|
** clausetype -- whether cinfo is in loc_restrictinfo or pathinfo in the
|
1997-09-07 07:04:48 +02:00
|
|
|
** path node
|
|
|
|
** upstream -- linked list pointer upwards
|
|
|
|
** downstream -- ditto, downwards
|
|
|
|
** groupup -- whether or not this node is in a group with the node upstream
|
|
|
|
** groupcost -- total cost of the group that node is in
|
|
|
|
** groupsel -- total selectivity of the group that node is in
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
|
|
|
typedef struct Stream *StreamPtr;
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct Stream
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
NodeTag type;
|
|
|
|
Path *pathptr;
|
1999-02-03 21:15:53 +01:00
|
|
|
RestrictInfo *cinfo;
|
1997-09-08 04:41:22 +02:00
|
|
|
int *clausetype;
|
|
|
|
struct Stream *upstream;
|
|
|
|
struct Stream *downstream;
|
|
|
|
bool groupup;
|
|
|
|
Cost groupcost;
|
|
|
|
Cost groupsel;
|
1997-09-08 23:56:23 +02:00
|
|
|
} Stream;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1998-09-01 06:40:42 +02:00
|
|
|
#endif /* RELATION_H */
|