mirror of
https://github.com/postgres/postgres.git
synced 2025-09-03 15:22:11 +03:00
Massive commit to run PGINDENT on all *.c and *.h files.
This commit is contained in:
@@ -1,18 +1,18 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* archive.c--
|
||||
* Support for planning scans on archived relations
|
||||
* Support for planning scans on archived relations
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/Attic/archive.c,v 1.1.1.1 1996/07/09 06:21:38 scrappy Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/Attic/archive.c,v 1.2 1997/09/07 04:44:09 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#include <stdio.h> /* for sprintf() */
|
||||
#include <sys/types.h> /* for u_int in relcache.h */
|
||||
#include <stdio.h> /* for sprintf() */
|
||||
#include <sys/types.h> /* for u_int in relcache.h */
|
||||
#include "postgres.h"
|
||||
|
||||
#include "utils/rel.h"
|
||||
@@ -26,41 +26,44 @@
|
||||
#include "commands/creatinh.h"
|
||||
|
||||
void
|
||||
plan_archive(List *rt)
|
||||
plan_archive(List * rt)
|
||||
{
|
||||
List *rtitem;
|
||||
RangeTblEntry *rte;
|
||||
TimeRange *trange;
|
||||
Relation r;
|
||||
Oid reloid;
|
||||
List *rtitem;
|
||||
RangeTblEntry *rte;
|
||||
TimeRange *trange;
|
||||
Relation r;
|
||||
Oid reloid;
|
||||
|
||||
foreach(rtitem, rt) {
|
||||
rte = lfirst(rtitem);
|
||||
trange = rte->timeRange;
|
||||
if (trange) {
|
||||
reloid = rte->relid;
|
||||
r = RelationIdGetRelation(reloid);
|
||||
if (r->rd_rel->relarch != 'n') {
|
||||
rte->archive = true;
|
||||
}
|
||||
foreach(rtitem, rt)
|
||||
{
|
||||
rte = lfirst(rtitem);
|
||||
trange = rte->timeRange;
|
||||
if (trange)
|
||||
{
|
||||
reloid = rte->relid;
|
||||
r = RelationIdGetRelation(reloid);
|
||||
if (r->rd_rel->relarch != 'n')
|
||||
{
|
||||
rte->archive = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* find_archive_rels -- Given a particular relid, find the archive
|
||||
* relation's relid.
|
||||
* find_archive_rels -- Given a particular relid, find the archive
|
||||
* relation's relid.
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
find_archive_rels(Oid relid)
|
||||
{
|
||||
Relation arel;
|
||||
char *arelName;
|
||||
Relation arel;
|
||||
char *arelName;
|
||||
|
||||
arelName = MakeArchiveName(relid);
|
||||
arel = RelationNameGetRelation(arelName);
|
||||
pfree(arelName);
|
||||
arelName = MakeArchiveName(relid);
|
||||
arel = RelationNameGetRelation(arelName);
|
||||
pfree(arelName);
|
||||
|
||||
return lconsi(arel->rd_id, lconsi(relid, NIL));
|
||||
return lconsi(arel->rd_id, lconsi(relid, NIL));
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -1,13 +1,13 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* preptlist.c--
|
||||
* Routines to preprocess the parse tree target list
|
||||
* Routines to preprocess the parse tree target list
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/preptlist.c,v 1.2 1997/01/22 01:42:38 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/preptlist.c,v 1.3 1997/09/07 04:44:13 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -25,7 +25,7 @@
|
||||
#include "utils/lsyscache.h"
|
||||
#include "utils/palloc.h"
|
||||
|
||||
#include "parser/parsetree.h" /* for getrelid() */
|
||||
#include "parser/parsetree.h" /* for getrelid() */
|
||||
#include "parser/catalog_utils.h"
|
||||
|
||||
#include "optimizer/internal.h"
|
||||
@@ -33,291 +33,315 @@
|
||||
#include "optimizer/clauses.h"
|
||||
#include "optimizer/tlist.h"
|
||||
|
||||
static List *expand_targetlist(List *tlist, Oid relid, int command_type,
|
||||
Index result_relation);
|
||||
static List *replace_matching_resname(List *new_tlist,
|
||||
List *old_tlist);
|
||||
static List *new_relation_targetlist(Oid relid, Index rt_index,
|
||||
NodeTag node_type);
|
||||
|
||||
static List *
|
||||
expand_targetlist(List * tlist, Oid relid, int command_type,
|
||||
Index result_relation);
|
||||
static List *
|
||||
replace_matching_resname(List * new_tlist,
|
||||
List * old_tlist);
|
||||
static List *
|
||||
new_relation_targetlist(Oid relid, Index rt_index,
|
||||
NodeTag node_type);
|
||||
|
||||
/*
|
||||
|
||||
/*
|
||||
* preprocess-targetlist--
|
||||
* Driver for preprocessing the parse tree targetlist.
|
||||
*
|
||||
* 1. Deal with appends and replaces by filling missing attributes
|
||||
* in the target list.
|
||||
* 2. Reset operator OIDs to the appropriate regproc ids.
|
||||
*
|
||||
* Returns the new targetlist.
|
||||
* Driver for preprocessing the parse tree targetlist.
|
||||
*
|
||||
* 1. Deal with appends and replaces by filling missing attributes
|
||||
* in the target list.
|
||||
* 2. Reset operator OIDs to the appropriate regproc ids.
|
||||
*
|
||||
* Returns the new targetlist.
|
||||
*/
|
||||
List *
|
||||
preprocess_targetlist(List *tlist,
|
||||
int command_type,
|
||||
Index result_relation,
|
||||
List *range_table)
|
||||
List *
|
||||
preprocess_targetlist(List * tlist,
|
||||
int command_type,
|
||||
Index result_relation,
|
||||
List * range_table)
|
||||
{
|
||||
List *expanded_tlist = NIL;
|
||||
Oid relid = InvalidOid;
|
||||
List *t_list = NIL;
|
||||
List *temp = NIL;
|
||||
List *expanded_tlist = NIL;
|
||||
Oid relid = InvalidOid;
|
||||
List *t_list = NIL;
|
||||
List *temp = NIL;
|
||||
|
||||
if (result_relation>=1 && command_type != CMD_SELECT) {
|
||||
relid = getrelid(result_relation, range_table);
|
||||
}
|
||||
|
||||
/*
|
||||
* for heap_formtuple to work, the targetlist must match the exact
|
||||
* order of the attributes. We also need to fill in the missing
|
||||
* attributes here. -ay 10/94
|
||||
*/
|
||||
expanded_tlist =
|
||||
expand_targetlist(tlist, relid, command_type, result_relation);
|
||||
if (result_relation >= 1 && command_type != CMD_SELECT)
|
||||
{
|
||||
relid = getrelid(result_relation, range_table);
|
||||
}
|
||||
|
||||
/* XXX should the fix-opids be this early?? */
|
||||
/* was mapCAR */
|
||||
foreach (temp,expanded_tlist) {
|
||||
TargetEntry *tle = lfirst(temp);
|
||||
if (tle->expr)
|
||||
fix_opid(tle->expr);
|
||||
}
|
||||
t_list = copyObject(expanded_tlist);
|
||||
/*
|
||||
* for heap_formtuple to work, the targetlist must match the exact
|
||||
* order of the attributes. We also need to fill in the missing
|
||||
* attributes here. -ay 10/94
|
||||
*/
|
||||
expanded_tlist =
|
||||
expand_targetlist(tlist, relid, command_type, result_relation);
|
||||
|
||||
/* ------------------
|
||||
* for "replace" or "delete" queries, add ctid of the result
|
||||
* relation into the target list so that the ctid can get
|
||||
* propogate through the execution and in the end ExecReplace()
|
||||
* will find the right tuple to replace or delete. This
|
||||
* extra field will be removed in ExecReplace().
|
||||
* For convinient, we append this extra field to the end of
|
||||
* the target list.
|
||||
* ------------------
|
||||
*/
|
||||
if (command_type == CMD_UPDATE || command_type == CMD_DELETE) {
|
||||
TargetEntry *ctid;
|
||||
Resdom *resdom;
|
||||
Var *var;
|
||||
/* XXX should the fix-opids be this early?? */
|
||||
/* was mapCAR */
|
||||
foreach(temp, expanded_tlist)
|
||||
{
|
||||
TargetEntry *tle = lfirst(temp);
|
||||
|
||||
resdom = makeResdom(length(t_list) + 1,
|
||||
27,
|
||||
6,
|
||||
"ctid",
|
||||
0,
|
||||
0,
|
||||
1);
|
||||
if (tle->expr)
|
||||
fix_opid(tle->expr);
|
||||
}
|
||||
t_list = copyObject(expanded_tlist);
|
||||
|
||||
var = makeVar(result_relation, -1, 27, result_relation, -1);
|
||||
/* ------------------
|
||||
* for "replace" or "delete" queries, add ctid of the result
|
||||
* relation into the target list so that the ctid can get
|
||||
* propogate through the execution and in the end ExecReplace()
|
||||
* will find the right tuple to replace or delete. This
|
||||
* extra field will be removed in ExecReplace().
|
||||
* For convinient, we append this extra field to the end of
|
||||
* the target list.
|
||||
* ------------------
|
||||
*/
|
||||
if (command_type == CMD_UPDATE || command_type == CMD_DELETE)
|
||||
{
|
||||
TargetEntry *ctid;
|
||||
Resdom *resdom;
|
||||
Var *var;
|
||||
|
||||
ctid = makeNode(TargetEntry);
|
||||
ctid->resdom = resdom;
|
||||
ctid->expr = (Node *)var;
|
||||
t_list = lappend(t_list, ctid);
|
||||
}
|
||||
resdom = makeResdom(length(t_list) + 1,
|
||||
27,
|
||||
6,
|
||||
"ctid",
|
||||
0,
|
||||
0,
|
||||
1);
|
||||
|
||||
return(t_list);
|
||||
var = makeVar(result_relation, -1, 27, result_relation, -1);
|
||||
|
||||
ctid = makeNode(TargetEntry);
|
||||
ctid->resdom = resdom;
|
||||
ctid->expr = (Node *) var;
|
||||
t_list = lappend(t_list, ctid);
|
||||
}
|
||||
|
||||
return (t_list);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* TARGETLIST EXPANSION
|
||||
* TARGETLIST EXPANSION
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
/*
|
||||
/*
|
||||
* expand-targetlist--
|
||||
* Given a target list as generated by the parser and a result relation,
|
||||
* add targetlist entries for the attributes which have not been used.
|
||||
*
|
||||
* XXX This code is only supposed to work with unnested relations.
|
||||
*
|
||||
* 'tlist' is the original target list
|
||||
* 'relid' is the relid of the result relation
|
||||
* 'command' is the update command
|
||||
*
|
||||
* Given a target list as generated by the parser and a result relation,
|
||||
* add targetlist entries for the attributes which have not been used.
|
||||
*
|
||||
* XXX This code is only supposed to work with unnested relations.
|
||||
*
|
||||
* 'tlist' is the original target list
|
||||
* 'relid' is the relid of the result relation
|
||||
* 'command' is the update command
|
||||
*
|
||||
* Returns the expanded target list, sorted in resno order.
|
||||
*/
|
||||
static List *
|
||||
expand_targetlist(List *tlist,
|
||||
Oid relid,
|
||||
int command_type,
|
||||
Index result_relation)
|
||||
static List *
|
||||
expand_targetlist(List * tlist,
|
||||
Oid relid,
|
||||
int command_type,
|
||||
Index result_relation)
|
||||
{
|
||||
NodeTag node_type = T_Invalid;
|
||||
|
||||
switch (command_type) {
|
||||
case CMD_INSERT:
|
||||
node_type = (NodeTag)T_Const;
|
||||
break;
|
||||
case CMD_UPDATE:
|
||||
node_type = (NodeTag)T_Var;
|
||||
break;
|
||||
}
|
||||
|
||||
if(node_type != T_Invalid) {
|
||||
List *ntlist = new_relation_targetlist(relid,
|
||||
result_relation,
|
||||
node_type);
|
||||
NodeTag node_type = T_Invalid;
|
||||
|
||||
return (replace_matching_resname(ntlist, tlist));
|
||||
} else {
|
||||
return (tlist);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
static List *
|
||||
replace_matching_resname(List *new_tlist, List *old_tlist)
|
||||
{
|
||||
List *temp, *i;
|
||||
List *t_list = NIL;
|
||||
|
||||
foreach (i,new_tlist) {
|
||||
TargetEntry *new_tle = (TargetEntry *)lfirst(i);
|
||||
TargetEntry *matching_old_tl = NULL;
|
||||
|
||||
foreach (temp, old_tlist) {
|
||||
TargetEntry *old_tle = (TargetEntry *)lfirst(temp);
|
||||
|
||||
old_tle = lfirst(temp);
|
||||
if (!strcmp(old_tle->resdom->resname,
|
||||
new_tle->resdom->resname)) {
|
||||
matching_old_tl = old_tle;
|
||||
switch (command_type)
|
||||
{
|
||||
case CMD_INSERT:
|
||||
node_type = (NodeTag) T_Const;
|
||||
break;
|
||||
case CMD_UPDATE:
|
||||
node_type = (NodeTag) T_Var;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(matching_old_tl) {
|
||||
matching_old_tl->resdom->resno =
|
||||
new_tle->resdom->resno;
|
||||
t_list = lappend(t_list, matching_old_tl);
|
||||
}
|
||||
else {
|
||||
t_list = lappend(t_list, new_tle);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* It is possible that 'old_tlist' has some negative
|
||||
* attributes (i.e. negative resnos). This only happens
|
||||
* if this is a replace/append command and we explicitly
|
||||
* specify a system attribute. Of course this is not a very good
|
||||
* idea if this is a user query, but on the other hand the rule
|
||||
* manager uses this mechanism to replace rule locks.
|
||||
*
|
||||
* So, copy all these entries to the end of the target list
|
||||
* and set their 'resjunk' value to 1 to show that these are
|
||||
* special attributes and have to be treated specially by the
|
||||
* executor!
|
||||
*/
|
||||
foreach (temp, old_tlist) {
|
||||
TargetEntry *old_tle, *new_tl;
|
||||
Resdom *newresno;
|
||||
if (node_type != T_Invalid)
|
||||
{
|
||||
List *ntlist = new_relation_targetlist(relid,
|
||||
result_relation,
|
||||
node_type);
|
||||
|
||||
old_tle = lfirst(temp);
|
||||
if (old_tle->resdom->resno < 0) {
|
||||
newresno = (Resdom*) copyObject((Node*)old_tle->resdom);
|
||||
newresno->resno = length(t_list) +1;
|
||||
newresno->resjunk = 1;
|
||||
new_tl = MakeTLE(newresno, old_tle->expr);
|
||||
t_list = lappend(t_list, new_tl);
|
||||
return (replace_matching_resname(ntlist, tlist));
|
||||
}
|
||||
else
|
||||
{
|
||||
return (tlist);
|
||||
}
|
||||
}
|
||||
|
||||
return (t_list);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
static List *
|
||||
replace_matching_resname(List * new_tlist, List * old_tlist)
|
||||
{
|
||||
List *temp,
|
||||
*i;
|
||||
List *t_list = NIL;
|
||||
|
||||
foreach(i, new_tlist)
|
||||
{
|
||||
TargetEntry *new_tle = (TargetEntry *) lfirst(i);
|
||||
TargetEntry *matching_old_tl = NULL;
|
||||
|
||||
foreach(temp, old_tlist)
|
||||
{
|
||||
TargetEntry *old_tle = (TargetEntry *) lfirst(temp);
|
||||
|
||||
old_tle = lfirst(temp);
|
||||
if (!strcmp(old_tle->resdom->resname,
|
||||
new_tle->resdom->resname))
|
||||
{
|
||||
matching_old_tl = old_tle;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (matching_old_tl)
|
||||
{
|
||||
matching_old_tl->resdom->resno =
|
||||
new_tle->resdom->resno;
|
||||
t_list = lappend(t_list, matching_old_tl);
|
||||
}
|
||||
else
|
||||
{
|
||||
t_list = lappend(t_list, new_tle);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* It is possible that 'old_tlist' has some negative attributes (i.e.
|
||||
* negative resnos). This only happens if this is a replace/append
|
||||
* command and we explicitly specify a system attribute. Of course
|
||||
* this is not a very good idea if this is a user query, but on the
|
||||
* other hand the rule manager uses this mechanism to replace rule
|
||||
* locks.
|
||||
*
|
||||
* So, copy all these entries to the end of the target list and set their
|
||||
* 'resjunk' value to 1 to show that these are special attributes and
|
||||
* have to be treated specially by the executor!
|
||||
*/
|
||||
foreach(temp, old_tlist)
|
||||
{
|
||||
TargetEntry *old_tle,
|
||||
*new_tl;
|
||||
Resdom *newresno;
|
||||
|
||||
old_tle = lfirst(temp);
|
||||
if (old_tle->resdom->resno < 0)
|
||||
{
|
||||
newresno = (Resdom *) copyObject((Node *) old_tle->resdom);
|
||||
newresno->resno = length(t_list) + 1;
|
||||
newresno->resjunk = 1;
|
||||
new_tl = MakeTLE(newresno, old_tle->expr);
|
||||
t_list = lappend(t_list, new_tl);
|
||||
}
|
||||
}
|
||||
|
||||
return (t_list);
|
||||
}
|
||||
|
||||
/*
|
||||
* new-relation-targetlist--
|
||||
* Generate a targetlist for the relation with relation OID 'relid'
|
||||
* and rangetable index 'rt-index'.
|
||||
*
|
||||
* Returns the new targetlist.
|
||||
* Generate a targetlist for the relation with relation OID 'relid'
|
||||
* and rangetable index 'rt-index'.
|
||||
*
|
||||
* Returns the new targetlist.
|
||||
*/
|
||||
static List *
|
||||
static List *
|
||||
new_relation_targetlist(Oid relid, Index rt_index, NodeTag node_type)
|
||||
{
|
||||
AttrNumber attno;
|
||||
List *t_list = NIL;
|
||||
char *attname;
|
||||
Oid atttype = 0;
|
||||
int16 typlen = 0;
|
||||
bool attisset = false;
|
||||
/* Oid type_id; */
|
||||
/* type_id = RelationIdGetTypeId(relid); */
|
||||
AttrNumber attno;
|
||||
List *t_list = NIL;
|
||||
char *attname;
|
||||
Oid atttype = 0;
|
||||
int16 typlen = 0;
|
||||
bool attisset = false;
|
||||
|
||||
for(attno=1; attno <= get_relnatts(relid); attno++) {
|
||||
attname = get_attname(/*type_id,*/ relid, attno);
|
||||
atttype = get_atttype(/*type_id,*/ relid, attno);
|
||||
/*
|
||||
* Since this is an append or replace, the size of any set
|
||||
* attribute is the size of the OID used to represent it.
|
||||
*/
|
||||
attisset = get_attisset(/* type_id,*/ relid, attname);
|
||||
if (attisset) {
|
||||
typlen = tlen(type("oid"));
|
||||
} else {
|
||||
typlen = get_typlen(atttype);
|
||||
/* Oid type_id; */
|
||||
/* type_id = RelationIdGetTypeId(relid); */
|
||||
|
||||
for (attno = 1; attno <= get_relnatts(relid); attno++)
|
||||
{
|
||||
attname = get_attname( /* type_id, */ relid, attno);
|
||||
atttype = get_atttype( /* type_id, */ relid, attno);
|
||||
|
||||
/*
|
||||
* Since this is an append or replace, the size of any set
|
||||
* attribute is the size of the OID used to represent it.
|
||||
*/
|
||||
attisset = get_attisset( /* type_id, */ relid, attname);
|
||||
if (attisset)
|
||||
{
|
||||
typlen = tlen(type("oid"));
|
||||
}
|
||||
else
|
||||
{
|
||||
typlen = get_typlen(atttype);
|
||||
}
|
||||
|
||||
switch (node_type)
|
||||
{
|
||||
case T_Const:
|
||||
{
|
||||
struct varlena *typedefault = get_typdefault(atttype);
|
||||
int temp = 0;
|
||||
Const *temp2 = (Const *) NULL;
|
||||
TargetEntry *temp3 = (TargetEntry *) NULL;
|
||||
|
||||
if (typedefault == NULL)
|
||||
temp = 0;
|
||||
else
|
||||
temp = typlen;
|
||||
|
||||
temp2 = makeConst(atttype,
|
||||
temp,
|
||||
(Datum) typedefault,
|
||||
(typedefault == (struct varlena *) NULL),
|
||||
/* XXX this is bullshit */
|
||||
false,
|
||||
false, /* not a set */
|
||||
false);
|
||||
|
||||
temp3 = MakeTLE(makeResdom(attno,
|
||||
atttype,
|
||||
typlen,
|
||||
attname,
|
||||
0,
|
||||
(Oid) 0,
|
||||
0),
|
||||
(Node *) temp2);
|
||||
t_list = lappend(t_list, temp3);
|
||||
break;
|
||||
}
|
||||
case T_Var:
|
||||
{
|
||||
Var *temp_var = (Var *) NULL;
|
||||
TargetEntry *temp_list = NULL;
|
||||
|
||||
temp_var =
|
||||
makeVar(rt_index, attno, atttype, rt_index, attno);
|
||||
|
||||
temp_list = MakeTLE(makeResdom(attno,
|
||||
atttype,
|
||||
typlen,
|
||||
attname,
|
||||
0,
|
||||
(Oid) 0,
|
||||
0),
|
||||
(Node *) temp_var);
|
||||
t_list = lappend(t_list, temp_list);
|
||||
break;
|
||||
}
|
||||
default: /* do nothing */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch (node_type) {
|
||||
case T_Const:
|
||||
{
|
||||
struct varlena *typedefault = get_typdefault(atttype);
|
||||
int temp = 0;
|
||||
Const *temp2 = (Const*)NULL;
|
||||
TargetEntry *temp3 = (TargetEntry *)NULL;
|
||||
|
||||
if (typedefault==NULL)
|
||||
temp = 0;
|
||||
else
|
||||
temp = typlen;
|
||||
|
||||
temp2 = makeConst (atttype,
|
||||
temp,
|
||||
(Datum)typedefault,
|
||||
(typedefault == (struct varlena *)NULL),
|
||||
/* XXX this is bullshit */
|
||||
false,
|
||||
false, /* not a set */
|
||||
false);
|
||||
|
||||
temp3 = MakeTLE (makeResdom(attno,
|
||||
atttype,
|
||||
typlen,
|
||||
attname,
|
||||
0,
|
||||
(Oid)0,
|
||||
0),
|
||||
(Node*)temp2);
|
||||
t_list = lappend(t_list,temp3);
|
||||
break;
|
||||
}
|
||||
case T_Var:
|
||||
{
|
||||
Var *temp_var = (Var*)NULL;
|
||||
TargetEntry *temp_list = NULL;
|
||||
|
||||
temp_var =
|
||||
makeVar(rt_index, attno, atttype, rt_index, attno);
|
||||
|
||||
temp_list = MakeTLE(makeResdom(attno,
|
||||
atttype,
|
||||
typlen,
|
||||
attname,
|
||||
0,
|
||||
(Oid)0,
|
||||
0),
|
||||
(Node*)temp_var);
|
||||
t_list = lappend(t_list,temp_list);
|
||||
break;
|
||||
}
|
||||
default: /* do nothing */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return(t_list);
|
||||
return (t_list);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -1,13 +1,13 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* prepunion.c--
|
||||
* Routines to plan archive, inheritance, union, and version queries
|
||||
* Routines to plan archive, inheritance, union, and version queries
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.3 1997/01/10 20:18:12 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.4 1997/09/07 04:44:14 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -34,370 +34,396 @@
|
||||
#include "optimizer/planner.h"
|
||||
#include "optimizer/prep.h"
|
||||
|
||||
static List *plan_union_query(List *relids, Index rt_index,
|
||||
RangeTblEntry *rt_entry, Query *parse, UnionFlag flag,
|
||||
List **union_rtentriesPtr);
|
||||
static RangeTblEntry *new_rangetable_entry(Oid new_relid,
|
||||
RangeTblEntry *old_entry);
|
||||
static Query *subst_rangetable(Query *root, Index index,
|
||||
RangeTblEntry *new_entry);
|
||||
static void fix_parsetree_attnums(Index rt_index, Oid old_relid,
|
||||
Oid new_relid, Query *parsetree);
|
||||
static Append *make_append(List *unionplans, Index rt_index,
|
||||
List *union_rt_entries, List *tlist);
|
||||
static List *
|
||||
plan_union_query(List * relids, Index rt_index,
|
||||
RangeTblEntry * rt_entry, Query * parse, UnionFlag flag,
|
||||
List ** union_rtentriesPtr);
|
||||
static RangeTblEntry *
|
||||
new_rangetable_entry(Oid new_relid,
|
||||
RangeTblEntry * old_entry);
|
||||
static Query *
|
||||
subst_rangetable(Query * root, Index index,
|
||||
RangeTblEntry * new_entry);
|
||||
static void
|
||||
fix_parsetree_attnums(Index rt_index, Oid old_relid,
|
||||
Oid new_relid, Query * parsetree);
|
||||
static Append *
|
||||
make_append(List * unionplans, Index rt_index,
|
||||
List * union_rt_entries, List * tlist);
|
||||
|
||||
|
||||
/*
|
||||
/*
|
||||
* find-all-inheritors -
|
||||
* Returns a list of relids corresponding to relations that inherit
|
||||
* attributes from any relations listed in either of the argument relid
|
||||
* lists.
|
||||
* Returns a list of relids corresponding to relations that inherit
|
||||
* attributes from any relations listed in either of the argument relid
|
||||
* lists.
|
||||
*/
|
||||
List *
|
||||
find_all_inheritors(List *unexamined_relids,
|
||||
List *examined_relids)
|
||||
List *
|
||||
find_all_inheritors(List * unexamined_relids,
|
||||
List * examined_relids)
|
||||
{
|
||||
List *new_inheritors = NIL;
|
||||
List *new_examined_relids = NIL;
|
||||
List *new_unexamined_relids = NIL;
|
||||
|
||||
/* Find all relations which inherit from members of
|
||||
* 'unexamined-relids' and store them in 'new-inheritors'.
|
||||
*/
|
||||
List *rels = NIL;
|
||||
List *newrels = NIL;
|
||||
|
||||
foreach(rels,unexamined_relids) {
|
||||
newrels = (List*)LispUnioni(find_inheritance_children(lfirsti(rels)),
|
||||
newrels);
|
||||
}
|
||||
new_inheritors = newrels;
|
||||
|
||||
new_examined_relids = (List*)LispUnioni(examined_relids,unexamined_relids);
|
||||
new_unexamined_relids = set_differencei(new_inheritors,
|
||||
new_examined_relids);
|
||||
|
||||
if (new_unexamined_relids==NULL) {
|
||||
return(new_examined_relids);
|
||||
} else {
|
||||
return (find_all_inheritors (new_unexamined_relids,
|
||||
new_examined_relids));
|
||||
}
|
||||
List *new_inheritors = NIL;
|
||||
List *new_examined_relids = NIL;
|
||||
List *new_unexamined_relids = NIL;
|
||||
|
||||
/*
|
||||
* Find all relations which inherit from members of
|
||||
* 'unexamined-relids' and store them in 'new-inheritors'.
|
||||
*/
|
||||
List *rels = NIL;
|
||||
List *newrels = NIL;
|
||||
|
||||
foreach(rels, unexamined_relids)
|
||||
{
|
||||
newrels = (List *) LispUnioni(find_inheritance_children(lfirsti(rels)),
|
||||
newrels);
|
||||
}
|
||||
new_inheritors = newrels;
|
||||
|
||||
new_examined_relids = (List *) LispUnioni(examined_relids, unexamined_relids);
|
||||
new_unexamined_relids = set_differencei(new_inheritors,
|
||||
new_examined_relids);
|
||||
|
||||
if (new_unexamined_relids == NULL)
|
||||
{
|
||||
return (new_examined_relids);
|
||||
}
|
||||
else
|
||||
{
|
||||
return (find_all_inheritors(new_unexamined_relids,
|
||||
new_examined_relids));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* first-matching-rt-entry -
|
||||
* Given a rangetable, find the first rangetable entry that represents
|
||||
* the appropriate special case.
|
||||
*
|
||||
* Returns a rangetable index., Returns -1 if no matches
|
||||
* Given a rangetable, find the first rangetable entry that represents
|
||||
* the appropriate special case.
|
||||
*
|
||||
* Returns a rangetable index., Returns -1 if no matches
|
||||
*/
|
||||
int
|
||||
first_matching_rt_entry (List *rangetable, UnionFlag flag)
|
||||
first_matching_rt_entry(List * rangetable, UnionFlag flag)
|
||||
{
|
||||
int count = 0;
|
||||
List *temp = NIL;
|
||||
int count = 0;
|
||||
List *temp = NIL;
|
||||
|
||||
foreach(temp, rangetable) {
|
||||
RangeTblEntry *rt_entry = lfirst(temp);
|
||||
|
||||
switch(flag) {
|
||||
case INHERITS_FLAG:
|
||||
if (rt_entry->inh)
|
||||
return count+1;
|
||||
break;
|
||||
case ARCHIVE_FLAG:
|
||||
if (rt_entry->archive)
|
||||
return count+1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
foreach(temp, rangetable)
|
||||
{
|
||||
RangeTblEntry *rt_entry = lfirst(temp);
|
||||
|
||||
switch (flag)
|
||||
{
|
||||
case INHERITS_FLAG:
|
||||
if (rt_entry->inh)
|
||||
return count + 1;
|
||||
break;
|
||||
case ARCHIVE_FLAG:
|
||||
if (rt_entry->archive)
|
||||
return count + 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
|
||||
return(-1);
|
||||
|
||||
return (-1);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
/*
|
||||
* plan-union-queries--
|
||||
*
|
||||
* Plans the queries for a given parent relation.
|
||||
*
|
||||
*
|
||||
* Plans the queries for a given parent relation.
|
||||
*
|
||||
* Returns a list containing a list of plans and a list of rangetable
|
||||
* entries to be inserted into an APPEND node.
|
||||
* XXX - what exactly does this mean, look for make_append
|
||||
*/
|
||||
Append *
|
||||
Append *
|
||||
plan_union_queries(Index rt_index,
|
||||
Query *parse,
|
||||
UnionFlag flag)
|
||||
Query * parse,
|
||||
UnionFlag flag)
|
||||
{
|
||||
List *rangetable = parse->rtable;
|
||||
RangeTblEntry *rt_entry = rt_fetch(rt_index,rangetable);
|
||||
List *union_relids = NIL;
|
||||
List *union_plans = NIL;
|
||||
List *union_rt_entries = NIL;
|
||||
|
||||
switch (flag) {
|
||||
case INHERITS_FLAG:
|
||||
union_relids =
|
||||
find_all_inheritors(lconsi(rt_entry->relid,
|
||||
NIL),
|
||||
NIL);
|
||||
break;
|
||||
List *rangetable = parse->rtable;
|
||||
RangeTblEntry *rt_entry = rt_fetch(rt_index, rangetable);
|
||||
List *union_relids = NIL;
|
||||
List *union_plans = NIL;
|
||||
List *union_rt_entries = NIL;
|
||||
|
||||
#if 0
|
||||
case UNION_FLAG:
|
||||
switch (flag)
|
||||
{
|
||||
Index rt_index = 0;
|
||||
union_plans = handleunion(root,rangetable,tlist,qual);
|
||||
return (make_append (union_plans,
|
||||
rt_index, rangetable,
|
||||
((Plan*)lfirst(union_plans))->targetlist ));
|
||||
}
|
||||
break;
|
||||
case INHERITS_FLAG:
|
||||
union_relids =
|
||||
find_all_inheritors(lconsi(rt_entry->relid,
|
||||
NIL),
|
||||
NIL);
|
||||
break;
|
||||
|
||||
#if 0
|
||||
case UNION_FLAG:
|
||||
{
|
||||
Index rt_index = 0;
|
||||
|
||||
union_plans = handleunion(root, rangetable, tlist, qual);
|
||||
return (make_append(union_plans,
|
||||
rt_index, rangetable,
|
||||
((Plan *) lfirst(union_plans))->targetlist));
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
case VERSION_FLAG:
|
||||
union_relids = VersionGetParents(rt_entry->relid);
|
||||
break;
|
||||
|
||||
case ARCHIVE_FLAG:
|
||||
union_relids = find_archive_rels(rt_entry->relid);
|
||||
break;
|
||||
|
||||
default:
|
||||
/* do nothing */
|
||||
break;
|
||||
}
|
||||
case VERSION_FLAG:
|
||||
union_relids = VersionGetParents(rt_entry->relid);
|
||||
break;
|
||||
|
||||
/*
|
||||
* Remove the flag for this relation, since we're about to handle it
|
||||
* (do it before recursing!).
|
||||
* XXX destructive parse tree change
|
||||
*/
|
||||
switch(flag) {
|
||||
case INHERITS_FLAG:
|
||||
rt_fetch(rt_index,rangetable)->inh = false;
|
||||
break;
|
||||
case ARCHIVE_FLAG:
|
||||
rt_fetch(rt_index,rangetable)->archive = false;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
case ARCHIVE_FLAG:
|
||||
union_relids = find_archive_rels(rt_entry->relid);
|
||||
break;
|
||||
|
||||
/* XXX - can't find any reason to sort union-relids
|
||||
* as paul did, so we're leaving it out for now
|
||||
* (maybe forever) - jeff & lp
|
||||
*
|
||||
* [maybe so. btw, jeff & lp did the lisp conversion, according to Paul.
|
||||
* -- ay 10/94.]
|
||||
*/
|
||||
union_plans = plan_union_query(union_relids, rt_index, rt_entry,
|
||||
parse, flag, &union_rt_entries);
|
||||
|
||||
return (make_append(union_plans,
|
||||
rt_index,
|
||||
union_rt_entries,
|
||||
((Plan*)lfirst(union_plans))->targetlist));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* plan-union-query--
|
||||
* Returns a list of plans for 'relids' and a list of range table entries
|
||||
* in union_rtentries.
|
||||
*/
|
||||
static List *
|
||||
plan_union_query(List *relids,
|
||||
Index rt_index,
|
||||
RangeTblEntry *rt_entry,
|
||||
Query *root,
|
||||
UnionFlag flag,
|
||||
List **union_rtentriesPtr)
|
||||
{
|
||||
List *i;
|
||||
List *union_plans = NIL;
|
||||
List *union_rtentries = NIL;
|
||||
|
||||
foreach (i, relids) {
|
||||
int relid = lfirsti(i);
|
||||
RangeTblEntry *new_rt_entry = new_rangetable_entry(relid,
|
||||
rt_entry);
|
||||
Query *new_root = subst_rangetable(root,
|
||||
rt_index,
|
||||
new_rt_entry);
|
||||
|
||||
/* reset the uniqueflag and sortclause in parse tree root, so that
|
||||
* sorting will only be done once after append
|
||||
*/
|
||||
/* new_root->uniqueFlag = false; */
|
||||
new_root->uniqueFlag = NULL;
|
||||
new_root->sortClause = NULL;
|
||||
if (flag == ARCHIVE_FLAG) {
|
||||
/*
|
||||
* the entire union query uses the same (most recent) schema.
|
||||
* to do otherwise would require either ragged tuples or careful
|
||||
* archiving and interpretation of pg_attribute...
|
||||
*/
|
||||
} else {
|
||||
fix_parsetree_attnums(rt_index,
|
||||
rt_entry->relid,
|
||||
relid,
|
||||
new_root);
|
||||
default:
|
||||
/* do nothing */
|
||||
break;
|
||||
}
|
||||
|
||||
union_plans = lappend(union_plans, planner(new_root));
|
||||
union_rtentries = lappend(union_rtentries, new_rt_entry);
|
||||
}
|
||||
/*
|
||||
* Remove the flag for this relation, since we're about to handle it
|
||||
* (do it before recursing!). XXX destructive parse tree change
|
||||
*/
|
||||
switch (flag)
|
||||
{
|
||||
case INHERITS_FLAG:
|
||||
rt_fetch(rt_index, rangetable)->inh = false;
|
||||
break;
|
||||
case ARCHIVE_FLAG:
|
||||
rt_fetch(rt_index, rangetable)->archive = false;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
*union_rtentriesPtr = union_rtentries;
|
||||
return(union_plans);
|
||||
/*
|
||||
* XXX - can't find any reason to sort union-relids as paul did, so
|
||||
* we're leaving it out for now (maybe forever) - jeff & lp
|
||||
*
|
||||
* [maybe so. btw, jeff & lp did the lisp conversion, according to Paul.
|
||||
* -- ay 10/94.]
|
||||
*/
|
||||
union_plans = plan_union_query(union_relids, rt_index, rt_entry,
|
||||
parse, flag, &union_rt_entries);
|
||||
|
||||
return (make_append(union_plans,
|
||||
rt_index,
|
||||
union_rt_entries,
|
||||
((Plan *) lfirst(union_plans))->targetlist));
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
/*
|
||||
* plan-union-query--
|
||||
* Returns a list of plans for 'relids' and a list of range table entries
|
||||
* in union_rtentries.
|
||||
*/
|
||||
static List *
|
||||
plan_union_query(List * relids,
|
||||
Index rt_index,
|
||||
RangeTblEntry * rt_entry,
|
||||
Query * root,
|
||||
UnionFlag flag,
|
||||
List ** union_rtentriesPtr)
|
||||
{
|
||||
List *i;
|
||||
List *union_plans = NIL;
|
||||
List *union_rtentries = NIL;
|
||||
|
||||
foreach(i, relids)
|
||||
{
|
||||
int relid = lfirsti(i);
|
||||
RangeTblEntry *new_rt_entry = new_rangetable_entry(relid,
|
||||
rt_entry);
|
||||
Query *new_root = subst_rangetable(root,
|
||||
rt_index,
|
||||
new_rt_entry);
|
||||
|
||||
/*
|
||||
* reset the uniqueflag and sortclause in parse tree root, so that
|
||||
* sorting will only be done once after append
|
||||
*/
|
||||
/* new_root->uniqueFlag = false; */
|
||||
new_root->uniqueFlag = NULL;
|
||||
new_root->sortClause = NULL;
|
||||
if (flag == ARCHIVE_FLAG)
|
||||
{
|
||||
|
||||
/*
|
||||
* the entire union query uses the same (most recent) schema.
|
||||
* to do otherwise would require either ragged tuples or
|
||||
* careful archiving and interpretation of pg_attribute...
|
||||
*/
|
||||
}
|
||||
else
|
||||
{
|
||||
fix_parsetree_attnums(rt_index,
|
||||
rt_entry->relid,
|
||||
relid,
|
||||
new_root);
|
||||
}
|
||||
|
||||
union_plans = lappend(union_plans, planner(new_root));
|
||||
union_rtentries = lappend(union_rtentries, new_rt_entry);
|
||||
}
|
||||
|
||||
*union_rtentriesPtr = union_rtentries;
|
||||
return (union_plans);
|
||||
}
|
||||
|
||||
/*
|
||||
* new-rangetable-entry -
|
||||
* Replaces the name and relid of 'old-entry' with the values for
|
||||
* 'new-relid'.
|
||||
*
|
||||
* Returns a copy of 'old-entry' with the parameters substituted.
|
||||
* Replaces the name and relid of 'old-entry' with the values for
|
||||
* 'new-relid'.
|
||||
*
|
||||
* Returns a copy of 'old-entry' with the parameters substituted.
|
||||
*/
|
||||
static RangeTblEntry *
|
||||
new_rangetable_entry(Oid new_relid, RangeTblEntry *old_entry)
|
||||
new_rangetable_entry(Oid new_relid, RangeTblEntry * old_entry)
|
||||
{
|
||||
RangeTblEntry *new_entry = copyObject(old_entry);
|
||||
RangeTblEntry *new_entry = copyObject(old_entry);
|
||||
|
||||
/* ??? someone tell me what the following is doing! - ay 11/94 */
|
||||
if (!strcmp(new_entry->refname, "*CURRENT*") ||
|
||||
!strcmp(new_entry->refname, "*NEW*"))
|
||||
new_entry->refname = get_rel_name(new_relid);
|
||||
else
|
||||
new_entry->relname = get_rel_name(new_relid);
|
||||
/* ??? someone tell me what the following is doing! - ay 11/94 */
|
||||
if (!strcmp(new_entry->refname, "*CURRENT*") ||
|
||||
!strcmp(new_entry->refname, "*NEW*"))
|
||||
new_entry->refname = get_rel_name(new_relid);
|
||||
else
|
||||
new_entry->relname = get_rel_name(new_relid);
|
||||
|
||||
new_entry->relid = new_relid;
|
||||
return(new_entry);
|
||||
new_entry->relid = new_relid;
|
||||
return (new_entry);
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* subst-rangetable--
|
||||
* Replaces the 'index'th rangetable entry in 'root' with 'new-entry'.
|
||||
*
|
||||
* Replaces the 'index'th rangetable entry in 'root' with 'new-entry'.
|
||||
*
|
||||
* Returns a new copy of 'root'.
|
||||
*/
|
||||
static Query *
|
||||
subst_rangetable(Query *root, Index index, RangeTblEntry *new_entry)
|
||||
static Query *
|
||||
subst_rangetable(Query * root, Index index, RangeTblEntry * new_entry)
|
||||
{
|
||||
Query *new_root = copyObject(root);
|
||||
List *temp = NIL;
|
||||
int i = 0;
|
||||
Query *new_root = copyObject(root);
|
||||
List *temp = NIL;
|
||||
int i = 0;
|
||||
|
||||
for(temp = new_root->rtable,i =1; i < index; temp =lnext(temp),i++)
|
||||
;
|
||||
lfirst(temp) = new_entry;
|
||||
for (temp = new_root->rtable, i = 1; i < index; temp = lnext(temp), i++)
|
||||
;
|
||||
lfirst(temp) = new_entry;
|
||||
|
||||
return (new_root);
|
||||
return (new_root);
|
||||
}
|
||||
|
||||
static void
|
||||
fix_parsetree_attnums_nodes(Index rt_index,
|
||||
Oid old_relid,
|
||||
Oid new_relid,
|
||||
Node *node)
|
||||
Oid old_relid,
|
||||
Oid new_relid,
|
||||
Node * node)
|
||||
{
|
||||
if (node==NULL)
|
||||
return;
|
||||
|
||||
switch(nodeTag(node)) {
|
||||
case T_TargetEntry:
|
||||
{
|
||||
TargetEntry *tle = (TargetEntry *)node;
|
||||
|
||||
fix_parsetree_attnums_nodes(rt_index, old_relid, new_relid,
|
||||
tle->expr);
|
||||
}
|
||||
break;
|
||||
case T_Expr:
|
||||
{
|
||||
Expr *expr = (Expr *)node;
|
||||
fix_parsetree_attnums_nodes(rt_index, old_relid, new_relid,
|
||||
(Node*)expr->args);
|
||||
}
|
||||
break;
|
||||
case T_Var:
|
||||
{
|
||||
Var *var = (Var *)node;
|
||||
Oid old_typeid, new_typeid;
|
||||
if (node == NULL)
|
||||
return;
|
||||
|
||||
/* old_typeid = RelationIdGetTypeId(old_relid);*/
|
||||
/* new_typeid = RelationIdGetTypeId(new_relid);*/
|
||||
old_typeid = old_relid;
|
||||
new_typeid = new_relid;
|
||||
|
||||
if (var->varno == rt_index && var->varattno != 0) {
|
||||
var->varattno =
|
||||
get_attnum(new_typeid,
|
||||
get_attname(old_typeid, var->varattno));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case T_List:
|
||||
switch (nodeTag(node))
|
||||
{
|
||||
List *l;
|
||||
foreach(l, (List*)node) {
|
||||
fix_parsetree_attnums_nodes(rt_index, old_relid, new_relid,
|
||||
(Node*)lfirst(l));
|
||||
}
|
||||
case T_TargetEntry:
|
||||
{
|
||||
TargetEntry *tle = (TargetEntry *) node;
|
||||
|
||||
fix_parsetree_attnums_nodes(rt_index, old_relid, new_relid,
|
||||
tle->expr);
|
||||
}
|
||||
break;
|
||||
case T_Expr:
|
||||
{
|
||||
Expr *expr = (Expr *) node;
|
||||
|
||||
fix_parsetree_attnums_nodes(rt_index, old_relid, new_relid,
|
||||
(Node *) expr->args);
|
||||
}
|
||||
break;
|
||||
case T_Var:
|
||||
{
|
||||
Var *var = (Var *) node;
|
||||
Oid old_typeid,
|
||||
new_typeid;
|
||||
|
||||
/* old_typeid = RelationIdGetTypeId(old_relid);*/
|
||||
/* new_typeid = RelationIdGetTypeId(new_relid);*/
|
||||
old_typeid = old_relid;
|
||||
new_typeid = new_relid;
|
||||
|
||||
if (var->varno == rt_index && var->varattno != 0)
|
||||
{
|
||||
var->varattno =
|
||||
get_attnum(new_typeid,
|
||||
get_attname(old_typeid, var->varattno));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case T_List:
|
||||
{
|
||||
List *l;
|
||||
|
||||
foreach(l, (List *) node)
|
||||
{
|
||||
fix_parsetree_attnums_nodes(rt_index, old_relid, new_relid,
|
||||
(Node *) lfirst(l));
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
/*
|
||||
* fix-parsetree-attnums--
|
||||
* Replaces attribute numbers from the relation represented by
|
||||
* 'old-relid' in 'parsetree' with the attribute numbers from
|
||||
* 'new-relid'.
|
||||
*
|
||||
* Replaces attribute numbers from the relation represented by
|
||||
* 'old-relid' in 'parsetree' with the attribute numbers from
|
||||
* 'new-relid'.
|
||||
*
|
||||
* Returns the destructively-modified parsetree.
|
||||
*
|
||||
*
|
||||
*/
|
||||
static void
|
||||
fix_parsetree_attnums(Index rt_index,
|
||||
Oid old_relid,
|
||||
Oid new_relid,
|
||||
Query *parsetree)
|
||||
Oid old_relid,
|
||||
Oid new_relid,
|
||||
Query * parsetree)
|
||||
{
|
||||
if (old_relid == new_relid)
|
||||
return;
|
||||
if (old_relid == new_relid)
|
||||
return;
|
||||
|
||||
fix_parsetree_attnums_nodes(rt_index, old_relid, new_relid,
|
||||
(Node*)parsetree->targetList);
|
||||
fix_parsetree_attnums_nodes(rt_index, old_relid, new_relid,
|
||||
parsetree->qual);
|
||||
fix_parsetree_attnums_nodes(rt_index, old_relid, new_relid,
|
||||
(Node *) parsetree->targetList);
|
||||
fix_parsetree_attnums_nodes(rt_index, old_relid, new_relid,
|
||||
parsetree->qual);
|
||||
}
|
||||
|
||||
static Append *
|
||||
make_append(List *unionplans,
|
||||
Index rt_index,
|
||||
List *union_rt_entries,
|
||||
List *tlist)
|
||||
static Append *
|
||||
make_append(List * unionplans,
|
||||
Index rt_index,
|
||||
List * union_rt_entries,
|
||||
List * tlist)
|
||||
{
|
||||
Append *node = makeNode(Append);
|
||||
Append *node = makeNode(Append);
|
||||
|
||||
node->unionplans = unionplans;
|
||||
node->unionrelid = rt_index;
|
||||
node->unionrtentries = union_rt_entries;
|
||||
node->plan.cost = 0.0;
|
||||
node->plan.state = (EState*)NULL;
|
||||
node->plan.targetlist = tlist;
|
||||
node->plan.qual = NIL;
|
||||
node->plan.lefttree = (Plan*)NULL;
|
||||
node->plan.righttree = (Plan*)NULL;
|
||||
node->unionplans = unionplans;
|
||||
node->unionrelid = rt_index;
|
||||
node->unionrtentries = union_rt_entries;
|
||||
node->plan.cost = 0.0;
|
||||
node->plan.state = (EState *) NULL;
|
||||
node->plan.targetlist = tlist;
|
||||
node->plan.qual = NIL;
|
||||
node->plan.lefttree = (Plan *) NULL;
|
||||
node->plan.righttree = (Plan *) NULL;
|
||||
|
||||
return(node);
|
||||
return (node);
|
||||
}
|
||||
|
Reference in New Issue
Block a user