mirror of
https://github.com/postgres/postgres.git
synced 2025-11-07 19:06:32 +03:00
pgindent run before 6.3 release, with Thomas' requested changes.
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
* geqo_erx.c--
|
||||
* edge recombination crossover [ER]
|
||||
*
|
||||
* $Id: geqo_erx.c,v 1.7 1998/01/07 21:03:40 momjian Exp $
|
||||
* $Id: geqo_erx.c,v 1.8 1998/02/26 04:32:20 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -65,7 +65,7 @@ static Gene edge_failure(Gene *gene, int index, Edge *edge_table, int num_gene);
|
||||
*
|
||||
*/
|
||||
|
||||
Edge *
|
||||
Edge *
|
||||
alloc_edge_table(int num_gene)
|
||||
{
|
||||
Edge *edge_table;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: geqo_eval.c,v 1.17 1998/01/07 21:03:42 momjian Exp $
|
||||
* $Id: geqo_eval.c,v 1.18 1998/02/26 04:32:21 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -98,7 +98,7 @@ geqo_eval(Query *root, Gene *tour, int num_gene)
|
||||
*
|
||||
* Returns a new join relation incorporating all joins in a left-sided tree.
|
||||
*/
|
||||
Rel *
|
||||
Rel *
|
||||
gimme_tree(Query *root, Gene *tour, int rel_count, int num_gene, Rel *outer_rel)
|
||||
{
|
||||
Rel *inner_rel; /* current relation */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: geqo_main.c,v 1.6 1997/09/08 21:44:25 momjian Exp $
|
||||
* $Id: geqo_main.c,v 1.7 1998/02/26 04:32:22 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -63,7 +63,7 @@
|
||||
* similar to a constrained Traveling Salesman Problem (TSP)
|
||||
*/
|
||||
|
||||
Rel *
|
||||
Rel *
|
||||
geqo(Query *root)
|
||||
{
|
||||
int generation;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: geqo_paths.c,v 1.7 1997/09/08 21:44:32 momjian Exp $
|
||||
* $Id: geqo_paths.c,v 1.8 1998/02/26 04:32:23 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -39,7 +39,7 @@ static Path *set_paths(Rel *rel, Path *unorderedpath);
|
||||
* Returns the resulting list.
|
||||
*
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
geqo_prune_rels(List *rel_list)
|
||||
{
|
||||
List *temp_list = NIL;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: geqo_pool.c,v 1.4 1997/09/08 21:44:34 momjian Exp $
|
||||
* $Id: geqo_pool.c,v 1.5 1998/02/26 04:32:23 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -50,7 +50,7 @@ static int compare(void *arg1, void *arg2);
|
||||
* alloc-pool--
|
||||
* allocates memory for GA pool
|
||||
*/
|
||||
Pool *
|
||||
Pool *
|
||||
alloc_pool(int pool_size, int string_length)
|
||||
{
|
||||
Pool *new_pool;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* geqo_recombination.c--
|
||||
* misc recombination procedures
|
||||
*
|
||||
* $Id: geqo_recombination.c,v 1.4 1997/09/08 21:44:36 momjian Exp $
|
||||
* $Id: geqo_recombination.c,v 1.5 1998/02/26 04:32:25 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -84,7 +84,7 @@ init_tour(Gene *tour, int num_gene)
|
||||
* allocate memory for city table
|
||||
*
|
||||
*/
|
||||
City *
|
||||
City *
|
||||
alloc_city_table(int num_gene)
|
||||
{
|
||||
City *city_table;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/allpaths.c,v 1.14 1997/12/21 05:18:18 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/allpaths.c,v 1.15 1998/02/26 04:32:27 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -53,7 +53,7 @@ static List *find_join_paths(Query *root, List *outer_rels, int levels_needed);
|
||||
*
|
||||
* 'rels' is the list of single relation entries appearing in the query
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
find_paths(Query *root, List *rels)
|
||||
{
|
||||
int levels_needed;
|
||||
@@ -189,66 +189,69 @@ find_join_paths(Query *root, List *outer_rels, int levels_needed)
|
||||
* rest will be deprecated in case of GEQO *
|
||||
*******************************************/
|
||||
|
||||
while (--levels_needed)
|
||||
{
|
||||
while (--levels_needed)
|
||||
{
|
||||
|
||||
/*
|
||||
* Determine all possible pairs of relations to be joined at this
|
||||
* level. Determine paths for joining these relation pairs and modify
|
||||
* 'new-rels' accordingly, then eliminate redundant join relations.
|
||||
* level. Determine paths for joining these relation pairs and
|
||||
* modify 'new-rels' accordingly, then eliminate redundant join
|
||||
* relations.
|
||||
*/
|
||||
new_rels = find_join_rels(root, outer_rels);
|
||||
|
||||
|
||||
find_all_join_paths(root, new_rels);
|
||||
|
||||
|
||||
prune_joinrels(new_rels);
|
||||
|
||||
|
||||
#if 0
|
||||
|
||||
|
||||
/*
|
||||
* * for each expensive predicate in each path in each distinct rel, *
|
||||
* consider doing pullup -- JMH
|
||||
* * for each expensive predicate in each path in each distinct
|
||||
* rel, * consider doing pullup -- JMH
|
||||
*/
|
||||
if (XfuncMode != XFUNC_NOPULL && XfuncMode != XFUNC_OFF)
|
||||
foreach(x, new_rels)
|
||||
xfunc_trypullup((Rel *) lfirst(x));
|
||||
#endif
|
||||
|
||||
|
||||
prune_rel_paths(new_rels);
|
||||
|
||||
|
||||
if (BushyPlanFlag)
|
||||
{
|
||||
|
||||
|
||||
/*
|
||||
* In case of bushy trees if there is still a join between a join
|
||||
* relation and another relation, add a new joininfo that involves
|
||||
* the join relation to the joininfo list of the other relation
|
||||
* In case of bushy trees if there is still a join between a
|
||||
* join relation and another relation, add a new joininfo that
|
||||
* involves the join relation to the joininfo list of the
|
||||
* other relation
|
||||
*/
|
||||
add_new_joininfos(root, new_rels, outer_rels);
|
||||
}
|
||||
|
||||
|
||||
foreach(x, new_rels)
|
||||
{
|
||||
rel = (Rel *) lfirst(x);
|
||||
if (rel->size <= 0)
|
||||
rel->size = compute_rel_size(rel);
|
||||
rel->width = compute_rel_width(rel);
|
||||
|
||||
/*#define OPTIMIZER_DEBUG*/
|
||||
|
||||
/* #define OPTIMIZER_DEBUG */
|
||||
#ifdef OPTIMIZER_DEBUG
|
||||
printf("levels left: %d\n", levels_left);
|
||||
debug_print_rel(root, rel);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
if (BushyPlanFlag)
|
||||
{
|
||||
|
||||
|
||||
/*
|
||||
* prune rels that have been completely incorporated into new join
|
||||
* rels
|
||||
* prune rels that have been completely incorporated into new
|
||||
* join rels
|
||||
*/
|
||||
outer_rels = prune_oldrels(outer_rels);
|
||||
|
||||
|
||||
/*
|
||||
* merge join rels if then contain the same list of base rels
|
||||
*/
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/clausesel.c,v 1.5 1998/02/13 03:29:36 vadim Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/clausesel.c,v 1.6 1998/02/26 04:32:29 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -273,16 +273,17 @@ compute_selec(Query *root, List *clauses, List *or_selectivities)
|
||||
/* this isn't an Oper, it's a Func!! */
|
||||
|
||||
/*
|
||||
* This is not an operator, so we guess at the selectivity.
|
||||
* THIS IS A HACK TO GET V4 OUT THE DOOR. FUNCS SHOULD BE ABLE
|
||||
* TO HAVE SELECTIVITIES THEMSELVES. -- JMH 7/9/92
|
||||
* This is not an operator, so we guess at the selectivity. THIS
|
||||
* IS A HACK TO GET V4 OUT THE DOOR. FUNCS SHOULD BE ABLE TO HAVE
|
||||
* SELECTIVITIES THEMSELVES. -- JMH 7/9/92
|
||||
*/
|
||||
s1 = 0.1;
|
||||
}
|
||||
else if (is_subplan ((Node *) clause))
|
||||
else if (is_subplan((Node *) clause))
|
||||
{
|
||||
|
||||
/*
|
||||
* Just for the moment! FIX ME! - vadim 02/04/98
|
||||
* Just for the moment! FIX ME! - vadim 02/04/98
|
||||
*/
|
||||
s1 = 1.0;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/hashutils.c,v 1.4 1997/09/08 21:44:51 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/hashutils.c,v 1.5 1998/02/26 04:32:30 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -34,7 +34,7 @@ static HInfo *match_hashop_hashinfo(Oid hashop, List *hashinfo_list);
|
||||
* Returns the new list of hashinfo nodes.
|
||||
*
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
group_clauses_by_hashop(List *clauseinfo_list,
|
||||
int inner_relid)
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/indxpath.c,v 1.13 1998/02/13 03:29:39 vadim Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/indxpath.c,v 1.14 1998/02/26 04:32:33 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -113,7 +113,7 @@ static bool SingleAttributeIndex(Rel *index);
|
||||
* Returns a list of index nodes.
|
||||
*
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
find_index_paths(Query *root,
|
||||
Rel *rel,
|
||||
List *indices,
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/joinrels.c,v 1.7 1997/09/08 21:45:00 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/joinrels.c,v 1.8 1998/02/26 04:32:38 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -58,7 +58,7 @@ set_joinrel_size(Rel *joinrel, Rel *outer_rel, Rel *inner_rel,
|
||||
*
|
||||
* Returns a list of rel nodes corresponding to the new join relations.
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
find_join_rels(Query *root, List *outer_rels)
|
||||
{
|
||||
List *joins = NIL;
|
||||
@@ -486,7 +486,7 @@ add_new_joininfos(Query *root, List *joinrels, List *outerrels)
|
||||
*
|
||||
* Returns the list of final join relations.
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
final_join_rels(List *join_rel_list)
|
||||
{
|
||||
List *xrel = NIL;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/joinutils.c,v 1.4 1997/09/08 21:45:01 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/joinutils.c,v 1.5 1998/02/26 04:32:40 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -73,7 +73,7 @@ new_matching_subkeys(Var *subkey, List *considered_subkeys,
|
||||
* Returns a list of matched join keys and a list of matched join clauses
|
||||
* in matchedJoinClausesPtr. - ay 11/94
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
match_pathkeys_joinkeys(List *pathkeys,
|
||||
List *joinkeys,
|
||||
List *joinclauses,
|
||||
@@ -211,7 +211,7 @@ every_func(List *joinkeys, List *pathkey, int which_subkey)
|
||||
* match_paths_joinkeys -
|
||||
* find the cheapest path that matches the join keys
|
||||
*/
|
||||
Path *
|
||||
Path *
|
||||
match_paths_joinkeys(List *joinkeys,
|
||||
PathOrder *ordering,
|
||||
List *paths,
|
||||
@@ -263,7 +263,7 @@ match_paths_joinkeys(List *joinkeys,
|
||||
* Returns a list of pathkeys: ((tlvar1)(tlvar2)...(tlvarN)).
|
||||
* [I've no idea why they have to be list of lists. Should be fixed. -ay 12/94]
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
extract_path_keys(List *joinkeys,
|
||||
List *tlist,
|
||||
int which_subkey)
|
||||
@@ -325,7 +325,7 @@ extract_path_keys(List *joinkeys,
|
||||
* Returns the list of new path keys.
|
||||
*
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
new_join_pathkeys(List *outer_pathkeys,
|
||||
List *join_rel_tlist,
|
||||
List *joinclauses)
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/mergeutils.c,v 1.4 1997/09/08 21:45:02 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/mergeutils.c,v 1.5 1998/02/26 04:32:41 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -33,7 +33,7 @@
|
||||
* Returns the new list of mergeinfo nodes.
|
||||
*
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
group_clauses_by_order(List *clauseinfo_list,
|
||||
int inner_relid)
|
||||
{
|
||||
@@ -105,7 +105,7 @@ group_clauses_by_order(List *clauseinfo_list,
|
||||
* Returns the node if it exists.
|
||||
*
|
||||
*/
|
||||
MInfo *
|
||||
MInfo *
|
||||
match_order_mergeinfo(PathOrder *ordering, List *mergeinfo_list)
|
||||
{
|
||||
MergeOrder *xmergeorder;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/orindxpath.c,v 1.4 1997/09/08 21:45:04 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/orindxpath.c,v 1.5 1998/02/26 04:32:41 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -50,7 +50,7 @@ best_or_subclause_index(Query *root, Rel *rel, Expr *subclause,
|
||||
* Returns a list of these index path nodes.
|
||||
*
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
create_or_index_paths(Query *root,
|
||||
Rel *rel, List *clauses)
|
||||
{
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/predmig.c,v 1.8 1998/01/07 21:03:51 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/predmig.c,v 1.9 1998/02/26 04:32:42 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -78,7 +78,7 @@ static int xfunc_stream_compare(void *arg1, void *arg2);
|
||||
static bool xfunc_check_stream(Stream node);
|
||||
static bool xfunc_in_stream(Stream node, Stream stream);
|
||||
|
||||
/* ----------------- MAIN FUNCTIONS ------------------------ */
|
||||
/* ----------------- MAIN FUNCTIONS ------------------------ */
|
||||
/*
|
||||
** xfunc_do_predmig
|
||||
** wrapper for Predicate Migration. It calls xfunc_predmig until no
|
||||
@@ -495,7 +495,7 @@ xfunc_form_groups(Query *queryInfo, Stream root, Stream bottom)
|
||||
}
|
||||
|
||||
|
||||
/* ------------------- UTILITY FUNCTIONS ------------------------- */
|
||||
/* ------------------- UTILITY FUNCTIONS ------------------------- */
|
||||
|
||||
/*
|
||||
** xfunc_free_stream --
|
||||
@@ -765,7 +765,7 @@ xfunc_stream_compare(void *arg1, void *arg2)
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------ DEBUGGING ROUTINES ---------------------------- */
|
||||
/* ------------------ DEBUGGING ROUTINES ---------------------------- */
|
||||
|
||||
/*
|
||||
** Make sure all pointers in stream make sense. Make sure no joins are
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/prune.c,v 1.11 1998/01/07 21:03:53 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/prune.c,v 1.12 1998/02/26 04:32:43 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -40,7 +40,8 @@ prune_joinrels(List *rel_list)
|
||||
List *i;
|
||||
|
||||
/*
|
||||
* rel_list can shorten while running as duplicate relations are deleted
|
||||
* rel_list can shorten while running as duplicate relations are
|
||||
* deleted
|
||||
*/
|
||||
foreach(i, rel_list)
|
||||
lnext(i) = prune_joinrel((Rel *) lfirst(i), lnext(i));
|
||||
@@ -60,13 +61,13 @@ prune_joinrels(List *rel_list)
|
||||
static List *
|
||||
prune_joinrel(Rel *rel, List *other_rels)
|
||||
{
|
||||
List *cur = NIL;
|
||||
List *return_list = NIL;
|
||||
List *cur = NIL;
|
||||
List *return_list = NIL;
|
||||
|
||||
/* find first relation that doesn't match */
|
||||
foreach(cur, other_rels)
|
||||
{
|
||||
Rel *other_rel = (Rel *) lfirst(cur);
|
||||
Rel *other_rel = (Rel *) lfirst(cur);
|
||||
|
||||
if (!same(rel->relids, other_rel->relids))
|
||||
break;
|
||||
@@ -74,18 +75,21 @@ prune_joinrel(Rel *rel, List *other_rels)
|
||||
|
||||
/* we now know cur doesn't match, or is NIL */
|
||||
return_list = cur;
|
||||
|
||||
/* remove relations that do match, we use lnext so we can remove easily */
|
||||
|
||||
/*
|
||||
* remove relations that do match, we use lnext so we can remove
|
||||
* easily
|
||||
*/
|
||||
while (cur != NIL && lnext(cur) != NIL)
|
||||
{
|
||||
Rel *other_rel = (Rel *) lfirst(lnext(cur));
|
||||
Rel *other_rel = (Rel *) lfirst(lnext(cur));
|
||||
|
||||
if (same(rel->relids, other_rel->relids))
|
||||
{
|
||||
rel->pathlist = add_pathlist(rel,
|
||||
rel->pathlist,
|
||||
other_rel->pathlist);
|
||||
lnext(cur) = lnext(lnext(cur)); /* delete it */
|
||||
lnext(cur) = lnext(lnext(cur)); /* delete it */
|
||||
}
|
||||
cur = lnext(cur);
|
||||
}
|
||||
@@ -145,7 +149,7 @@ prune_rel_paths(List *rel_list)
|
||||
* Returns the cheapest path.
|
||||
*
|
||||
*/
|
||||
Path *
|
||||
Path *
|
||||
prune_rel_path(Rel *rel, Path *unorderedpath)
|
||||
{
|
||||
Path *cheapest = set_cheapest(rel, rel->pathlist);
|
||||
@@ -176,7 +180,7 @@ prune_rel_path(Rel *rel, Path *unorderedpath)
|
||||
*
|
||||
* Returns one pruned rel node list
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
merge_joinrels(List *rel_list1, List *rel_list2)
|
||||
{
|
||||
List *xrel = NIL;
|
||||
@@ -202,7 +206,7 @@ merge_joinrels(List *rel_list1, List *rel_list2)
|
||||
*
|
||||
* Returns a new list of rel nodes
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
prune_oldrels(List *old_rels)
|
||||
{
|
||||
Rel *rel;
|
||||
@@ -223,7 +227,7 @@ prune_oldrels(List *old_rels)
|
||||
foreach(xjoininfo, joininfo_list)
|
||||
{
|
||||
JInfo *joininfo = (JInfo *) lfirst(xjoininfo);
|
||||
|
||||
|
||||
if (!joininfo->inactive)
|
||||
{
|
||||
temp_list = lcons(rel, temp_list);
|
||||
@@ -232,5 +236,5 @@ prune_oldrels(List *old_rels)
|
||||
}
|
||||
}
|
||||
}
|
||||
return temp_list;
|
||||
return temp_list;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/xfunc.c,v 1.12 1998/01/13 04:04:07 scrappy Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/xfunc.c,v 1.13 1998/02/26 04:32:44 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -34,7 +34,7 @@
|
||||
#include "optimizer/internal.h"
|
||||
#include "optimizer/keys.h"
|
||||
#include "optimizer/pathnode.h"
|
||||
#include "optimizer/tlist.h" /* for get_expr */
|
||||
#include "optimizer/tlist.h" /* for get_expr */
|
||||
#include "optimizer/xfunc.h"
|
||||
#include "storage/buf_internals.h" /* for NBuffers */
|
||||
#include "tcop/dest.h"
|
||||
@@ -532,7 +532,7 @@ xfunc_func_expense(LispValue node, LispValue args)
|
||||
if (nargs > 0)
|
||||
argOidVect = proc->proargtypes;
|
||||
planlist = (List) pg_parse_and_plan(pq_src, argOidVect, nargs,
|
||||
&parseTree_list, None);
|
||||
&parseTree_list, None);
|
||||
if (IsA(node, Func))
|
||||
set_func_planlist((Func) node, planlist);
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.26 1998/02/13 03:36:54 vadim Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.27 1998/02/26 04:32:48 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -46,33 +46,44 @@
|
||||
static List *switch_outer(List *clauses);
|
||||
static Scan *create_scan_node(Path *best_path, List *tlist);
|
||||
static Join *create_join_node(JoinPath *best_path, List *tlist);
|
||||
static SeqScan *create_seqscan_node(Path *best_path, List *tlist,
|
||||
static SeqScan *
|
||||
create_seqscan_node(Path *best_path, List *tlist,
|
||||
List *scan_clauses);
|
||||
static IndexScan *create_indexscan_node(IndexPath *best_path, List *tlist,
|
||||
static IndexScan *
|
||||
create_indexscan_node(IndexPath *best_path, List *tlist,
|
||||
List *scan_clauses);
|
||||
static NestLoop *create_nestloop_node(JoinPath *best_path, List *tlist,
|
||||
static NestLoop *
|
||||
create_nestloop_node(JoinPath *best_path, List *tlist,
|
||||
List *clauses, Plan *outer_node, List *outer_tlist,
|
||||
Plan *inner_node, List *inner_tlist);
|
||||
static MergeJoin *create_mergejoin_node(MergePath *best_path, List *tlist,
|
||||
static MergeJoin *
|
||||
create_mergejoin_node(MergePath *best_path, List *tlist,
|
||||
List *clauses, Plan *outer_node, List *outer_tlist,
|
||||
Plan *inner_node, List *inner_tlist);
|
||||
static HashJoin *create_hashjoin_node(HashPath *best_path, List *tlist,
|
||||
static HashJoin *
|
||||
create_hashjoin_node(HashPath *best_path, List *tlist,
|
||||
List *clauses, Plan *outer_node, List *outer_tlist,
|
||||
Plan *inner_node, List *inner_tlist);
|
||||
static Node *fix_indxqual_references(Node *clause, Path *index_path);
|
||||
static Temp *make_temp(List *tlist, List *keys, Oid *operators,
|
||||
static Temp *
|
||||
make_temp(List *tlist, List *keys, Oid *operators,
|
||||
Plan *plan_node, int temptype);
|
||||
static IndexScan *make_indexscan(List *qptlist, List *qpqual, Index scanrelid,
|
||||
static IndexScan *
|
||||
make_indexscan(List *qptlist, List *qpqual, Index scanrelid,
|
||||
List *indxid, List *indxqual, Cost cost);
|
||||
static NestLoop *make_nestloop(List *qptlist, List *qpqual, Plan *lefttree,
|
||||
static NestLoop *
|
||||
make_nestloop(List *qptlist, List *qpqual, Plan *lefttree,
|
||||
Plan *righttree);
|
||||
static HashJoin *make_hashjoin(List *tlist, List *qpqual,
|
||||
static HashJoin *
|
||||
make_hashjoin(List *tlist, List *qpqual,
|
||||
List *hashclauses, Plan *lefttree, Plan *righttree);
|
||||
static Hash *make_hash(List *tlist, Var *hashkey, Plan *lefttree);
|
||||
static MergeJoin *make_mergesort(List *tlist, List *qpqual,
|
||||
static MergeJoin *
|
||||
make_mergesort(List *tlist, List *qpqual,
|
||||
List *mergeclauses, Oid opcode, Oid *rightorder,
|
||||
Oid *leftorder, Plan *righttree, Plan *lefttree);
|
||||
static Material *make_material(List *tlist, Oid tempid, Plan *lefttree,
|
||||
static Material *
|
||||
make_material(List *tlist, Oid tempid, Plan *lefttree,
|
||||
int keycount);
|
||||
|
||||
/*
|
||||
@@ -90,7 +101,7 @@ static Material *make_material(List *tlist, Oid tempid, Plan *lefttree,
|
||||
*
|
||||
* Returns the optimal(?) access plan.
|
||||
*/
|
||||
Plan *
|
||||
Plan *
|
||||
create_plan(Path *best_path)
|
||||
{
|
||||
List *tlist;
|
||||
@@ -931,7 +942,7 @@ make_seqscan(List *qptlist,
|
||||
SeqScan *node = makeNode(SeqScan);
|
||||
Plan *plan = &node->plan;
|
||||
|
||||
plan->cost = (lefttree ? lefttree->cost : 0);
|
||||
plan->cost = (lefttree ? lefttree->cost : 0);
|
||||
plan->state = (EState *) NULL;
|
||||
plan->targetlist = qptlist;
|
||||
plan->qual = qpqual;
|
||||
@@ -949,7 +960,7 @@ make_indexscan(List *qptlist,
|
||||
Index scanrelid,
|
||||
List *indxid,
|
||||
List *indxqual,
|
||||
Cost cost)
|
||||
Cost cost)
|
||||
{
|
||||
IndexScan *node = makeNode(IndexScan);
|
||||
Plan *plan = &node->scan.plan;
|
||||
@@ -978,8 +989,8 @@ make_nestloop(List *qptlist,
|
||||
NestLoop *node = makeNode(NestLoop);
|
||||
Plan *plan = &node->join;
|
||||
|
||||
plan->cost = (lefttree ? lefttree->cost : 0) +
|
||||
(righttree ? righttree->cost : 0);
|
||||
plan->cost = (lefttree ? lefttree->cost : 0) +
|
||||
(righttree ? righttree->cost : 0);
|
||||
plan->state = (EState *) NULL;
|
||||
plan->targetlist = qptlist;
|
||||
plan->qual = qpqual;
|
||||
@@ -1000,8 +1011,8 @@ make_hashjoin(List *tlist,
|
||||
HashJoin *node = makeNode(HashJoin);
|
||||
Plan *plan = &node->join;
|
||||
|
||||
plan->cost = (lefttree ? lefttree->cost : 0) +
|
||||
(righttree ? righttree->cost : 0);
|
||||
plan->cost = (lefttree ? lefttree->cost : 0) +
|
||||
(righttree ? righttree->cost : 0);
|
||||
plan->cost = 0.0;
|
||||
plan->state = (EState *) NULL;
|
||||
plan->targetlist = tlist;
|
||||
@@ -1023,7 +1034,7 @@ make_hash(List *tlist, Var *hashkey, Plan *lefttree)
|
||||
Hash *node = makeNode(Hash);
|
||||
Plan *plan = &node->plan;
|
||||
|
||||
plan->cost = (lefttree ? lefttree->cost : 0);
|
||||
plan->cost = (lefttree ? lefttree->cost : 0);
|
||||
plan->cost = 0.0;
|
||||
plan->state = (EState *) NULL;
|
||||
plan->targetlist = tlist;
|
||||
@@ -1051,8 +1062,8 @@ make_mergesort(List *tlist,
|
||||
MergeJoin *node = makeNode(MergeJoin);
|
||||
Plan *plan = &node->join;
|
||||
|
||||
plan->cost = (lefttree ? lefttree->cost : 0) +
|
||||
(righttree ? righttree->cost : 0);
|
||||
plan->cost = (lefttree ? lefttree->cost : 0) +
|
||||
(righttree ? righttree->cost : 0);
|
||||
plan->state = (EState *) NULL;
|
||||
plan->targetlist = tlist;
|
||||
plan->qual = qpqual;
|
||||
@@ -1066,13 +1077,13 @@ make_mergesort(List *tlist,
|
||||
return (node);
|
||||
}
|
||||
|
||||
Sort *
|
||||
Sort *
|
||||
make_sort(List *tlist, Oid tempid, Plan *lefttree, int keycount)
|
||||
{
|
||||
Sort *node = makeNode(Sort);
|
||||
Plan *plan = &node->plan;
|
||||
|
||||
plan->cost = (lefttree ? lefttree->cost : 0);
|
||||
plan->cost = (lefttree ? lefttree->cost : 0);
|
||||
plan->state = (EState *) NULL;
|
||||
plan->targetlist = tlist;
|
||||
plan->qual = NIL;
|
||||
@@ -1093,7 +1104,7 @@ make_material(List *tlist,
|
||||
Material *node = makeNode(Material);
|
||||
Plan *plan = &node->plan;
|
||||
|
||||
plan->cost = (lefttree ? lefttree->cost : 0);
|
||||
plan->cost = (lefttree ? lefttree->cost : 0);
|
||||
plan->state = (EState *) NULL;
|
||||
plan->targetlist = tlist;
|
||||
plan->qual = NIL;
|
||||
@@ -1105,12 +1116,12 @@ make_material(List *tlist,
|
||||
return (node);
|
||||
}
|
||||
|
||||
Agg *
|
||||
Agg *
|
||||
make_agg(List *tlist, Plan *lefttree)
|
||||
{
|
||||
Agg *node = makeNode(Agg);
|
||||
|
||||
node->plan.cost = (lefttree ? lefttree->cost : 0);
|
||||
node->plan.cost = (lefttree ? lefttree->cost : 0);
|
||||
node->plan.state = (EState *) NULL;
|
||||
node->plan.qual = NULL;
|
||||
node->plan.targetlist = tlist;
|
||||
@@ -1121,7 +1132,7 @@ make_agg(List *tlist, Plan *lefttree)
|
||||
return (node);
|
||||
}
|
||||
|
||||
Group *
|
||||
Group *
|
||||
make_group(List *tlist,
|
||||
bool tuplePerGroup,
|
||||
int ngrp,
|
||||
@@ -1130,7 +1141,7 @@ make_group(List *tlist,
|
||||
{
|
||||
Group *node = makeNode(Group);
|
||||
|
||||
node->plan.cost = (lefttree ? lefttree->plan.cost : 0);
|
||||
node->plan.cost = (lefttree ? lefttree->plan.cost : 0);
|
||||
node->plan.state = (EState *) NULL;
|
||||
node->plan.qual = NULL;
|
||||
node->plan.targetlist = tlist;
|
||||
@@ -1151,13 +1162,13 @@ make_group(List *tlist,
|
||||
* or "*"
|
||||
*/
|
||||
|
||||
Unique *
|
||||
Unique *
|
||||
make_unique(List *tlist, Plan *lefttree, char *uniqueAttr)
|
||||
{
|
||||
Unique *node = makeNode(Unique);
|
||||
Plan *plan = &node->plan;
|
||||
|
||||
plan->cost = (lefttree ? lefttree->cost : 0);
|
||||
plan->cost = (lefttree ? lefttree->cost : 0);
|
||||
plan->state = (EState *) NULL;
|
||||
plan->targetlist = tlist;
|
||||
plan->qual = NIL;
|
||||
@@ -1175,7 +1186,7 @@ make_unique(List *tlist, Plan *lefttree, char *uniqueAttr)
|
||||
}
|
||||
|
||||
#ifdef NOT_USED
|
||||
List *
|
||||
List *
|
||||
generate_fjoin(List *tlist)
|
||||
{
|
||||
List tlistP;
|
||||
@@ -1228,5 +1239,5 @@ generate_fjoin(List *tlist)
|
||||
return newTlist;
|
||||
return tlist; /* do nothing for now - ay 10/94 */
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planmain.c,v 1.19 1998/02/13 03:36:57 vadim Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planmain.c,v 1.20 1998/02/26 04:32:50 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -64,7 +64,7 @@ make_groupPlan(List **tlist, bool tuplePerGroup,
|
||||
*
|
||||
* Returns a query plan.
|
||||
*/
|
||||
Plan *
|
||||
Plan *
|
||||
query_planner(Query *root,
|
||||
int command_type,
|
||||
List *tlist,
|
||||
@@ -74,18 +74,18 @@ query_planner(Query *root,
|
||||
List *var_only_tlist = NIL;
|
||||
List *level_tlist = NIL;
|
||||
Plan *subplan = NULL;
|
||||
|
||||
if ( PlannerQueryLevel > 1 )
|
||||
|
||||
if (PlannerQueryLevel > 1)
|
||||
{
|
||||
/* should copy be made ? */
|
||||
tlist = (List *) SS_replace_correlation_vars ((Node*)tlist);
|
||||
qual = (List *) SS_replace_correlation_vars ((Node*)qual);
|
||||
tlist = (List *) SS_replace_correlation_vars((Node *) tlist);
|
||||
qual = (List *) SS_replace_correlation_vars((Node *) qual);
|
||||
}
|
||||
if (root->hasSubLinks)
|
||||
qual = (List *) SS_process_sublinks ((Node*) qual);
|
||||
|
||||
qual = (List *) SS_process_sublinks((Node *) qual);
|
||||
|
||||
qual = cnfify((Expr *) qual, true);
|
||||
|
||||
|
||||
/*
|
||||
* A command without a target list or qualification is an error,
|
||||
* except for "delete foo".
|
||||
@@ -158,7 +158,7 @@ query_planner(Query *root,
|
||||
if (constant_qual != NULL)
|
||||
{
|
||||
return ((Plan *) make_result(tlist,
|
||||
(Node *) constant_qual,
|
||||
(Node *) constant_qual,
|
||||
(Plan *) scan));
|
||||
}
|
||||
else
|
||||
@@ -187,10 +187,10 @@ query_planner(Query *root,
|
||||
*/
|
||||
if (constant_qual)
|
||||
{
|
||||
subplan = (Plan *)make_result((!root->hasAggs && !root->groupClause)
|
||||
? tlist : subplan->targetlist,
|
||||
(Node *) constant_qual,
|
||||
subplan);
|
||||
subplan = (Plan *) make_result((!root->hasAggs && !root->groupClause)
|
||||
? tlist : subplan->targetlist,
|
||||
(Node *) constant_qual,
|
||||
subplan);
|
||||
|
||||
/*
|
||||
* Change all varno's of the Result's node target list.
|
||||
@@ -200,6 +200,7 @@ query_planner(Query *root,
|
||||
|
||||
return subplan;
|
||||
}
|
||||
|
||||
/*
|
||||
* fix up the flattened target list of the plan root node so that
|
||||
* expressions are evaluated. this forces expression evaluations that
|
||||
@@ -213,15 +214,16 @@ query_planner(Query *root,
|
||||
* aggregates fixing only other entries (i.e. - GroupBy-ed and so
|
||||
* fixed by make_groupPlan). - vadim 04/05/97
|
||||
*/
|
||||
else
|
||||
{
|
||||
else
|
||||
{
|
||||
if (!root->hasAggs && !root->groupClause)
|
||||
subplan->targetlist = flatten_tlist_vars(tlist,
|
||||
subplan->targetlist);
|
||||
subplan->targetlist);
|
||||
return subplan;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#ifdef NOT_USED
|
||||
|
||||
/*
|
||||
* Destructively modify the query plan's targetlist to add fjoin lists
|
||||
* to flatten functions that return sets of base types
|
||||
@@ -330,7 +332,7 @@ make_result(List *tlist,
|
||||
#ifdef NOT_USED
|
||||
tlist = generate_fjoin(tlist);
|
||||
#endif
|
||||
plan->cost = (subplan ? subplan->cost : 0);
|
||||
plan->cost = (subplan ? subplan->cost : 0);
|
||||
plan->state = (EState *) NULL;
|
||||
plan->targetlist = tlist;
|
||||
plan->lefttree = subplan;
|
||||
@@ -379,9 +381,9 @@ make_groupPlan(List **tlist,
|
||||
*/
|
||||
foreach(sl, sort_tlist)
|
||||
{
|
||||
Resdom *resdom = NULL;
|
||||
TargetEntry *te = (TargetEntry *) lfirst(sl);
|
||||
int keyno = 0;
|
||||
Resdom *resdom = NULL;
|
||||
TargetEntry *te = (TargetEntry *) lfirst(sl);
|
||||
int keyno = 0;
|
||||
|
||||
foreach(gl, groupClause)
|
||||
{
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.22 1998/02/13 03:36:59 vadim Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.23 1998/02/26 04:32:51 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -49,7 +49,8 @@
|
||||
#include "executor/executor.h"
|
||||
|
||||
static Plan *make_sortplan(List *tlist, List *sortcls, Plan *plannode);
|
||||
extern Plan *make_groupPlan(List **tlist, bool tuplePerGroup,
|
||||
extern Plan *
|
||||
make_groupPlan(List **tlist, bool tuplePerGroup,
|
||||
List *groupClause, Plan *subplan);
|
||||
|
||||
/*****************************************************************************
|
||||
@@ -58,27 +59,27 @@ extern Plan *make_groupPlan(List **tlist, bool tuplePerGroup,
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
Plan*
|
||||
Plan *
|
||||
planner(Query *parse)
|
||||
{
|
||||
Plan *result_plan;
|
||||
|
||||
|
||||
PlannerQueryLevel = 1;
|
||||
PlannerVarParam = NULL;
|
||||
PlannerParamVar = NULL;
|
||||
PlannerInitPlan = NULL;
|
||||
PlannerPlanId = 0;
|
||||
|
||||
result_plan = union_planner (parse);
|
||||
|
||||
Assert (PlannerQueryLevel == 1);
|
||||
if ( PlannerPlanId > 0 )
|
||||
|
||||
result_plan = union_planner(parse);
|
||||
|
||||
Assert(PlannerQueryLevel == 1);
|
||||
if (PlannerPlanId > 0)
|
||||
{
|
||||
result_plan->initPlan = PlannerInitPlan;
|
||||
(void) SS_finalize_plan (result_plan);
|
||||
(void) SS_finalize_plan(result_plan);
|
||||
}
|
||||
result_plan->nParamExec = length (PlannerParamVar);
|
||||
|
||||
result_plan->nParamExec = length(PlannerParamVar);
|
||||
|
||||
return (result_plan);
|
||||
}
|
||||
|
||||
@@ -91,7 +92,7 @@ planner(Query *parse)
|
||||
* Returns a query plan.
|
||||
*
|
||||
*/
|
||||
Plan *
|
||||
Plan *
|
||||
union_planner(Query *parse)
|
||||
{
|
||||
List *tlist = parse->targetList;
|
||||
@@ -100,7 +101,7 @@ union_planner(Query *parse)
|
||||
Plan *result_plan = (Plan *) NULL;
|
||||
|
||||
Index rt_index;
|
||||
|
||||
|
||||
|
||||
if (parse->unionClause)
|
||||
{
|
||||
@@ -112,7 +113,7 @@ union_planner(Query *parse)
|
||||
parse->rtable);
|
||||
}
|
||||
else if ((rt_index =
|
||||
first_inherit_rt_entry(rangetable)) != -1)
|
||||
first_inherit_rt_entry(rangetable)) != -1)
|
||||
{
|
||||
result_plan = (Plan *) plan_inherit_queries(parse, rt_index);
|
||||
/* XXX do we need to do this? bjm 12/19/97 */
|
||||
@@ -123,27 +124,27 @@ union_planner(Query *parse)
|
||||
}
|
||||
else
|
||||
{
|
||||
List **vpm = NULL;
|
||||
|
||||
List **vpm = NULL;
|
||||
|
||||
tlist = preprocess_targetlist(tlist,
|
||||
parse->commandType,
|
||||
parse->resultRelation,
|
||||
parse->rtable);
|
||||
if ( parse->rtable != NULL )
|
||||
if (parse->rtable != NULL)
|
||||
{
|
||||
vpm = (List **) palloc (length (parse->rtable) * sizeof (List*));
|
||||
memset (vpm, 0, length (parse->rtable) * sizeof (List*));
|
||||
vpm = (List **) palloc(length(parse->rtable) * sizeof(List *));
|
||||
memset(vpm, 0, length(parse->rtable) * sizeof(List *));
|
||||
}
|
||||
PlannerVarParam = lcons (vpm, PlannerVarParam);
|
||||
PlannerVarParam = lcons(vpm, PlannerVarParam);
|
||||
result_plan = query_planner(parse,
|
||||
parse->commandType,
|
||||
tlist,
|
||||
(List*) parse->qual);
|
||||
PlannerVarParam = lnext (PlannerVarParam);
|
||||
if ( vpm != NULL )
|
||||
pfree (vpm);
|
||||
(List *) parse->qual);
|
||||
PlannerVarParam = lnext(PlannerVarParam);
|
||||
if (vpm != NULL)
|
||||
pfree(vpm);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* If we have a GROUP BY clause, insert a group node (with the
|
||||
* appropriate sort node.)
|
||||
@@ -161,10 +162,10 @@ union_planner(Query *parse)
|
||||
tuplePerGroup = parse->hasAggs;
|
||||
|
||||
result_plan =
|
||||
make_groupPlan( &tlist,
|
||||
tuplePerGroup,
|
||||
parse->groupClause,
|
||||
result_plan);
|
||||
make_groupPlan(&tlist,
|
||||
tuplePerGroup,
|
||||
parse->groupClause,
|
||||
result_plan);
|
||||
|
||||
}
|
||||
|
||||
@@ -173,14 +174,14 @@ union_planner(Query *parse)
|
||||
*/
|
||||
if (parse->hasAggs)
|
||||
{
|
||||
result_plan = (Plan *)make_agg(tlist, result_plan);
|
||||
result_plan = (Plan *) make_agg(tlist, result_plan);
|
||||
|
||||
/*
|
||||
* set the varno/attno entries to the appropriate references to
|
||||
* the result tuple of the subplans.
|
||||
*/
|
||||
((Agg *)result_plan)->aggs =
|
||||
set_agg_tlist_references((Agg *)result_plan);
|
||||
((Agg *) result_plan)->aggs =
|
||||
set_agg_tlist_references((Agg *) result_plan);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/setrefs.c,v 1.18 1998/02/13 03:37:02 vadim Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/setrefs.c,v 1.19 1998/02/26 04:32:53 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -36,9 +36,11 @@
|
||||
static void set_join_tlist_references(Join *join);
|
||||
static void set_tempscan_tlist_references(SeqScan *tempscan);
|
||||
static void set_temp_tlist_references(Temp *temp);
|
||||
static List *replace_clause_joinvar_refs(Expr *clause,
|
||||
static List *
|
||||
replace_clause_joinvar_refs(Expr *clause,
|
||||
List *outer_tlist, List *inner_tlist);
|
||||
static List *replace_subclause_joinvar_refs(List *clauses,
|
||||
static List *
|
||||
replace_subclause_joinvar_refs(List *clauses,
|
||||
List *outer_tlist, List *inner_tlist);
|
||||
static Var *replace_joinvar_refs(Var *var, List *outer_tlist, List *inner_tlist);
|
||||
static List *tlist_temp_references(Oid tempid, List *tlist);
|
||||
@@ -216,7 +218,7 @@ set_temp_tlist_references(Temp *temp)
|
||||
* Returns the new join clauses.
|
||||
*
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
join_references(List *clauses,
|
||||
List *outer_tlist,
|
||||
List *inner_tlist)
|
||||
@@ -242,7 +244,7 @@ join_references(List *clauses,
|
||||
* Returns the new list of clauses.
|
||||
*
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
index_outerjoin_references(List *inner_indxqual,
|
||||
List *outer_tlist,
|
||||
Index inner_relid)
|
||||
@@ -407,19 +409,19 @@ replace_clause_joinvar_refs(Expr *clause,
|
||||
}
|
||||
else if (is_subplan(clause))
|
||||
{
|
||||
((Expr*) clause)->args =
|
||||
replace_subclause_joinvar_refs(((Expr*) clause)->args,
|
||||
outer_tlist,
|
||||
inner_tlist);
|
||||
((SubPlan*) ((Expr*) clause)->oper)->sublink->oper =
|
||||
replace_subclause_joinvar_refs(((SubPlan*) ((Expr*) clause)->oper)->sublink->oper,
|
||||
outer_tlist,
|
||||
inner_tlist);
|
||||
return ((List*) clause);
|
||||
((Expr *) clause)->args =
|
||||
replace_subclause_joinvar_refs(((Expr *) clause)->args,
|
||||
outer_tlist,
|
||||
inner_tlist);
|
||||
((SubPlan *) ((Expr *) clause)->oper)->sublink->oper =
|
||||
replace_subclause_joinvar_refs(((SubPlan *) ((Expr *) clause)->oper)->sublink->oper,
|
||||
outer_tlist,
|
||||
inner_tlist);
|
||||
return ((List *) clause);
|
||||
}
|
||||
/* shouldn't reach here */
|
||||
elog (ERROR, "replace_clause_joinvar_refs: unsupported clause %d",
|
||||
nodeTag (clause));
|
||||
elog(ERROR, "replace_clause_joinvar_refs: unsupported clause %d",
|
||||
nodeTag(clause));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -612,7 +614,7 @@ replace_result_clause(Node *clause,
|
||||
}
|
||||
else if (is_funcclause(clause))
|
||||
{
|
||||
List *subExpr;
|
||||
List *subExpr;
|
||||
|
||||
/*
|
||||
* This is a function. Recursively call this routine for its
|
||||
@@ -627,7 +629,7 @@ replace_result_clause(Node *clause,
|
||||
else if (IsA(clause, ArrayRef))
|
||||
{
|
||||
ArrayRef *aref = (ArrayRef *) clause;
|
||||
|
||||
|
||||
/*
|
||||
* This is an arrayref. Recursively call this routine for its
|
||||
* expression and its index expression...
|
||||
@@ -647,18 +649,18 @@ replace_result_clause(Node *clause,
|
||||
}
|
||||
else if (is_opclause(clause))
|
||||
{
|
||||
Node *subNode;
|
||||
Node *subNode;
|
||||
|
||||
/*
|
||||
* This is an operator. Recursively call this routine for both its
|
||||
* left and right operands
|
||||
*/
|
||||
subNode = (Node *)get_leftop((Expr *) clause);
|
||||
subNode = (Node *) get_leftop((Expr *) clause);
|
||||
replace_result_clause(subNode, subplanTargetList);
|
||||
subNode = (Node *) get_rightop((Expr *) clause);
|
||||
replace_result_clause(subNode, subplanTargetList);
|
||||
}
|
||||
else if (IsA(clause, Param) || IsA(clause, Const))
|
||||
else if (IsA(clause, Param) ||IsA(clause, Const))
|
||||
{
|
||||
/* do nothing! */
|
||||
}
|
||||
@@ -730,7 +732,7 @@ set_agg_tlist_references(Agg *aggNode)
|
||||
TargetEntry *tle = lfirst(tl);
|
||||
|
||||
aggreg_list = nconc(
|
||||
replace_agg_clause(tle->expr, subplanTargetList),aggreg_list);
|
||||
replace_agg_clause(tle->expr, subplanTargetList), aggreg_list);
|
||||
}
|
||||
return aggreg_list;
|
||||
}
|
||||
@@ -739,7 +741,7 @@ static List *
|
||||
replace_agg_clause(Node *clause, List *subplanTargetList)
|
||||
{
|
||||
List *t;
|
||||
List *agg_list = NIL;
|
||||
List *agg_list = NIL;
|
||||
|
||||
if (IsA(clause, Var))
|
||||
{
|
||||
@@ -760,6 +762,7 @@ replace_agg_clause(Node *clause, List *subplanTargetList)
|
||||
}
|
||||
else if (is_funcclause(clause))
|
||||
{
|
||||
|
||||
/*
|
||||
* This is a function. Recursively call this routine for its
|
||||
* arguments...
|
||||
@@ -767,19 +770,19 @@ replace_agg_clause(Node *clause, List *subplanTargetList)
|
||||
foreach(t, ((Expr *) clause)->args)
|
||||
{
|
||||
agg_list = nconc(agg_list,
|
||||
replace_agg_clause(lfirst(t), subplanTargetList));
|
||||
replace_agg_clause(lfirst(t), subplanTargetList));
|
||||
}
|
||||
return agg_list;
|
||||
}
|
||||
else if (IsA(clause, Aggreg))
|
||||
{
|
||||
return lcons(clause,
|
||||
replace_agg_clause(((Aggreg *) clause)->target, subplanTargetList));
|
||||
replace_agg_clause(((Aggreg *) clause)->target, subplanTargetList));
|
||||
}
|
||||
else if (IsA(clause, ArrayRef))
|
||||
{
|
||||
ArrayRef *aref = (ArrayRef *) clause;
|
||||
|
||||
|
||||
/*
|
||||
* This is an arrayref. Recursively call this routine for its
|
||||
* expression and its index expression...
|
||||
@@ -787,35 +790,36 @@ replace_agg_clause(Node *clause, List *subplanTargetList)
|
||||
foreach(t, aref->refupperindexpr)
|
||||
{
|
||||
agg_list = nconc(agg_list,
|
||||
replace_agg_clause(lfirst(t), subplanTargetList));
|
||||
replace_agg_clause(lfirst(t), subplanTargetList));
|
||||
}
|
||||
foreach(t, aref->reflowerindexpr)
|
||||
{
|
||||
agg_list = nconc(agg_list,
|
||||
replace_agg_clause(lfirst(t), subplanTargetList));
|
||||
replace_agg_clause(lfirst(t), subplanTargetList));
|
||||
}
|
||||
agg_list = nconc(agg_list,
|
||||
replace_agg_clause(aref->refexpr, subplanTargetList));
|
||||
replace_agg_clause(aref->refexpr, subplanTargetList));
|
||||
agg_list = nconc(agg_list,
|
||||
replace_agg_clause(aref->refassgnexpr, subplanTargetList));
|
||||
replace_agg_clause(aref->refassgnexpr, subplanTargetList));
|
||||
|
||||
return agg_list;
|
||||
}
|
||||
else if (is_opclause(clause))
|
||||
{
|
||||
|
||||
/*
|
||||
* This is an operator. Recursively call this routine for both its
|
||||
* left and right operands
|
||||
*/
|
||||
Node *left = (Node *) get_leftop((Expr *) clause);
|
||||
Node *right = (Node *) get_rightop((Expr *) clause);
|
||||
|
||||
|
||||
if (left != (Node *) NULL)
|
||||
agg_list = nconc(agg_list,
|
||||
replace_agg_clause(left, subplanTargetList));
|
||||
replace_agg_clause(left, subplanTargetList));
|
||||
if (right != (Node *) NULL)
|
||||
agg_list = nconc(agg_list,
|
||||
replace_agg_clause(right, subplanTargetList));
|
||||
replace_agg_clause(right, subplanTargetList));
|
||||
|
||||
return agg_list;
|
||||
}
|
||||
@@ -840,7 +844,8 @@ replace_agg_clause(Node *clause, List *subplanTargetList)
|
||||
* Remove the Agg nodes from the target list
|
||||
* We do this so inheritance only does aggregates in the upper node
|
||||
*/
|
||||
void del_agg_tlist_references(List *tlist)
|
||||
void
|
||||
del_agg_tlist_references(List *tlist)
|
||||
{
|
||||
List *tl;
|
||||
|
||||
@@ -863,6 +868,7 @@ del_agg_clause(Node *clause)
|
||||
}
|
||||
else if (is_funcclause(clause))
|
||||
{
|
||||
|
||||
/*
|
||||
* This is a function. Recursively call this routine for its
|
||||
* arguments...
|
||||
|
||||
@@ -26,61 +26,61 @@
|
||||
#include "optimizer/var.h"
|
||||
#include "optimizer/cost.h"
|
||||
|
||||
int PlannerQueryLevel; /* level of current query */
|
||||
List *PlannerVarParam; /* correlation Vars to Param mapper */
|
||||
List *PlannerParamVar; /* to get Var from Param->paramid */
|
||||
List *PlannerInitPlan; /* init subplans for current query */
|
||||
int PlannerPlanId;
|
||||
int PlannerQueryLevel; /* level of current query */
|
||||
List *PlannerVarParam; /* correlation Vars to Param mapper */
|
||||
List *PlannerParamVar; /* to get Var from Param->paramid */
|
||||
List *PlannerInitPlan; /* init subplans for current query */
|
||||
int PlannerPlanId;
|
||||
|
||||
|
||||
static int
|
||||
_new_param (Var *var, int varlevel)
|
||||
_new_param(Var *var, int varlevel)
|
||||
{
|
||||
List *last;
|
||||
int i = 0;
|
||||
|
||||
if ( PlannerParamVar == NULL )
|
||||
List *last;
|
||||
int i = 0;
|
||||
|
||||
if (PlannerParamVar == NULL)
|
||||
last = PlannerParamVar = makeNode(List);
|
||||
else
|
||||
{
|
||||
for (last = PlannerParamVar; ; )
|
||||
for (last = PlannerParamVar;;)
|
||||
{
|
||||
i++;
|
||||
if ( lnext(last) == NULL )
|
||||
if (lnext(last) == NULL)
|
||||
break;
|
||||
last = lnext(last);
|
||||
}
|
||||
lnext(last) = makeNode(List);
|
||||
last = lnext(last);
|
||||
}
|
||||
|
||||
|
||||
lnext(last) = NULL;
|
||||
lfirst(last) = makeVar (var->varno, var->varattno, var->vartype,
|
||||
var->vartypmod, varlevel, var->varnoold, var->varoattno);
|
||||
|
||||
lfirst(last) = makeVar(var->varno, var->varattno, var->vartype,
|
||||
var->vartypmod, varlevel, var->varnoold, var->varoattno);
|
||||
|
||||
return (i);
|
||||
}
|
||||
|
||||
static Param*
|
||||
_replace_var (Var *var)
|
||||
static Param *
|
||||
_replace_var(Var *var)
|
||||
{
|
||||
List **rt = (List**) nth (var->varlevelsup, PlannerVarParam);
|
||||
List *vpe = rt[var->varno - 1];
|
||||
Param *retval;
|
||||
int i;
|
||||
|
||||
if ( vpe == NULL )
|
||||
List **rt = (List **) nth(var->varlevelsup, PlannerVarParam);
|
||||
List *vpe = rt[var->varno - 1];
|
||||
Param *retval;
|
||||
int i;
|
||||
|
||||
if (vpe == NULL)
|
||||
{
|
||||
vpe = rt[var->varno - 1] = makeNode(List);
|
||||
lfirsti(vpe) = -1;
|
||||
lnext(vpe) = NULL;
|
||||
}
|
||||
|
||||
for (i = 1; ; i++)
|
||||
|
||||
for (i = 1;; i++)
|
||||
{
|
||||
if ( i == var->varattno )
|
||||
if (i == var->varattno)
|
||||
break;
|
||||
if ( lnext(vpe) == NULL )
|
||||
if (lnext(vpe) == NULL)
|
||||
{
|
||||
lnext(vpe) = makeNode(List);
|
||||
vpe = lnext(vpe);
|
||||
@@ -90,381 +90,385 @@ _replace_var (Var *var)
|
||||
else
|
||||
vpe = lnext(vpe);
|
||||
}
|
||||
|
||||
if ( (i = lfirsti(vpe)) < 0 ) /* parameter is not assigned */
|
||||
|
||||
if ((i = lfirsti(vpe)) < 0) /* parameter is not assigned */
|
||||
{
|
||||
i = _new_param (var, PlannerQueryLevel - var->varlevelsup);
|
||||
i = _new_param(var, PlannerQueryLevel - var->varlevelsup);
|
||||
}
|
||||
|
||||
|
||||
retval = makeNode(Param);
|
||||
retval->paramkind = PARAM_EXEC;
|
||||
retval->paramid = (AttrNumber) i;
|
||||
retval->paramtype = var->vartype;
|
||||
|
||||
|
||||
return (retval);
|
||||
}
|
||||
|
||||
static Node*
|
||||
_make_subplan (SubLink *slink)
|
||||
static Node *
|
||||
_make_subplan(SubLink *slink)
|
||||
{
|
||||
SubPlan *node = makeNode (SubPlan);
|
||||
SubPlan *node = makeNode(SubPlan);
|
||||
Plan *plan;
|
||||
List *lst;
|
||||
Node *result;
|
||||
List *saved_ip = PlannerInitPlan;
|
||||
|
||||
|
||||
PlannerInitPlan = NULL;
|
||||
|
||||
|
||||
PlannerQueryLevel++; /* we becomes child */
|
||||
|
||||
node->plan = plan = union_planner ((Query*) slink->subselect);
|
||||
|
||||
/*
|
||||
* Assign subPlan, extParam and locParam to plan nodes.
|
||||
* At the moment, SS_finalize_plan doesn't handle initPlan-s
|
||||
* and so we assigne them to the topmost plan node and take
|
||||
* care about its extParam too.
|
||||
|
||||
node->plan = plan = union_planner((Query *) slink->subselect);
|
||||
|
||||
/*
|
||||
* Assign subPlan, extParam and locParam to plan nodes. At the moment,
|
||||
* SS_finalize_plan doesn't handle initPlan-s and so we assigne them
|
||||
* to the topmost plan node and take care about its extParam too.
|
||||
*/
|
||||
(void) SS_finalize_plan (plan);
|
||||
(void) SS_finalize_plan(plan);
|
||||
plan->initPlan = PlannerInitPlan;
|
||||
|
||||
|
||||
/* Get extParam from InitPlan-s */
|
||||
foreach (lst, PlannerInitPlan)
|
||||
foreach(lst, PlannerInitPlan)
|
||||
{
|
||||
List *lp;
|
||||
|
||||
foreach (lp, ((SubPlan*) lfirst (lst))->plan->extParam)
|
||||
List *lp;
|
||||
|
||||
foreach(lp, ((SubPlan *) lfirst(lst))->plan->extParam)
|
||||
{
|
||||
if ( !intMember (lfirsti(lp), plan->extParam) )
|
||||
plan->extParam = lappendi (plan->extParam, lfirsti(lp));
|
||||
if (!intMember(lfirsti(lp), plan->extParam))
|
||||
plan->extParam = lappendi(plan->extParam, lfirsti(lp));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* and now we are parent again */
|
||||
PlannerInitPlan = saved_ip;
|
||||
PlannerQueryLevel--;
|
||||
|
||||
|
||||
node->plan_id = PlannerPlanId++;
|
||||
node->rtable = ((Query*) slink->subselect)->rtable;
|
||||
node->rtable = ((Query *) slink->subselect)->rtable;
|
||||
node->sublink = slink;
|
||||
slink->subselect = NULL; /* cool ?! */
|
||||
|
||||
|
||||
/* make parParam list */
|
||||
foreach (lst, plan->extParam)
|
||||
foreach(lst, plan->extParam)
|
||||
{
|
||||
Var *var = nth (lfirsti(lst), PlannerParamVar);
|
||||
|
||||
if ( var->varlevelsup == PlannerQueryLevel )
|
||||
node->parParam = lappendi (node->parParam, lfirsti(lst));
|
||||
Var *var = nth(lfirsti(lst), PlannerParamVar);
|
||||
|
||||
if (var->varlevelsup == PlannerQueryLevel)
|
||||
node->parParam = lappendi(node->parParam, lfirsti(lst));
|
||||
}
|
||||
|
||||
/*
|
||||
* Un-correlated or undirect correlated plans of EXISTS or EXPR
|
||||
* types can be used as initPlans...
|
||||
|
||||
/*
|
||||
* Un-correlated or undirect correlated plans of EXISTS or EXPR types
|
||||
* can be used as initPlans...
|
||||
*/
|
||||
if ( node->parParam == NULL && slink->subLinkType == EXPR_SUBLINK )
|
||||
if (node->parParam == NULL && slink->subLinkType == EXPR_SUBLINK)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
int i = 0;
|
||||
|
||||
/* transform right side of all sublink Oper-s into Param */
|
||||
foreach (lst, slink->oper)
|
||||
foreach(lst, slink->oper)
|
||||
{
|
||||
List *rside = lnext(((Expr*) lfirst(lst))->args);
|
||||
TargetEntry *te = nth (i, plan->targetlist);
|
||||
Var *var = makeVar (0, 0, te->resdom->restype,
|
||||
te->resdom->restypmod,
|
||||
PlannerQueryLevel, 0, 0);
|
||||
Param *prm = makeNode(Param);
|
||||
|
||||
List *rside = lnext(((Expr *) lfirst(lst))->args);
|
||||
TargetEntry *te = nth(i, plan->targetlist);
|
||||
Var *var = makeVar(0, 0, te->resdom->restype,
|
||||
te->resdom->restypmod,
|
||||
PlannerQueryLevel, 0, 0);
|
||||
Param *prm = makeNode(Param);
|
||||
|
||||
prm->paramkind = PARAM_EXEC;
|
||||
prm->paramid = (AttrNumber) _new_param (var, PlannerQueryLevel);
|
||||
prm->paramid = (AttrNumber) _new_param(var, PlannerQueryLevel);
|
||||
prm->paramtype = var->vartype;
|
||||
lfirst(rside) = prm;
|
||||
node->setParam = lappendi (node->setParam, prm->paramid);
|
||||
pfree (var);
|
||||
node->setParam = lappendi(node->setParam, prm->paramid);
|
||||
pfree(var);
|
||||
i++;
|
||||
}
|
||||
PlannerInitPlan = lappend (PlannerInitPlan, node);
|
||||
if ( i > 1 )
|
||||
result = (Node*) ((slink->useor) ? make_orclause (slink->oper) :
|
||||
make_andclause (slink->oper));
|
||||
PlannerInitPlan = lappend(PlannerInitPlan, node);
|
||||
if (i > 1)
|
||||
result = (Node *) ((slink->useor) ? make_orclause(slink->oper) :
|
||||
make_andclause(slink->oper));
|
||||
else
|
||||
result = (Node*) lfirst (slink->oper);
|
||||
result = (Node *) lfirst(slink->oper);
|
||||
}
|
||||
else if ( node->parParam == NULL && slink->subLinkType == EXISTS_SUBLINK )
|
||||
else if (node->parParam == NULL && slink->subLinkType == EXISTS_SUBLINK)
|
||||
{
|
||||
Var *var = makeVar (0, 0, BOOLOID, -1, PlannerQueryLevel, 0, 0);
|
||||
Var *var = makeVar(0, 0, BOOLOID, -1, PlannerQueryLevel, 0, 0);
|
||||
Param *prm = makeNode(Param);
|
||||
|
||||
|
||||
prm->paramkind = PARAM_EXEC;
|
||||
prm->paramid = (AttrNumber) _new_param (var, PlannerQueryLevel);
|
||||
prm->paramid = (AttrNumber) _new_param(var, PlannerQueryLevel);
|
||||
prm->paramtype = var->vartype;
|
||||
node->setParam = lappendi (node->setParam, prm->paramid);
|
||||
pfree (var);
|
||||
PlannerInitPlan = lappend (PlannerInitPlan, node);
|
||||
result = (Node*) prm;
|
||||
node->setParam = lappendi(node->setParam, prm->paramid);
|
||||
pfree(var);
|
||||
PlannerInitPlan = lappend(PlannerInitPlan, node);
|
||||
result = (Node *) prm;
|
||||
}
|
||||
else /* make expression of SUBPLAN type */
|
||||
else
|
||||
/* make expression of SUBPLAN type */
|
||||
{
|
||||
Expr *expr = makeNode (Expr);
|
||||
List *args = NULL;
|
||||
int i = 0;
|
||||
|
||||
Expr *expr = makeNode(Expr);
|
||||
List *args = NULL;
|
||||
int i = 0;
|
||||
|
||||
expr->typeOid = BOOLOID;
|
||||
expr->opType = SUBPLAN_EXPR;
|
||||
expr->oper = (Node*) node;
|
||||
|
||||
/*
|
||||
* Make expr->args from parParam. Left sides of sublink Oper-s
|
||||
* are handled by optimizer directly...
|
||||
* Also, transform right side of sublink Oper-s into Const.
|
||||
expr->oper = (Node *) node;
|
||||
|
||||
/*
|
||||
* Make expr->args from parParam. Left sides of sublink Oper-s are
|
||||
* handled by optimizer directly... Also, transform right side of
|
||||
* sublink Oper-s into Const.
|
||||
*/
|
||||
foreach (lst, node->parParam)
|
||||
foreach(lst, node->parParam)
|
||||
{
|
||||
Var *var = nth (lfirsti (lst), PlannerParamVar);
|
||||
|
||||
var = (Var*) copyObject (var);
|
||||
Var *var = nth(lfirsti(lst), PlannerParamVar);
|
||||
|
||||
var = (Var *) copyObject(var);
|
||||
var->varlevelsup = 0;
|
||||
args = lappend (args, var);
|
||||
args = lappend(args, var);
|
||||
}
|
||||
foreach (lst, slink->oper)
|
||||
foreach(lst, slink->oper)
|
||||
{
|
||||
List *rside = lnext(((Expr*) lfirst(lst))->args);
|
||||
TargetEntry *te = nth (i, plan->targetlist);
|
||||
Const *con = makeConst (te->resdom->restype,
|
||||
0, 0, true, 0, 0, 0);
|
||||
List *rside = lnext(((Expr *) lfirst(lst))->args);
|
||||
TargetEntry *te = nth(i, plan->targetlist);
|
||||
Const *con = makeConst(te->resdom->restype,
|
||||
0, 0, true, 0, 0, 0);
|
||||
|
||||
lfirst(rside) = con;
|
||||
i++;
|
||||
}
|
||||
expr->args = args;
|
||||
result = (Node*) expr;
|
||||
result = (Node *) expr;
|
||||
}
|
||||
|
||||
|
||||
return (result);
|
||||
|
||||
|
||||
}
|
||||
|
||||
static List *
|
||||
set_unioni (List *l1, List *l2)
|
||||
set_unioni(List *l1, List *l2)
|
||||
{
|
||||
if (l1 == NULL)
|
||||
return (l2);
|
||||
if (l2 == NULL)
|
||||
return (l1);
|
||||
|
||||
return (nconc (l1, set_differencei (l2, l1)));
|
||||
|
||||
return (nconc(l1, set_differencei(l2, l1)));
|
||||
}
|
||||
|
||||
static List *
|
||||
_finalize_primnode (void *expr, List **subplan)
|
||||
_finalize_primnode(void *expr, List **subplan)
|
||||
{
|
||||
List *result = NULL;
|
||||
|
||||
if ( expr == NULL )
|
||||
List *result = NULL;
|
||||
|
||||
if (expr == NULL)
|
||||
return (NULL);
|
||||
|
||||
if (IsA (expr, Param))
|
||||
|
||||
if (IsA(expr, Param))
|
||||
{
|
||||
if ( ((Param*) expr)->paramkind == PARAM_EXEC )
|
||||
return (lconsi (((Param*) expr)->paramid, (List*) NULL));
|
||||
if (((Param *) expr)->paramkind == PARAM_EXEC)
|
||||
return (lconsi(((Param *) expr)->paramid, (List *) NULL));
|
||||
}
|
||||
else if (single_node(expr))
|
||||
return (NULL);
|
||||
else if (IsA (expr, List))
|
||||
else if (IsA(expr, List))
|
||||
{
|
||||
List *le;
|
||||
foreach (le, (List*) expr)
|
||||
result = set_unioni (result,
|
||||
_finalize_primnode (lfirst(le), subplan));
|
||||
List *le;
|
||||
|
||||
foreach(le, (List *) expr)
|
||||
result = set_unioni(result,
|
||||
_finalize_primnode(lfirst(le), subplan));
|
||||
}
|
||||
else if (IsA (expr, Iter))
|
||||
return (_finalize_primnode (((Iter*) expr)->iterexpr, subplan));
|
||||
else if (or_clause(expr) || and_clause(expr) || is_opclause(expr) ||
|
||||
not_clause (expr) || is_funcclause(expr))
|
||||
return (_finalize_primnode (((Expr*) expr)->args, subplan));
|
||||
else if (IsA (expr, Aggreg))
|
||||
return (_finalize_primnode (((Aggreg *) expr)->target, subplan));
|
||||
else if (IsA (expr, ArrayRef))
|
||||
else if (IsA(expr, Iter))
|
||||
return (_finalize_primnode(((Iter *) expr)->iterexpr, subplan));
|
||||
else if (or_clause(expr) || and_clause(expr) || is_opclause(expr) ||
|
||||
not_clause(expr) || is_funcclause(expr))
|
||||
return (_finalize_primnode(((Expr *) expr)->args, subplan));
|
||||
else if (IsA(expr, Aggreg))
|
||||
return (_finalize_primnode(((Aggreg *) expr)->target, subplan));
|
||||
else if (IsA(expr, ArrayRef))
|
||||
{
|
||||
result = _finalize_primnode (((ArrayRef*) expr)->refupperindexpr, subplan);
|
||||
result = set_unioni (result,
|
||||
_finalize_primnode (((ArrayRef *) expr)->reflowerindexpr, subplan));
|
||||
result = set_unioni (result,
|
||||
_finalize_primnode (((ArrayRef *) expr)->refexpr, subplan));
|
||||
result = set_unioni (result,
|
||||
_finalize_primnode (((ArrayRef *) expr)->refassgnexpr, subplan));
|
||||
result = _finalize_primnode(((ArrayRef *) expr)->refupperindexpr, subplan);
|
||||
result = set_unioni(result,
|
||||
_finalize_primnode(((ArrayRef *) expr)->reflowerindexpr, subplan));
|
||||
result = set_unioni(result,
|
||||
_finalize_primnode(((ArrayRef *) expr)->refexpr, subplan));
|
||||
result = set_unioni(result,
|
||||
_finalize_primnode(((ArrayRef *) expr)->refassgnexpr, subplan));
|
||||
}
|
||||
else if (IsA (expr, TargetEntry))
|
||||
return (_finalize_primnode (((TargetEntry*) expr)->expr, subplan));
|
||||
else if (is_subplan (expr))
|
||||
else if (IsA(expr, TargetEntry))
|
||||
return (_finalize_primnode(((TargetEntry *) expr)->expr, subplan));
|
||||
else if (is_subplan(expr))
|
||||
{
|
||||
List *lst;
|
||||
|
||||
*subplan = lappend (*subplan, ((Expr*) expr)->oper);
|
||||
foreach (lst, ((SubPlan*) ((Expr*) expr)->oper)->plan->extParam)
|
||||
List *lst;
|
||||
|
||||
*subplan = lappend(*subplan, ((Expr *) expr)->oper);
|
||||
foreach(lst, ((SubPlan *) ((Expr *) expr)->oper)->plan->extParam)
|
||||
{
|
||||
Var *var = nth (lfirsti(lst), PlannerParamVar);
|
||||
|
||||
if ( var->varlevelsup < PlannerQueryLevel &&
|
||||
!intMember (lfirsti(lst), result) )
|
||||
result = lappendi (result, lfirsti(lst));
|
||||
Var *var = nth(lfirsti(lst), PlannerParamVar);
|
||||
|
||||
if (var->varlevelsup < PlannerQueryLevel &&
|
||||
!intMember(lfirsti(lst), result))
|
||||
result = lappendi(result, lfirsti(lst));
|
||||
}
|
||||
}
|
||||
else
|
||||
elog (ERROR, "_finalize_primnode: can't handle node %d",
|
||||
nodeTag (expr));
|
||||
|
||||
elog(ERROR, "_finalize_primnode: can't handle node %d",
|
||||
nodeTag(expr));
|
||||
|
||||
return (result);
|
||||
}
|
||||
|
||||
Node *
|
||||
SS_replace_correlation_vars (Node *expr)
|
||||
SS_replace_correlation_vars(Node *expr)
|
||||
{
|
||||
|
||||
if ( expr == NULL )
|
||||
if (expr == NULL)
|
||||
return (NULL);
|
||||
if (IsA (expr, List))
|
||||
if (IsA(expr, List))
|
||||
{
|
||||
List *le;
|
||||
foreach (le, (List*) expr)
|
||||
lfirst(le) = SS_replace_correlation_vars ((Node*) lfirst(le));
|
||||
List *le;
|
||||
|
||||
foreach(le, (List *) expr)
|
||||
lfirst(le) = SS_replace_correlation_vars((Node *) lfirst(le));
|
||||
}
|
||||
else if (IsA (expr, Var))
|
||||
else if (IsA(expr, Var))
|
||||
{
|
||||
if ( ((Var*) expr)->varlevelsup > 0 )
|
||||
if (((Var *) expr)->varlevelsup > 0)
|
||||
{
|
||||
Assert (((Var*) expr)->varlevelsup < PlannerQueryLevel);
|
||||
expr = (Node*) _replace_var ((Var*) expr);
|
||||
Assert(((Var *) expr)->varlevelsup < PlannerQueryLevel);
|
||||
expr = (Node *) _replace_var((Var *) expr);
|
||||
}
|
||||
}
|
||||
else if (IsA (expr, Iter))
|
||||
else if (IsA(expr, Iter))
|
||||
{
|
||||
((Iter*) expr)->iterexpr =
|
||||
SS_replace_correlation_vars(((Iter*) expr)->iterexpr);
|
||||
((Iter *) expr)->iterexpr =
|
||||
SS_replace_correlation_vars(((Iter *) expr)->iterexpr);
|
||||
}
|
||||
else if (single_node(expr))
|
||||
return (expr);
|
||||
else if (or_clause(expr) || and_clause(expr) || is_opclause(expr) ||
|
||||
not_clause (expr) || is_funcclause(expr))
|
||||
((Expr *) expr)->args = (List*)
|
||||
SS_replace_correlation_vars ((Node*) ((Expr *) expr)->args);
|
||||
else if (IsA (expr, Aggreg))
|
||||
((Aggreg *) expr)->target =
|
||||
SS_replace_correlation_vars ((Node*) ((Aggreg *) expr)->target);
|
||||
else if (IsA (expr, ArrayRef))
|
||||
else if (or_clause(expr) || and_clause(expr) || is_opclause(expr) ||
|
||||
not_clause(expr) || is_funcclause(expr))
|
||||
((Expr *) expr)->args = (List *)
|
||||
SS_replace_correlation_vars((Node *) ((Expr *) expr)->args);
|
||||
else if (IsA(expr, Aggreg))
|
||||
((Aggreg *) expr)->target =
|
||||
SS_replace_correlation_vars((Node *) ((Aggreg *) expr)->target);
|
||||
else if (IsA(expr, ArrayRef))
|
||||
{
|
||||
((ArrayRef *) expr)->refupperindexpr = (List*)
|
||||
SS_replace_correlation_vars ((Node*) ((ArrayRef *) expr)->refupperindexpr);
|
||||
((ArrayRef *) expr)->reflowerindexpr = (List*)
|
||||
SS_replace_correlation_vars ((Node*) ((ArrayRef *) expr)->reflowerindexpr);
|
||||
((ArrayRef *) expr)->refexpr =
|
||||
SS_replace_correlation_vars ((Node*) ((ArrayRef *) expr)->refexpr);
|
||||
((ArrayRef *) expr)->refassgnexpr =
|
||||
SS_replace_correlation_vars (((ArrayRef *) expr)->refassgnexpr);
|
||||
((ArrayRef *) expr)->refupperindexpr = (List *)
|
||||
SS_replace_correlation_vars((Node *) ((ArrayRef *) expr)->refupperindexpr);
|
||||
((ArrayRef *) expr)->reflowerindexpr = (List *)
|
||||
SS_replace_correlation_vars((Node *) ((ArrayRef *) expr)->reflowerindexpr);
|
||||
((ArrayRef *) expr)->refexpr =
|
||||
SS_replace_correlation_vars((Node *) ((ArrayRef *) expr)->refexpr);
|
||||
((ArrayRef *) expr)->refassgnexpr =
|
||||
SS_replace_correlation_vars(((ArrayRef *) expr)->refassgnexpr);
|
||||
}
|
||||
else if (IsA (expr, TargetEntry))
|
||||
((TargetEntry*) expr)->expr =
|
||||
SS_replace_correlation_vars ((Node*) ((TargetEntry*) expr)->expr);
|
||||
else if (IsA (expr, SubLink))
|
||||
else if (IsA(expr, TargetEntry))
|
||||
((TargetEntry *) expr)->expr =
|
||||
SS_replace_correlation_vars((Node *) ((TargetEntry *) expr)->expr);
|
||||
else if (IsA(expr, SubLink))
|
||||
{
|
||||
List *le;
|
||||
|
||||
foreach (le, ((SubLink*) expr)->oper) /* left sides only */
|
||||
List *le;
|
||||
|
||||
foreach(le, ((SubLink *) expr)->oper) /* left sides only */
|
||||
{
|
||||
List *oparg = ((Expr*) lfirst (le))->args;
|
||||
|
||||
lfirst (oparg) = (List*)
|
||||
SS_replace_correlation_vars ((Node*) lfirst (oparg));
|
||||
List *oparg = ((Expr *) lfirst(le))->args;
|
||||
|
||||
lfirst(oparg) = (List *)
|
||||
SS_replace_correlation_vars((Node *) lfirst(oparg));
|
||||
}
|
||||
((SubLink*) expr)->lefthand = (List*)
|
||||
SS_replace_correlation_vars ((Node*) ((SubLink*) expr)->lefthand);
|
||||
((SubLink *) expr)->lefthand = (List *)
|
||||
SS_replace_correlation_vars((Node *) ((SubLink *) expr)->lefthand);
|
||||
}
|
||||
else
|
||||
elog (NOTICE, "SS_replace_correlation_vars: can't handle node %d",
|
||||
nodeTag (expr));
|
||||
|
||||
elog(NOTICE, "SS_replace_correlation_vars: can't handle node %d",
|
||||
nodeTag(expr));
|
||||
|
||||
return (expr);
|
||||
}
|
||||
|
||||
Node*
|
||||
SS_process_sublinks (Node *expr)
|
||||
Node *
|
||||
SS_process_sublinks(Node *expr)
|
||||
{
|
||||
if ( expr == NULL )
|
||||
if (expr == NULL)
|
||||
return (NULL);
|
||||
if (IsA (expr, List))
|
||||
if (IsA(expr, List))
|
||||
{
|
||||
List *le;
|
||||
foreach (le, (List*) expr)
|
||||
lfirst(le) = SS_process_sublinks ((Node*) lfirst(le));
|
||||
List *le;
|
||||
|
||||
foreach(le, (List *) expr)
|
||||
lfirst(le) = SS_process_sublinks((Node *) lfirst(le));
|
||||
}
|
||||
else if (or_clause(expr) || and_clause(expr) || is_opclause(expr) ||
|
||||
not_clause (expr) || is_funcclause(expr))
|
||||
((Expr *) expr)->args = (List*)
|
||||
SS_process_sublinks ((Node*) ((Expr *) expr)->args);
|
||||
else if (IsA (expr, SubLink)) /* got it! */
|
||||
expr = _make_subplan ((SubLink*) expr);
|
||||
|
||||
else if (or_clause(expr) || and_clause(expr) || is_opclause(expr) ||
|
||||
not_clause(expr) || is_funcclause(expr))
|
||||
((Expr *) expr)->args = (List *)
|
||||
SS_process_sublinks((Node *) ((Expr *) expr)->args);
|
||||
else if (IsA(expr, SubLink))/* got it! */
|
||||
expr = _make_subplan((SubLink *) expr);
|
||||
|
||||
return (expr);
|
||||
}
|
||||
|
||||
List*
|
||||
SS_finalize_plan (Plan *plan)
|
||||
List *
|
||||
SS_finalize_plan(Plan *plan)
|
||||
{
|
||||
List *extParam = NULL;
|
||||
List *locParam = NULL;
|
||||
List *subPlan = NULL;
|
||||
List *param_list;
|
||||
List *lst;
|
||||
|
||||
if ( plan == NULL )
|
||||
List *extParam = NULL;
|
||||
List *locParam = NULL;
|
||||
List *subPlan = NULL;
|
||||
List *param_list;
|
||||
List *lst;
|
||||
|
||||
if (plan == NULL)
|
||||
return (NULL);
|
||||
|
||||
param_list = _finalize_primnode (plan->targetlist, &subPlan);
|
||||
Assert (subPlan == NULL);
|
||||
|
||||
|
||||
param_list = _finalize_primnode(plan->targetlist, &subPlan);
|
||||
Assert(subPlan == NULL);
|
||||
|
||||
switch (nodeTag(plan))
|
||||
{
|
||||
case T_Result:
|
||||
param_list = set_unioni (param_list,
|
||||
_finalize_primnode (((Result*) plan)->resconstantqual, &subPlan));
|
||||
param_list = set_unioni(param_list,
|
||||
_finalize_primnode(((Result *) plan)->resconstantqual, &subPlan));
|
||||
break;
|
||||
|
||||
case T_Append:
|
||||
foreach (lst, ((Append*) plan)->unionplans)
|
||||
param_list = set_unioni (param_list,
|
||||
SS_finalize_plan ((Plan*) lfirst (lst)));
|
||||
foreach(lst, ((Append *) plan)->unionplans)
|
||||
param_list = set_unioni(param_list,
|
||||
SS_finalize_plan((Plan *) lfirst(lst)));
|
||||
break;
|
||||
|
||||
|
||||
case T_IndexScan:
|
||||
param_list = set_unioni (param_list,
|
||||
_finalize_primnode (((IndexScan*) plan)->indxqual, &subPlan));
|
||||
Assert (subPlan == NULL);
|
||||
param_list = set_unioni(param_list,
|
||||
_finalize_primnode(((IndexScan *) plan)->indxqual, &subPlan));
|
||||
Assert(subPlan == NULL);
|
||||
break;
|
||||
|
||||
case T_MergeJoin:
|
||||
param_list = set_unioni (param_list,
|
||||
_finalize_primnode (((MergeJoin*) plan)->mergeclauses, &subPlan));
|
||||
Assert (subPlan == NULL);
|
||||
param_list = set_unioni(param_list,
|
||||
_finalize_primnode(((MergeJoin *) plan)->mergeclauses, &subPlan));
|
||||
Assert(subPlan == NULL);
|
||||
break;
|
||||
|
||||
case T_HashJoin:
|
||||
param_list = set_unioni (param_list,
|
||||
_finalize_primnode (((HashJoin*) plan)->hashclauses, &subPlan));
|
||||
Assert (subPlan == NULL);
|
||||
param_list = set_unioni(param_list,
|
||||
_finalize_primnode(((HashJoin *) plan)->hashclauses, &subPlan));
|
||||
Assert(subPlan == NULL);
|
||||
break;
|
||||
|
||||
|
||||
case T_Hash:
|
||||
param_list = set_unioni (param_list,
|
||||
_finalize_primnode (((Hash*) plan)->hashkey, &subPlan));
|
||||
Assert (subPlan == NULL);
|
||||
param_list = set_unioni(param_list,
|
||||
_finalize_primnode(((Hash *) plan)->hashkey, &subPlan));
|
||||
Assert(subPlan == NULL);
|
||||
break;
|
||||
|
||||
case T_Agg:
|
||||
param_list = set_unioni (param_list,
|
||||
_finalize_primnode (((Agg*) plan)->aggs, &subPlan));
|
||||
Assert (subPlan == NULL);
|
||||
param_list = set_unioni(param_list,
|
||||
_finalize_primnode(((Agg *) plan)->aggs, &subPlan));
|
||||
Assert(subPlan == NULL);
|
||||
break;
|
||||
|
||||
|
||||
case T_SeqScan:
|
||||
case T_NestLoop:
|
||||
case T_Material:
|
||||
@@ -476,74 +480,75 @@ SS_finalize_plan (Plan *plan)
|
||||
elog(ERROR, "SS_finalize_plan: node %d unsupported", nodeTag(plan));
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
param_list = set_unioni (param_list, _finalize_primnode (plan->qual, &subPlan));
|
||||
param_list = set_unioni (param_list, SS_finalize_plan (plan->lefttree));
|
||||
param_list = set_unioni (param_list, SS_finalize_plan (plan->righttree));
|
||||
|
||||
foreach (lst, param_list)
|
||||
|
||||
param_list = set_unioni(param_list, _finalize_primnode(plan->qual, &subPlan));
|
||||
param_list = set_unioni(param_list, SS_finalize_plan(plan->lefttree));
|
||||
param_list = set_unioni(param_list, SS_finalize_plan(plan->righttree));
|
||||
|
||||
foreach(lst, param_list)
|
||||
{
|
||||
Var *var = nth (lfirsti(lst), PlannerParamVar);
|
||||
|
||||
if ( var->varlevelsup < PlannerQueryLevel )
|
||||
extParam = lappendi (extParam, lfirsti(lst));
|
||||
else if ( var->varlevelsup > PlannerQueryLevel )
|
||||
elog (ERROR, "SS_finalize_plan: plan shouldn't reference subplan' variable");
|
||||
Var *var = nth(lfirsti(lst), PlannerParamVar);
|
||||
|
||||
if (var->varlevelsup < PlannerQueryLevel)
|
||||
extParam = lappendi(extParam, lfirsti(lst));
|
||||
else if (var->varlevelsup > PlannerQueryLevel)
|
||||
elog(ERROR, "SS_finalize_plan: plan shouldn't reference subplan' variable");
|
||||
else
|
||||
{
|
||||
Assert (var->varno == 0 && var->varattno == 0);
|
||||
locParam = lappendi (locParam, lfirsti(lst));
|
||||
Assert(var->varno == 0 && var->varattno == 0);
|
||||
locParam = lappendi(locParam, lfirsti(lst));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
plan->extParam = extParam;
|
||||
plan->locParam = locParam;
|
||||
plan->subPlan = subPlan;
|
||||
|
||||
|
||||
return (param_list);
|
||||
|
||||
}
|
||||
|
||||
List *SS_pull_subplan (void *expr);
|
||||
List *SS_pull_subplan(void *expr);
|
||||
|
||||
List *
|
||||
SS_pull_subplan (void *expr)
|
||||
SS_pull_subplan(void *expr)
|
||||
{
|
||||
List *result = NULL;
|
||||
|
||||
if ( expr == NULL || single_node(expr) )
|
||||
List *result = NULL;
|
||||
|
||||
if (expr == NULL || single_node(expr))
|
||||
return (NULL);
|
||||
|
||||
if (IsA (expr, List))
|
||||
|
||||
if (IsA(expr, List))
|
||||
{
|
||||
List *le;
|
||||
foreach (le, (List*) expr)
|
||||
result = nconc (result, SS_pull_subplan (lfirst(le)));
|
||||
List *le;
|
||||
|
||||
foreach(le, (List *) expr)
|
||||
result = nconc(result, SS_pull_subplan(lfirst(le)));
|
||||
}
|
||||
else if (IsA (expr, Iter))
|
||||
return (SS_pull_subplan (((Iter*) expr)->iterexpr));
|
||||
else if (or_clause(expr) || and_clause(expr) || is_opclause(expr) ||
|
||||
not_clause (expr) || is_funcclause(expr))
|
||||
return (SS_pull_subplan (((Expr*) expr)->args));
|
||||
else if (IsA (expr, Aggreg))
|
||||
return (SS_pull_subplan (((Aggreg *) expr)->target));
|
||||
else if (IsA (expr, ArrayRef))
|
||||
else if (IsA(expr, Iter))
|
||||
return (SS_pull_subplan(((Iter *) expr)->iterexpr));
|
||||
else if (or_clause(expr) || and_clause(expr) || is_opclause(expr) ||
|
||||
not_clause(expr) || is_funcclause(expr))
|
||||
return (SS_pull_subplan(((Expr *) expr)->args));
|
||||
else if (IsA(expr, Aggreg))
|
||||
return (SS_pull_subplan(((Aggreg *) expr)->target));
|
||||
else if (IsA(expr, ArrayRef))
|
||||
{
|
||||
result = SS_pull_subplan (((ArrayRef*) expr)->refupperindexpr);
|
||||
result = nconc (result,
|
||||
SS_pull_subplan (((ArrayRef *) expr)->reflowerindexpr));
|
||||
result = nconc (result,
|
||||
SS_pull_subplan (((ArrayRef *) expr)->refexpr));
|
||||
result = nconc (result,
|
||||
SS_pull_subplan (((ArrayRef *) expr)->refassgnexpr));
|
||||
result = SS_pull_subplan(((ArrayRef *) expr)->refupperindexpr);
|
||||
result = nconc(result,
|
||||
SS_pull_subplan(((ArrayRef *) expr)->reflowerindexpr));
|
||||
result = nconc(result,
|
||||
SS_pull_subplan(((ArrayRef *) expr)->refexpr));
|
||||
result = nconc(result,
|
||||
SS_pull_subplan(((ArrayRef *) expr)->refassgnexpr));
|
||||
}
|
||||
else if (IsA (expr, TargetEntry))
|
||||
return (SS_pull_subplan (((TargetEntry*) expr)->expr));
|
||||
else if (is_subplan (expr))
|
||||
return (lcons (((Expr*) expr)->oper, NULL));
|
||||
else if (IsA(expr, TargetEntry))
|
||||
return (SS_pull_subplan(((TargetEntry *) expr)->expr));
|
||||
else if (is_subplan(expr))
|
||||
return (lcons(((Expr *) expr)->oper, NULL));
|
||||
else
|
||||
elog (ERROR, "SS_pull_subplan: can't handle node %d",
|
||||
nodeTag (expr));
|
||||
|
||||
elog(ERROR, "SS_pull_subplan: can't handle node %d",
|
||||
nodeTag(expr));
|
||||
|
||||
return (result);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepqual.c,v 1.7 1997/12/18 12:54:15 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepqual.c,v 1.8 1998/02/26 04:32:57 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -64,7 +64,7 @@ static List *remove_duplicates(List *list);
|
||||
* and from the rule manager (removeAndFlag = false).
|
||||
*
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
cnfify(Expr *qual, bool removeAndFlag)
|
||||
{
|
||||
Expr *newqual = NULL;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/preptlist.c,v 1.9 1998/02/10 04:01:15 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/preptlist.c,v 1.10 1998/02/26 04:33:02 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -55,7 +55,7 @@ new_relation_targetlist(Oid relid, Index rt_index,
|
||||
*
|
||||
* Returns the new targetlist.
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
preprocess_targetlist(List *tlist,
|
||||
int command_type,
|
||||
Index result_relation,
|
||||
@@ -297,7 +297,7 @@ new_relation_targetlist(Oid relid, Index rt_index, NodeTag node_type)
|
||||
temp,
|
||||
(Datum) typedefault,
|
||||
(typedefault == (struct varlena *) NULL),
|
||||
/* XXX ? */
|
||||
/* XXX ? */
|
||||
false,
|
||||
false, /* not a set */
|
||||
false);
|
||||
@@ -325,7 +325,7 @@ new_relation_targetlist(Oid relid, Index rt_index, NodeTag node_type)
|
||||
|
||||
temp_list = MakeTLE(makeResdom(attno,
|
||||
atttype,
|
||||
get_atttypmod(relid, attno),
|
||||
get_atttypmod(relid, attno),
|
||||
attname,
|
||||
0,
|
||||
(Oid) 0,
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.19 1998/02/13 03:39:26 vadim Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.20 1998/02/26 04:33:05 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -34,16 +34,21 @@
|
||||
#include "optimizer/planner.h"
|
||||
#include "optimizer/planmain.h"
|
||||
|
||||
static List *plan_inherit_query(List *relids, Index rt_index,
|
||||
RangeTblEntry *rt_entry, Query *parse,
|
||||
List **union_rtentriesPtr);
|
||||
static RangeTblEntry *new_rangetable_entry(Oid new_relid,
|
||||
static List *
|
||||
plan_inherit_query(List *relids, Index rt_index,
|
||||
RangeTblEntry *rt_entry, Query *parse,
|
||||
List **union_rtentriesPtr);
|
||||
static RangeTblEntry *
|
||||
new_rangetable_entry(Oid new_relid,
|
||||
RangeTblEntry *old_entry);
|
||||
static Query *subst_rangetable(Query *root, Index index,
|
||||
static Query *
|
||||
subst_rangetable(Query *root, Index index,
|
||||
RangeTblEntry *new_entry);
|
||||
static void fix_parsetree_attnums(Index rt_index, Oid old_relid,
|
||||
static void
|
||||
fix_parsetree_attnums(Index rt_index, Oid old_relid,
|
||||
Oid new_relid, Query *parsetree);
|
||||
static Append *make_append(List *unionplans, List *unionrts, Index rt_index,
|
||||
static Append *
|
||||
make_append(List *unionplans, List *unionrts, Index rt_index,
|
||||
List *union_rt_entries, List *tlist);
|
||||
|
||||
|
||||
@@ -54,61 +59,43 @@ static Append *make_append(List *unionplans, List *unionrts, Index rt_index,
|
||||
*
|
||||
* Returns a list containing a list of plans and a list of rangetables
|
||||
*/
|
||||
Append *
|
||||
Append *
|
||||
plan_union_queries(Query *parse)
|
||||
{
|
||||
List *union_plans = NIL, *ulist, *unionall_queries, *union_rts,
|
||||
*last_union = NIL;
|
||||
bool union_all_found = false, union_found = false,
|
||||
last_unionall_flag = false;
|
||||
|
||||
List *union_plans = NIL,
|
||||
*ulist,
|
||||
*unionall_queries,
|
||||
*union_rts,
|
||||
*last_union = NIL;
|
||||
bool union_all_found = false,
|
||||
union_found = false,
|
||||
last_unionall_flag = false;
|
||||
|
||||
/*
|
||||
* Do we need to split up our unions because we have UNION
|
||||
* and UNION ALL?
|
||||
* Do we need to split up our unions because we have UNION and UNION
|
||||
* ALL?
|
||||
*
|
||||
* We are checking for the case of:
|
||||
* SELECT 1
|
||||
* UNION
|
||||
* SELECT 2
|
||||
* UNION
|
||||
* SELECT 3
|
||||
* UNION ALL
|
||||
* SELECT 4
|
||||
* UNION ALL
|
||||
* SELECT 5
|
||||
* We are checking for the case of: SELECT 1 UNION SELECT 2 UNION SELECT
|
||||
* 3 UNION ALL SELECT 4 UNION ALL SELECT 5
|
||||
*
|
||||
* where we have to do a DISTINCT on the output of the first three
|
||||
* queries, then add the rest. If they have used UNION and
|
||||
* UNION ALL, we grab all queries up to the last UNION query,
|
||||
* make them their own UNION with the owner as the first query
|
||||
* in the list. Then, we take the remaining queries, which is UNION
|
||||
* ALL, and add them to the list of union queries.
|
||||
* where we have to do a DISTINCT on the output of the first three
|
||||
* queries, then add the rest. If they have used UNION and UNION ALL,
|
||||
* we grab all queries up to the last UNION query, make them their own
|
||||
* UNION with the owner as the first query in the list. Then, we take
|
||||
* the remaining queries, which is UNION ALL, and add them to the list
|
||||
* of union queries.
|
||||
*
|
||||
* So the above query becomes:
|
||||
* So the above query becomes:
|
||||
*
|
||||
* Append Node { Sort and Unique { Append Node { SELECT 1
|
||||
* This is really a sub-UNION, unionClause We run a
|
||||
* DISTINCT on these. { SELECT 2 SELECT 3 } } } SELECT 4 SELECT 5 }
|
||||
*
|
||||
* Append Node
|
||||
* {
|
||||
* Sort and Unique
|
||||
* {
|
||||
* Append Node
|
||||
* {
|
||||
* SELECT 1 This is really a sub-UNION,
|
||||
* unionClause We run a DISTINCT on these.
|
||||
* {
|
||||
* SELECT 2
|
||||
* SELECT 3
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
* SELECT 4
|
||||
* SELECT 5
|
||||
* }
|
||||
*
|
||||
*/
|
||||
|
||||
foreach(ulist, parse->unionClause)
|
||||
{
|
||||
Query *union_query = lfirst(ulist);
|
||||
Query *union_query = lfirst(ulist);
|
||||
|
||||
if (union_query->unionall)
|
||||
union_all_found = true;
|
||||
@@ -123,18 +110,18 @@ plan_union_queries(Query *parse)
|
||||
/* Is this a simple one */
|
||||
if (!union_all_found ||
|
||||
!union_found ||
|
||||
/* A trailing UNION negates the affect of earlier UNION ALLs */
|
||||
/* A trailing UNION negates the affect of earlier UNION ALLs */
|
||||
!last_unionall_flag)
|
||||
{
|
||||
List *hold_unionClause = parse->unionClause;
|
||||
List *hold_unionClause = parse->unionClause;
|
||||
|
||||
parse->unionClause = NIL; /* prevent recursion */
|
||||
parse->unionClause = NIL; /* prevent recursion */
|
||||
union_plans = lcons(union_planner(parse), NIL);
|
||||
union_rts = lcons(parse->rtable, NIL);
|
||||
|
||||
foreach(ulist, hold_unionClause)
|
||||
{
|
||||
Query *union_query = lfirst(ulist);
|
||||
Query *union_query = lfirst(ulist);
|
||||
|
||||
union_plans = lappend(union_plans, union_planner(union_query));
|
||||
union_rts = lappend(union_rts, union_query->rtable);
|
||||
@@ -142,22 +129,23 @@ plan_union_queries(Query *parse)
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/*
|
||||
* We have mixed unions and non-unions
|
||||
* We have mixed unions and non-unions
|
||||
*
|
||||
* We need to restructure this to put the UNIONs on their own
|
||||
* so we can do a DISTINCT.
|
||||
* We need to restructure this to put the UNIONs on their own so we
|
||||
* can do a DISTINCT.
|
||||
*/
|
||||
|
||||
/* save off everthing past the last UNION */
|
||||
/* save off everthing past the last UNION */
|
||||
unionall_queries = lnext(last_union);
|
||||
|
||||
/* clip off the list to remove the trailing UNION ALLs */
|
||||
lnext(last_union) = NIL;
|
||||
|
||||
/*
|
||||
* Recursion, but UNION only.
|
||||
* The last one is a UNION, so it will not come here in recursion,
|
||||
* Recursion, but UNION only. The last one is a UNION, so it will
|
||||
* not come here in recursion,
|
||||
*/
|
||||
union_plans = lcons(union_planner(parse), NIL);
|
||||
union_rts = lcons(parse->rtable, NIL);
|
||||
@@ -165,20 +153,20 @@ plan_union_queries(Query *parse)
|
||||
/* Append the remainging UNION ALLs */
|
||||
foreach(ulist, unionall_queries)
|
||||
{
|
||||
Query *unionall_query = lfirst(ulist);
|
||||
Query *unionall_query = lfirst(ulist);
|
||||
|
||||
union_plans = lappend(union_plans, union_planner(unionall_query));
|
||||
union_rts = lappend(union_rts, unionall_query->rtable);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* We have already split UNION and UNION ALL and we made it consistent */
|
||||
if (!last_unionall_flag)
|
||||
{
|
||||
parse->uniqueFlag = "*";
|
||||
parse->sortClause = transformSortClause(NULL, NIL,
|
||||
parse->sortClause,
|
||||
parse->targetList, "*");
|
||||
parse->sortClause,
|
||||
parse->targetList, "*");
|
||||
}
|
||||
else
|
||||
/* needed so we don't take the flag from the first query */
|
||||
@@ -204,7 +192,7 @@ plan_union_queries(Query *parse)
|
||||
* entries to be inserted into an APPEND node.
|
||||
* XXX - what exactly does this mean, look for make_append
|
||||
*/
|
||||
Append *
|
||||
Append *
|
||||
plan_inherit_queries(Query *parse, Index rt_index)
|
||||
{
|
||||
List *union_plans = NIL;
|
||||
@@ -218,6 +206,7 @@ plan_inherit_queries(Query *parse, Index rt_index)
|
||||
find_all_inheritors(lconsi(rt_entry->relid,
|
||||
NIL),
|
||||
NIL);
|
||||
|
||||
/*
|
||||
* Remove the flag for this relation, since we're about to handle it
|
||||
* (do it before recursing!). XXX destructive parse tree change
|
||||
@@ -225,7 +214,7 @@ plan_inherit_queries(Query *parse, Index rt_index)
|
||||
rt_fetch(rt_index, rangetable)->inh = false;
|
||||
|
||||
union_plans = plan_inherit_query(union_relids, rt_index, rt_entry,
|
||||
parse, &union_rt_entries);
|
||||
parse, &union_rt_entries);
|
||||
|
||||
return (make_append(union_plans,
|
||||
NULL,
|
||||
@@ -241,10 +230,10 @@ plan_inherit_queries(Query *parse, Index rt_index)
|
||||
*/
|
||||
static List *
|
||||
plan_inherit_query(List *relids,
|
||||
Index rt_index,
|
||||
RangeTblEntry *rt_entry,
|
||||
Query *root,
|
||||
List **union_rtentriesPtr)
|
||||
Index rt_index,
|
||||
RangeTblEntry *rt_entry,
|
||||
Query *root,
|
||||
List **union_rtentriesPtr)
|
||||
{
|
||||
List *i;
|
||||
List *union_plans = NIL;
|
||||
@@ -290,7 +279,7 @@ plan_inherit_query(List *relids,
|
||||
* attributes from any relations listed in either of the argument relid
|
||||
* lists.
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
find_all_inheritors(List *unexamined_relids,
|
||||
List *examined_relids)
|
||||
{
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/Attic/clauseinfo.c,v 1.6 1997/09/08 21:45:44 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/Attic/clauseinfo.c,v 1.7 1998/02/26 04:33:09 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -44,7 +44,7 @@ valid_or_clause(CInfo *clauseinfo)
|
||||
* Returns a list containing the clauses from 'clauseinfo-list'.
|
||||
*
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
get_actual_clauses(List *clauseinfo_list)
|
||||
{
|
||||
List *temp = NIL;
|
||||
@@ -173,7 +173,7 @@ get_joinvars(Oid relid,
|
||||
* of a list of clauseinfo nodes to be used with an index.
|
||||
*
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
get_opnos(List *clauseinfo_list)
|
||||
{
|
||||
CInfo *temp = (CInfo *) NULL;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v 1.15 1998/02/13 03:40:19 vadim Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v 1.16 1998/02/26 04:33:11 momjian Exp $
|
||||
*
|
||||
* HISTORY
|
||||
* AUTHOR DATE MAJOR EVENT
|
||||
@@ -38,7 +38,7 @@
|
||||
static bool agg_clause(Node *clause);
|
||||
|
||||
|
||||
Expr *
|
||||
Expr *
|
||||
make_clause(int type, Node *oper, List *args)
|
||||
{
|
||||
if (type == AND_EXPR || type == OR_EXPR || type == NOT_EXPR ||
|
||||
@@ -58,7 +58,7 @@ make_clause(int type, Node *oper, List *args)
|
||||
}
|
||||
else
|
||||
{
|
||||
elog (ERROR, "make_clause: unsupported type %d", type);
|
||||
elog(ERROR, "make_clause: unsupported type %d", type);
|
||||
/* will this ever happen? translated from lispy C code - ay 10/94 */
|
||||
return ((Expr *) args);
|
||||
}
|
||||
@@ -94,7 +94,7 @@ is_opclause(Node *clause)
|
||||
* operand (if it is non-null).
|
||||
*
|
||||
*/
|
||||
Expr *
|
||||
Expr *
|
||||
make_opclause(Oper *op, Var *leftop, Var *rightop)
|
||||
{
|
||||
Expr *expr = makeNode(Expr);
|
||||
@@ -113,7 +113,7 @@ make_opclause(Oper *op, Var *leftop, Var *rightop)
|
||||
* or (op expr)
|
||||
* NB: it is assumed (for now) that all expr must be Var nodes
|
||||
*/
|
||||
Var *
|
||||
Var *
|
||||
get_leftop(Expr *clause)
|
||||
{
|
||||
if (clause->args != NULL)
|
||||
@@ -128,7 +128,7 @@ get_leftop(Expr *clause)
|
||||
* Returns the right operand in a clause of the form (op expr expr).
|
||||
*
|
||||
*/
|
||||
Var *
|
||||
Var *
|
||||
get_rightop(Expr *clause)
|
||||
{
|
||||
if (clause->args != NULL && lnext(clause->args) != NULL)
|
||||
@@ -173,7 +173,7 @@ is_funcclause(Node *clause)
|
||||
* arguments.
|
||||
*
|
||||
*/
|
||||
Expr *
|
||||
Expr *
|
||||
make_funcclause(Func *func, List *funcargs)
|
||||
{
|
||||
Expr *expr = makeNode(Expr);
|
||||
@@ -209,7 +209,7 @@ or_clause(Node *clause)
|
||||
* Creates an 'or' clause given a list of its subclauses.
|
||||
*
|
||||
*/
|
||||
Expr *
|
||||
Expr *
|
||||
make_orclause(List *orclauses)
|
||||
{
|
||||
Expr *expr = makeNode(Expr);
|
||||
@@ -245,7 +245,7 @@ not_clause(Node *clause)
|
||||
* Create a 'not' clause given the expression to be negated.
|
||||
*
|
||||
*/
|
||||
Expr *
|
||||
Expr *
|
||||
make_notclause(Expr *notclause)
|
||||
{
|
||||
Expr *expr = makeNode(Expr);
|
||||
@@ -263,7 +263,7 @@ make_notclause(Expr *notclause)
|
||||
* Retrieve the clause within a 'not' clause
|
||||
*
|
||||
*/
|
||||
Expr *
|
||||
Expr *
|
||||
get_notclausearg(Expr *notclause)
|
||||
{
|
||||
return (lfirst(notclause->args));
|
||||
@@ -294,7 +294,7 @@ and_clause(Node *clause)
|
||||
* Create an 'and' clause given its arguments in a list.
|
||||
*
|
||||
*/
|
||||
Expr *
|
||||
Expr *
|
||||
make_andclause(List *andclauses)
|
||||
{
|
||||
Expr *expr = makeNode(Expr);
|
||||
@@ -322,7 +322,7 @@ make_andclause(List *andclauses)
|
||||
* quals as the return value.
|
||||
*
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
pull_constant_clauses(List *quals, List **constantQual)
|
||||
{
|
||||
List *q;
|
||||
@@ -377,8 +377,8 @@ clause_relids_vars(Node *clause, List **relids, List **vars)
|
||||
foreach(vi, var_list)
|
||||
{
|
||||
Var *in_list = (Var *) lfirst(vi);
|
||||
|
||||
Assert (var->varlevelsup == 0);
|
||||
|
||||
Assert(var->varlevelsup == 0);
|
||||
if (in_list->varno == var->varno &&
|
||||
in_list->varattno == var->varattno)
|
||||
break;
|
||||
@@ -553,15 +553,15 @@ fix_opid(Node *clause)
|
||||
{
|
||||
fix_opid(((Aggreg *) clause)->target);
|
||||
}
|
||||
else if (is_subplan(clause) &&
|
||||
((SubPlan*) ((Expr*) clause)->oper)->sublink->subLinkType != EXISTS_SUBLINK)
|
||||
else if (is_subplan(clause) &&
|
||||
((SubPlan *) ((Expr *) clause)->oper)->sublink->subLinkType != EXISTS_SUBLINK)
|
||||
{
|
||||
List *lst;
|
||||
|
||||
foreach (lst, ((SubPlan*) ((Expr*) clause)->oper)->sublink->oper)
|
||||
List *lst;
|
||||
|
||||
foreach(lst, ((SubPlan *) ((Expr *) clause)->oper)->sublink->oper)
|
||||
{
|
||||
replace_opid((Oper*) ((Expr*) lfirst(lst))->oper);
|
||||
fix_opid((Node*) get_leftop((Expr*) lfirst(lst)));
|
||||
replace_opid((Oper *) ((Expr *) lfirst(lst))->oper);
|
||||
fix_opid((Node *) get_leftop((Expr *) lfirst(lst)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -574,7 +574,7 @@ fix_opid(Node *clause)
|
||||
* Returns its argument.
|
||||
*
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
fix_opids(List *clauses)
|
||||
{
|
||||
List *clause;
|
||||
@@ -642,7 +642,7 @@ get_relattval(Node *clause,
|
||||
|
||||
}
|
||||
}
|
||||
else if (is_opclause(clause) && IsA(left, Var) && IsA(right, Param))
|
||||
else if (is_opclause(clause) && IsA(left, Var) &&IsA(right, Param))
|
||||
{
|
||||
*relid = left->varno;
|
||||
*attno = left->varattno;
|
||||
@@ -653,8 +653,8 @@ get_relattval(Node *clause,
|
||||
is_funcclause((Node *) left) &&
|
||||
IsA(right, Const))
|
||||
{
|
||||
List *vars = pull_var_clause((Node*)left);
|
||||
|
||||
List *vars = pull_var_clause((Node *) left);
|
||||
|
||||
*relid = ((Var *) lfirst(vars))->varno;
|
||||
*attno = InvalidAttrNumber;
|
||||
*constval = ((Const *) right)->constvalue;
|
||||
@@ -664,8 +664,8 @@ get_relattval(Node *clause,
|
||||
is_funcclause((Node *) right) &&
|
||||
IsA(left, Const))
|
||||
{
|
||||
List *vars = pull_var_clause((Node*)right);
|
||||
|
||||
List *vars = pull_var_clause((Node *) right);
|
||||
|
||||
*relid = ((Var *) lfirst(vars))->varno;
|
||||
*attno = InvalidAttrNumber;
|
||||
*constval = ((Const *) left)->constvalue;
|
||||
@@ -692,7 +692,7 @@ get_relattval(Node *clause,
|
||||
*flag = (_SELEC_NOT_CONSTANT_);
|
||||
}
|
||||
}
|
||||
else if (is_opclause(clause) && IsA(right, Var) && IsA(left, Param))
|
||||
else if (is_opclause(clause) && IsA(right, Var) &&IsA(left, Param))
|
||||
{
|
||||
*relid = right->varno;
|
||||
*attno = right->varattno;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/Attic/indexnode.c,v 1.5 1997/09/08 21:45:48 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/Attic/indexnode.c,v 1.6 1998/02/26 04:33:13 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -32,7 +32,7 @@ static List *find_secondary_index(Query *root, Oid relid);
|
||||
* each (secondary) index defined on a relation.
|
||||
*
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
find_relation_indices(Query *root, Rel *rel)
|
||||
{
|
||||
if (rel->indexed)
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/Attic/internal.c,v 1.6 1997/09/08 21:45:49 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/Attic/internal.c,v 1.7 1998/02/26 04:33:17 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -48,7 +48,7 @@ MakeTLE(Resdom *resdom, Node *expr)
|
||||
return rt;
|
||||
}
|
||||
|
||||
Var *
|
||||
Var *
|
||||
get_expr(TargetEntry *tle)
|
||||
{
|
||||
Assert(tle != NULL);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/joininfo.c,v 1.5 1997/09/08 21:45:50 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/joininfo.c,v 1.6 1998/02/26 04:33:18 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -35,7 +35,7 @@
|
||||
* exists.
|
||||
*
|
||||
*/
|
||||
JInfo *
|
||||
JInfo *
|
||||
joininfo_member(List *join_relids, List *joininfo_list)
|
||||
{
|
||||
List *i = NIL;
|
||||
@@ -61,7 +61,7 @@ joininfo_member(List *join_relids, List *joininfo_list)
|
||||
* Returns a joininfo node.
|
||||
*
|
||||
*/
|
||||
JInfo *
|
||||
JInfo *
|
||||
find_joininfo_node(Rel *this_rel, List *join_relids)
|
||||
{
|
||||
JInfo *joininfo = joininfo_member(join_relids,
|
||||
@@ -88,7 +88,7 @@ find_joininfo_node(Rel *this_rel, List *join_relids)
|
||||
* Returns the other var node in the joinclause if it is, nil if not.
|
||||
*
|
||||
*/
|
||||
Var *
|
||||
Var *
|
||||
other_join_clause_var(Var *var, Expr *clause)
|
||||
{
|
||||
Var *retval;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/Attic/keys.c,v 1.5 1997/09/08 21:45:51 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/Attic/keys.c,v 1.6 1998/02/26 04:33:19 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -85,7 +85,7 @@ equal_indexkey_var(int index_key, Var *var)
|
||||
* lelation.
|
||||
*
|
||||
*/
|
||||
Var *
|
||||
Var *
|
||||
extract_subkey(JoinKey *jk, int which_subkey)
|
||||
{
|
||||
Var *retval;
|
||||
@@ -178,7 +178,7 @@ matching2_tlvar(int var, List *tlist, bool (*test) ())
|
||||
}
|
||||
|
||||
|
||||
List *
|
||||
List *
|
||||
collect_index_pathkeys(int *index_keys, List *tlist)
|
||||
{
|
||||
List *retval = NIL;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/pathnode.c,v 1.6 1997/09/08 21:45:53 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/pathnode.c,v 1.7 1998/02/26 04:33:20 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -61,7 +61,7 @@ path_is_cheaper(Path *path1, Path *path2)
|
||||
* is minimum.
|
||||
*
|
||||
*/
|
||||
Path *
|
||||
Path *
|
||||
set_cheapest(Rel *parent_rel, List *pathlist)
|
||||
{
|
||||
List *p;
|
||||
@@ -100,7 +100,7 @@ set_cheapest(Rel *parent_rel, List *pathlist)
|
||||
* Returns the list of unique pathnodes.
|
||||
*
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
add_pathlist(Rel *parent_rel, List *unique_paths, List *new_paths)
|
||||
{
|
||||
List *x;
|
||||
@@ -207,7 +207,7 @@ better_path(Path *new_path, List *unique_paths, bool *noOther)
|
||||
* pathnode.
|
||||
*
|
||||
*/
|
||||
Path *
|
||||
Path *
|
||||
create_seqscan_path(Rel *rel)
|
||||
{
|
||||
int relid = 0;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/plancat.c,v 1.15 1998/02/11 19:10:47 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/plancat.c,v 1.16 1998/02/26 04:33:21 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -403,7 +403,7 @@ join_selectivity(Oid functionObjectId,
|
||||
* Returns a LISP list containing the OIDs of all relations which
|
||||
* inherits from the relation with OID 'inhparent'.
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
find_inheritance_children(Oid inhparent)
|
||||
{
|
||||
static ScanKeyData key[1] = {
|
||||
@@ -440,7 +440,7 @@ find_inheritance_children(Oid inhparent)
|
||||
* Returns a LISP list containing the OIDs of all relations which are
|
||||
* base relations of the relation with OID 'verrelid'.
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
VersionGetParents(Oid verrelid)
|
||||
{
|
||||
static ScanKeyData key[1] = {
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/relnode.c,v 1.4 1997/09/08 21:45:54 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/relnode.c,v 1.5 1998/02/26 04:33:21 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -27,7 +27,7 @@
|
||||
* necessary. This is for base relations.
|
||||
*
|
||||
*/
|
||||
Rel *
|
||||
Rel *
|
||||
get_base_rel(Query *root, int relid)
|
||||
{
|
||||
List *relids;
|
||||
@@ -100,7 +100,7 @@ get_base_rel(Query *root, int relid)
|
||||
* creating a new one if necessary. This is for join relations.
|
||||
*
|
||||
*/
|
||||
Rel *
|
||||
Rel *
|
||||
get_join_rel(Query *root, List *relid)
|
||||
{
|
||||
return rel_member(relid, root->join_relation_list_);
|
||||
@@ -114,7 +114,7 @@ get_join_rel(Query *root, List *relid)
|
||||
* Returns the corresponding entry in 'rels' if it is there.
|
||||
*
|
||||
*/
|
||||
Rel *
|
||||
Rel *
|
||||
rel_member(List *relid, List *rels)
|
||||
{
|
||||
List *temp = NIL;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/tlist.c,v 1.11 1998/02/13 03:40:21 vadim Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/tlist.c,v 1.12 1998/02/26 04:33:22 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -68,7 +68,7 @@ tlistentry_member(Var *var, List *targetlist)
|
||||
* REQUIRES: "test" operates on lispval unions,
|
||||
*
|
||||
*/
|
||||
Expr *
|
||||
Expr *
|
||||
matching_tlvar(Var *var, List *targetlist)
|
||||
{
|
||||
TargetEntry *tlentry;
|
||||
@@ -153,7 +153,7 @@ create_tl_element(Var *var, int resdomno)
|
||||
* Returns the targetlist elements from a relation tlist.
|
||||
*
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
get_actual_tlist(List *tlist)
|
||||
{
|
||||
|
||||
@@ -200,7 +200,7 @@ get_actual_tlist(List *tlist)
|
||||
* Returns the resdom entry of the matching var node.
|
||||
*
|
||||
*/
|
||||
Resdom *
|
||||
Resdom *
|
||||
tlist_member(Var *var, List *tlist)
|
||||
{
|
||||
List *i = NIL;
|
||||
@@ -230,7 +230,7 @@ tlist_member(Var *var, List *tlist)
|
||||
/*
|
||||
* Routine to get the resdom out of a targetlist.
|
||||
*/
|
||||
Resdom *
|
||||
Resdom *
|
||||
tlist_resdom(List *tlist, Resdom *resnode)
|
||||
{
|
||||
Resdom *resdom = (Resdom *) NULL;
|
||||
@@ -273,7 +273,7 @@ match_varid(Var *test_var, List *tlist)
|
||||
|
||||
type_var = (Oid) test_var->vartype;
|
||||
|
||||
Assert (test_var->varlevelsup == 0);
|
||||
Assert(test_var->varlevelsup == 0);
|
||||
foreach(tl, tlist)
|
||||
{
|
||||
TargetEntry *entry;
|
||||
@@ -289,9 +289,9 @@ match_varid(Var *test_var, List *tlist)
|
||||
* we test the original varno (instead of varno which might be
|
||||
* changed to INNER/OUTER.
|
||||
*/
|
||||
Assert (tlvar->varlevelsup == 0);
|
||||
Assert(tlvar->varlevelsup == 0);
|
||||
if (tlvar->varnoold == test_var->varnoold &&
|
||||
tlvar->varoattno == test_var->varoattno)
|
||||
tlvar->varoattno == test_var->varoattno)
|
||||
{
|
||||
|
||||
if (tlvar->vartype == type_var)
|
||||
@@ -313,7 +313,7 @@ match_varid(Var *test_var, List *tlist)
|
||||
* Returns the resulting target list.
|
||||
*
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
new_unsorted_tlist(List *targetlist)
|
||||
{
|
||||
List *new_targetlist = (List *) copyObject((Node *) targetlist);
|
||||
@@ -341,7 +341,7 @@ new_unsorted_tlist(List *targetlist)
|
||||
* Returns a new target list.
|
||||
*
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
copy_vars(List *target, List *source)
|
||||
{
|
||||
List *result = NIL;
|
||||
@@ -369,7 +369,7 @@ copy_vars(List *target, List *source)
|
||||
* Returns the "flattened" new target list.
|
||||
*
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
flatten_tlist(List *tlist)
|
||||
{
|
||||
int last_resdomno = 1;
|
||||
@@ -425,7 +425,7 @@ flatten_tlist(List *tlist)
|
||||
* Returns the modified actual target list.
|
||||
*
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
flatten_tlist_vars(List *full_tlist, List *flat_tlist)
|
||||
{
|
||||
List *x = NIL;
|
||||
@@ -556,7 +556,7 @@ MakeTLE(Resdom *resdom, Node *expr)
|
||||
return rt;
|
||||
}
|
||||
|
||||
Var *
|
||||
Var *
|
||||
get_expr(TargetEntry *tle)
|
||||
{
|
||||
Assert(tle != NULL);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/var.c,v 1.10 1998/02/13 03:40:23 vadim Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/var.c,v 1.11 1998/02/26 04:33:22 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -35,7 +35,7 @@
|
||||
* XXX assumes varno's are always integers, which shouldn't be true...
|
||||
* (though it currently is, see primnodes.h)
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
pull_varnos(Node *me)
|
||||
{
|
||||
List *i,
|
||||
@@ -107,9 +107,9 @@ contain_var_clause(Node *clause)
|
||||
return TRUE;
|
||||
}
|
||||
/* Ok - check left sides of Oper-s */
|
||||
foreach(temp, ((SubPlan*) ((Expr *) clause)->oper)->sublink->oper)
|
||||
foreach(temp, ((SubPlan *) ((Expr *) clause)->oper)->sublink->oper)
|
||||
{
|
||||
if (contain_var_clause(lfirst(((Expr*) lfirst(temp))->args)))
|
||||
if (contain_var_clause(lfirst(((Expr *) lfirst(temp))->args)))
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
@@ -150,7 +150,7 @@ contain_var_clause(Node *clause)
|
||||
*
|
||||
* Returns list of varnodes found.
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
pull_var_clause(Node *clause)
|
||||
{
|
||||
List *retval = NIL;
|
||||
@@ -174,12 +174,12 @@ pull_var_clause(Node *clause)
|
||||
{
|
||||
List *temp;
|
||||
|
||||
foreach(temp, ((Expr*) clause)->args)
|
||||
foreach(temp, ((Expr *) clause)->args)
|
||||
retval = nconc(retval, pull_var_clause(lfirst(temp)));
|
||||
/* Ok - get Var-s from left sides of Oper-s */
|
||||
foreach(temp, ((SubPlan*) ((Expr*) clause)->oper)->sublink->oper)
|
||||
retval = nconc(retval,
|
||||
pull_var_clause(lfirst(((Expr*) lfirst(temp))->args)));
|
||||
foreach(temp, ((SubPlan *) ((Expr *) clause)->oper)->sublink->oper)
|
||||
retval = nconc(retval,
|
||||
pull_var_clause(lfirst(((Expr *) lfirst(temp))->args)));
|
||||
}
|
||||
else if (IsA(clause, Aggreg))
|
||||
{
|
||||
@@ -224,7 +224,7 @@ var_equal(Var *var1, Var *var2)
|
||||
(((Var *) var1)->varlevelsup == ((Var *) var2)->varlevelsup) &&
|
||||
(((Var *) var1)->varattno == ((Var *) var2)->varattno))
|
||||
{
|
||||
Assert (((Var *) var1)->varlevelsup == 0);
|
||||
Assert(((Var *) var1)->varlevelsup == 0);
|
||||
return (true);
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user