mirror of
https://github.com/postgres/postgres.git
synced 2025-06-25 01:02:05 +03:00
Another PGINDENT run that changes variable indenting and case label indenting. Also static variable indenting.
This commit is contained in:
@ -4,7 +4,7 @@
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: geqo_copy.c,v 1.2 1997/09/07 04:43:01 momjian Exp $
|
||||
* $Id: geqo_copy.c,v 1.3 1997/09/08 02:23:47 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -58,7 +58,7 @@
|
||||
void
|
||||
geqo_copy(Chromosome * chromo1, Chromosome * chromo2, int string_length)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < string_length; i++)
|
||||
chromo1->string[i] = chromo2->string[i];
|
||||
|
@ -6,7 +6,7 @@
|
||||
* CX operator according to Oliver et al
|
||||
* (Proc 2nd Int'l Conf on GA's)
|
||||
*
|
||||
* $Id: geqo_cx.c,v 1.2 1997/09/07 04:43:02 momjian Exp $
|
||||
* $Id: geqo_cx.c,v 1.3 1997/09/08 02:23:49 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -63,11 +63,11 @@ int
|
||||
cx(Gene * tour1, Gene * tour2, Gene * offspring, int num_gene, City * city_table)
|
||||
{
|
||||
|
||||
int i,
|
||||
start_pos,
|
||||
curr_pos;
|
||||
int count = 0;
|
||||
int num_diffs = 0;
|
||||
int i,
|
||||
start_pos,
|
||||
curr_pos;
|
||||
int count = 0;
|
||||
int num_diffs = 0;
|
||||
|
||||
/* initialize city table */
|
||||
for (i = 1; i <= num_gene; i++)
|
||||
|
@ -3,7 +3,7 @@
|
||||
* geqo_erx.c--
|
||||
* edge recombination crossover [ER]
|
||||
*
|
||||
* $Id: geqo_erx.c,v 1.3 1997/09/07 04:43:04 momjian Exp $
|
||||
* $Id: geqo_erx.c,v 1.4 1997/09/08 02:23:52 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -52,11 +52,11 @@
|
||||
#include "optimizer/geqo_random.h"
|
||||
|
||||
|
||||
static int gimme_edge(Gene gene1, Gene gene2, Edge * edge_table);
|
||||
static void remove_gene(Gene gene, Edge edge, Edge * edge_table);
|
||||
static Gene gimme_gene(Edge edge, Edge * edge_table);
|
||||
static int gimme_edge(Gene gene1, Gene gene2, Edge * edge_table);
|
||||
static void remove_gene(Gene gene, Edge edge, Edge * edge_table);
|
||||
static Gene gimme_gene(Edge edge, Edge * edge_table);
|
||||
|
||||
static Gene edge_failure(Gene * gene, int index, Edge * edge_table, int num_gene);
|
||||
static Gene edge_failure(Gene * gene, int index, Edge * edge_table, int num_gene);
|
||||
|
||||
|
||||
/* alloc_edge_table--
|
||||
@ -65,10 +65,10 @@ static Gene edge_failure(Gene * gene, int index, Edge * edge_table, int num_gen
|
||||
*
|
||||
*/
|
||||
|
||||
Edge *
|
||||
Edge *
|
||||
alloc_edge_table(int num_gene)
|
||||
{
|
||||
Edge *edge_table;
|
||||
Edge *edge_table;
|
||||
|
||||
/*
|
||||
* palloc one extra location so that nodes numbered 1..n can be
|
||||
@ -107,10 +107,10 @@ free_edge_table(Edge * edge_table)
|
||||
float
|
||||
gimme_edge_table(Gene * tour1, Gene * tour2, int num_gene, Edge * edge_table)
|
||||
{
|
||||
int i,
|
||||
index1,
|
||||
index2;
|
||||
int edge_total; /* total number of unique edges in two
|
||||
int i,
|
||||
index1,
|
||||
index2;
|
||||
int edge_total; /* total number of unique edges in two
|
||||
* genes */
|
||||
|
||||
/* at first clear the edge table's old data */
|
||||
@ -167,10 +167,10 @@ gimme_edge_table(Gene * tour1, Gene * tour2, int num_gene, Edge * edge_table)
|
||||
static int
|
||||
gimme_edge(Gene gene1, Gene gene2, Edge * edge_table)
|
||||
{
|
||||
int i;
|
||||
int edges;
|
||||
int city1 = (int) gene1;
|
||||
int city2 = (int) gene2;
|
||||
int i;
|
||||
int edges;
|
||||
int city1 = (int) gene1;
|
||||
int city2 = (int) gene2;
|
||||
|
||||
|
||||
/* check whether edge city1->city2 already exists */
|
||||
@ -209,8 +209,8 @@ gimme_edge(Gene gene1, Gene gene2, Edge * edge_table)
|
||||
int
|
||||
gimme_tour(Edge * edge_table, Gene * new_gene, int num_gene)
|
||||
{
|
||||
int i;
|
||||
int edge_failures = 0;
|
||||
int i;
|
||||
int edge_failures = 0;
|
||||
|
||||
new_gene[0] = (Gene) geqo_randint(num_gene, 1); /* choose int between 1
|
||||
* and num_gene */
|
||||
@ -258,10 +258,10 @@ gimme_tour(Edge * edge_table, Gene * new_gene, int num_gene)
|
||||
static void
|
||||
remove_gene(Gene gene, Edge edge, Edge * edge_table)
|
||||
{
|
||||
int i,
|
||||
j;
|
||||
int possess_edge;
|
||||
int genes_remaining;
|
||||
int i,
|
||||
j;
|
||||
int possess_edge;
|
||||
int genes_remaining;
|
||||
|
||||
/*
|
||||
* do for every gene known to have an edge to input gene (i.e. in
|
||||
@ -297,14 +297,14 @@ remove_gene(Gene gene, Edge edge, Edge * edge_table)
|
||||
* (i.e. edges which both genes possess)
|
||||
*
|
||||
*/
|
||||
static Gene
|
||||
static Gene
|
||||
gimme_gene(Edge edge, Edge * edge_table)
|
||||
{
|
||||
int i;
|
||||
Gene friend;
|
||||
int minimum_edges;
|
||||
int minimum_count = -1;
|
||||
int rand_decision;
|
||||
int i;
|
||||
Gene friend;
|
||||
int minimum_edges;
|
||||
int minimum_count = -1;
|
||||
int rand_decision;
|
||||
|
||||
/*
|
||||
* no point has edges to more than 4 other points thus, this contrived
|
||||
@ -388,14 +388,14 @@ gimme_gene(Edge edge, Edge * edge_table)
|
||||
* routine for handling edge failure
|
||||
*
|
||||
*/
|
||||
static Gene
|
||||
static Gene
|
||||
edge_failure(Gene * gene, int index, Edge * edge_table, int num_gene)
|
||||
{
|
||||
int i;
|
||||
Gene fail_gene = gene[index];
|
||||
int remaining_edges = 0;
|
||||
int four_count = 0;
|
||||
int rand_decision;
|
||||
int i;
|
||||
Gene fail_gene = gene[index];
|
||||
int remaining_edges = 0;
|
||||
int four_count = 0;
|
||||
int rand_decision;
|
||||
|
||||
|
||||
/*
|
||||
|
@ -5,7 +5,7 @@
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: geqo_eval.c,v 1.13 1997/09/07 04:43:06 momjian Exp $
|
||||
* $Id: geqo_eval.c,v 1.14 1997/09/08 02:23:53 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -50,13 +50,13 @@
|
||||
#include "optimizer/geqo_paths.h"
|
||||
|
||||
|
||||
static List *gimme_clause_joins(Query * root, Rel * outer_rel, Rel * inner_rel);
|
||||
static Rel *gimme_clauseless_join(Rel * outer_rel, Rel * inner_rel);
|
||||
static Rel *init_join_rel(Rel * outer_rel, Rel * inner_rel, JInfo * joininfo);
|
||||
static List *new_join_tlist(List * tlist, List * other_relids, int first_resdomno);
|
||||
static List *new_joininfo_list(List * joininfo_list, List * join_relids);
|
||||
static void geqo_joinrel_size(Rel * joinrel, Rel * outer_rel, Rel * inner_rel);
|
||||
static Rel *geqo_nth(int stop, List * rels);
|
||||
static List *gimme_clause_joins(Query * root, Rel * outer_rel, Rel * inner_rel);
|
||||
static Rel *gimme_clauseless_join(Rel * outer_rel, Rel * inner_rel);
|
||||
static Rel *init_join_rel(Rel * outer_rel, Rel * inner_rel, JInfo * joininfo);
|
||||
static List *new_join_tlist(List * tlist, List * other_relids, int first_resdomno);
|
||||
static List *new_joininfo_list(List * joininfo_list, List * join_relids);
|
||||
static void geqo_joinrel_size(Rel * joinrel, Rel * outer_rel, Rel * inner_rel);
|
||||
static Rel *geqo_nth(int stop, List * rels);
|
||||
|
||||
/*
|
||||
* geqo_eval--
|
||||
@ -66,9 +66,9 @@ static Rel *geqo_nth(int stop, List * rels);
|
||||
Cost
|
||||
geqo_eval(Query * root, Gene * tour, int num_gene)
|
||||
{
|
||||
Rel *joinrel;
|
||||
Cost fitness;
|
||||
List *temp;
|
||||
Rel *joinrel;
|
||||
Cost fitness;
|
||||
List *temp;
|
||||
|
||||
|
||||
/* remember root->join_relation_list_ ... */
|
||||
@ -98,14 +98,14 @@ 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 */
|
||||
int base_rel_index;
|
||||
Rel *inner_rel; /* current relation */
|
||||
int base_rel_index;
|
||||
|
||||
List *new_rels = NIL;
|
||||
Rel *new_rel = NULL;
|
||||
List *new_rels = NIL;
|
||||
Rel *new_rel = NULL;
|
||||
|
||||
if (rel_count < num_gene)
|
||||
{ /* tree not yet finished */
|
||||
@ -190,21 +190,21 @@ gimme_tree(Query * root, Gene * tour, int rel_count, int num_gene, Rel * outer_r
|
||||
* Returns a list of new join relations.
|
||||
*/
|
||||
|
||||
static List *
|
||||
static List *
|
||||
gimme_clause_joins(Query * root, Rel * outer_rel, Rel * inner_rel)
|
||||
{
|
||||
List *join_list = NIL;
|
||||
List *i = NIL;
|
||||
List *joininfo_list = (List *) outer_rel->joininfo;
|
||||
List *join_list = NIL;
|
||||
List *i = NIL;
|
||||
List *joininfo_list = (List *) outer_rel->joininfo;
|
||||
|
||||
foreach(i, joininfo_list)
|
||||
{
|
||||
JInfo *joininfo = (JInfo *) lfirst(i);
|
||||
Rel *rel = NULL;
|
||||
JInfo *joininfo = (JInfo *) lfirst(i);
|
||||
Rel *rel = NULL;
|
||||
|
||||
if (!joininfo->inactive)
|
||||
{
|
||||
List *other_rels = (List *) joininfo->otherrels;
|
||||
List *other_rels = (List *) joininfo->otherrels;
|
||||
|
||||
if (other_rels != NIL)
|
||||
{
|
||||
@ -243,7 +243,7 @@ gimme_clause_joins(Query * root, Rel * outer_rel, Rel * inner_rel)
|
||||
* Returns a new join relation.
|
||||
*/
|
||||
|
||||
static Rel *
|
||||
static Rel *
|
||||
gimme_clauseless_join(Rel * outer_rel, Rel * inner_rel)
|
||||
{
|
||||
return (init_join_rel(outer_rel, inner_rel, (JInfo *) NULL));
|
||||
@ -260,13 +260,13 @@ gimme_clauseless_join(Rel * outer_rel, Rel * inner_rel)
|
||||
*
|
||||
* Returns the new join relation node.
|
||||
*/
|
||||
static Rel *
|
||||
static Rel *
|
||||
init_join_rel(Rel * outer_rel, Rel * inner_rel, JInfo * joininfo)
|
||||
{
|
||||
Rel *joinrel = makeNode(Rel);
|
||||
List *joinrel_joininfo_list = NIL;
|
||||
List *new_outer_tlist;
|
||||
List *new_inner_tlist;
|
||||
Rel *joinrel = makeNode(Rel);
|
||||
List *joinrel_joininfo_list = NIL;
|
||||
List *new_outer_tlist;
|
||||
List *new_inner_tlist;
|
||||
|
||||
/*
|
||||
* Create a new tlist by removing irrelevant elements from both tlists
|
||||
@ -338,18 +338,18 @@ init_join_rel(Rel * outer_rel, Rel * inner_rel, JInfo * joininfo)
|
||||
*
|
||||
* Returns the new target list.
|
||||
*/
|
||||
static List *
|
||||
static List *
|
||||
new_join_tlist(List * tlist,
|
||||
List * other_relids,
|
||||
int first_resdomno)
|
||||
{
|
||||
int resdomno = first_resdomno - 1;
|
||||
TargetEntry *xtl = NULL;
|
||||
List *temp_node = NIL;
|
||||
List *t_list = NIL;
|
||||
List *i = NIL;
|
||||
List *join_list = NIL;
|
||||
bool in_final_tlist = false;
|
||||
int resdomno = first_resdomno - 1;
|
||||
TargetEntry *xtl = NULL;
|
||||
List *temp_node = NIL;
|
||||
List *t_list = NIL;
|
||||
List *i = NIL;
|
||||
List *join_list = NIL;
|
||||
bool in_final_tlist = false;
|
||||
|
||||
|
||||
foreach(i, tlist)
|
||||
@ -388,18 +388,18 @@ new_join_tlist(List * tlist,
|
||||
*
|
||||
* Returns a list of joininfo nodes, new and old.
|
||||
*/
|
||||
static List *
|
||||
static List *
|
||||
new_joininfo_list(List * joininfo_list, List * join_relids)
|
||||
{
|
||||
List *current_joininfo_list = NIL;
|
||||
List *new_otherrels = NIL;
|
||||
JInfo *other_joininfo = (JInfo *) NULL;
|
||||
List *xjoininfo = NIL;
|
||||
List *current_joininfo_list = NIL;
|
||||
List *new_otherrels = NIL;
|
||||
JInfo *other_joininfo = (JInfo *) NULL;
|
||||
List *xjoininfo = NIL;
|
||||
|
||||
foreach(xjoininfo, joininfo_list)
|
||||
{
|
||||
List *or;
|
||||
JInfo *joininfo = (JInfo *) lfirst(xjoininfo);
|
||||
List *or;
|
||||
JInfo *joininfo = (JInfo *) lfirst(xjoininfo);
|
||||
|
||||
new_otherrels = joininfo->otherrels;
|
||||
foreach(or, new_otherrels)
|
||||
@ -456,21 +456,21 @@ new_joininfo_list(List * joininfo_list, List * join_relids)
|
||||
static void
|
||||
geqo_add_new_joininfos(Query * root, List * joinrels, List * outerrels)
|
||||
{
|
||||
List *xjoinrel = NIL;
|
||||
List *xrelid = NIL;
|
||||
List *xrel = NIL;
|
||||
List *xjoininfo = NIL;
|
||||
List *xjoinrel = NIL;
|
||||
List *xrelid = NIL;
|
||||
List *xrel = NIL;
|
||||
List *xjoininfo = NIL;
|
||||
|
||||
Rel *rel;
|
||||
List *relids;
|
||||
Rel *rel;
|
||||
List *relids;
|
||||
|
||||
List *super_rels;
|
||||
List *xsuper_rel = NIL;
|
||||
JInfo *new_joininfo;
|
||||
List *super_rels;
|
||||
List *xsuper_rel = NIL;
|
||||
JInfo *new_joininfo;
|
||||
|
||||
foreach(xjoinrel, joinrels)
|
||||
{
|
||||
Rel *joinrel = (Rel *) lfirst(xjoinrel);
|
||||
Rel *joinrel = (Rel *) lfirst(xjoinrel);
|
||||
|
||||
foreach(xrelid, joinrel->relids)
|
||||
{
|
||||
@ -506,15 +506,15 @@ geqo_add_new_joininfos(Query * root, List * joinrels, List * outerrels)
|
||||
}
|
||||
foreach(xjoinrel, joinrels)
|
||||
{
|
||||
Rel *joinrel = (Rel *) lfirst(xjoinrel);
|
||||
Rel *joinrel = (Rel *) lfirst(xjoinrel);
|
||||
|
||||
foreach(xjoininfo, joinrel->joininfo)
|
||||
{
|
||||
JInfo *joininfo = (JInfo *) lfirst(xjoininfo);
|
||||
List *other_rels = joininfo->otherrels;
|
||||
List *clause_info = joininfo->jinfoclauseinfo;
|
||||
bool mergesortable = joininfo->mergesortable;
|
||||
bool hashjoinable = joininfo->hashjoinable;
|
||||
JInfo *joininfo = (JInfo *) lfirst(xjoininfo);
|
||||
List *other_rels = joininfo->otherrels;
|
||||
List *clause_info = joininfo->jinfoclauseinfo;
|
||||
bool mergesortable = joininfo->mergesortable;
|
||||
bool hashjoinable = joininfo->hashjoinable;
|
||||
|
||||
foreach(xrelid, other_rels)
|
||||
{
|
||||
@ -553,12 +553,12 @@ geqo_add_new_joininfos(Query * root, List * joinrels, List * outerrels)
|
||||
|
||||
foreach(xsuper_rel, super_rels)
|
||||
{
|
||||
Rel *super_rel = (Rel *) lfirst(xsuper_rel);
|
||||
Rel *super_rel = (Rel *) lfirst(xsuper_rel);
|
||||
|
||||
if (nonoverlap_rels(super_rel, joinrel))
|
||||
{
|
||||
List *new_relids = super_rel->relids;
|
||||
JInfo *other_joininfo =
|
||||
List *new_relids = super_rel->relids;
|
||||
JInfo *other_joininfo =
|
||||
joininfo_member(new_relids,
|
||||
joinrel->joininfo);
|
||||
|
||||
@ -570,7 +570,7 @@ geqo_add_new_joininfos(Query * root, List * joinrels, List * outerrels)
|
||||
}
|
||||
else
|
||||
{
|
||||
JInfo *new_joininfo = makeNode(JInfo);
|
||||
JInfo *new_joininfo = makeNode(JInfo);
|
||||
|
||||
new_joininfo->otherrels = new_relids;
|
||||
new_joininfo->jinfoclauseinfo = clause_info;
|
||||
@ -602,12 +602,12 @@ geqo_add_new_joininfos(Query * root, List * joinrels, List * outerrels)
|
||||
*
|
||||
* Returns the list of final join relations.
|
||||
*/
|
||||
static List *
|
||||
static List *
|
||||
geqo_final_join_rels(List * join_rel_list)
|
||||
{
|
||||
List *xrel = NIL;
|
||||
List *temp = NIL;
|
||||
List *t_list = NIL;
|
||||
List *xrel = NIL;
|
||||
List *temp = NIL;
|
||||
List *t_list = NIL;
|
||||
|
||||
/*
|
||||
* find the relations that has no further joins, i.e., its joininfos
|
||||
@ -615,13 +615,13 @@ geqo_final_join_rels(List * join_rel_list)
|
||||
*/
|
||||
foreach(xrel, join_rel_list)
|
||||
{
|
||||
Rel *rel = (Rel *) lfirst(xrel);
|
||||
List *xjoininfo = NIL;
|
||||
bool final = true;
|
||||
Rel *rel = (Rel *) lfirst(xrel);
|
||||
List *xjoininfo = NIL;
|
||||
bool final = true;
|
||||
|
||||
foreach(xjoininfo, rel->joininfo)
|
||||
{
|
||||
JInfo *joininfo = (JInfo *) lfirst(xjoininfo);
|
||||
JInfo *joininfo = (JInfo *) lfirst(xjoininfo);
|
||||
|
||||
if (joininfo->otherrels != NIL)
|
||||
{
|
||||
@ -663,20 +663,20 @@ add_superrels(Rel * rel, Rel * super_rel)
|
||||
*
|
||||
* Returns non-nil if rel1 and rel2 do not overlap.
|
||||
*/
|
||||
static bool
|
||||
static bool
|
||||
nonoverlap_rels(Rel * rel1, Rel * rel2)
|
||||
{
|
||||
return (nonoverlap_sets(rel1->relids, rel2->relids));
|
||||
}
|
||||
|
||||
static bool
|
||||
static bool
|
||||
nonoverlap_sets(List * s1, List * s2)
|
||||
{
|
||||
List *x = NIL;
|
||||
List *x = NIL;
|
||||
|
||||
foreach(x, s1)
|
||||
{
|
||||
int e = lfirsti(x);
|
||||
int e = lfirsti(x);
|
||||
|
||||
if (intMember(e, s2))
|
||||
return (false);
|
||||
@ -694,8 +694,8 @@ nonoverlap_sets(List * s1, List * s2)
|
||||
static void
|
||||
geqo_joinrel_size(Rel * joinrel, Rel * outer_rel, Rel * inner_rel)
|
||||
{
|
||||
Cost temp;
|
||||
int ntuples;
|
||||
Cost temp;
|
||||
int ntuples;
|
||||
|
||||
temp = (Cost) inner_rel->tuples * (Cost) outer_rel->tuples; /* cartesian product */
|
||||
|
||||
@ -725,11 +725,11 @@ geqo_log(double x, double b)
|
||||
return (log(x) / log(b));
|
||||
}
|
||||
|
||||
static Rel *
|
||||
static Rel *
|
||||
geqo_nth(int stop, List * rels)
|
||||
{
|
||||
List *r;
|
||||
int i = 1;
|
||||
List *r;
|
||||
int i = 1;
|
||||
|
||||
foreach(r, rels)
|
||||
{
|
||||
|
@ -6,7 +6,7 @@
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: geqo_main.c,v 1.4 1997/09/07 04:43:09 momjian Exp $
|
||||
* $Id: geqo_main.c,v 1.5 1997/09/08 02:23:55 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -63,42 +63,42 @@
|
||||
* similar to a constrained Traveling Salesman Problem (TSP)
|
||||
*/
|
||||
|
||||
Rel *
|
||||
Rel *
|
||||
geqo(Query * root)
|
||||
{
|
||||
int generation;
|
||||
Chromosome *momma;
|
||||
Chromosome *daddy;
|
||||
Chromosome *kid;
|
||||
int generation;
|
||||
Chromosome *momma;
|
||||
Chromosome *daddy;
|
||||
Chromosome *kid;
|
||||
|
||||
#if defined(ERX)
|
||||
Edge *edge_table; /* list of edges */
|
||||
int edge_failures = 0;
|
||||
float difference;
|
||||
Edge *edge_table; /* list of edges */
|
||||
int edge_failures = 0;
|
||||
float difference;
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(CX) || defined(PX) || defined(OX1) || defined(OX2)
|
||||
City *city_table; /* list of cities */
|
||||
City *city_table; /* list of cities */
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(CX)
|
||||
int cycle_diffs = 0;
|
||||
int mutations = 0;
|
||||
int cycle_diffs = 0;
|
||||
int mutations = 0;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
int number_of_rels;
|
||||
int number_of_rels;
|
||||
|
||||
Pool *pool;
|
||||
int pool_size,
|
||||
number_generations,
|
||||
status_interval;
|
||||
Pool *pool;
|
||||
int pool_size,
|
||||
number_generations,
|
||||
status_interval;
|
||||
|
||||
Gene *best_tour;
|
||||
Rel *best_rel;
|
||||
Gene *best_tour;
|
||||
Rel *best_rel;
|
||||
|
||||
/* Plan *best_plan; */
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: geqo_misc.c,v 1.3 1997/09/07 04:43:10 momjian Exp $
|
||||
* $Id: geqo_misc.c,v 1.4 1997/09/08 02:23:57 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -41,7 +41,7 @@
|
||||
#include "optimizer/geqo_recombination.h"
|
||||
#include "optimizer/geqo_misc.h"
|
||||
|
||||
static float avg_pool(Pool * pool);
|
||||
static float avg_pool(Pool * pool);
|
||||
|
||||
/* avg_pool--
|
||||
*
|
||||
@ -49,8 +49,8 @@ static float avg_pool(Pool * pool);
|
||||
static float
|
||||
avg_pool(Pool * pool)
|
||||
{
|
||||
int i;
|
||||
double cumulative = 0.0;
|
||||
int i;
|
||||
double cumulative = 0.0;
|
||||
|
||||
if (pool->size == 0)
|
||||
elog(WARN, "avg_pool: pool_size of zero");
|
||||
@ -66,8 +66,8 @@ avg_pool(Pool * pool)
|
||||
void
|
||||
print_pool(FILE * fp, Pool * pool, int start, int stop)
|
||||
{
|
||||
int i,
|
||||
j;
|
||||
int i,
|
||||
j;
|
||||
|
||||
/* be extra careful that start and stop are valid inputs */
|
||||
|
||||
@ -99,7 +99,7 @@ print_pool(FILE * fp, Pool * pool, int start, int stop)
|
||||
void
|
||||
print_gen(FILE * fp, Pool * pool, int generation)
|
||||
{
|
||||
int lowest;
|
||||
int lowest;
|
||||
|
||||
/* Get index to lowest ranking gene in poplulation. */
|
||||
/* Use 2nd to last since last is buffer. */
|
||||
@ -118,8 +118,8 @@ print_gen(FILE * fp, Pool * pool, int generation)
|
||||
void
|
||||
print_edge_table(FILE * fp, Edge * edge_table, int num_gene)
|
||||
{
|
||||
int i,
|
||||
j;
|
||||
int i,
|
||||
j;
|
||||
|
||||
fprintf(fp, "\nEDGE TABLE\n");
|
||||
|
||||
@ -141,12 +141,12 @@ print_edge_table(FILE * fp, Edge * edge_table, int num_gene)
|
||||
void
|
||||
geqo_print_joinclauses(Query * root, List * clauses)
|
||||
{
|
||||
List *l;
|
||||
extern void print_expr(Node * expr, List * rtable); /* in print.c */
|
||||
List *l;
|
||||
extern void print_expr(Node * expr, List * rtable); /* in print.c */
|
||||
|
||||
foreach(l, clauses)
|
||||
{
|
||||
CInfo *c = lfirst(l);
|
||||
CInfo *c = lfirst(l);
|
||||
|
||||
print_expr((Node *) c->clause, root->rtable);
|
||||
if (lnext(l))
|
||||
@ -157,88 +157,88 @@ geqo_print_joinclauses(Query * root, List * clauses)
|
||||
void
|
||||
geqo_print_path(Query * root, Path * path, int indent)
|
||||
{
|
||||
char *ptype = NULL;
|
||||
JoinPath *jp;
|
||||
bool join = false;
|
||||
int i;
|
||||
char *ptype = NULL;
|
||||
JoinPath *jp;
|
||||
bool join = false;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < indent; i++)
|
||||
printf("\t");
|
||||
|
||||
switch (nodeTag(path))
|
||||
{
|
||||
case T_Path:
|
||||
ptype = "SeqScan";
|
||||
join = false;
|
||||
break;
|
||||
case T_IndexPath:
|
||||
ptype = "IdxScan";
|
||||
join = false;
|
||||
break;
|
||||
case T_JoinPath:
|
||||
ptype = "Nestloop";
|
||||
join = true;
|
||||
break;
|
||||
case T_MergePath:
|
||||
ptype = "MergeJoin";
|
||||
join = true;
|
||||
break;
|
||||
case T_HashPath:
|
||||
ptype = "HashJoin";
|
||||
join = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case T_Path:
|
||||
ptype = "SeqScan";
|
||||
join = false;
|
||||
break;
|
||||
case T_IndexPath:
|
||||
ptype = "IdxScan";
|
||||
join = false;
|
||||
break;
|
||||
case T_JoinPath:
|
||||
ptype = "Nestloop";
|
||||
join = true;
|
||||
break;
|
||||
case T_MergePath:
|
||||
ptype = "MergeJoin";
|
||||
join = true;
|
||||
break;
|
||||
case T_HashPath:
|
||||
ptype = "HashJoin";
|
||||
join = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (join)
|
||||
{
|
||||
int size = path->parent->size;
|
||||
int size = path->parent->size;
|
||||
|
||||
jp = (JoinPath *) path;
|
||||
printf("%s size=%d cost=%f\n", ptype, size, path->path_cost);
|
||||
switch (nodeTag(path))
|
||||
{
|
||||
case T_MergePath:
|
||||
case T_HashPath:
|
||||
for (i = 0; i < indent + 1; i++)
|
||||
printf("\t");
|
||||
printf(" clauses=(");
|
||||
geqo_print_joinclauses(root,
|
||||
((JoinPath *) path)->pathclauseinfo);
|
||||
printf(")\n");
|
||||
case T_MergePath:
|
||||
case T_HashPath:
|
||||
for (i = 0; i < indent + 1; i++)
|
||||
printf("\t");
|
||||
printf(" clauses=(");
|
||||
geqo_print_joinclauses(root,
|
||||
((JoinPath *) path)->pathclauseinfo);
|
||||
printf(")\n");
|
||||
|
||||
if (nodeTag(path) == T_MergePath)
|
||||
{
|
||||
MergePath *mp = (MergePath *) path;
|
||||
|
||||
if (mp->outersortkeys || mp->innersortkeys)
|
||||
if (nodeTag(path) == T_MergePath)
|
||||
{
|
||||
for (i = 0; i < indent + 1; i++)
|
||||
printf("\t");
|
||||
printf(" sortouter=%d sortinner=%d\n",
|
||||
((mp->outersortkeys) ? 1 : 0),
|
||||
((mp->innersortkeys) ? 1 : 0));
|
||||
MergePath *mp = (MergePath *) path;
|
||||
|
||||
if (mp->outersortkeys || mp->innersortkeys)
|
||||
{
|
||||
for (i = 0; i < indent + 1; i++)
|
||||
printf("\t");
|
||||
printf(" sortouter=%d sortinner=%d\n",
|
||||
((mp->outersortkeys) ? 1 : 0),
|
||||
((mp->innersortkeys) ? 1 : 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
geqo_print_path(root, jp->outerjoinpath, indent + 1);
|
||||
geqo_print_path(root, jp->innerjoinpath, indent + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
int size = path->parent->size;
|
||||
int relid = lfirsti(path->parent->relids);
|
||||
int size = path->parent->size;
|
||||
int relid = lfirsti(path->parent->relids);
|
||||
|
||||
printf("%s(%d) size=%d cost=%f",
|
||||
ptype, relid, size, path->path_cost);
|
||||
|
||||
if (nodeTag(path) == T_IndexPath)
|
||||
{
|
||||
List *k,
|
||||
*l;
|
||||
List *k,
|
||||
*l;
|
||||
|
||||
printf(" keys=");
|
||||
foreach(k, path->keys)
|
||||
@ -246,7 +246,7 @@ geqo_print_path(Query * root, Path * path, int indent)
|
||||
printf("(");
|
||||
foreach(l, lfirst(k))
|
||||
{
|
||||
Var *var = lfirst(l);
|
||||
Var *var = lfirst(l);
|
||||
|
||||
printf("%d.%d", var->varnoold, var->varoattno);
|
||||
if (lnext(l))
|
||||
@ -264,7 +264,7 @@ geqo_print_path(Query * root, Path * path, int indent)
|
||||
void
|
||||
geqo_print_rel(Query * root, Rel * rel)
|
||||
{
|
||||
List *l;
|
||||
List *l;
|
||||
|
||||
printf("______________________________\n");
|
||||
printf("(");
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* TSP mutation routines
|
||||
*
|
||||
* $Id: geqo_mutation.c,v 1.2 1997/09/07 04:43:13 momjian Exp $
|
||||
* $Id: geqo_mutation.c,v 1.3 1997/09/08 02:23:57 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -53,10 +53,10 @@
|
||||
void
|
||||
geqo_mutation(Gene * tour, int num_gene)
|
||||
{
|
||||
int swap1;
|
||||
int swap2;
|
||||
int num_swaps = geqo_randint(num_gene / 3, 0);
|
||||
Gene temp;
|
||||
int swap1;
|
||||
int swap2;
|
||||
int num_swaps = geqo_randint(num_gene / 3, 0);
|
||||
Gene temp;
|
||||
|
||||
|
||||
while (num_swaps > 0)
|
||||
|
@ -6,7 +6,7 @@
|
||||
* OX1 operator according to Davis
|
||||
* (Proc Int'l Joint Conf on AI)
|
||||
*
|
||||
* $Id: geqo_ox1.c,v 1.2 1997/09/07 04:43:14 momjian Exp $
|
||||
* $Id: geqo_ox1.c,v 1.3 1997/09/08 02:23:58 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -61,11 +61,11 @@
|
||||
void
|
||||
ox1(Gene * tour1, Gene * tour2, Gene * offspring, int num_gene, City * city_table)
|
||||
{
|
||||
int left,
|
||||
right,
|
||||
k,
|
||||
p,
|
||||
temp;
|
||||
int left,
|
||||
right,
|
||||
k,
|
||||
p,
|
||||
temp;
|
||||
|
||||
/* initialize city table */
|
||||
for (k = 1; k <= num_gene; k++)
|
||||
|
@ -6,7 +6,7 @@
|
||||
* OX2 operator according to Syswerda
|
||||
* (The Genetic Algorithms Handbook, ed L Davis)
|
||||
*
|
||||
* $Id: geqo_ox2.c,v 1.2 1997/09/07 04:43:15 momjian Exp $
|
||||
* $Id: geqo_ox2.c,v 1.3 1997/09/08 02:23:59 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -61,12 +61,12 @@
|
||||
void
|
||||
ox2(Gene * tour1, Gene * tour2, Gene * offspring, int num_gene, City * city_table)
|
||||
{
|
||||
int k,
|
||||
j,
|
||||
count,
|
||||
pos,
|
||||
select,
|
||||
num_positions;
|
||||
int k,
|
||||
j,
|
||||
count,
|
||||
pos,
|
||||
select,
|
||||
num_positions;
|
||||
|
||||
/* initialize city table */
|
||||
for (k = 1; k <= num_gene; k++)
|
||||
|
@ -5,7 +5,7 @@
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: geqo_params.c,v 1.6 1997/09/07 04:43:16 momjian Exp $
|
||||
* $Id: geqo_params.c,v 1.7 1997/09/08 02:24:00 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -58,9 +58,9 @@
|
||||
#define MAX_TOKEN 80 /* Maximum size of one token in the *
|
||||
* configuration file */
|
||||
|
||||
static int gimme_pool_size(int string_length);
|
||||
static int gimme_number_generations(int pool_size, int effort);
|
||||
static int next_token(FILE *, char *, int);
|
||||
static int gimme_pool_size(int string_length);
|
||||
static int gimme_number_generations(int pool_size, int effort);
|
||||
static int next_token(FILE *, char *, int);
|
||||
|
||||
/*
|
||||
* geqo_param--
|
||||
@ -69,19 +69,19 @@ static int next_token(FILE *, char *, int);
|
||||
void
|
||||
geqo_params(int string_length)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
char buf[MAX_TOKEN];
|
||||
FILE *file;
|
||||
char buf[MAX_TOKEN];
|
||||
FILE *file;
|
||||
|
||||
char *conf_file;
|
||||
char *conf_file;
|
||||
|
||||
/* these static variables are used to signal that a value has been set */
|
||||
int pool_size = 0;
|
||||
int number_trials = 0;
|
||||
int random_seed = 0;
|
||||
int selection_bias = 0;
|
||||
int effort = 0;
|
||||
int pool_size = 0;
|
||||
int number_trials = 0;
|
||||
int random_seed = 0;
|
||||
int selection_bias = 0;
|
||||
int effort = 0;
|
||||
|
||||
|
||||
/* put together the full pathname to the config file */
|
||||
@ -272,8 +272,8 @@ geqo_params(int string_length)
|
||||
static int
|
||||
next_token(FILE * fp, char *buf, int bufsz)
|
||||
{
|
||||
int c;
|
||||
char *eb = buf + (bufsz - 1);
|
||||
int c;
|
||||
char *eb = buf + (bufsz - 1);
|
||||
|
||||
/* Discard inital whitespace */
|
||||
while (isspace(c = getc(fp)));
|
||||
@ -309,8 +309,8 @@ next_token(FILE * fp, char *buf, int bufsz)
|
||||
static int
|
||||
gimme_pool_size(int string_length)
|
||||
{
|
||||
double exponent;
|
||||
double size;
|
||||
double exponent;
|
||||
double size;
|
||||
|
||||
exponent = (double) string_length + 1.0;
|
||||
|
||||
@ -335,7 +335,7 @@ gimme_pool_size(int string_length)
|
||||
static int
|
||||
gimme_number_generations(int pool_size, int effort)
|
||||
{
|
||||
int number_gens;
|
||||
int number_gens;
|
||||
|
||||
number_gens = (int) ceil(geqo_log((double) pool_size, 2.0));
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: geqo_paths.c,v 1.5 1997/09/07 04:43:17 momjian Exp $
|
||||
* $Id: geqo_paths.c,v 1.6 1997/09/08 02:24:05 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -28,8 +28,8 @@
|
||||
#include "optimizer/geqo_paths.h"
|
||||
|
||||
|
||||
static List *geqo_prune_rel(Rel * rel, List * other_rels);
|
||||
static Path *set_paths(Rel * rel, Path * unorderedpath);
|
||||
static List *geqo_prune_rel(Rel * rel, List * other_rels);
|
||||
static Path *set_paths(Rel * rel, Path * unorderedpath);
|
||||
|
||||
/*
|
||||
* geqo-prune-rels--
|
||||
@ -39,10 +39,10 @@ static Path *set_paths(Rel * rel, Path * unorderedpath);
|
||||
* Returns the resulting list.
|
||||
*
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
geqo_prune_rels(List * rel_list)
|
||||
{
|
||||
List *temp_list = NIL;
|
||||
List *temp_list = NIL;
|
||||
|
||||
if (rel_list != NIL)
|
||||
{
|
||||
@ -64,13 +64,13 @@ geqo_prune_rels(List * rel_list)
|
||||
* of 'rel' appropriately.
|
||||
*
|
||||
*/
|
||||
static List *
|
||||
static List *
|
||||
geqo_prune_rel(Rel * rel, List * other_rels)
|
||||
{
|
||||
List *i = NIL;
|
||||
List *t_list = NIL;
|
||||
List *temp_node = NIL;
|
||||
Rel *other_rel = (Rel *) NULL;
|
||||
List *i = NIL;
|
||||
List *t_list = NIL;
|
||||
List *temp_node = NIL;
|
||||
Rel *other_rel = (Rel *) NULL;
|
||||
|
||||
foreach(i, other_rels)
|
||||
{
|
||||
@ -104,9 +104,9 @@ geqo_prune_rel(Rel * rel, List * other_rels)
|
||||
void
|
||||
geqo_rel_paths(Rel * rel)
|
||||
{
|
||||
List *y = NIL;
|
||||
Path *path = (Path *) NULL;
|
||||
JoinPath *cheapest = (JoinPath *) NULL;
|
||||
List *y = NIL;
|
||||
Path *path = (Path *) NULL;
|
||||
JoinPath *cheapest = (JoinPath *) NULL;
|
||||
|
||||
rel->size = 0;
|
||||
foreach(y, rel->pathlist)
|
||||
@ -133,10 +133,10 @@ geqo_rel_paths(Rel * rel)
|
||||
* Returns the cheapest path.
|
||||
*
|
||||
*/
|
||||
static Path *
|
||||
static Path *
|
||||
set_paths(Rel * rel, Path * unorderedpath)
|
||||
{
|
||||
Path *cheapest = set_cheapest(rel, rel->pathlist);
|
||||
Path *cheapest = set_cheapest(rel, rel->pathlist);
|
||||
|
||||
/* don't prune if not pruneable -- JMH, 11/23/92 */
|
||||
if (unorderedpath != cheapest
|
||||
|
@ -6,7 +6,7 @@
|
||||
* PMX operator according to Goldberg & Lingle
|
||||
* (Proc Int'l Conf on GA's)
|
||||
*
|
||||
* $Id: geqo_pmx.c,v 1.2 1997/09/07 04:43:18 momjian Exp $
|
||||
* $Id: geqo_pmx.c,v 1.3 1997/09/08 02:24:06 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -61,20 +61,20 @@
|
||||
void
|
||||
pmx(Gene * tour1, Gene * tour2, Gene * offspring, int num_gene)
|
||||
{
|
||||
int *failed = (int *) palloc((num_gene + 1) * sizeof(int));
|
||||
int *from = (int *) palloc((num_gene + 1) * sizeof(int));
|
||||
int *indx = (int *) palloc((num_gene + 1) * sizeof(int));
|
||||
int *check_list = (int *) palloc((num_gene + 1) * sizeof(int));
|
||||
int *failed = (int *) palloc((num_gene + 1) * sizeof(int));
|
||||
int *from = (int *) palloc((num_gene + 1) * sizeof(int));
|
||||
int *indx = (int *) palloc((num_gene + 1) * sizeof(int));
|
||||
int *check_list = (int *) palloc((num_gene + 1) * sizeof(int));
|
||||
|
||||
int left,
|
||||
right,
|
||||
temp,
|
||||
i,
|
||||
j,
|
||||
k;
|
||||
int mx_fail,
|
||||
found,
|
||||
mx_hold;
|
||||
int left,
|
||||
right,
|
||||
temp,
|
||||
i,
|
||||
j,
|
||||
k;
|
||||
int mx_fail,
|
||||
found,
|
||||
mx_hold;
|
||||
|
||||
|
||||
/* no mutation so start up the pmx replacement algorithm */
|
||||
|
@ -5,7 +5,7 @@
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: geqo_pool.c,v 1.2 1997/09/07 04:43:19 momjian Exp $
|
||||
* $Id: geqo_pool.c,v 1.3 1997/09/08 02:24:06 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -44,18 +44,18 @@
|
||||
#include "optimizer/geqo_recombination.h"
|
||||
|
||||
|
||||
static int compare(void *arg1, void *arg2);
|
||||
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;
|
||||
Chromosome *chromo;
|
||||
int i;
|
||||
Pool *new_pool;
|
||||
Chromosome *chromo;
|
||||
int i;
|
||||
|
||||
/* pool */
|
||||
new_pool = (Pool *) palloc(sizeof(Pool));
|
||||
@ -82,8 +82,8 @@ alloc_pool(int pool_size, int string_length)
|
||||
void
|
||||
free_pool(Pool * pool)
|
||||
{
|
||||
Chromosome *chromo;
|
||||
int i;
|
||||
Chromosome *chromo;
|
||||
int i;
|
||||
|
||||
/* all gene */
|
||||
chromo = (Chromosome *) pool->data; /* vector of all chromos */
|
||||
@ -104,14 +104,14 @@ free_pool(Pool * pool)
|
||||
void
|
||||
random_init_pool(Query * root, Pool * pool, int strt, int stp)
|
||||
{
|
||||
Chromosome *chromo = (Chromosome *) pool->data;
|
||||
int i;
|
||||
Chromosome *chromo = (Chromosome *) pool->data;
|
||||
int i;
|
||||
|
||||
for (i = strt; i < stp; i++)
|
||||
{
|
||||
init_tour(chromo[i].string, pool->string_length); /* from
|
||||
* "geqo_recombination.c"
|
||||
* */
|
||||
* */
|
||||
|
||||
pool->data[i].worth =
|
||||
geqo_eval(root, chromo[i].string, pool->string_length); /* "from geqo_eval.c" */
|
||||
@ -141,8 +141,8 @@ sort_pool(Pool * pool)
|
||||
static int
|
||||
compare(void *arg1, void *arg2)
|
||||
{
|
||||
Chromosome chromo1 = *(Chromosome *) arg1;
|
||||
Chromosome chromo2 = *(Chromosome *) arg2;
|
||||
Chromosome chromo1 = *(Chromosome *) arg1;
|
||||
Chromosome chromo2 = *(Chromosome *) arg2;
|
||||
|
||||
if (chromo1.worth == chromo2.worth)
|
||||
return (0);
|
||||
@ -155,10 +155,10 @@ compare(void *arg1, void *arg2)
|
||||
/* alloc_chromo--
|
||||
* allocates a chromosome and string space
|
||||
*/
|
||||
Chromosome *
|
||||
Chromosome *
|
||||
alloc_chromo(int string_length)
|
||||
{
|
||||
Chromosome *chromo;
|
||||
Chromosome *chromo;
|
||||
|
||||
chromo = (Chromosome *) palloc(sizeof(Chromosome));
|
||||
chromo->string = (Gene *) palloc((string_length + 1) * sizeof(Gene));
|
||||
@ -183,13 +183,13 @@ free_chromo(Chromosome * chromo)
|
||||
void
|
||||
spread_chromo(Chromosome * chromo, Pool * pool)
|
||||
{
|
||||
int top,
|
||||
mid,
|
||||
bot;
|
||||
int i,
|
||||
index;
|
||||
Chromosome swap_chromo,
|
||||
tmp_chromo;
|
||||
int top,
|
||||
mid,
|
||||
bot;
|
||||
int i,
|
||||
index;
|
||||
Chromosome swap_chromo,
|
||||
tmp_chromo;
|
||||
|
||||
/* new chromo is so bad we can't use it */
|
||||
if (chromo->worth > pool->data[pool->size - 1].worth)
|
||||
|
@ -6,7 +6,7 @@
|
||||
* PX operator according to Syswerda
|
||||
* (The Genetic Algorithms Handbook, L Davis, ed)
|
||||
*
|
||||
* $Id: geqo_px.c,v 1.2 1997/09/07 04:43:20 momjian Exp $
|
||||
* $Id: geqo_px.c,v 1.3 1997/09/08 02:24:07 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -62,11 +62,11 @@ void
|
||||
px(Gene * tour1, Gene * tour2, Gene * offspring, int num_gene, City * city_table)
|
||||
{
|
||||
|
||||
int num_positions;
|
||||
int i,
|
||||
pos,
|
||||
tour2_index,
|
||||
offspring_index;
|
||||
int num_positions;
|
||||
int i,
|
||||
pos,
|
||||
tour2_index,
|
||||
offspring_index;
|
||||
|
||||
/* initialize city table */
|
||||
for (i = 1; i <= num_gene; i++)
|
||||
|
@ -3,7 +3,7 @@
|
||||
* geqo_recombination.c--
|
||||
* misc recombination procedures
|
||||
*
|
||||
* $Id: geqo_recombination.c,v 1.2 1997/09/07 04:43:21 momjian Exp $
|
||||
* $Id: geqo_recombination.c,v 1.3 1997/09/08 02:24:08 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -53,10 +53,10 @@
|
||||
void
|
||||
init_tour(Gene * tour, int num_gene)
|
||||
{
|
||||
Gene *tmp;
|
||||
int remainder;
|
||||
int next,
|
||||
i;
|
||||
Gene *tmp;
|
||||
int remainder;
|
||||
int next,
|
||||
i;
|
||||
|
||||
tmp = (Gene *) palloc(num_gene * sizeof(Gene));
|
||||
|
||||
@ -84,10 +84,10 @@ init_tour(Gene * tour, int num_gene)
|
||||
* allocate memory for city table
|
||||
*
|
||||
*/
|
||||
City *
|
||||
City *
|
||||
alloc_city_table(int num_gene)
|
||||
{
|
||||
City *city_table;
|
||||
City *city_table;
|
||||
|
||||
/*
|
||||
* palloc one extra location so that nodes numbered 1..n can be
|
||||
|
@ -5,7 +5,7 @@
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: geqo_selection.c,v 1.2 1997/09/07 04:43:24 momjian Exp $
|
||||
* $Id: geqo_selection.c,v 1.3 1997/09/08 02:24:08 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -55,7 +55,7 @@
|
||||
#include "optimizer/geqo_copy.h"
|
||||
#include "optimizer/geqo_random.h"
|
||||
|
||||
static int linear(int max, double bias);
|
||||
static int linear(int max, double bias);
|
||||
|
||||
/* geqo_selection--
|
||||
*
|
||||
@ -65,8 +65,8 @@ static int linear(int max, double bias);
|
||||
void
|
||||
geqo_selection(Chromosome * momma, Chromosome * daddy, Pool * pool, double bias)
|
||||
{
|
||||
int first,
|
||||
second;
|
||||
int first,
|
||||
second;
|
||||
|
||||
first = (int) linear(pool->size, bias);
|
||||
second = (int) linear(pool->size, bias);
|
||||
@ -94,8 +94,8 @@ static int
|
||||
linear(int pool_size, double bias) /* bias is y-intercept of linear
|
||||
* distribution */
|
||||
{
|
||||
double index; /* index between 0 and pop_size */
|
||||
double max = (double) pool_size;
|
||||
double index; /* index between 0 and pop_size */
|
||||
double max = (double) pool_size;
|
||||
|
||||
index =
|
||||
max * (bias - sqrt((bias * bias) - 4.0 * (bias - 1.0) * geqo_rand()))
|
||||
|
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/geqo/Attic/minspantree.c,v 1.2 1997/09/07 04:43:25 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/geqo/Attic/minspantree.c,v 1.3 1997/09/08 02:24:09 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -43,35 +43,35 @@
|
||||
void
|
||||
minspantree(Query * root, List * join_rels, Rel * garel)
|
||||
{
|
||||
int number_of_rels = length(root->base_relation_list_);
|
||||
int number_of_joins = length(join_rels);
|
||||
int *connectto;
|
||||
int number_of_rels = length(root->base_relation_list_);
|
||||
int number_of_joins = length(join_rels);
|
||||
int *connectto;
|
||||
|
||||
/* connectto[i] = 0, if node i is already connected */
|
||||
/* to the tree, otherwise connectto[i] is the node */
|
||||
/* nearest to i, which is already connected. */
|
||||
|
||||
Cost *disttoconnect; /* disttoconnect[i]: distance
|
||||
* between i and connectto[i] */
|
||||
Cost *disttoconnect; /* disttoconnect[i]: distance between i
|
||||
* and connectto[i] */
|
||||
|
||||
Cost dist, /* temporary */
|
||||
mindist; /* minimal distance between connected and
|
||||
Cost dist, /* temporary */
|
||||
mindist; /* minimal distance between connected and
|
||||
* unconnected node */
|
||||
|
||||
Cost mstlength = 0.0; /* the total length of the minimum
|
||||
* spanning tree */
|
||||
Cost mstlength = 0.0;/* the total length of the minimum
|
||||
* spanning tree */
|
||||
|
||||
int count;
|
||||
int n, /* newly attached node */
|
||||
nextn, /* next node to be attached */
|
||||
tempn;
|
||||
int count;
|
||||
int n, /* newly attached node */
|
||||
nextn, /* next node to be attached */
|
||||
tempn;
|
||||
|
||||
int i,
|
||||
id1,
|
||||
id2;
|
||||
List *r = NIL;
|
||||
Rel *joinrel = NULL;
|
||||
Rel **tmprel_array;
|
||||
int i,
|
||||
id1,
|
||||
id2;
|
||||
List *r = NIL;
|
||||
Rel *joinrel = NULL;
|
||||
Rel **tmprel_array;
|
||||
|
||||
|
||||
/* allocate memory for matrix tmprel_array[x][y] */
|
||||
@ -113,9 +113,9 @@ minspantree(Query * root, List * join_rels, Rel * garel)
|
||||
|
||||
else if (number_of_joins == 3)
|
||||
{
|
||||
Rel *rel12 = (Rel *) & tmprel_array[1][2];
|
||||
Rel *rel13 = (Rel *) & tmprel_array[1][3];
|
||||
Rel *rel23 = (Rel *) & tmprel_array[2][3];
|
||||
Rel *rel12 = (Rel *) & tmprel_array[1][2];
|
||||
Rel *rel13 = (Rel *) & tmprel_array[1][3];
|
||||
Rel *rel23 = (Rel *) & tmprel_array[2][3];
|
||||
|
||||
if (rel12->cheapestpath->path_cost > rel13->cheapestpath->path_cost)
|
||||
{
|
||||
|
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/allpaths.c,v 1.11 1997/09/07 04:43:27 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/allpaths.c,v 1.12 1997/09/08 02:24:11 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -34,17 +34,17 @@
|
||||
#include "optimizer/geqo.h"
|
||||
|
||||
#ifdef GEQO
|
||||
bool _use_geqo_ = true;
|
||||
bool _use_geqo_ = true;
|
||||
|
||||
#else
|
||||
bool _use_geqo_ = false;
|
||||
bool _use_geqo_ = false;
|
||||
|
||||
#endif
|
||||
int32 _use_geqo_rels_ = GEQO_RELS;
|
||||
int32 _use_geqo_rels_ = GEQO_RELS;
|
||||
|
||||
|
||||
static void find_rel_paths(Query * root, List * rels);
|
||||
static List *find_join_paths(Query * root, List * outer_rels, int levels_left);
|
||||
static void find_rel_paths(Query * root, List * rels);
|
||||
static List *find_join_paths(Query * root, List * outer_rels, int levels_left);
|
||||
|
||||
/*
|
||||
* find-paths--
|
||||
@ -53,10 +53,10 @@ static List *find_join_paths(Query * root, List * outer_rels, int levels_left
|
||||
*
|
||||
* 'rels' is the list of single relation entries appearing in the query
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
find_paths(Query * root, List * rels)
|
||||
{
|
||||
int levels_left;
|
||||
int levels_left;
|
||||
|
||||
/*
|
||||
* Set the number of join (not nesting) levels yet to be processed.
|
||||
@ -104,15 +104,15 @@ find_paths(Query * root, List * rels)
|
||||
static void
|
||||
find_rel_paths(Query * root, List * rels)
|
||||
{
|
||||
List *temp;
|
||||
Rel *rel;
|
||||
List *lastpath;
|
||||
List *temp;
|
||||
Rel *rel;
|
||||
List *lastpath;
|
||||
|
||||
foreach(temp, rels)
|
||||
{
|
||||
List *sequential_scan_list;
|
||||
List *rel_index_scan_list;
|
||||
List *or_index_scan_list;
|
||||
List *sequential_scan_list;
|
||||
List *rel_index_scan_list;
|
||||
List *or_index_scan_list;
|
||||
|
||||
rel = (Rel *) lfirst(temp);
|
||||
sequential_scan_list = lcons(create_seqscan_path(rel),
|
||||
@ -171,12 +171,12 @@ find_rel_paths(Query * root, List * rels)
|
||||
* Returns the final level of join relations, i.e., the relation that is
|
||||
* the result of joining all the original relations togehter.
|
||||
*/
|
||||
static List *
|
||||
static List *
|
||||
find_join_paths(Query * root, List * outer_rels, int levels_left)
|
||||
{
|
||||
List *x;
|
||||
List *new_rels;
|
||||
Rel *rel;
|
||||
List *x;
|
||||
List *new_rels;
|
||||
Rel *rel;
|
||||
|
||||
/*******************************************
|
||||
* genetic query optimizer entry point *
|
||||
@ -283,12 +283,12 @@ find_join_paths(Query * root, List * outer_rels, int levels_left)
|
||||
static void
|
||||
print_joinclauses(Query * root, List * clauses)
|
||||
{
|
||||
List *l;
|
||||
extern void print_expr(Node * expr, List * rtable); /* in print.c */
|
||||
List *l;
|
||||
extern void print_expr(Node * expr, List * rtable); /* in print.c */
|
||||
|
||||
foreach(l, clauses)
|
||||
{
|
||||
CInfo *c = lfirst(l);
|
||||
CInfo *c = lfirst(l);
|
||||
|
||||
print_expr((Node *) c->clause, root->rtable);
|
||||
if (lnext(l))
|
||||
@ -299,88 +299,88 @@ print_joinclauses(Query * root, List * clauses)
|
||||
static void
|
||||
print_path(Query * root, Path * path, int indent)
|
||||
{
|
||||
char *ptype = NULL;
|
||||
JoinPath *jp;
|
||||
bool join = false;
|
||||
int i;
|
||||
char *ptype = NULL;
|
||||
JoinPath *jp;
|
||||
bool join = false;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < indent; i++)
|
||||
printf("\t");
|
||||
|
||||
switch (nodeTag(path))
|
||||
{
|
||||
case T_Path:
|
||||
ptype = "SeqScan";
|
||||
join = false;
|
||||
break;
|
||||
case T_IndexPath:
|
||||
ptype = "IdxScan";
|
||||
join = false;
|
||||
break;
|
||||
case T_JoinPath:
|
||||
ptype = "Nestloop";
|
||||
join = true;
|
||||
break;
|
||||
case T_MergePath:
|
||||
ptype = "MergeJoin";
|
||||
join = true;
|
||||
break;
|
||||
case T_HashPath:
|
||||
ptype = "HashJoin";
|
||||
join = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case T_Path:
|
||||
ptype = "SeqScan";
|
||||
join = false;
|
||||
break;
|
||||
case T_IndexPath:
|
||||
ptype = "IdxScan";
|
||||
join = false;
|
||||
break;
|
||||
case T_JoinPath:
|
||||
ptype = "Nestloop";
|
||||
join = true;
|
||||
break;
|
||||
case T_MergePath:
|
||||
ptype = "MergeJoin";
|
||||
join = true;
|
||||
break;
|
||||
case T_HashPath:
|
||||
ptype = "HashJoin";
|
||||
join = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (join)
|
||||
{
|
||||
int size = path->parent->size;
|
||||
int size = path->parent->size;
|
||||
|
||||
jp = (JoinPath *) path;
|
||||
printf("%s size=%d cost=%f\n", ptype, size, path->path_cost);
|
||||
switch (nodeTag(path))
|
||||
{
|
||||
case T_MergePath:
|
||||
case T_HashPath:
|
||||
for (i = 0; i < indent + 1; i++)
|
||||
printf("\t");
|
||||
printf(" clauses=(");
|
||||
print_joinclauses(root,
|
||||
((JoinPath *) path)->pathclauseinfo);
|
||||
printf(")\n");
|
||||
case T_MergePath:
|
||||
case T_HashPath:
|
||||
for (i = 0; i < indent + 1; i++)
|
||||
printf("\t");
|
||||
printf(" clauses=(");
|
||||
print_joinclauses(root,
|
||||
((JoinPath *) path)->pathclauseinfo);
|
||||
printf(")\n");
|
||||
|
||||
if (nodeTag(path) == T_MergePath)
|
||||
{
|
||||
MergePath *mp = (MergePath *) path;
|
||||
|
||||
if (mp->outersortkeys || mp->innersortkeys)
|
||||
if (nodeTag(path) == T_MergePath)
|
||||
{
|
||||
for (i = 0; i < indent + 1; i++)
|
||||
printf("\t");
|
||||
printf(" sortouter=%d sortinner=%d\n",
|
||||
((mp->outersortkeys) ? 1 : 0),
|
||||
((mp->innersortkeys) ? 1 : 0));
|
||||
MergePath *mp = (MergePath *) path;
|
||||
|
||||
if (mp->outersortkeys || mp->innersortkeys)
|
||||
{
|
||||
for (i = 0; i < indent + 1; i++)
|
||||
printf("\t");
|
||||
printf(" sortouter=%d sortinner=%d\n",
|
||||
((mp->outersortkeys) ? 1 : 0),
|
||||
((mp->innersortkeys) ? 1 : 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
print_path(root, jp->outerjoinpath, indent + 1);
|
||||
print_path(root, jp->innerjoinpath, indent + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
int size = path->parent->size;
|
||||
int relid = lfirsti(path->parent->relids);
|
||||
int size = path->parent->size;
|
||||
int relid = lfirsti(path->parent->relids);
|
||||
|
||||
printf("%s(%d) size=%d cost=%f",
|
||||
ptype, relid, size, path->path_cost);
|
||||
|
||||
if (nodeTag(path) == T_IndexPath)
|
||||
{
|
||||
List *k,
|
||||
*l;
|
||||
List *k,
|
||||
*l;
|
||||
|
||||
printf(" keys=");
|
||||
foreach(k, path->keys)
|
||||
@ -388,7 +388,7 @@ print_path(Query * root, Path * path, int indent)
|
||||
printf("(");
|
||||
foreach(l, lfirst(k))
|
||||
{
|
||||
Var *var = lfirst(l);
|
||||
Var *var = lfirst(l);
|
||||
|
||||
printf("%d.%d", var->varnoold, var->varoattno);
|
||||
if (lnext(l))
|
||||
@ -406,7 +406,7 @@ print_path(Query * root, Path * path, int indent)
|
||||
static void
|
||||
debug_print_rel(Query * root, Rel * rel)
|
||||
{
|
||||
List *l;
|
||||
List *l;
|
||||
|
||||
printf("(");
|
||||
foreach(l, rel->relids)
|
||||
|
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/clausesel.c,v 1.2 1997/09/07 04:43:31 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/clausesel.c,v 1.3 1997/09/08 02:24:14 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -31,7 +31,7 @@
|
||||
#include "utils/elog.h"
|
||||
#include "utils/lsyscache.h"
|
||||
|
||||
static Cost compute_selec(Query * root, List * clauses, List * or_selectivities);
|
||||
static Cost compute_selec(Query * root, List * clauses, List * or_selectivities);
|
||||
|
||||
/****************************************************************************
|
||||
* ROUTINES TO SET CLAUSE SELECTIVITIES
|
||||
@ -49,9 +49,9 @@ static Cost compute_selec(Query * root, List * clauses, List * or_selectivities
|
||||
void
|
||||
set_clause_selectivities(List * clauseinfo_list, Cost new_selectivity)
|
||||
{
|
||||
List *temp;
|
||||
CInfo *clausenode;
|
||||
Cost cost_clause;
|
||||
List *temp;
|
||||
CInfo *clausenode;
|
||||
Cost cost_clause;
|
||||
|
||||
foreach(temp, clauseinfo_list)
|
||||
{
|
||||
@ -73,12 +73,12 @@ set_clause_selectivities(List * clauseinfo_list, Cost new_selectivity)
|
||||
Cost
|
||||
product_selec(List * clauseinfo_list)
|
||||
{
|
||||
Cost result = 1.0;
|
||||
Cost result = 1.0;
|
||||
|
||||
if (clauseinfo_list != NIL)
|
||||
{
|
||||
List *xclausenode = NIL;
|
||||
Cost temp;
|
||||
List *xclausenode = NIL;
|
||||
Cost temp;
|
||||
|
||||
foreach(xclausenode, clauseinfo_list)
|
||||
{
|
||||
@ -101,8 +101,8 @@ product_selec(List * clauseinfo_list)
|
||||
void
|
||||
set_rest_relselec(Query * root, List * rel_list)
|
||||
{
|
||||
Rel *rel;
|
||||
List *x;
|
||||
Rel *rel;
|
||||
List *x;
|
||||
|
||||
foreach(x, rel_list)
|
||||
{
|
||||
@ -122,9 +122,9 @@ set_rest_relselec(Query * root, List * rel_list)
|
||||
void
|
||||
set_rest_selec(Query * root, List * clauseinfo_list)
|
||||
{
|
||||
List *temp = NIL;
|
||||
CInfo *clausenode = (CInfo *) NULL;
|
||||
Cost cost_clause;
|
||||
List *temp = NIL;
|
||||
CInfo *clausenode = (CInfo *) NULL;
|
||||
Cost cost_clause;
|
||||
|
||||
foreach(temp, clauseinfo_list)
|
||||
{
|
||||
@ -222,11 +222,11 @@ compute_clause_selec(Query * root, Node * clause, List * or_selectivities)
|
||||
* Returns the clause selectivity as a flonum.
|
||||
*
|
||||
*/
|
||||
static Cost
|
||||
static Cost
|
||||
compute_selec(Query * root, List * clauses, List * or_selectivities)
|
||||
{
|
||||
Cost s1 = 0;
|
||||
List *clause = lfirst(clauses);
|
||||
Cost s1 = 0;
|
||||
List *clause = lfirst(clauses);
|
||||
|
||||
if (clauses == NULL)
|
||||
{
|
||||
@ -243,8 +243,8 @@ compute_selec(Query * root, List * clauses, List * or_selectivities)
|
||||
}
|
||||
else if (IsA(clause, Var))
|
||||
{
|
||||
Oid relid = getrelid(((Var *) clause)->varno,
|
||||
root->rtable);
|
||||
Oid relid = getrelid(((Var *) clause)->varno,
|
||||
root->rtable);
|
||||
|
||||
/*
|
||||
* we have a bool Var. This is exactly equivalent to the clause:
|
||||
@ -264,7 +264,7 @@ compute_selec(Query * root, List * clauses, List * or_selectivities)
|
||||
else if (or_selectivities)
|
||||
{
|
||||
/* If s1 has already been assigned by an index, use that value. */
|
||||
List *this_sel = lfirst(or_selectivities);
|
||||
List *this_sel = lfirst(or_selectivities);
|
||||
|
||||
s1 = floatVal(this_sel);
|
||||
}
|
||||
@ -288,13 +288,13 @@ compute_selec(Query * root, List * clauses, List * or_selectivities)
|
||||
* clause selectivity will be based on the operator selectivity
|
||||
* and operand values.
|
||||
*/
|
||||
Oid opno = ((Oper *) ((Expr *) clause)->oper)->opno;
|
||||
RegProcedure oprrest = get_oprrest(opno);
|
||||
Oid relid;
|
||||
int relidx;
|
||||
AttrNumber attno;
|
||||
Datum constval;
|
||||
int flag;
|
||||
Oid opno = ((Oper *) ((Expr *) clause)->oper)->opno;
|
||||
RegProcedure oprrest = get_oprrest(opno);
|
||||
Oid relid;
|
||||
int relidx;
|
||||
AttrNumber attno;
|
||||
Datum constval;
|
||||
int flag;
|
||||
|
||||
get_relattval((Node *) clause, &relidx, &attno, &constval, &flag);
|
||||
relid = getrelid(relidx, root->rtable);
|
||||
@ -332,12 +332,12 @@ compute_selec(Query * root, List * clauses, List * or_selectivities)
|
||||
* be based on the relations to be scanned and the attributes they
|
||||
* are to be joined on.
|
||||
*/
|
||||
Oid opno = ((Oper *) ((Expr *) clause)->oper)->opno;
|
||||
RegProcedure oprjoin = get_oprjoin(opno);
|
||||
int relid1,
|
||||
relid2;
|
||||
AttrNumber attno1,
|
||||
attno2;
|
||||
Oid opno = ((Oper *) ((Expr *) clause)->oper)->opno;
|
||||
RegProcedure oprjoin = get_oprjoin(opno);
|
||||
int relid1,
|
||||
relid2;
|
||||
AttrNumber attno1,
|
||||
attno2;
|
||||
|
||||
get_rels_atts((Node *) clause, &relid1, &attno1, &relid2, &attno2);
|
||||
relid1 = getrelid(relid1, root->rtable);
|
||||
@ -372,7 +372,7 @@ compute_selec(Query * root, List * clauses, List * or_selectivities)
|
||||
{
|
||||
/* Compute selectivity of the 'or'ed subclauses. */
|
||||
/* Added check for taking lnext(NIL). -- JMH 3/9/92 */
|
||||
Cost s2;
|
||||
Cost s2;
|
||||
|
||||
if (or_selectivities != NIL)
|
||||
s2 = compute_selec(root, lnext(clauses), lnext(or_selectivities));
|
||||
|
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.17 1997/09/07 04:43:33 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.18 1997/09/08 02:24:18 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -37,24 +37,24 @@
|
||||
|
||||
#include "storage/bufmgr.h" /* for BLCKSZ */
|
||||
|
||||
extern int NBuffers;
|
||||
extern int NBuffers;
|
||||
|
||||
static int compute_attribute_width(TargetEntry * tlistentry);
|
||||
static double base_log(double x, double b);
|
||||
static int compute_targetlist_width(List * targetlist);
|
||||
static int compute_attribute_width(TargetEntry * tlistentry);
|
||||
static double base_log(double x, double b);
|
||||
static int compute_targetlist_width(List * targetlist);
|
||||
|
||||
int _disable_cost_ = 30000000;
|
||||
int _disable_cost_ = 30000000;
|
||||
|
||||
bool _enable_seqscan_ = true;
|
||||
bool _enable_indexscan_ = true;
|
||||
bool _enable_sort_ = true;
|
||||
bool _enable_hash_ = true;
|
||||
bool _enable_nestloop_ = true;
|
||||
bool _enable_mergesort_ = true;
|
||||
bool _enable_hashjoin_ = true;
|
||||
bool _enable_seqscan_ = true;
|
||||
bool _enable_indexscan_ = true;
|
||||
bool _enable_sort_ = true;
|
||||
bool _enable_hash_ = true;
|
||||
bool _enable_nestloop_ = true;
|
||||
bool _enable_mergesort_ = true;
|
||||
bool _enable_hashjoin_ = true;
|
||||
|
||||
Cost _cpu_page_wight_ = _CPU_PAGE_WEIGHT_;
|
||||
Cost _cpu_index_page_wight_ = _CPU_INDEX_PAGE_WEIGHT_;
|
||||
Cost _cpu_page_wight_ = _CPU_PAGE_WEIGHT_;
|
||||
Cost _cpu_index_page_wight_ = _CPU_INDEX_PAGE_WEIGHT_;
|
||||
|
||||
/*
|
||||
* cost_seqscan--
|
||||
@ -79,7 +79,7 @@ Cost _cpu_index_page_wight_ = _CPU_INDEX_PAGE_WEIGHT_;
|
||||
Cost
|
||||
cost_seqscan(int relid, int relpages, int reltuples)
|
||||
{
|
||||
Cost temp = 0;
|
||||
Cost temp = 0;
|
||||
|
||||
if (!_enable_seqscan_)
|
||||
temp += _disable_cost_;
|
||||
@ -131,8 +131,8 @@ cost_index(Oid indexid,
|
||||
int indextuples,
|
||||
bool is_injoin)
|
||||
{
|
||||
Cost temp;
|
||||
double temp2;
|
||||
Cost temp;
|
||||
double temp2;
|
||||
|
||||
temp = (Cost) 0;
|
||||
|
||||
@ -179,10 +179,10 @@ cost_index(Oid indexid,
|
||||
Cost
|
||||
cost_sort(List * keys, int tuples, int width, bool noread)
|
||||
{
|
||||
Cost temp = 0;
|
||||
int npages = page_size(tuples, width);
|
||||
Cost pages = (Cost) npages;
|
||||
Cost numTuples = tuples;
|
||||
Cost temp = 0;
|
||||
int npages = page_size(tuples, width);
|
||||
Cost pages = (Cost) npages;
|
||||
Cost numTuples = tuples;
|
||||
|
||||
if (!_enable_sort_)
|
||||
temp += _disable_cost_;
|
||||
@ -220,7 +220,7 @@ cost_sort(List * keys, int tuples, int width, bool noread)
|
||||
Cost
|
||||
cost_result(int tuples, int width)
|
||||
{
|
||||
Cost temp = 0;
|
||||
Cost temp = 0;
|
||||
|
||||
temp = temp + page_size(tuples, width);
|
||||
temp = temp + _cpu_page_wight_ * tuples;
|
||||
@ -250,7 +250,7 @@ cost_nestloop(Cost outercost,
|
||||
int outerpages,
|
||||
bool is_indexjoin)
|
||||
{
|
||||
Cost temp = 0;
|
||||
Cost temp = 0;
|
||||
|
||||
if (!_enable_nestloop_)
|
||||
temp += _disable_cost_;
|
||||
@ -285,7 +285,7 @@ cost_mergesort(Cost outercost,
|
||||
int outerwidth,
|
||||
int innerwidth)
|
||||
{
|
||||
Cost temp = 0;
|
||||
Cost temp = 0;
|
||||
|
||||
if (!_enable_mergesort_)
|
||||
temp += _disable_cost_;
|
||||
@ -323,10 +323,10 @@ cost_hashjoin(Cost outercost,
|
||||
int outerwidth,
|
||||
int innerwidth)
|
||||
{
|
||||
Cost temp = 0;
|
||||
int outerpages = page_size(outersize, outerwidth);
|
||||
int innerpages = page_size(innersize, innerwidth);
|
||||
int nrun = ceil((double) outerpages / (double) NBuffers);
|
||||
Cost temp = 0;
|
||||
int outerpages = page_size(outersize, outerwidth);
|
||||
int innerpages = page_size(innersize, innerwidth);
|
||||
int nrun = ceil((double) outerpages / (double) NBuffers);
|
||||
|
||||
if (outerpages < innerpages)
|
||||
return _disable_cost_;
|
||||
@ -365,8 +365,8 @@ cost_hashjoin(Cost outercost,
|
||||
int
|
||||
compute_rel_size(Rel * rel)
|
||||
{
|
||||
Cost temp;
|
||||
int temp1;
|
||||
Cost temp;
|
||||
int temp1;
|
||||
|
||||
temp = rel->tuples * product_selec(rel->clauseinfo);
|
||||
Assert(temp >= 0);
|
||||
@ -404,8 +404,8 @@ compute_rel_width(Rel * rel)
|
||||
static int
|
||||
compute_targetlist_width(List * targetlist)
|
||||
{
|
||||
List *temp_tl;
|
||||
int tuple_width = 0;
|
||||
List *temp_tl;
|
||||
int tuple_width = 0;
|
||||
|
||||
foreach(temp_tl, targetlist)
|
||||
{
|
||||
@ -427,7 +427,7 @@ compute_targetlist_width(List * targetlist)
|
||||
static int
|
||||
compute_attribute_width(TargetEntry * tlistentry)
|
||||
{
|
||||
int width = get_typlen(tlistentry->resdom->restype);
|
||||
int width = get_typlen(tlistentry->resdom->restype);
|
||||
|
||||
if (width < 0)
|
||||
return (_DEFAULT_ATTRIBUTE_WIDTH_);
|
||||
@ -444,8 +444,8 @@ compute_attribute_width(TargetEntry * tlistentry)
|
||||
int
|
||||
compute_joinrel_size(JoinPath * joinpath)
|
||||
{
|
||||
Cost temp = 1.0;
|
||||
int temp1 = 0;
|
||||
Cost temp = 1.0;
|
||||
int temp1 = 0;
|
||||
|
||||
temp *= ((Path *) joinpath->outerjoinpath)->parent->size;
|
||||
temp *= ((Path *) joinpath->innerjoinpath)->parent->size;
|
||||
@ -477,7 +477,7 @@ compute_joinrel_size(JoinPath * joinpath)
|
||||
int
|
||||
page_size(int tuples, int width)
|
||||
{
|
||||
int temp = 0;
|
||||
int temp = 0;
|
||||
|
||||
temp = ceil((double) (tuples * (width + sizeof(HeapTupleData)))
|
||||
/ BLCKSZ);
|
||||
|
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/hashutils.c,v 1.2 1997/09/07 04:43:34 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/hashutils.c,v 1.3 1997/09/08 02:24:20 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -20,7 +20,7 @@
|
||||
#include "optimizer/clauses.h"
|
||||
|
||||
|
||||
static HInfo *match_hashop_hashinfo(Oid hashop, List * hashinfo_list);
|
||||
static HInfo *match_hashop_hashinfo(Oid hashop, List * hashinfo_list);
|
||||
|
||||
/*
|
||||
* group-clauses-by-hashop--
|
||||
@ -34,14 +34,14 @@ 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)
|
||||
{
|
||||
List *hashinfo_list = NIL;
|
||||
CInfo *clauseinfo = (CInfo *) NULL;
|
||||
List *i = NIL;
|
||||
Oid hashjoinop = 0;
|
||||
List *hashinfo_list = NIL;
|
||||
CInfo *clauseinfo = (CInfo *) NULL;
|
||||
List *i = NIL;
|
||||
Oid hashjoinop = 0;
|
||||
|
||||
foreach(i, clauseinfo_list)
|
||||
{
|
||||
@ -54,11 +54,11 @@ group_clauses_by_hashop(List * clauseinfo_list,
|
||||
*/
|
||||
if (hashjoinop)
|
||||
{
|
||||
HInfo *xhashinfo = (HInfo *) NULL;
|
||||
Expr *clause = clauseinfo->clause;
|
||||
Var *leftop = get_leftop(clause);
|
||||
Var *rightop = get_rightop(clause);
|
||||
JoinKey *keys = (JoinKey *) NULL;
|
||||
HInfo *xhashinfo = (HInfo *) NULL;
|
||||
Expr *clause = clauseinfo->clause;
|
||||
Var *leftop = get_leftop(clause);
|
||||
Var *rightop = get_rightop(clause);
|
||||
JoinKey *keys = (JoinKey *) NULL;
|
||||
|
||||
xhashinfo =
|
||||
match_hashop_hashinfo(hashjoinop, hashinfo_list);
|
||||
@ -108,12 +108,12 @@ group_clauses_by_hashop(List * clauseinfo_list,
|
||||
* Returns the node if it exists.
|
||||
*
|
||||
*/
|
||||
static HInfo *
|
||||
static HInfo *
|
||||
match_hashop_hashinfo(Oid hashop, List * hashinfo_list)
|
||||
{
|
||||
Oid key = 0;
|
||||
HInfo *xhashinfo = (HInfo *) NULL;
|
||||
List *i = NIL;
|
||||
Oid key = 0;
|
||||
HInfo *xhashinfo = (HInfo *) NULL;
|
||||
List *i = NIL;
|
||||
|
||||
foreach(i, hashinfo_list)
|
||||
{
|
||||
|
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/indxpath.c,v 1.9 1997/09/07 04:43:36 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/indxpath.c,v 1.10 1997/09/08 02:24:21 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -52,37 +52,37 @@ match_index_orclauses(Rel * rel, Rel * index, int indexkey,
|
||||
static bool
|
||||
match_index_to_operand(int indexkey, Expr * operand,
|
||||
Rel * rel, Rel * index);
|
||||
static List *
|
||||
static List *
|
||||
match_index_orclause(Rel * rel, Rel * index, int indexkey,
|
||||
int xclass, List * or_clauses, List * other_matching_indices);
|
||||
static List *
|
||||
static List *
|
||||
group_clauses_by_indexkey(Rel * rel, Rel * index,
|
||||
int *indexkeys, Oid * classes, List * clauseinfo_list);
|
||||
static List *
|
||||
static List *
|
||||
group_clauses_by_ikey_for_joins(Rel * rel, Rel * index,
|
||||
int *indexkeys, Oid * classes, List * join_cinfo_list, List * restr_cinfo_list);
|
||||
static CInfo *
|
||||
static CInfo *
|
||||
match_clause_to_indexkey(Rel * rel, Rel * index, int indexkey,
|
||||
int xclass, CInfo * clauseInfo, bool join);
|
||||
static bool
|
||||
pred_test(List * predicate_list, List * clauseinfo_list,
|
||||
List * joininfo_list);
|
||||
static bool one_pred_test(Expr * predicate, List * clauseinfo_list);
|
||||
static bool one_pred_clause_expr_test(Expr * predicate, Node * clause);
|
||||
static bool one_pred_clause_test(Expr * predicate, Node * clause);
|
||||
static bool clause_pred_clause_test(Expr * predicate, Node * clause);
|
||||
static List *
|
||||
static bool one_pred_test(Expr * predicate, List * clauseinfo_list);
|
||||
static bool one_pred_clause_expr_test(Expr * predicate, Node * clause);
|
||||
static bool one_pred_clause_test(Expr * predicate, Node * clause);
|
||||
static bool clause_pred_clause_test(Expr * predicate, Node * clause);
|
||||
static List *
|
||||
indexable_joinclauses(Rel * rel, Rel * index,
|
||||
List * joininfo_list, List * clauseinfo_list);
|
||||
static List *
|
||||
static List *
|
||||
index_innerjoin(Query * root, Rel * rel,
|
||||
List * clausegroup_list, Rel * index);
|
||||
static List *
|
||||
static List *
|
||||
create_index_paths(Query * root, Rel * rel, Rel * index,
|
||||
List * clausegroup_list, bool join);
|
||||
static List *add_index_paths(List * indexpaths, List * new_indexpaths);
|
||||
static bool function_index_operand(Expr * funcOpnd, Rel * rel, Rel * index);
|
||||
static bool SingleAttributeIndex(Rel * index);
|
||||
static List *add_index_paths(List * indexpaths, List * new_indexpaths);
|
||||
static bool function_index_operand(Expr * funcOpnd, Rel * rel, Rel * index);
|
||||
static bool SingleAttributeIndex(Rel * index);
|
||||
|
||||
/* If Spyros can use a constant PRS2_BOOL_TYPEID, I can use this */
|
||||
#define BOOL_TYPEID ((Oid) 16)
|
||||
@ -113,19 +113,19 @@ static bool SingleAttributeIndex(Rel * index);
|
||||
* Returns a list of index nodes.
|
||||
*
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
find_index_paths(Query * root,
|
||||
Rel * rel,
|
||||
List * indices,
|
||||
List * clauseinfo_list,
|
||||
List * joininfo_list)
|
||||
{
|
||||
List *scanclausegroups = NIL;
|
||||
List *scanpaths = NIL;
|
||||
Rel *index = (Rel *) NULL;
|
||||
List *joinclausegroups = NIL;
|
||||
List *joinpaths = NIL;
|
||||
List *retval = NIL;
|
||||
List *scanclausegroups = NIL;
|
||||
List *scanpaths = NIL;
|
||||
Rel *index = (Rel *) NULL;
|
||||
List *joinclausegroups = NIL;
|
||||
List *joinpaths = NIL;
|
||||
List *retval = NIL;
|
||||
|
||||
if (indices == NIL)
|
||||
return (NULL);
|
||||
@ -193,11 +193,11 @@ find_index_paths(Query * root,
|
||||
|
||||
if (joinclausegroups != NIL)
|
||||
{
|
||||
List *new_join_paths = create_index_paths(root, rel,
|
||||
index,
|
||||
List *new_join_paths = create_index_paths(root, rel,
|
||||
index,
|
||||
joinclausegroups,
|
||||
true);
|
||||
List *innerjoin_paths = index_innerjoin(root, rel, joinclausegroups, index);
|
||||
true);
|
||||
List *innerjoin_paths = index_innerjoin(root, rel, joinclausegroups, index);
|
||||
|
||||
rel->innerjoin = nconc(rel->innerjoin, innerjoin_paths);
|
||||
joinpaths = new_join_paths;
|
||||
@ -246,8 +246,8 @@ match_index_orclauses(Rel * rel,
|
||||
int xclass,
|
||||
List * clauseinfo_list)
|
||||
{
|
||||
CInfo *clauseinfo = (CInfo *) NULL;
|
||||
List *i = NIL;
|
||||
CInfo *clauseinfo = (CInfo *) NULL;
|
||||
List *i = NIL;
|
||||
|
||||
foreach(i, clauseinfo_list)
|
||||
{
|
||||
@ -275,7 +275,7 @@ match_index_orclauses(Rel * rel,
|
||||
* and the operand on the rhs of a restriction clause. Now check
|
||||
* for functional indices as well.
|
||||
*/
|
||||
static bool
|
||||
static bool
|
||||
match_index_to_operand(int indexkey,
|
||||
Expr * operand,
|
||||
Rel * rel,
|
||||
@ -315,7 +315,7 @@ match_index_to_operand(int indexkey,
|
||||
* 'or-clauses', d,e,f match the second subclause, no indices
|
||||
* match the third, g,h match the fourth, etc.
|
||||
*/
|
||||
static List *
|
||||
static List *
|
||||
match_index_orclause(Rel * rel,
|
||||
Rel * index,
|
||||
int indexkey,
|
||||
@ -323,11 +323,11 @@ match_index_orclause(Rel * rel,
|
||||
List * or_clauses,
|
||||
List * other_matching_indices)
|
||||
{
|
||||
Node *clause = NULL;
|
||||
List *matched_indices = other_matching_indices;
|
||||
List *index_list = NIL;
|
||||
List *clist;
|
||||
List *ind;
|
||||
Node *clause = NULL;
|
||||
List *matched_indices = other_matching_indices;
|
||||
List *index_list = NIL;
|
||||
List *clist;
|
||||
List *ind;
|
||||
|
||||
if (!matched_indices)
|
||||
matched_indices = lcons(NIL, NIL);
|
||||
@ -397,32 +397,32 @@ match_index_orclause(Rel * rel,
|
||||
* returned for an index with 2 keys.
|
||||
*
|
||||
*/
|
||||
static List *
|
||||
static List *
|
||||
group_clauses_by_indexkey(Rel * rel,
|
||||
Rel * index,
|
||||
int *indexkeys,
|
||||
Oid * classes,
|
||||
List * clauseinfo_list)
|
||||
{
|
||||
List *curCinfo = NIL;
|
||||
CInfo *matched_clause = (CInfo *) NULL;
|
||||
List *clausegroup = NIL;
|
||||
int curIndxKey;
|
||||
Oid curClass;
|
||||
List *curCinfo = NIL;
|
||||
CInfo *matched_clause = (CInfo *) NULL;
|
||||
List *clausegroup = NIL;
|
||||
int curIndxKey;
|
||||
Oid curClass;
|
||||
|
||||
if (clauseinfo_list == NIL)
|
||||
return NIL;
|
||||
|
||||
while (!DoneMatchingIndexKeys(indexkeys, index))
|
||||
{
|
||||
List *tempgroup = NIL;
|
||||
List *tempgroup = NIL;
|
||||
|
||||
curIndxKey = indexkeys[0];
|
||||
curClass = classes[0];
|
||||
|
||||
foreach(curCinfo, clauseinfo_list)
|
||||
{
|
||||
CInfo *temp = (CInfo *) lfirst(curCinfo);
|
||||
CInfo *temp = (CInfo *) lfirst(curCinfo);
|
||||
|
||||
matched_clause = match_clause_to_indexkey(rel,
|
||||
index,
|
||||
@ -459,7 +459,7 @@ group_clauses_by_indexkey(Rel * rel,
|
||||
* - vadim 03/18/97
|
||||
*
|
||||
*/
|
||||
static List *
|
||||
static List *
|
||||
group_clauses_by_ikey_for_joins(Rel * rel,
|
||||
Rel * index,
|
||||
int *indexkeys,
|
||||
@ -467,26 +467,26 @@ group_clauses_by_ikey_for_joins(Rel * rel,
|
||||
List * join_cinfo_list,
|
||||
List * restr_cinfo_list)
|
||||
{
|
||||
List *curCinfo = NIL;
|
||||
CInfo *matched_clause = (CInfo *) NULL;
|
||||
List *clausegroup = NIL;
|
||||
int curIndxKey;
|
||||
Oid curClass;
|
||||
bool jfound = false;
|
||||
List *curCinfo = NIL;
|
||||
CInfo *matched_clause = (CInfo *) NULL;
|
||||
List *clausegroup = NIL;
|
||||
int curIndxKey;
|
||||
Oid curClass;
|
||||
bool jfound = false;
|
||||
|
||||
if (join_cinfo_list == NIL)
|
||||
return NIL;
|
||||
|
||||
while (!DoneMatchingIndexKeys(indexkeys, index))
|
||||
{
|
||||
List *tempgroup = NIL;
|
||||
List *tempgroup = NIL;
|
||||
|
||||
curIndxKey = indexkeys[0];
|
||||
curClass = classes[0];
|
||||
|
||||
foreach(curCinfo, join_cinfo_list)
|
||||
{
|
||||
CInfo *temp = (CInfo *) lfirst(curCinfo);
|
||||
CInfo *temp = (CInfo *) lfirst(curCinfo);
|
||||
|
||||
matched_clause = match_clause_to_indexkey(rel,
|
||||
index,
|
||||
@ -502,7 +502,7 @@ group_clauses_by_ikey_for_joins(Rel * rel,
|
||||
}
|
||||
foreach(curCinfo, restr_cinfo_list)
|
||||
{
|
||||
CInfo *temp = (CInfo *) lfirst(curCinfo);
|
||||
CInfo *temp = (CInfo *) lfirst(curCinfo);
|
||||
|
||||
matched_clause = match_clause_to_indexkey(rel,
|
||||
index,
|
||||
@ -582,7 +582,7 @@ group_clauses_by_ikey_for_joins(Rel * rel,
|
||||
* NOTE: returns nil if clause is an or_clause.
|
||||
*
|
||||
*/
|
||||
static CInfo *
|
||||
static CInfo *
|
||||
match_clause_to_indexkey(Rel * rel,
|
||||
Rel * index,
|
||||
int indexkey,
|
||||
@ -590,12 +590,12 @@ match_clause_to_indexkey(Rel * rel,
|
||||
CInfo * clauseInfo,
|
||||
bool join)
|
||||
{
|
||||
Expr *clause = clauseInfo->clause;
|
||||
Var *leftop,
|
||||
*rightop;
|
||||
Oid join_op = InvalidOid;
|
||||
Oid restrict_op = InvalidOid;
|
||||
bool isIndexable = false;
|
||||
Expr *clause = clauseInfo->clause;
|
||||
Var *leftop,
|
||||
*rightop;
|
||||
Oid join_op = InvalidOid;
|
||||
Oid restrict_op = InvalidOid;
|
||||
bool isIndexable = false;
|
||||
|
||||
if (or_clause((Node *) clause) ||
|
||||
not_clause((Node *) clause) || single_node((Node *) clause))
|
||||
@ -719,12 +719,12 @@ match_clause_to_indexkey(Rel * rel,
|
||||
* succeed whenever possible (assuming the predicate has been
|
||||
* successfully cnfify()-ed). --Nels, Jan '93
|
||||
*/
|
||||
static bool
|
||||
static bool
|
||||
pred_test(List * predicate_list, List * clauseinfo_list, List * joininfo_list)
|
||||
{
|
||||
List *pred,
|
||||
*items,
|
||||
*item;
|
||||
List *pred,
|
||||
*items,
|
||||
*item;
|
||||
|
||||
/*
|
||||
* Note: if Postgres tried to optimize queries by forming equivalence
|
||||
@ -770,11 +770,11 @@ pred_test(List * predicate_list, List * clauseinfo_list, List * joininfo_list)
|
||||
* Does the "predicate inclusion test" for one conjunct of a predicate
|
||||
* expression.
|
||||
*/
|
||||
static bool
|
||||
static bool
|
||||
one_pred_test(Expr * predicate, List * clauseinfo_list)
|
||||
{
|
||||
CInfo *clauseinfo;
|
||||
List *item;
|
||||
CInfo *clauseinfo;
|
||||
List *item;
|
||||
|
||||
Assert(predicate != NULL);
|
||||
foreach(item, clauseinfo_list)
|
||||
@ -793,11 +793,11 @@ one_pred_test(Expr * predicate, List * clauseinfo_list)
|
||||
* Does the "predicate inclusion test" for a general restriction-clause
|
||||
* expression.
|
||||
*/
|
||||
static bool
|
||||
static bool
|
||||
one_pred_clause_expr_test(Expr * predicate, Node * clause)
|
||||
{
|
||||
List *items,
|
||||
*item;
|
||||
List *items,
|
||||
*item;
|
||||
|
||||
if (is_opclause(clause))
|
||||
return one_pred_clause_test(predicate, clause);
|
||||
@ -840,11 +840,11 @@ one_pred_clause_expr_test(Expr * predicate, Node * clause)
|
||||
* Does the "predicate inclusion test" for one conjunct of a predicate
|
||||
* expression for a simple restriction clause.
|
||||
*/
|
||||
static bool
|
||||
static bool
|
||||
one_pred_clause_test(Expr * predicate, Node * clause)
|
||||
{
|
||||
List *items,
|
||||
*item;
|
||||
List *items,
|
||||
*item;
|
||||
|
||||
if (is_opclause((Node *) predicate))
|
||||
return clause_pred_clause_test(predicate, clause);
|
||||
@ -903,7 +903,7 @@ one_pred_clause_test(Expr * predicate, Node * clause)
|
||||
* this test should always be considered false.
|
||||
*/
|
||||
|
||||
StrategyNumber BT_implic_table[BTMaxStrategyNumber][BTMaxStrategyNumber] = {
|
||||
StrategyNumber BT_implic_table[BTMaxStrategyNumber][BTMaxStrategyNumber] = {
|
||||
{2, 2, 0, 0, 0},
|
||||
{1, 2, 0, 0, 0},
|
||||
{1, 2, 3, 4, 5},
|
||||
@ -922,29 +922,29 @@ StrategyNumber BT_implic_table[BTMaxStrategyNumber][BTMaxStrategyNumber] = {
|
||||
* Eventually, rtree operators could also be handled by defining an
|
||||
* appropriate "RT_implic_table" array.
|
||||
*/
|
||||
static bool
|
||||
static bool
|
||||
clause_pred_clause_test(Expr * predicate, Node * clause)
|
||||
{
|
||||
Var *pred_var,
|
||||
*clause_var;
|
||||
Const *pred_const,
|
||||
*clause_const;
|
||||
Oid pred_op,
|
||||
clause_op,
|
||||
test_op;
|
||||
Oid opclass_id;
|
||||
StrategyNumber pred_strategy,
|
||||
clause_strategy,
|
||||
test_strategy;
|
||||
Oper *test_oper;
|
||||
Expr *test_expr;
|
||||
bool test_result,
|
||||
isNull;
|
||||
Relation relation;
|
||||
HeapScanDesc scan;
|
||||
HeapTuple tuple;
|
||||
ScanKeyData entry[3];
|
||||
Form_pg_amop form;
|
||||
Var *pred_var,
|
||||
*clause_var;
|
||||
Const *pred_const,
|
||||
*clause_const;
|
||||
Oid pred_op,
|
||||
clause_op,
|
||||
test_op;
|
||||
Oid opclass_id;
|
||||
StrategyNumber pred_strategy,
|
||||
clause_strategy,
|
||||
test_strategy;
|
||||
Oper *test_oper;
|
||||
Expr *test_expr;
|
||||
bool test_result,
|
||||
isNull;
|
||||
Relation relation;
|
||||
HeapScanDesc scan;
|
||||
HeapTuple tuple;
|
||||
ScanKeyData entry[3];
|
||||
Form_pg_amop form;
|
||||
|
||||
pred_var = (Var *) get_leftop(predicate);
|
||||
pred_const = (Const *) get_rightop(predicate);
|
||||
@ -1120,14 +1120,14 @@ clause_pred_clause_test(Expr * predicate, Node * clause)
|
||||
* when a key is in both join & restriction clauses. - vadim 03/18/97
|
||||
*
|
||||
*/
|
||||
static List *
|
||||
static List *
|
||||
indexable_joinclauses(Rel * rel, Rel * index,
|
||||
List * joininfo_list, List * clauseinfo_list)
|
||||
{
|
||||
JInfo *joininfo = (JInfo *) NULL;
|
||||
List *cg_list = NIL;
|
||||
List *i = NIL;
|
||||
List *clausegroups = NIL;
|
||||
JInfo *joininfo = (JInfo *) NULL;
|
||||
List *cg_list = NIL;
|
||||
List *i = NIL;
|
||||
List *clausegroups = NIL;
|
||||
|
||||
foreach(i, joininfo_list)
|
||||
{
|
||||
@ -1145,7 +1145,7 @@ indexable_joinclauses(Rel * rel, Rel * index,
|
||||
|
||||
if (clausegroups != NIL)
|
||||
{
|
||||
List *clauses = lfirst(clausegroups);
|
||||
List *clauses = lfirst(clausegroups);
|
||||
|
||||
((CInfo *) lfirst(clauses))->cinfojoinid =
|
||||
joininfo->otherrels;
|
||||
@ -1165,15 +1165,15 @@ indexable_joinclauses(Rel * rel, Rel * index,
|
||||
* This routine returns the restriction clauses only.
|
||||
*/
|
||||
#ifdef NOT_USED
|
||||
static List *
|
||||
static List *
|
||||
extract_restrict_clauses(List * clausegroup)
|
||||
{
|
||||
List *restrict_cls = NIL;
|
||||
List *l;
|
||||
List *restrict_cls = NIL;
|
||||
List *l;
|
||||
|
||||
foreach(l, clausegroup)
|
||||
{
|
||||
CInfo *cinfo = lfirst(l);
|
||||
CInfo *cinfo = lfirst(l);
|
||||
|
||||
if (!join_clause_p((Node *) cinfo->clause))
|
||||
{
|
||||
@ -1196,21 +1196,21 @@ extract_restrict_clauses(List * clausegroup)
|
||||
* Returns a list of index pathnodes.
|
||||
*
|
||||
*/
|
||||
static List *
|
||||
static List *
|
||||
index_innerjoin(Query * root, Rel * rel, List * clausegroup_list, Rel * index)
|
||||
{
|
||||
List *clausegroup = NIL;
|
||||
List *cg_list = NIL;
|
||||
List *i = NIL;
|
||||
IndexPath *pathnode = (IndexPath *) NULL;
|
||||
Cost temp_selec;
|
||||
float temp_pages;
|
||||
List *clausegroup = NIL;
|
||||
List *cg_list = NIL;
|
||||
List *i = NIL;
|
||||
IndexPath *pathnode = (IndexPath *) NULL;
|
||||
Cost temp_selec;
|
||||
float temp_pages;
|
||||
|
||||
foreach(i, clausegroup_list)
|
||||
{
|
||||
List *attnos,
|
||||
*values,
|
||||
*flags;
|
||||
List *attnos,
|
||||
*values,
|
||||
*flags;
|
||||
|
||||
clausegroup = lfirst(i);
|
||||
pathnode = makeNode(IndexPath);
|
||||
@ -1281,24 +1281,24 @@ index_innerjoin(Query * root, Rel * rel, List * clausegroup_list, Rel * index)
|
||||
* Returns a list of new index path nodes.
|
||||
*
|
||||
*/
|
||||
static List *
|
||||
static List *
|
||||
create_index_paths(Query * root,
|
||||
Rel * rel,
|
||||
Rel * index,
|
||||
List * clausegroup_list,
|
||||
bool join)
|
||||
{
|
||||
List *clausegroup = NIL;
|
||||
List *ip_list = NIL;
|
||||
List *i = NIL;
|
||||
List *j = NIL;
|
||||
IndexPath *temp_path;
|
||||
List *clausegroup = NIL;
|
||||
List *ip_list = NIL;
|
||||
List *i = NIL;
|
||||
List *j = NIL;
|
||||
IndexPath *temp_path;
|
||||
|
||||
foreach(i, clausegroup_list)
|
||||
{
|
||||
CInfo *clauseinfo;
|
||||
List *temp_node = NIL;
|
||||
bool temp = true;
|
||||
CInfo *clauseinfo;
|
||||
List *temp_node = NIL;
|
||||
bool temp = true;
|
||||
|
||||
clausegroup = lfirst(i);
|
||||
|
||||
@ -1324,21 +1324,21 @@ create_index_paths(Query * root,
|
||||
return (ip_list);
|
||||
}
|
||||
|
||||
static List *
|
||||
static List *
|
||||
add_index_paths(List * indexpaths, List * new_indexpaths)
|
||||
{
|
||||
return append(indexpaths, new_indexpaths);
|
||||
}
|
||||
|
||||
static bool
|
||||
static bool
|
||||
function_index_operand(Expr * funcOpnd, Rel * rel, Rel * index)
|
||||
{
|
||||
Oid heapRelid = (Oid) lfirsti(rel->relids);
|
||||
Func *function;
|
||||
List *funcargs;
|
||||
int *indexKeys = index->indexkeys;
|
||||
List *arg;
|
||||
int i;
|
||||
Oid heapRelid = (Oid) lfirsti(rel->relids);
|
||||
Func *function;
|
||||
List *funcargs;
|
||||
int *indexKeys = index->indexkeys;
|
||||
List *arg;
|
||||
int i;
|
||||
|
||||
/*
|
||||
* sanity check, make sure we know what we're dealing with here.
|
||||
@ -1390,7 +1390,7 @@ function_index_operand(Expr * funcOpnd, Rel * rel, Rel * index)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
static bool
|
||||
SingleAttributeIndex(Rel * index)
|
||||
{
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/joinpath.c,v 1.3 1997/09/07 04:43:38 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/joinpath.c,v 1.4 1997/09/08 02:24:22 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -29,19 +29,19 @@
|
||||
#include "optimizer/cost.h" /* for _enable_{hashjoin,
|
||||
* _enable_mergesort} */
|
||||
|
||||
static Path *best_innerjoin(List * join_paths, List * outer_relid);
|
||||
static List *
|
||||
static Path *best_innerjoin(List * join_paths, List * outer_relid);
|
||||
static List *
|
||||
sort_inner_and_outer(Rel * joinrel, Rel * outerrel, Rel * innerrel,
|
||||
List * mergeinfo_list);
|
||||
static List *
|
||||
static List *
|
||||
match_unsorted_outer(Rel * joinrel, Rel * outerrel, Rel * innerrel,
|
||||
List * outerpath_list, Path * cheapest_inner, Path * best_innerjoin,
|
||||
List * mergeinfo_list);
|
||||
static List *
|
||||
static List *
|
||||
match_unsorted_inner(Rel * joinrel, Rel * outerrel, Rel * innerrel,
|
||||
List * innerpath_list, List * mergeinfo_list);
|
||||
static bool EnoughMemoryForHashjoin(Rel * hashrel);
|
||||
static List *
|
||||
static bool EnoughMemoryForHashjoin(Rel * hashrel);
|
||||
static List *
|
||||
hash_inner_and_outer(Rel * joinrel, Rel * outerrel, Rel * innerrel,
|
||||
List * hashinfo_list);
|
||||
|
||||
@ -69,20 +69,20 @@ hash_inner_and_outer(Rel * joinrel, Rel * outerrel, Rel * innerrel,
|
||||
void
|
||||
find_all_join_paths(Query * root, List * joinrels)
|
||||
{
|
||||
List *mergeinfo_list = NIL;
|
||||
List *hashinfo_list = NIL;
|
||||
List *temp_list = NIL;
|
||||
List *path = NIL;
|
||||
List *mergeinfo_list = NIL;
|
||||
List *hashinfo_list = NIL;
|
||||
List *temp_list = NIL;
|
||||
List *path = NIL;
|
||||
|
||||
while (joinrels != NIL)
|
||||
{
|
||||
Rel *joinrel = (Rel *) lfirst(joinrels);
|
||||
List *innerrelids;
|
||||
List *outerrelids;
|
||||
Rel *innerrel;
|
||||
Rel *outerrel;
|
||||
Path *bestinnerjoin;
|
||||
List *pathlist = NIL;
|
||||
Rel *joinrel = (Rel *) lfirst(joinrels);
|
||||
List *innerrelids;
|
||||
List *outerrelids;
|
||||
Rel *innerrel;
|
||||
Rel *outerrel;
|
||||
Path *bestinnerjoin;
|
||||
List *pathlist = NIL;
|
||||
|
||||
innerrelids = lsecond(joinrel->relids);
|
||||
outerrelids = lfirst(joinrel->relids);
|
||||
@ -205,15 +205,15 @@ find_all_join_paths(Query * root, List * joinrels)
|
||||
*
|
||||
* Returns the pathnode of the selected path.
|
||||
*/
|
||||
static Path *
|
||||
static Path *
|
||||
best_innerjoin(List * join_paths, List * outer_relids)
|
||||
{
|
||||
Path *cheapest = (Path *) NULL;
|
||||
List *join_path;
|
||||
Path *cheapest = (Path *) NULL;
|
||||
List *join_path;
|
||||
|
||||
foreach(join_path, join_paths)
|
||||
{
|
||||
Path *path = (Path *) lfirst(join_path);
|
||||
Path *path = (Path *) lfirst(join_path);
|
||||
|
||||
if (intMember(lfirsti(path->joinid), outer_relids)
|
||||
&& ((cheapest == NULL ||
|
||||
@ -239,19 +239,19 @@ best_innerjoin(List * join_paths, List * outer_relids)
|
||||
*
|
||||
* Returns a list of mergesort paths.
|
||||
*/
|
||||
static List *
|
||||
static List *
|
||||
sort_inner_and_outer(Rel * joinrel,
|
||||
Rel * outerrel,
|
||||
Rel * innerrel,
|
||||
List * mergeinfo_list)
|
||||
{
|
||||
List *ms_list = NIL;
|
||||
MInfo *xmergeinfo = (MInfo *) NULL;
|
||||
MergePath *temp_node = (MergePath *) NULL;
|
||||
List *i;
|
||||
List *outerkeys = NIL;
|
||||
List *innerkeys = NIL;
|
||||
List *merge_pathkeys = NIL;
|
||||
List *ms_list = NIL;
|
||||
MInfo *xmergeinfo = (MInfo *) NULL;
|
||||
MergePath *temp_node = (MergePath *) NULL;
|
||||
List *i;
|
||||
List *outerkeys = NIL;
|
||||
List *innerkeys = NIL;
|
||||
List *merge_pathkeys = NIL;
|
||||
|
||||
foreach(i, mergeinfo_list)
|
||||
{
|
||||
@ -317,7 +317,7 @@ sort_inner_and_outer(Rel * joinrel,
|
||||
*
|
||||
* Returns a list of possible join path nodes.
|
||||
*/
|
||||
static List *
|
||||
static List *
|
||||
match_unsorted_outer(Rel * joinrel,
|
||||
Rel * outerrel,
|
||||
Rel * innerrel,
|
||||
@ -326,21 +326,21 @@ match_unsorted_outer(Rel * joinrel,
|
||||
Path * best_innerjoin,
|
||||
List * mergeinfo_list)
|
||||
{
|
||||
Path *outerpath = (Path *) NULL;
|
||||
List *jp_list = NIL;
|
||||
List *temp_node = NIL;
|
||||
List *merge_pathkeys = NIL;
|
||||
Path *nestinnerpath = (Path *) NULL;
|
||||
List *paths = NIL;
|
||||
List *i = NIL;
|
||||
PathOrder *outerpath_ordering = NULL;
|
||||
Path *outerpath = (Path *) NULL;
|
||||
List *jp_list = NIL;
|
||||
List *temp_node = NIL;
|
||||
List *merge_pathkeys = NIL;
|
||||
Path *nestinnerpath = (Path *) NULL;
|
||||
List *paths = NIL;
|
||||
List *i = NIL;
|
||||
PathOrder *outerpath_ordering = NULL;
|
||||
|
||||
foreach(i, outerpath_list)
|
||||
{
|
||||
List *clauses = NIL;
|
||||
List *matchedJoinKeys = NIL;
|
||||
List *matchedJoinClauses = NIL;
|
||||
MInfo *xmergeinfo = (MInfo *) NULL;
|
||||
List *clauses = NIL;
|
||||
List *matchedJoinKeys = NIL;
|
||||
List *matchedJoinClauses = NIL;
|
||||
MInfo *xmergeinfo = (MInfo *) NULL;
|
||||
|
||||
outerpath = (Path *) lfirst(i);
|
||||
|
||||
@ -360,8 +360,8 @@ match_unsorted_outer(Rel * joinrel,
|
||||
|
||||
if (clauses)
|
||||
{
|
||||
List *keys = xmergeinfo->jmethod.jmkeys;
|
||||
List *clauses = xmergeinfo->jmethod.clauses;
|
||||
List *keys = xmergeinfo->jmethod.jmkeys;
|
||||
List *clauses = xmergeinfo->jmethod.clauses;
|
||||
|
||||
matchedJoinKeys =
|
||||
match_pathkeys_joinkeys(outerpath->keys,
|
||||
@ -397,9 +397,9 @@ match_unsorted_outer(Rel * joinrel,
|
||||
|
||||
if (clauses && matchedJoinKeys)
|
||||
{
|
||||
bool path_is_cheaper_than_sort;
|
||||
List *varkeys = NIL;
|
||||
Path *mergeinnerpath =
|
||||
bool path_is_cheaper_than_sort;
|
||||
List *varkeys = NIL;
|
||||
Path *mergeinnerpath =
|
||||
match_paths_joinkeys(matchedJoinKeys,
|
||||
outerpath_ordering,
|
||||
innerrel->pathlist,
|
||||
@ -484,27 +484,27 @@ match_unsorted_outer(Rel * joinrel,
|
||||
*
|
||||
* Returns a list of possible merge paths.
|
||||
*/
|
||||
static List *
|
||||
static List *
|
||||
match_unsorted_inner(Rel * joinrel,
|
||||
Rel * outerrel,
|
||||
Rel * innerrel,
|
||||
List * innerpath_list,
|
||||
List * mergeinfo_list)
|
||||
{
|
||||
Path *innerpath = (Path *) NULL;
|
||||
List *mp_list = NIL;
|
||||
List *temp_node = NIL;
|
||||
PathOrder *innerpath_ordering = NULL;
|
||||
Cost temp1 = 0.0;
|
||||
bool temp2 = false;
|
||||
List *i = NIL;
|
||||
Path *innerpath = (Path *) NULL;
|
||||
List *mp_list = NIL;
|
||||
List *temp_node = NIL;
|
||||
PathOrder *innerpath_ordering = NULL;
|
||||
Cost temp1 = 0.0;
|
||||
bool temp2 = false;
|
||||
List *i = NIL;
|
||||
|
||||
foreach(i, innerpath_list)
|
||||
{
|
||||
MInfo *xmergeinfo = (MInfo *) NULL;
|
||||
List *clauses = NIL;
|
||||
List *matchedJoinKeys = NIL;
|
||||
List *matchedJoinClauses = NIL;
|
||||
MInfo *xmergeinfo = (MInfo *) NULL;
|
||||
List *clauses = NIL;
|
||||
List *matchedJoinKeys = NIL;
|
||||
List *matchedJoinClauses = NIL;
|
||||
|
||||
innerpath = (Path *) lfirst(i);
|
||||
|
||||
@ -524,8 +524,8 @@ match_unsorted_inner(Rel * joinrel,
|
||||
|
||||
if (clauses)
|
||||
{
|
||||
List *keys = xmergeinfo->jmethod.jmkeys;
|
||||
List *cls = xmergeinfo->jmethod.clauses;
|
||||
List *keys = xmergeinfo->jmethod.jmkeys;
|
||||
List *cls = xmergeinfo->jmethod.clauses;
|
||||
|
||||
matchedJoinKeys =
|
||||
match_pathkeys_joinkeys(innerpath->keys,
|
||||
@ -550,11 +550,11 @@ match_unsorted_inner(Rel * joinrel,
|
||||
|
||||
if (temp2)
|
||||
{
|
||||
List *outerkeys =
|
||||
List *outerkeys =
|
||||
extract_path_keys(matchedJoinKeys,
|
||||
outerrel->targetlist,
|
||||
OUTER);
|
||||
List *merge_pathkeys =
|
||||
List *merge_pathkeys =
|
||||
new_join_pathkeys(outerkeys,
|
||||
joinrel->targetlist,
|
||||
clauses);
|
||||
@ -582,12 +582,12 @@ match_unsorted_inner(Rel * joinrel,
|
||||
|
||||
}
|
||||
|
||||
static bool
|
||||
static bool
|
||||
EnoughMemoryForHashjoin(Rel * hashrel)
|
||||
{
|
||||
int ntuples;
|
||||
int tupsize;
|
||||
int pages;
|
||||
int ntuples;
|
||||
int tupsize;
|
||||
int pages;
|
||||
|
||||
ntuples = hashrel->size;
|
||||
if (ntuples == 0)
|
||||
@ -616,19 +616,19 @@ EnoughMemoryForHashjoin(Rel * hashrel)
|
||||
*
|
||||
* Returns a list of hashjoin paths.
|
||||
*/
|
||||
static List *
|
||||
static List *
|
||||
hash_inner_and_outer(Rel * joinrel,
|
||||
Rel * outerrel,
|
||||
Rel * innerrel,
|
||||
List * hashinfo_list)
|
||||
{
|
||||
HInfo *xhashinfo = (HInfo *) NULL;
|
||||
List *hjoin_list = NIL;
|
||||
HashPath *temp_node = (HashPath *) NULL;
|
||||
List *i = NIL;
|
||||
List *outerkeys = NIL;
|
||||
List *innerkeys = NIL;
|
||||
List *hash_pathkeys = NIL;
|
||||
HInfo *xhashinfo = (HInfo *) NULL;
|
||||
List *hjoin_list = NIL;
|
||||
HashPath *temp_node = (HashPath *) NULL;
|
||||
List *i = NIL;
|
||||
List *outerkeys = NIL;
|
||||
List *innerkeys = NIL;
|
||||
List *hash_pathkeys = NIL;
|
||||
|
||||
foreach(i, hashinfo_list)
|
||||
{
|
||||
|
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/joinrels.c,v 1.5 1997/09/07 04:43:40 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/joinrels.c,v 1.6 1997/09/08 02:24:23 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -24,23 +24,23 @@
|
||||
#include "optimizer/pathnode.h"
|
||||
|
||||
#ifdef USE_RIGHT_SIDED_PLANS
|
||||
bool _use_right_sided_plans_ = true;
|
||||
bool _use_right_sided_plans_ = true;
|
||||
|
||||
#else
|
||||
bool _use_right_sided_plans_ = false;
|
||||
bool _use_right_sided_plans_ = false;
|
||||
|
||||
#endif
|
||||
|
||||
static List *find_clause_joins(Query * root, Rel * outer_rel, List * joininfo_list);
|
||||
static List *find_clauseless_joins(Rel * outer_rel, List * inner_rels);
|
||||
static Rel *init_join_rel(Rel * outer_rel, Rel * inner_rel, JInfo * joininfo);
|
||||
static List *
|
||||
static List *find_clause_joins(Query * root, Rel * outer_rel, List * joininfo_list);
|
||||
static List *find_clauseless_joins(Rel * outer_rel, List * inner_rels);
|
||||
static Rel *init_join_rel(Rel * outer_rel, Rel * inner_rel, JInfo * joininfo);
|
||||
static List *
|
||||
new_join_tlist(List * tlist, List * other_relids,
|
||||
int first_resdomno);
|
||||
static List *new_joininfo_list(List * joininfo_list, List * join_relids);
|
||||
static void add_superrels(Rel * rel, Rel * super_rel);
|
||||
static bool nonoverlap_rels(Rel * rel1, Rel * rel2);
|
||||
static bool nonoverlap_sets(List * s1, List * s2);
|
||||
static List *new_joininfo_list(List * joininfo_list, List * join_relids);
|
||||
static void add_superrels(Rel * rel, Rel * super_rel);
|
||||
static bool nonoverlap_rels(Rel * rel1, Rel * rel2);
|
||||
static bool nonoverlap_sets(List * s1, List * s2);
|
||||
static void
|
||||
set_joinrel_size(Rel * joinrel, Rel * outer_rel, Rel * inner_rel,
|
||||
JInfo * jinfo);
|
||||
@ -58,16 +58,16 @@ 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;
|
||||
List *join_list = NIL;
|
||||
List *r = NIL;
|
||||
List *joins = NIL;
|
||||
List *join_list = NIL;
|
||||
List *r = NIL;
|
||||
|
||||
foreach(r, outer_rels)
|
||||
{
|
||||
Rel *outer_rel = (Rel *) lfirst(r);
|
||||
Rel *outer_rel = (Rel *) lfirst(r);
|
||||
|
||||
if (!(joins = find_clause_joins(root, outer_rel, outer_rel->joininfo)))
|
||||
if (BushyPlanFlag)
|
||||
@ -96,20 +96,20 @@ find_join_rels(Query * root, List * outer_rels)
|
||||
*
|
||||
* Returns a list of new join relations.
|
||||
*/
|
||||
static List *
|
||||
static List *
|
||||
find_clause_joins(Query * root, Rel * outer_rel, List * joininfo_list)
|
||||
{
|
||||
List *join_list = NIL;
|
||||
List *i = NIL;
|
||||
List *join_list = NIL;
|
||||
List *i = NIL;
|
||||
|
||||
foreach(i, joininfo_list)
|
||||
{
|
||||
JInfo *joininfo = (JInfo *) lfirst(i);
|
||||
Rel *rel;
|
||||
JInfo *joininfo = (JInfo *) lfirst(i);
|
||||
Rel *rel;
|
||||
|
||||
if (!joininfo->inactive)
|
||||
{
|
||||
List *other_rels = joininfo->otherrels;
|
||||
List *other_rels = joininfo->otherrels;
|
||||
|
||||
if (other_rels != NIL)
|
||||
{
|
||||
@ -157,13 +157,13 @@ find_clause_joins(Query * root, Rel * outer_rel, List * joininfo_list)
|
||||
*
|
||||
* Returns a list of new join relations.
|
||||
*/
|
||||
static List *
|
||||
static List *
|
||||
find_clauseless_joins(Rel * outer_rel, List * inner_rels)
|
||||
{
|
||||
Rel *inner_rel;
|
||||
List *t_list = NIL;
|
||||
List *temp_node = NIL;
|
||||
List *i = NIL;
|
||||
Rel *inner_rel;
|
||||
List *t_list = NIL;
|
||||
List *temp_node = NIL;
|
||||
List *i = NIL;
|
||||
|
||||
foreach(i, inner_rels)
|
||||
{
|
||||
@ -192,13 +192,13 @@ find_clauseless_joins(Rel * outer_rel, List * inner_rels)
|
||||
*
|
||||
* Returns the new join relation node.
|
||||
*/
|
||||
static Rel *
|
||||
static Rel *
|
||||
init_join_rel(Rel * outer_rel, Rel * inner_rel, JInfo * joininfo)
|
||||
{
|
||||
Rel *joinrel = makeNode(Rel);
|
||||
List *joinrel_joininfo_list = NIL;
|
||||
List *new_outer_tlist;
|
||||
List *new_inner_tlist;
|
||||
Rel *joinrel = makeNode(Rel);
|
||||
List *joinrel_joininfo_list = NIL;
|
||||
List *new_outer_tlist;
|
||||
List *new_inner_tlist;
|
||||
|
||||
/*
|
||||
* Create a new tlist by removing irrelevant elements from both tlists
|
||||
@ -272,18 +272,18 @@ init_join_rel(Rel * outer_rel, Rel * inner_rel, JInfo * joininfo)
|
||||
*
|
||||
* Returns the new target list.
|
||||
*/
|
||||
static List *
|
||||
static List *
|
||||
new_join_tlist(List * tlist,
|
||||
List * other_relids,
|
||||
int first_resdomno)
|
||||
{
|
||||
int resdomno = first_resdomno - 1;
|
||||
TargetEntry *xtl = NULL;
|
||||
List *temp_node = NIL;
|
||||
List *t_list = NIL;
|
||||
List *i = NIL;
|
||||
List *join_list = NIL;
|
||||
bool in_final_tlist = false;
|
||||
int resdomno = first_resdomno - 1;
|
||||
TargetEntry *xtl = NULL;
|
||||
List *temp_node = NIL;
|
||||
List *t_list = NIL;
|
||||
List *i = NIL;
|
||||
List *join_list = NIL;
|
||||
bool in_final_tlist = false;
|
||||
|
||||
|
||||
foreach(i, tlist)
|
||||
@ -322,18 +322,18 @@ new_join_tlist(List * tlist,
|
||||
*
|
||||
* Returns a list of joininfo nodes, new and old.
|
||||
*/
|
||||
static List *
|
||||
static List *
|
||||
new_joininfo_list(List * joininfo_list, List * join_relids)
|
||||
{
|
||||
List *current_joininfo_list = NIL;
|
||||
List *new_otherrels = NIL;
|
||||
JInfo *other_joininfo = (JInfo *) NULL;
|
||||
List *xjoininfo = NIL;
|
||||
List *current_joininfo_list = NIL;
|
||||
List *new_otherrels = NIL;
|
||||
JInfo *other_joininfo = (JInfo *) NULL;
|
||||
List *xjoininfo = NIL;
|
||||
|
||||
foreach(xjoininfo, joininfo_list)
|
||||
{
|
||||
List *or;
|
||||
JInfo *joininfo = (JInfo *) lfirst(xjoininfo);
|
||||
List *or;
|
||||
JInfo *joininfo = (JInfo *) lfirst(xjoininfo);
|
||||
|
||||
new_otherrels = joininfo->otherrels;
|
||||
foreach(or, new_otherrels)
|
||||
@ -389,42 +389,42 @@ new_joininfo_list(List * joininfo_list, List * join_relids)
|
||||
void
|
||||
add_new_joininfos(Query * root, List * joinrels, List * outerrels)
|
||||
{
|
||||
List *xjoinrel = NIL;
|
||||
List *xrelid = NIL;
|
||||
List *xrel = NIL;
|
||||
List *xjoininfo = NIL;
|
||||
List *xjoinrel = NIL;
|
||||
List *xrelid = NIL;
|
||||
List *xrel = NIL;
|
||||
List *xjoininfo = NIL;
|
||||
|
||||
foreach(xjoinrel, joinrels)
|
||||
{
|
||||
Rel *joinrel = (Rel *) lfirst(xjoinrel);
|
||||
Rel *joinrel = (Rel *) lfirst(xjoinrel);
|
||||
|
||||
foreach(xrelid, joinrel->relids)
|
||||
{
|
||||
Relid relid = (Relid) lfirst(xrelid);
|
||||
Rel *rel = get_join_rel(root, relid);
|
||||
Relid relid = (Relid) lfirst(xrelid);
|
||||
Rel *rel = get_join_rel(root, relid);
|
||||
|
||||
add_superrels(rel, joinrel);
|
||||
}
|
||||
}
|
||||
foreach(xjoinrel, joinrels)
|
||||
{
|
||||
Rel *joinrel = (Rel *) lfirst(xjoinrel);
|
||||
Rel *joinrel = (Rel *) lfirst(xjoinrel);
|
||||
|
||||
foreach(xjoininfo, joinrel->joininfo)
|
||||
{
|
||||
JInfo *joininfo = (JInfo *) lfirst(xjoininfo);
|
||||
List *other_rels = joininfo->otherrels;
|
||||
List *clause_info = joininfo->jinfoclauseinfo;
|
||||
bool mergesortable = joininfo->mergesortable;
|
||||
bool hashjoinable = joininfo->hashjoinable;
|
||||
JInfo *joininfo = (JInfo *) lfirst(xjoininfo);
|
||||
List *other_rels = joininfo->otherrels;
|
||||
List *clause_info = joininfo->jinfoclauseinfo;
|
||||
bool mergesortable = joininfo->mergesortable;
|
||||
bool hashjoinable = joininfo->hashjoinable;
|
||||
|
||||
foreach(xrelid, other_rels)
|
||||
{
|
||||
Relid relid = (Relid) lfirst(xrelid);
|
||||
Rel *rel = get_join_rel(root, relid);
|
||||
List *super_rels = rel->superrels;
|
||||
List *xsuper_rel = NIL;
|
||||
JInfo *new_joininfo = makeNode(JInfo);
|
||||
Relid relid = (Relid) lfirst(xrelid);
|
||||
Rel *rel = get_join_rel(root, relid);
|
||||
List *super_rels = rel->superrels;
|
||||
List *xsuper_rel = NIL;
|
||||
JInfo *new_joininfo = makeNode(JInfo);
|
||||
|
||||
new_joininfo->otherrels = joinrel->relids;
|
||||
new_joininfo->jinfoclauseinfo = clause_info;
|
||||
@ -436,12 +436,12 @@ add_new_joininfos(Query * root, List * joinrels, List * outerrels)
|
||||
|
||||
foreach(xsuper_rel, super_rels)
|
||||
{
|
||||
Rel *super_rel = (Rel *) lfirst(xsuper_rel);
|
||||
Rel *super_rel = (Rel *) lfirst(xsuper_rel);
|
||||
|
||||
if (nonoverlap_rels(super_rel, joinrel))
|
||||
{
|
||||
List *new_relids = super_rel->relids;
|
||||
JInfo *other_joininfo =
|
||||
List *new_relids = super_rel->relids;
|
||||
JInfo *other_joininfo =
|
||||
joininfo_member(new_relids,
|
||||
joinrel->joininfo);
|
||||
|
||||
@ -453,7 +453,7 @@ add_new_joininfos(Query * root, List * joinrels, List * outerrels)
|
||||
}
|
||||
else
|
||||
{
|
||||
JInfo *new_joininfo = makeNode(JInfo);
|
||||
JInfo *new_joininfo = makeNode(JInfo);
|
||||
|
||||
new_joininfo->otherrels = new_relids;
|
||||
new_joininfo->jinfoclauseinfo = clause_info;
|
||||
@ -471,7 +471,7 @@ add_new_joininfos(Query * root, List * joinrels, List * outerrels)
|
||||
}
|
||||
foreach(xrel, outerrels)
|
||||
{
|
||||
Rel *rel = (Rel *) lfirst(xrel);
|
||||
Rel *rel = (Rel *) lfirst(xrel);
|
||||
|
||||
rel->superrels = NIL;
|
||||
}
|
||||
@ -486,12 +486,12 @@ 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;
|
||||
List *temp = NIL;
|
||||
List *t_list = NIL;
|
||||
List *xrel = NIL;
|
||||
List *temp = NIL;
|
||||
List *t_list = NIL;
|
||||
|
||||
/*
|
||||
* find the relations that has no further joins, i.e., its joininfos
|
||||
@ -499,13 +499,13 @@ final_join_rels(List * join_rel_list)
|
||||
*/
|
||||
foreach(xrel, join_rel_list)
|
||||
{
|
||||
Rel *rel = (Rel *) lfirst(xrel);
|
||||
List *xjoininfo = NIL;
|
||||
bool final = true;
|
||||
Rel *rel = (Rel *) lfirst(xrel);
|
||||
List *xjoininfo = NIL;
|
||||
bool final = true;
|
||||
|
||||
foreach(xjoininfo, rel->joininfo)
|
||||
{
|
||||
JInfo *joininfo = (JInfo *) lfirst(xjoininfo);
|
||||
JInfo *joininfo = (JInfo *) lfirst(xjoininfo);
|
||||
|
||||
if (joininfo->otherrels != NIL)
|
||||
{
|
||||
@ -547,20 +547,20 @@ add_superrels(Rel * rel, Rel * super_rel)
|
||||
*
|
||||
* Returns non-nil if rel1 and rel2 do not overlap.
|
||||
*/
|
||||
static bool
|
||||
static bool
|
||||
nonoverlap_rels(Rel * rel1, Rel * rel2)
|
||||
{
|
||||
return (nonoverlap_sets(rel1->relids, rel2->relids));
|
||||
}
|
||||
|
||||
static bool
|
||||
static bool
|
||||
nonoverlap_sets(List * s1, List * s2)
|
||||
{
|
||||
List *x = NIL;
|
||||
List *x = NIL;
|
||||
|
||||
foreach(x, s1)
|
||||
{
|
||||
int e = lfirsti(x);
|
||||
int e = lfirsti(x);
|
||||
|
||||
if (intMember(e, s2))
|
||||
return (false);
|
||||
@ -571,8 +571,8 @@ nonoverlap_sets(List * s1, List * s2)
|
||||
static void
|
||||
set_joinrel_size(Rel * joinrel, Rel * outer_rel, Rel * inner_rel, JInfo * jinfo)
|
||||
{
|
||||
int ntuples;
|
||||
float selec;
|
||||
int ntuples;
|
||||
float selec;
|
||||
|
||||
/*
|
||||
* voodoo magic. but better than a size of 0. I have no idea why we
|
||||
|
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/joinutils.c,v 1.2 1997/09/07 04:43:42 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/joinutils.c,v 1.3 1997/09/08 02:24:23 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -32,11 +32,11 @@ match_pathkey_joinkeys(List * pathkey, List * joinkeys,
|
||||
static bool
|
||||
every_func(List * joinkeys, List * pathkey,
|
||||
int which_subkey);
|
||||
static List *
|
||||
static List *
|
||||
new_join_pathkey(List * subkeys,
|
||||
List * considered_subkeys, List * join_rel_tlist,
|
||||
List * joinclauses);
|
||||
static List *
|
||||
static List *
|
||||
new_matching_subkeys(Var * subkey, List * considered_subkeys,
|
||||
List * join_rel_tlist, List * joinclauses);
|
||||
|
||||
@ -73,18 +73,18 @@ 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,
|
||||
int which_subkey,
|
||||
List ** matchedJoinClausesPtr)
|
||||
{
|
||||
List *matched_joinkeys = NIL;
|
||||
List *matched_joinclauses = NIL;
|
||||
List *pathkey = NIL;
|
||||
List *i = NIL;
|
||||
int matched_joinkey_index = -1;
|
||||
List *matched_joinkeys = NIL;
|
||||
List *matched_joinclauses = NIL;
|
||||
List *pathkey = NIL;
|
||||
List *i = NIL;
|
||||
int matched_joinkey_index = -1;
|
||||
|
||||
foreach(i, pathkeys)
|
||||
{
|
||||
@ -94,8 +94,8 @@ match_pathkeys_joinkeys(List * pathkeys,
|
||||
|
||||
if (matched_joinkey_index != -1)
|
||||
{
|
||||
List *xjoinkey = nth(matched_joinkey_index, joinkeys);
|
||||
List *joinclause = nth(matched_joinkey_index, joinclauses);
|
||||
List *xjoinkey = nth(matched_joinkey_index, joinkeys);
|
||||
List *joinclause = nth(matched_joinkey_index, joinclauses);
|
||||
|
||||
/* XXX was "push" function */
|
||||
matched_joinkeys = lappend(matched_joinkeys, xjoinkey);
|
||||
@ -131,11 +131,11 @@ match_pathkey_joinkeys(List * pathkey,
|
||||
List * joinkeys,
|
||||
int which_subkey)
|
||||
{
|
||||
Var *path_subkey;
|
||||
int pos;
|
||||
List *i = NIL;
|
||||
List *x = NIL;
|
||||
JoinKey *jk;
|
||||
Var *path_subkey;
|
||||
int pos;
|
||||
List *i = NIL;
|
||||
List *x = NIL;
|
||||
JoinKey *jk;
|
||||
|
||||
foreach(i, pathkey)
|
||||
{
|
||||
@ -174,15 +174,15 @@ match_pathkey_joinkeys(List * pathkey,
|
||||
*
|
||||
* Returns the matching path node if one exists, nil otherwise.
|
||||
*/
|
||||
static bool
|
||||
static bool
|
||||
every_func(List * joinkeys, List * pathkey, int which_subkey)
|
||||
{
|
||||
JoinKey *xjoinkey;
|
||||
Var *temp;
|
||||
Var *tempkey = NULL;
|
||||
bool found = false;
|
||||
List *i = NIL;
|
||||
List *j = NIL;
|
||||
JoinKey *xjoinkey;
|
||||
Var *temp;
|
||||
Var *tempkey = NULL;
|
||||
bool found = false;
|
||||
List *i = NIL;
|
||||
List *j = NIL;
|
||||
|
||||
foreach(i, joinkeys)
|
||||
{
|
||||
@ -211,19 +211,19 @@ 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,
|
||||
int which_subkey)
|
||||
{
|
||||
Path *matched_path = NULL;
|
||||
bool key_match = false;
|
||||
List *i = NIL;
|
||||
Path *matched_path = NULL;
|
||||
bool key_match = false;
|
||||
List *i = NIL;
|
||||
|
||||
foreach(i, paths)
|
||||
{
|
||||
Path *path = (Path *) lfirst(i);
|
||||
Path *path = (Path *) lfirst(i);
|
||||
|
||||
key_match = every_func(joinkeys, path->keys, which_subkey);
|
||||
|
||||
@ -263,20 +263,20 @@ 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)
|
||||
{
|
||||
List *pathkeys = NIL;
|
||||
List *jk;
|
||||
List *pathkeys = NIL;
|
||||
List *jk;
|
||||
|
||||
foreach(jk, joinkeys)
|
||||
{
|
||||
JoinKey *jkey = (JoinKey *) lfirst(jk);
|
||||
Var *var,
|
||||
*key;
|
||||
List *p;
|
||||
JoinKey *jkey = (JoinKey *) lfirst(jk);
|
||||
Var *var,
|
||||
*key;
|
||||
List *p;
|
||||
|
||||
/*
|
||||
* find the right Var in the target list for this key
|
||||
@ -289,7 +289,7 @@ extract_path_keys(List * joinkeys,
|
||||
*/
|
||||
foreach(p, pathkeys)
|
||||
{
|
||||
Var *pkey = lfirst((List *) lfirst(p)); /* XXX fix me */
|
||||
Var *pkey = lfirst((List *) lfirst(p)); /* XXX fix me */
|
||||
|
||||
if (key == pkey)
|
||||
break;
|
||||
@ -325,15 +325,15 @@ 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)
|
||||
{
|
||||
List *outer_pathkey = NIL;
|
||||
List *t_list = NIL;
|
||||
List *x;
|
||||
List *i = NIL;
|
||||
List *outer_pathkey = NIL;
|
||||
List *t_list = NIL;
|
||||
List *x;
|
||||
List *i = NIL;
|
||||
|
||||
foreach(i, outer_pathkeys)
|
||||
{
|
||||
@ -365,18 +365,18 @@ new_join_pathkeys(List * outer_pathkeys,
|
||||
* Returns a new pathkey(list of subkeys).
|
||||
*
|
||||
*/
|
||||
static List *
|
||||
static List *
|
||||
new_join_pathkey(List * subkeys,
|
||||
List * considered_subkeys,
|
||||
List * join_rel_tlist,
|
||||
List * joinclauses)
|
||||
{
|
||||
List *t_list = NIL;
|
||||
Var *subkey;
|
||||
List *i = NIL;
|
||||
List *matched_subkeys = NIL;
|
||||
Expr *tlist_key = (Expr *) NULL;
|
||||
List *newly_considered_subkeys = NIL;
|
||||
List *t_list = NIL;
|
||||
Var *subkey;
|
||||
List *i = NIL;
|
||||
List *matched_subkeys = NIL;
|
||||
Expr *tlist_key = (Expr *) NULL;
|
||||
List *newly_considered_subkeys = NIL;
|
||||
|
||||
foreach(i, subkeys)
|
||||
{
|
||||
@ -425,17 +425,17 @@ new_join_pathkey(List * subkeys,
|
||||
* Returns a list of new subkeys.
|
||||
*
|
||||
*/
|
||||
static List *
|
||||
static List *
|
||||
new_matching_subkeys(Var * subkey,
|
||||
List * considered_subkeys,
|
||||
List * join_rel_tlist,
|
||||
List * joinclauses)
|
||||
{
|
||||
Expr *joinclause = NULL;
|
||||
List *t_list = NIL;
|
||||
List *temp = NIL;
|
||||
List *i = NIL;
|
||||
Expr *tlist_other_var = (Expr *) NULL;
|
||||
Expr *joinclause = NULL;
|
||||
List *t_list = NIL;
|
||||
List *temp = NIL;
|
||||
List *i = NIL;
|
||||
Expr *tlist_other_var = (Expr *) NULL;
|
||||
|
||||
foreach(i, joinclauses)
|
||||
{
|
||||
|
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/mergeutils.c,v 1.2 1997/09/07 04:43:45 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/mergeutils.c,v 1.3 1997/09/08 02:24:24 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -33,17 +33,17 @@
|
||||
* Returns the new list of mergeinfo nodes.
|
||||
*
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
group_clauses_by_order(List * clauseinfo_list,
|
||||
int inner_relid)
|
||||
{
|
||||
List *mergeinfo_list = NIL;
|
||||
List *xclauseinfo = NIL;
|
||||
List *mergeinfo_list = NIL;
|
||||
List *xclauseinfo = NIL;
|
||||
|
||||
foreach(xclauseinfo, clauseinfo_list)
|
||||
{
|
||||
CInfo *clauseinfo = (CInfo *) lfirst(xclauseinfo);
|
||||
MergeOrder *merge_ordering = clauseinfo->mergesortorder;
|
||||
CInfo *clauseinfo = (CInfo *) lfirst(xclauseinfo);
|
||||
MergeOrder *merge_ordering = clauseinfo->mergesortorder;
|
||||
|
||||
if (merge_ordering)
|
||||
{
|
||||
@ -52,12 +52,12 @@ group_clauses_by_order(List * clauseinfo_list,
|
||||
* Create a new mergeinfo node and add it to 'mergeinfo-list'
|
||||
* if one does not yet exist for this merge ordering.
|
||||
*/
|
||||
PathOrder p_ordering;
|
||||
MInfo *xmergeinfo;
|
||||
Expr *clause = clauseinfo->clause;
|
||||
Var *leftop = get_leftop(clause);
|
||||
Var *rightop = get_rightop(clause);
|
||||
JoinKey *keys;
|
||||
PathOrder p_ordering;
|
||||
MInfo *xmergeinfo;
|
||||
Expr *clause = clauseinfo->clause;
|
||||
Var *leftop = get_leftop(clause);
|
||||
Var *rightop = get_rightop(clause);
|
||||
JoinKey *keys;
|
||||
|
||||
p_ordering.ordtype = MERGE_ORDER;
|
||||
p_ordering.ord.merge = merge_ordering;
|
||||
@ -105,15 +105,15 @@ 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;
|
||||
List *xmergeinfo = NIL;
|
||||
MergeOrder *xmergeorder;
|
||||
List *xmergeinfo = NIL;
|
||||
|
||||
foreach(xmergeinfo, mergeinfo_list)
|
||||
{
|
||||
MInfo *mergeinfo = (MInfo *) lfirst(xmergeinfo);
|
||||
MInfo *mergeinfo = (MInfo *) lfirst(xmergeinfo);
|
||||
|
||||
xmergeorder = mergeinfo->m_ordering;
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/orindxpath.c,v 1.2 1997/09/07 04:43:46 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/orindxpath.c,v 1.3 1997/09/08 02:24:25 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -50,15 +50,15 @@ 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)
|
||||
{
|
||||
List *t_list = NIL;
|
||||
List *t_list = NIL;
|
||||
|
||||
if (clauses != NIL)
|
||||
{
|
||||
CInfo *clausenode = (CInfo *) (lfirst(clauses));
|
||||
CInfo *clausenode = (CInfo *) (lfirst(clauses));
|
||||
|
||||
/*
|
||||
* Check to see if this clause is an 'or' clause, and, if so,
|
||||
@ -70,9 +70,9 @@ create_or_index_paths(Query * root,
|
||||
if (valid_or_clause(clausenode) &&
|
||||
clausenode->indexids)
|
||||
{
|
||||
List *temp = NIL;
|
||||
List *index_list = NIL;
|
||||
bool index_flag = true;
|
||||
List *temp = NIL;
|
||||
List *index_list = NIL;
|
||||
bool index_flag = true;
|
||||
|
||||
index_list = clausenode->indexids;
|
||||
foreach(temp, index_list)
|
||||
@ -82,10 +82,10 @@ create_or_index_paths(Query * root,
|
||||
}
|
||||
if (index_flag)
|
||||
{ /* used to be a lisp every function */
|
||||
IndexPath *pathnode = makeNode(IndexPath);
|
||||
List *indexids;
|
||||
Cost cost;
|
||||
List *selecs;
|
||||
IndexPath *pathnode = makeNode(IndexPath);
|
||||
List *indexids;
|
||||
Cost cost;
|
||||
List *selecs;
|
||||
|
||||
best_or_subclause_indices(root,
|
||||
rel,
|
||||
@ -177,9 +177,9 @@ best_or_subclause_indices(Query * root,
|
||||
}
|
||||
else
|
||||
{
|
||||
int best_indexid;
|
||||
Cost best_cost;
|
||||
Cost best_selec;
|
||||
int best_indexid;
|
||||
Cost best_cost;
|
||||
Cost best_selec;
|
||||
|
||||
best_or_subclause_index(root, rel, lfirst(subclauses), lfirst(indices),
|
||||
&best_indexid, &best_cost, &best_selec);
|
||||
@ -223,18 +223,18 @@ best_or_subclause_index(Query * root,
|
||||
{
|
||||
if (indices != NIL)
|
||||
{
|
||||
Datum value;
|
||||
int flag = 0;
|
||||
Cost subcost;
|
||||
Rel *index = (Rel *) lfirst(indices);
|
||||
AttrNumber attno = (get_leftop(subclause))->varattno;
|
||||
Oid opno = ((Oper *) subclause->oper)->opno;
|
||||
bool constant_on_right = non_null((Expr *) get_rightop(subclause));
|
||||
float npages,
|
||||
selec;
|
||||
int subclause_indexid;
|
||||
Cost subclause_cost;
|
||||
Cost subclause_selec;
|
||||
Datum value;
|
||||
int flag = 0;
|
||||
Cost subcost;
|
||||
Rel *index = (Rel *) lfirst(indices);
|
||||
AttrNumber attno = (get_leftop(subclause))->varattno;
|
||||
Oid opno = ((Oper *) subclause->oper)->opno;
|
||||
bool constant_on_right = non_null((Expr *) get_rightop(subclause));
|
||||
float npages,
|
||||
selec;
|
||||
int subclause_indexid;
|
||||
Cost subclause_cost;
|
||||
Cost subclause_selec;
|
||||
|
||||
if (constant_on_right)
|
||||
{
|
||||
|
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/predmig.c,v 1.3 1997/09/07 04:43:47 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/predmig.c,v 1.4 1997/09/08 02:24:26 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -57,28 +57,28 @@
|
||||
static void
|
||||
xfunc_predmig(JoinPath pathnode, Stream streamroot,
|
||||
Stream laststream, bool * progressp);
|
||||
static bool xfunc_series_llel(Stream stream);
|
||||
static bool xfunc_llel_chains(Stream root, Stream bottom);
|
||||
static Stream xfunc_complete_stream(Stream stream);
|
||||
static bool xfunc_series_llel(Stream stream);
|
||||
static bool xfunc_llel_chains(Stream root, Stream bottom);
|
||||
static Stream xfunc_complete_stream(Stream stream);
|
||||
static bool
|
||||
xfunc_prdmig_pullup(Stream origstream, Stream pullme,
|
||||
JoinPath joinpath);
|
||||
static void xfunc_form_groups(Stream root, Stream bottom);
|
||||
static void xfunc_free_stream(Stream root);
|
||||
static Stream xfunc_add_clauses(Stream current);
|
||||
static void xfunc_setup_group(Stream node, Stream bottom);
|
||||
static void xfunc_form_groups(Stream root, Stream bottom);
|
||||
static void xfunc_free_stream(Stream root);
|
||||
static Stream xfunc_add_clauses(Stream current);
|
||||
static void xfunc_setup_group(Stream node, Stream bottom);
|
||||
static Stream
|
||||
xfunc_streaminsert(CInfo clauseinfo, Stream current,
|
||||
int clausetype);
|
||||
static int xfunc_num_relids(Stream node);
|
||||
static int xfunc_num_relids(Stream node);
|
||||
static StreamPtr xfunc_get_downjoin(Stream node);
|
||||
static StreamPtr xfunc_get_upjoin(Stream node);
|
||||
static Stream xfunc_stream_qsort(Stream root, Stream bottom);
|
||||
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);
|
||||
static Stream xfunc_stream_qsort(Stream root, Stream bottom);
|
||||
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
|
||||
@ -88,8 +88,8 @@ static bool xfunc_in_stream(Stream node, Stream stream);
|
||||
bool
|
||||
xfunc_do_predmig(Path root)
|
||||
{
|
||||
bool progress,
|
||||
changed = false;
|
||||
bool progress,
|
||||
changed = false;
|
||||
|
||||
if (is_join(root))
|
||||
do
|
||||
@ -122,7 +122,7 @@ xfunc_predmig(JoinPath pathnode,/* root of the join tree */
|
||||
* and the lowest node created so far */
|
||||
bool * progressp)
|
||||
{
|
||||
Stream newstream;
|
||||
Stream newstream;
|
||||
|
||||
/*
|
||||
* * traverse the join tree dfs-style, constructing a stream as you
|
||||
@ -153,7 +153,7 @@ xfunc_predmig(JoinPath pathnode,/* root of the join tree */
|
||||
if (!is_join(pathnode))
|
||||
{
|
||||
/* form a fleshed-out copy of the stream */
|
||||
Stream fullstream = xfunc_complete_stream(streamroot);
|
||||
Stream fullstream = xfunc_complete_stream(streamroot);
|
||||
|
||||
/* sort it via series-llel */
|
||||
if (xfunc_series_llel(fullstream))
|
||||
@ -188,9 +188,9 @@ xfunc_predmig(JoinPath pathnode,/* root of the join tree */
|
||||
static bool
|
||||
xfunc_series_llel(Stream stream)
|
||||
{
|
||||
Stream temp,
|
||||
next;
|
||||
bool progress = false;
|
||||
Stream temp,
|
||||
next;
|
||||
bool progress = false;
|
||||
|
||||
for (temp = stream; temp != (Stream) NULL; temp = next)
|
||||
{
|
||||
@ -219,11 +219,11 @@ xfunc_series_llel(Stream stream)
|
||||
static bool
|
||||
xfunc_llel_chains(Stream root, Stream bottom)
|
||||
{
|
||||
bool progress = false;
|
||||
Stream origstream;
|
||||
Stream tmpstream,
|
||||
pathstream;
|
||||
Stream rootcopy = root;
|
||||
bool progress = false;
|
||||
Stream origstream;
|
||||
Stream tmpstream,
|
||||
pathstream;
|
||||
Stream rootcopy = root;
|
||||
|
||||
Assert(xfunc_check_stream(root));
|
||||
|
||||
@ -282,9 +282,9 @@ xfunc_llel_chains(Stream root, Stream bottom)
|
||||
static Stream
|
||||
xfunc_complete_stream(Stream stream)
|
||||
{
|
||||
Stream tmpstream,
|
||||
copystream,
|
||||
curstream = (Stream) NULL;
|
||||
Stream tmpstream,
|
||||
copystream,
|
||||
curstream = (Stream) NULL;
|
||||
|
||||
copystream = (Stream) copyObject((Node) stream);
|
||||
Assert(xfunc_check_stream(copystream));
|
||||
@ -316,15 +316,15 @@ xfunc_complete_stream(Stream stream)
|
||||
** nodes. We use the original stream to find out what joins are
|
||||
** above the clause.
|
||||
*/
|
||||
static bool
|
||||
static bool
|
||||
xfunc_prdmig_pullup(Stream origstream, Stream pullme, JoinPath joinpath)
|
||||
{
|
||||
CInfo clauseinfo = get_cinfo(pullme);
|
||||
bool progress = false;
|
||||
Stream upjoin,
|
||||
orignode,
|
||||
temp;
|
||||
int whichchild;
|
||||
CInfo clauseinfo = get_cinfo(pullme);
|
||||
bool progress = false;
|
||||
Stream upjoin,
|
||||
orignode,
|
||||
temp;
|
||||
int whichchild;
|
||||
|
||||
/* find node in origstream that contains clause */
|
||||
for (orignode = origstream;
|
||||
@ -412,12 +412,12 @@ xfunc_prdmig_pullup(Stream origstream, Stream pullme, JoinPath joinpath)
|
||||
static void
|
||||
xfunc_form_groups(Query * queryInfo, Stream root, Stream bottom)
|
||||
{
|
||||
Stream temp,
|
||||
parent;
|
||||
int lowest = xfunc_num_relids((Stream) xfunc_get_upjoin(bottom));
|
||||
bool progress;
|
||||
LispValue primjoin;
|
||||
int whichchild;
|
||||
Stream temp,
|
||||
parent;
|
||||
int lowest = xfunc_num_relids((Stream) xfunc_get_upjoin(bottom));
|
||||
bool progress;
|
||||
LispValue primjoin;
|
||||
int whichchild;
|
||||
|
||||
if (!lowest)
|
||||
return; /* no joins in stream, so no groups */
|
||||
@ -495,7 +495,7 @@ xfunc_form_groups(Query * queryInfo, Stream root, Stream bottom)
|
||||
}
|
||||
|
||||
|
||||
/* ------------------- UTILITY FUNCTIONS ------------------------- */
|
||||
/* ------------------- UTILITY FUNCTIONS ------------------------- */
|
||||
|
||||
/*
|
||||
** xfunc_free_stream --
|
||||
@ -504,8 +504,8 @@ xfunc_form_groups(Query * queryInfo, Stream root, Stream bottom)
|
||||
static void
|
||||
xfunc_free_stream(Stream root)
|
||||
{
|
||||
Stream cur,
|
||||
next;
|
||||
Stream cur,
|
||||
next;
|
||||
|
||||
Assert(xfunc_check_stream(root));
|
||||
|
||||
@ -525,9 +525,9 @@ xfunc_free_stream(Stream root)
|
||||
static Stream
|
||||
xfunc_add_clauses(Stream current)
|
||||
{
|
||||
Stream topnode = current;
|
||||
LispValue temp;
|
||||
LispValue primjoin;
|
||||
Stream topnode = current;
|
||||
LispValue temp;
|
||||
LispValue primjoin;
|
||||
|
||||
/* first add in the local clauses */
|
||||
foreach(temp, get_locclauseinfo((Path) get_pathptr(current)))
|
||||
@ -561,7 +561,7 @@ xfunc_add_clauses(Stream current)
|
||||
static void
|
||||
xfunc_setup_group(Stream node, Stream bottom)
|
||||
{
|
||||
Stream temp;
|
||||
Stream temp;
|
||||
|
||||
if (node != bottom)
|
||||
/* traverse downwards */
|
||||
@ -598,12 +598,12 @@ xfunc_setup_group(Stream node, Stream bottom)
|
||||
** Make a new Stream node to hold clause, and insert it above current.
|
||||
** Return new node.
|
||||
*/
|
||||
static Stream
|
||||
static Stream
|
||||
xfunc_streaminsert(CInfo clauseinfo,
|
||||
Stream current,
|
||||
int clausetype) /* XFUNC_LOCPRD or XFUNC_JOINPRD */
|
||||
{
|
||||
Stream newstream = RMakeStream();
|
||||
Stream newstream = RMakeStream();
|
||||
|
||||
set_upstream(newstream, get_upstream(current));
|
||||
if (get_upstream(current))
|
||||
@ -640,7 +640,7 @@ xfunc_num_relids(Stream node)
|
||||
static StreamPtr
|
||||
xfunc_get_downjoin(Stream node)
|
||||
{
|
||||
Stream temp;
|
||||
Stream temp;
|
||||
|
||||
if (!is_clause(node)) /* if this is a join */
|
||||
node = (Stream) get_downstream(node);
|
||||
@ -658,7 +658,7 @@ xfunc_get_downjoin(Stream node)
|
||||
static StreamPtr
|
||||
xfunc_get_upjoin(Stream node)
|
||||
{
|
||||
Stream temp;
|
||||
Stream temp;
|
||||
|
||||
if (!is_clause(node)) /* if this is a join */
|
||||
node = (Stream) get_upstream(node);
|
||||
@ -677,11 +677,11 @@ xfunc_get_upjoin(Stream node)
|
||||
static Stream
|
||||
xfunc_stream_qsort(Stream root, Stream bottom)
|
||||
{
|
||||
int i;
|
||||
size_t num;
|
||||
Stream *nodearray,
|
||||
output;
|
||||
Stream tmp;
|
||||
int i;
|
||||
size_t num;
|
||||
Stream *nodearray,
|
||||
output;
|
||||
Stream tmp;
|
||||
|
||||
/* find size of list */
|
||||
for (num = 0, tmp = root; tmp != bottom;
|
||||
@ -725,10 +725,10 @@ xfunc_stream_qsort(Stream root, Stream bottom)
|
||||
static int
|
||||
xfunc_stream_compare(void *arg1, void *arg2)
|
||||
{
|
||||
Stream stream1 = *(Stream *) arg1;
|
||||
Stream stream2 = *(Stream *) arg2;
|
||||
Cost rank1,
|
||||
rank2;
|
||||
Stream stream1 = *(Stream *) arg1;
|
||||
Stream stream2 = *(Stream *) arg2;
|
||||
Cost rank1,
|
||||
rank2;
|
||||
|
||||
rank1 = get_grouprank(stream1);
|
||||
rank2 = get_grouprank(stream2);
|
||||
@ -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
|
||||
@ -774,9 +774,9 @@ xfunc_stream_compare(void *arg1, void *arg2)
|
||||
static bool
|
||||
xfunc_check_stream(Stream node)
|
||||
{
|
||||
Stream temp;
|
||||
int numrelids,
|
||||
tmp;
|
||||
Stream temp;
|
||||
int numrelids,
|
||||
tmp;
|
||||
|
||||
/* set numrelids higher than max */
|
||||
if (!is_clause(node))
|
||||
@ -814,7 +814,7 @@ xfunc_check_stream(Stream node)
|
||||
static bool
|
||||
xfunc_in_stream(Stream node, Stream stream)
|
||||
{
|
||||
Stream temp;
|
||||
Stream temp;
|
||||
|
||||
for (temp = stream; temp; temp = (Stream) get_downstream(temp))
|
||||
if (temp == node)
|
||||
|
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/prune.c,v 1.4 1997/09/07 04:43:49 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/prune.c,v 1.5 1997/09/08 02:24:27 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -24,7 +24,7 @@
|
||||
#include "utils/elog.h"
|
||||
|
||||
|
||||
static List *prune_joinrel(Rel * rel, List * other_rels);
|
||||
static List *prune_joinrel(Rel * rel, List * other_rels);
|
||||
|
||||
/*
|
||||
* prune-joinrels--
|
||||
@ -34,10 +34,10 @@ static List *prune_joinrel(Rel * rel, List * other_rels);
|
||||
* Returns the resulting list.
|
||||
*
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
prune_joinrels(List * rel_list)
|
||||
{
|
||||
List *temp_list = NIL;
|
||||
List *temp_list = NIL;
|
||||
|
||||
if (rel_list != NIL)
|
||||
{
|
||||
@ -59,13 +59,13 @@ prune_joinrels(List * rel_list)
|
||||
* of 'rel' appropriately.
|
||||
*
|
||||
*/
|
||||
static List *
|
||||
static List *
|
||||
prune_joinrel(Rel * rel, List * other_rels)
|
||||
{
|
||||
List *i = NIL;
|
||||
List *t_list = NIL;
|
||||
List *temp_node = NIL;
|
||||
Rel *other_rel = (Rel *) NULL;
|
||||
List *i = NIL;
|
||||
List *t_list = NIL;
|
||||
List *temp_node = NIL;
|
||||
Rel *other_rel = (Rel *) NULL;
|
||||
|
||||
foreach(i, other_rels)
|
||||
{
|
||||
@ -99,11 +99,11 @@ prune_joinrel(Rel * rel, List * other_rels)
|
||||
void
|
||||
prune_rel_paths(List * rel_list)
|
||||
{
|
||||
List *x = NIL;
|
||||
List *y = NIL;
|
||||
Path *path = NULL;
|
||||
Rel *rel = (Rel *) NULL;
|
||||
JoinPath *cheapest = (JoinPath *) NULL;
|
||||
List *x = NIL;
|
||||
List *y = NIL;
|
||||
Path *path = NULL;
|
||||
Rel *rel = (Rel *) NULL;
|
||||
JoinPath *cheapest = (JoinPath *) NULL;
|
||||
|
||||
foreach(x, rel_list)
|
||||
{
|
||||
@ -139,10 +139,10 @@ 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);
|
||||
Path *cheapest = set_cheapest(rel, rel->pathlist);
|
||||
|
||||
/* don't prune if not pruneable -- JMH, 11/23/92 */
|
||||
if (unorderedpath != cheapest
|
||||
@ -170,14 +170,14 @@ 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;
|
||||
List *xrel = NIL;
|
||||
|
||||
foreach(xrel, rel_list1)
|
||||
{
|
||||
Rel *rel = (Rel *) lfirst(xrel);
|
||||
Rel *rel = (Rel *) lfirst(xrel);
|
||||
|
||||
rel_list2 = prune_joinrel(rel, rel_list2);
|
||||
}
|
||||
@ -196,12 +196,12 @@ merge_joinrels(List * rel_list1, List * rel_list2)
|
||||
*
|
||||
* Returns a new list of rel nodes
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
prune_oldrels(List * old_rels)
|
||||
{
|
||||
Rel *rel;
|
||||
List *joininfo_list,
|
||||
*xjoininfo;
|
||||
Rel *rel;
|
||||
List *joininfo_list,
|
||||
*xjoininfo;
|
||||
|
||||
if (old_rels == NIL)
|
||||
return (NIL);
|
||||
@ -213,7 +213,7 @@ prune_oldrels(List * old_rels)
|
||||
|
||||
foreach(xjoininfo, joininfo_list)
|
||||
{
|
||||
JInfo *joininfo = (JInfo *) lfirst(xjoininfo);
|
||||
JInfo *joininfo = (JInfo *) lfirst(xjoininfo);
|
||||
|
||||
if (!joininfo->inactive)
|
||||
return (lcons(rel, prune_oldrels(lnext(old_rels))));
|
||||
|
@ -9,7 +9,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/xfunc.c,v 1.4 1997/09/07 04:43:50 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/xfunc.c,v 1.5 1997/09/08 02:24:28 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -62,13 +62,13 @@ xfunc_card_unreferenced(Query * queryInfo,
|
||||
void
|
||||
xfunc_trypullup(Rel rel)
|
||||
{
|
||||
LispValue y; /* list ptr */
|
||||
CInfo maxcinfo; /* The CInfo to pull up, as calculated by
|
||||
LispValue y; /* list ptr */
|
||||
CInfo maxcinfo; /* The CInfo to pull up, as calculated by
|
||||
* xfunc_shouldpull() */
|
||||
JoinPath curpath; /* current path in list */
|
||||
int progress; /* has progress been made this time
|
||||
JoinPath curpath; /* current path in list */
|
||||
int progress; /* has progress been made this time
|
||||
* through? */
|
||||
int clausetype;
|
||||
int clausetype;
|
||||
|
||||
do
|
||||
{
|
||||
@ -153,17 +153,16 @@ xfunc_shouldpull(Query * queryInfo,
|
||||
CInfo * maxcinfopt) /* Out: pointer to clause to
|
||||
* pullup */
|
||||
{
|
||||
LispValue clauselist,
|
||||
tmplist; /* lists of clauses */
|
||||
CInfo maxcinfo; /* clause to pullup */
|
||||
LispValue primjoinclause /* primary join clause */
|
||||
LispValue clauselist,
|
||||
tmplist; /* lists of clauses */
|
||||
CInfo maxcinfo; /* clause to pullup */
|
||||
LispValue primjoinclause /* primary join clause */
|
||||
= xfunc_primary_join(parentpath);
|
||||
Cost tmprank,
|
||||
maxrank = (-1 * MAXFLOAT); /* ranks of clauses */
|
||||
Cost joinselec = 0; /* selectivity of the join
|
||||
* predicate */
|
||||
Cost joincost = 0; /* join cost + primjoinclause cost */
|
||||
int retval = XFUNC_LOCPRD;
|
||||
Cost tmprank,
|
||||
maxrank = (-1 * MAXFLOAT); /* ranks of clauses */
|
||||
Cost joinselec = 0; /* selectivity of the join predicate */
|
||||
Cost joincost = 0; /* join cost + primjoinclause cost */
|
||||
int retval = XFUNC_LOCPRD;
|
||||
|
||||
clauselist = get_locclauseinfo(childpath);
|
||||
|
||||
@ -275,11 +274,11 @@ xfunc_pullup(Query * queryInfo,
|
||||
int whichchild, /* whether child is INNER or OUTER of join */
|
||||
int clausetype) /* whether clause to pull is join or local */
|
||||
{
|
||||
Path newkid;
|
||||
Rel newrel;
|
||||
Cost pulled_selec;
|
||||
Cost cost;
|
||||
CInfo newinfo;
|
||||
Path newkid;
|
||||
Rel newrel;
|
||||
Cost pulled_selec;
|
||||
Cost cost;
|
||||
CInfo newinfo;
|
||||
|
||||
/* remove clause from childpath */
|
||||
newkid = (Path) copyObject((Node) childpath);
|
||||
@ -363,8 +362,8 @@ xfunc_pullup(Query * queryInfo,
|
||||
Cost
|
||||
xfunc_rank(Query * queryInfo, LispValue clause)
|
||||
{
|
||||
Cost selec = compute_clause_selec(queryInfo, clause, LispNil);
|
||||
Cost cost = xfunc_expense(queryInfo, clause);
|
||||
Cost selec = compute_clause_selec(queryInfo, clause, LispNil);
|
||||
Cost cost = xfunc_expense(queryInfo, clause);
|
||||
|
||||
if (cost == 0)
|
||||
if (selec > 1)
|
||||
@ -381,13 +380,13 @@ xfunc_rank(Query * queryInfo, LispValue clause)
|
||||
*/
|
||||
Cost
|
||||
xfunc_expense(Query * queryInfo, clause)
|
||||
LispValue clause;
|
||||
LispValue clause;
|
||||
{
|
||||
Cost cost = xfunc_local_expense(clause);
|
||||
Cost cost = xfunc_local_expense(clause);
|
||||
|
||||
if (cost)
|
||||
{
|
||||
Count card = xfunc_card_unreferenced(queryInfo, clause, LispNil);
|
||||
Count card = xfunc_card_unreferenced(queryInfo, clause, LispNil);
|
||||
|
||||
if (card)
|
||||
cost /= card;
|
||||
@ -403,15 +402,15 @@ LispValue clause;
|
||||
Cost
|
||||
xfunc_join_expense(Query * queryInfo, JoinPath path, int whichchild)
|
||||
{
|
||||
LispValue primjoinclause = xfunc_primary_join(path);
|
||||
LispValue primjoinclause = xfunc_primary_join(path);
|
||||
|
||||
/*
|
||||
* * the second argument to xfunc_card_unreferenced reflects all the *
|
||||
* relations involved in the join clause, i.e. all the relids in the
|
||||
* Rel * of the join clause
|
||||
*/
|
||||
Count card = 0;
|
||||
Cost cost = xfunc_expense_per_tuple(path, whichchild);
|
||||
Count card = 0;
|
||||
Cost cost = xfunc_expense_per_tuple(path, whichchild);
|
||||
|
||||
card = xfunc_card_unreferenced(queryInfo,
|
||||
primjoinclause,
|
||||
@ -432,8 +431,8 @@ xfunc_join_expense(Query * queryInfo, JoinPath path, int whichchild)
|
||||
Cost
|
||||
xfunc_local_expense(LispValue clause)
|
||||
{
|
||||
Cost cost = 0; /* running expense */
|
||||
LispValue tmpclause;
|
||||
Cost cost = 0; /* running expense */
|
||||
LispValue tmpclause;
|
||||
|
||||
/* First handle the base case */
|
||||
if (IsA(clause, Const) || IsA(clause, Var) || IsA(clause, Param))
|
||||
@ -484,15 +483,15 @@ xfunc_local_expense(LispValue clause)
|
||||
Cost
|
||||
xfunc_func_expense(LispValue node, LispValue args)
|
||||
{
|
||||
HeapTuple tupl; /* the pg_proc tuple for each function */
|
||||
Form_pg_proc proc; /* a data structure to hold the pg_proc
|
||||
HeapTuple tupl; /* the pg_proc tuple for each function */
|
||||
Form_pg_proc proc; /* a data structure to hold the pg_proc
|
||||
* tuple */
|
||||
int width = 0; /* byte width of the field referenced by
|
||||
int width = 0; /* byte width of the field referenced by
|
||||
* each clause */
|
||||
RegProcedure funcid; /* ID of function associate with node */
|
||||
Cost cost = 0; /* running expense */
|
||||
LispValue tmpclause;
|
||||
LispValue operand; /* one operand of an operator */
|
||||
RegProcedure funcid; /* ID of function associate with node */
|
||||
Cost cost = 0; /* running expense */
|
||||
LispValue tmpclause;
|
||||
LispValue operand; /* one operand of an operator */
|
||||
|
||||
if (IsA(node, Oper))
|
||||
{
|
||||
@ -517,15 +516,15 @@ xfunc_func_expense(LispValue node, LispValue args)
|
||||
*/
|
||||
if (proc->prolang == SQLlanguageId)
|
||||
{
|
||||
LispValue tmpplan;
|
||||
List planlist;
|
||||
LispValue tmpplan;
|
||||
List planlist;
|
||||
|
||||
if (IsA(node, Oper) || get_func_planlist((Func) node) == LispNil)
|
||||
{
|
||||
Oid *argOidVect; /* vector of argtypes */
|
||||
char *pq_src; /* text of PQ function */
|
||||
int nargs; /* num args to PQ function */
|
||||
QueryTreeList *queryTree_list; /* dummy variable */
|
||||
Oid *argOidVect; /* vector of argtypes */
|
||||
char *pq_src; /* text of PQ function */
|
||||
int nargs; /* num args to PQ function */
|
||||
QueryTreeList *queryTree_list; /* dummy variable */
|
||||
|
||||
/*
|
||||
* * plan the function, storing it in the Func node for later *
|
||||
@ -599,10 +598,10 @@ xfunc_func_expense(LispValue node, LispValue args)
|
||||
int
|
||||
xfunc_width(LispValue clause)
|
||||
{
|
||||
Relation rd; /* Relation Descriptor */
|
||||
HeapTuple tupl; /* structure to hold a cached tuple */
|
||||
TypeTupleForm type; /* structure to hold a type tuple */
|
||||
int retval = 0;
|
||||
Relation rd; /* Relation Descriptor */
|
||||
HeapTuple tupl; /* structure to hold a cached tuple */
|
||||
TypeTupleForm type; /* structure to hold a type tuple */
|
||||
int retval = 0;
|
||||
|
||||
if (IsA(clause, Const))
|
||||
{
|
||||
@ -695,7 +694,7 @@ xfunc_width(LispValue clause)
|
||||
}
|
||||
else if (fast_is_funcclause(clause))
|
||||
{
|
||||
Func func = (Func) get_function(clause);
|
||||
Func func = (Func) get_function(clause);
|
||||
|
||||
if (get_func_tlist(func) != LispNil)
|
||||
{
|
||||
@ -735,13 +734,13 @@ exit:
|
||||
** User may pass in referenced list, if they know it (useful
|
||||
** for joins).
|
||||
*/
|
||||
static Count
|
||||
static Count
|
||||
xfunc_card_unreferenced(Query * queryInfo,
|
||||
LispValue clause, Relid referenced)
|
||||
{
|
||||
Relid unreferenced,
|
||||
allrelids = LispNil;
|
||||
LispValue temp;
|
||||
Relid unreferenced,
|
||||
allrelids = LispNil;
|
||||
LispValue temp;
|
||||
|
||||
/* find all relids of base relations referenced in query */
|
||||
foreach(temp, queryInfo->base_relation_list_)
|
||||
@ -766,11 +765,11 @@ xfunc_card_unreferenced(Query * queryInfo,
|
||||
Count
|
||||
xfunc_card_product(Query * queryInfo, Relid relids)
|
||||
{
|
||||
LispValue cinfonode;
|
||||
LispValue temp;
|
||||
Rel currel;
|
||||
Cost tuples;
|
||||
Count retval = 0;
|
||||
LispValue cinfonode;
|
||||
LispValue temp;
|
||||
Rel currel;
|
||||
Cost tuples;
|
||||
Count retval = 0;
|
||||
|
||||
foreach(temp, relids)
|
||||
{
|
||||
@ -808,8 +807,8 @@ xfunc_card_product(Query * queryInfo, Relid relids)
|
||||
List
|
||||
xfunc_find_references(LispValue clause)
|
||||
{
|
||||
List retval = (List) LispNil;
|
||||
LispValue tmpclause;
|
||||
List retval = (List) LispNil;
|
||||
LispValue tmpclause;
|
||||
|
||||
/* Base cases */
|
||||
if (IsA(clause, Var))
|
||||
@ -870,12 +869,12 @@ xfunc_find_references(LispValue clause)
|
||||
LispValue
|
||||
xfunc_primary_join(JoinPath pathnode)
|
||||
{
|
||||
LispValue joinclauselist = get_pathclauseinfo(pathnode);
|
||||
CInfo mincinfo;
|
||||
LispValue tmplist;
|
||||
LispValue minclause = LispNil;
|
||||
Cost minrank,
|
||||
tmprank;
|
||||
LispValue joinclauselist = get_pathclauseinfo(pathnode);
|
||||
CInfo mincinfo;
|
||||
LispValue tmplist;
|
||||
LispValue minclause = LispNil;
|
||||
Cost minrank,
|
||||
tmprank;
|
||||
|
||||
if (IsA(pathnode, MergePath))
|
||||
{
|
||||
@ -932,9 +931,9 @@ xfunc_primary_join(JoinPath pathnode)
|
||||
Cost
|
||||
xfunc_get_path_cost(Query * queryInfo, Path pathnode)
|
||||
{
|
||||
Cost cost = 0;
|
||||
LispValue tmplist;
|
||||
Cost selec = 1.0;
|
||||
Cost cost = 0;
|
||||
LispValue tmplist;
|
||||
Cost selec = 1.0;
|
||||
|
||||
/*
|
||||
* * first add in the expensive local function costs. * We ensure that
|
||||
@ -1025,12 +1024,12 @@ xfunc_get_path_cost(Query * queryInfo, Path pathnode)
|
||||
Cost
|
||||
xfunc_total_path_cost(JoinPath pathnode)
|
||||
{
|
||||
Cost cost = xfunc_get_path_cost((Path) pathnode);
|
||||
Cost cost = xfunc_get_path_cost((Path) pathnode);
|
||||
|
||||
Assert(IsA(pathnode, JoinPath));
|
||||
if (IsA(pathnode, MergePath))
|
||||
{
|
||||
MergePath mrgnode = (MergePath) pathnode;
|
||||
MergePath mrgnode = (MergePath) pathnode;
|
||||
|
||||
cost += cost_mergesort(get_path_cost((Path) get_outerjoinpath(mrgnode)),
|
||||
get_path_cost((Path) get_innerjoinpath(mrgnode)),
|
||||
@ -1049,7 +1048,7 @@ xfunc_total_path_cost(JoinPath pathnode)
|
||||
}
|
||||
else if (IsA(pathnode, HashPath))
|
||||
{
|
||||
HashPath hashnode = (HashPath) pathnode;
|
||||
HashPath hashnode = (HashPath) pathnode;
|
||||
|
||||
cost += cost_hashjoin(get_path_cost((Path) get_outerjoinpath(hashnode)),
|
||||
get_path_cost((Path) get_innerjoinpath(hashnode)),
|
||||
@ -1105,10 +1104,10 @@ xfunc_total_path_cost(JoinPath pathnode)
|
||||
Cost
|
||||
xfunc_expense_per_tuple(JoinPath joinnode, int whichchild)
|
||||
{
|
||||
Rel outerrel = get_parent((Path) get_outerjoinpath(joinnode));
|
||||
Rel innerrel = get_parent((Path) get_innerjoinpath(joinnode));
|
||||
Count outerwidth = get_width(outerrel);
|
||||
Count outers_per_page = ceil(BLCKSZ / (outerwidth + sizeof(HeapTupleData)));
|
||||
Rel outerrel = get_parent((Path) get_outerjoinpath(joinnode));
|
||||
Rel innerrel = get_parent((Path) get_innerjoinpath(joinnode));
|
||||
Count outerwidth = get_width(outerrel);
|
||||
Count outers_per_page = ceil(BLCKSZ / (outerwidth + sizeof(HeapTupleData)));
|
||||
|
||||
if (IsA(joinnode, HashPath))
|
||||
{
|
||||
@ -1150,8 +1149,8 @@ xfunc_fixvars(LispValue clause, /* clause being pulled up */
|
||||
Rel rel, /* rel it's being pulled from */
|
||||
int varno) /* whether rel is INNER or OUTER of join */
|
||||
{
|
||||
LispValue tmpclause; /* temporary variable */
|
||||
TargetEntry *tle; /* tlist member corresponding to var */
|
||||
LispValue tmpclause; /* temporary variable */
|
||||
TargetEntry *tle; /* tlist member corresponding to var */
|
||||
|
||||
|
||||
if (IsA(clause, Const) || IsA(clause, Param))
|
||||
@ -1205,11 +1204,11 @@ xfunc_fixvars(LispValue clause, /* clause being pulled up */
|
||||
int
|
||||
xfunc_cinfo_compare(void *arg1, void *arg2)
|
||||
{
|
||||
CInfo info1 = *(CInfo *) arg1;
|
||||
CInfo info2 = *(CInfo *) arg2;
|
||||
CInfo info1 = *(CInfo *) arg1;
|
||||
CInfo info2 = *(CInfo *) arg2;
|
||||
|
||||
LispValue clause1 = (LispValue) get_clause(info1),
|
||||
clause2 = (LispValue) get_clause(info2);
|
||||
LispValue clause1 = (LispValue) get_clause(info1),
|
||||
clause2 = (LispValue) get_clause(info2);
|
||||
|
||||
return (xfunc_clause_compare((void *) &clause1, (void *) &clause2));
|
||||
}
|
||||
@ -1222,10 +1221,10 @@ xfunc_cinfo_compare(void *arg1, void *arg2)
|
||||
int
|
||||
xfunc_clause_compare(void *arg1, void *arg2)
|
||||
{
|
||||
LispValue clause1 = *(LispValue *) arg1;
|
||||
LispValue clause2 = *(LispValue *) arg2;
|
||||
Cost rank1, /* total xfunc rank of clause1 */
|
||||
rank2; /* total xfunc rank of clause2 */
|
||||
LispValue clause1 = *(LispValue *) arg1;
|
||||
LispValue clause2 = *(LispValue *) arg2;
|
||||
Cost rank1, /* total xfunc rank of clause1 */
|
||||
rank2; /* total xfunc rank of clause2 */
|
||||
|
||||
rank1 = xfunc_rank(clause1);
|
||||
rank2 = xfunc_rank(clause2);
|
||||
@ -1247,7 +1246,7 @@ xfunc_clause_compare(void *arg1, void *arg2)
|
||||
void
|
||||
xfunc_disjunct_sort(LispValue clause_list)
|
||||
{
|
||||
LispValue temp;
|
||||
LispValue temp;
|
||||
|
||||
foreach(temp, clause_list)
|
||||
if (or_clause(lfirst(temp)))
|
||||
@ -1264,14 +1263,14 @@ xfunc_disjunct_sort(LispValue clause_list)
|
||||
int
|
||||
xfunc_disjunct_compare(Query * queryInfo, void *arg1, void *arg2)
|
||||
{
|
||||
LispValue disjunct1 = *(LispValue *) arg1;
|
||||
LispValue disjunct2 = *(LispValue *) arg2;
|
||||
Cost cost1, /* total cost of disjunct1 */
|
||||
cost2, /* total cost of disjunct2 */
|
||||
selec1,
|
||||
selec2;
|
||||
Cost rank1,
|
||||
rank2;
|
||||
LispValue disjunct1 = *(LispValue *) arg1;
|
||||
LispValue disjunct2 = *(LispValue *) arg2;
|
||||
Cost cost1, /* total cost of disjunct1 */
|
||||
cost2, /* total cost of disjunct2 */
|
||||
selec1,
|
||||
selec2;
|
||||
Cost rank1,
|
||||
rank2;
|
||||
|
||||
cost1 = xfunc_expense(queryInfo, disjunct1);
|
||||
cost2 = xfunc_expense(queryInfo, disjunct2);
|
||||
@ -1310,12 +1309,12 @@ xfunc_disjunct_compare(Query * queryInfo, void *arg1, void *arg2)
|
||||
int
|
||||
xfunc_func_width(RegProcedure funcid, LispValue args)
|
||||
{
|
||||
Relation rd; /* Relation Descriptor */
|
||||
HeapTuple tupl; /* structure to hold a cached tuple */
|
||||
Form_pg_proc proc; /* structure to hold the pg_proc tuple */
|
||||
TypeTupleForm type; /* structure to hold the pg_type tuple */
|
||||
LispValue tmpclause;
|
||||
int retval;
|
||||
Relation rd; /* Relation Descriptor */
|
||||
HeapTuple tupl; /* structure to hold a cached tuple */
|
||||
Form_pg_proc proc; /* structure to hold the pg_proc tuple */
|
||||
TypeTupleForm type; /* structure to hold the pg_type tuple */
|
||||
LispValue tmpclause;
|
||||
int retval;
|
||||
|
||||
/* lookup function and find its return type */
|
||||
Assert(RegProcedureIsValid(funcid));
|
||||
@ -1370,9 +1369,9 @@ exit:
|
||||
int
|
||||
xfunc_tuple_width(Relation rd)
|
||||
{
|
||||
int i;
|
||||
int retval = 0;
|
||||
TupleDesc tdesc = RelationGetTupleDescriptor(rd);
|
||||
int i;
|
||||
int retval = 0;
|
||||
TupleDesc tdesc = RelationGetTupleDescriptor(rd);
|
||||
|
||||
for (i = 0; i < tdesc->natts; i++)
|
||||
{
|
||||
@ -1392,7 +1391,7 @@ xfunc_tuple_width(Relation rd)
|
||||
int
|
||||
xfunc_num_join_clauses(JoinPath path)
|
||||
{
|
||||
int num = length(get_pathclauseinfo(path));
|
||||
int num = length(get_pathclauseinfo(path));
|
||||
|
||||
if (IsA(path, MergePath))
|
||||
return (num + length(get_path_mergeclauses((MergePath) path)));
|
||||
@ -1409,9 +1408,9 @@ xfunc_num_join_clauses(JoinPath path)
|
||||
LispValue
|
||||
xfunc_LispRemove(LispValue foo, List bar)
|
||||
{
|
||||
LispValue temp = LispNil;
|
||||
LispValue result = LispNil;
|
||||
int sanity = false;
|
||||
LispValue temp = LispNil;
|
||||
LispValue result = LispNil;
|
||||
int sanity = false;
|
||||
|
||||
for (temp = bar; !null(temp); temp = lnext(temp))
|
||||
if (!equal((Node) (foo), (Node) (lfirst(temp))))
|
||||
@ -1439,7 +1438,7 @@ xfunc_LispRemove(LispValue foo, List bar)
|
||||
bool
|
||||
xfunc_copyrel(Rel from, Rel * to)
|
||||
{
|
||||
Rel newnode;
|
||||
Rel newnode;
|
||||
|
||||
Pointer(*alloc) () = palloc;
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.12 1997/09/07 04:43:57 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.13 1997/09/08 02:24:31 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -44,9 +44,9 @@
|
||||
#define TEMP_SORT 1
|
||||
#define TEMP_MATERIAL 2
|
||||
|
||||
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 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,
|
||||
List * scan_clauses);
|
||||
@ -65,8 +65,8 @@ 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 *
|
||||
static Node *fix_indxqual_references(Node * clause, Path * index_path);
|
||||
static Temp *
|
||||
make_temp(List * tlist, List * keys, Oid * operators,
|
||||
Plan * plan_node, int temptype);
|
||||
static IndexScan *
|
||||
@ -78,7 +78,7 @@ make_nestloop(List * qptlist, List * qpqual, Plan * lefttree,
|
||||
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 Hash *make_hash(List * tlist, Var * hashkey, Plan * lefttree);
|
||||
static MergeJoin *
|
||||
make_mergesort(List * tlist, List * qpqual,
|
||||
List * mergeclauses, Oid opcode, Oid * rightorder,
|
||||
@ -102,16 +102,16 @@ make_material(List * tlist, Oid tempid, Plan * lefttree,
|
||||
*
|
||||
* Returns the optimal(?) access plan.
|
||||
*/
|
||||
Plan *
|
||||
Plan *
|
||||
create_plan(Path * best_path)
|
||||
{
|
||||
List *tlist;
|
||||
Plan *plan_node = (Plan *) NULL;
|
||||
Rel *parent_rel;
|
||||
int size;
|
||||
int width;
|
||||
int pages;
|
||||
int tuples;
|
||||
List *tlist;
|
||||
Plan *plan_node = (Plan *) NULL;
|
||||
Rel *parent_rel;
|
||||
int size;
|
||||
int width;
|
||||
int pages;
|
||||
int tuples;
|
||||
|
||||
parent_rel = best_path->parent;
|
||||
tlist = get_actual_tlist(parent_rel->targetlist);
|
||||
@ -122,18 +122,18 @@ create_plan(Path * best_path)
|
||||
|
||||
switch (best_path->pathtype)
|
||||
{
|
||||
case T_IndexScan:
|
||||
case T_SeqScan:
|
||||
plan_node = (Plan *) create_scan_node(best_path, tlist);
|
||||
break;
|
||||
case T_HashJoin:
|
||||
case T_MergeJoin:
|
||||
case T_NestLoop:
|
||||
plan_node = (Plan *) create_join_node((JoinPath *) best_path, tlist);
|
||||
break;
|
||||
default:
|
||||
/* do nothing */
|
||||
break;
|
||||
case T_IndexScan:
|
||||
case T_SeqScan:
|
||||
plan_node = (Plan *) create_scan_node(best_path, tlist);
|
||||
break;
|
||||
case T_HashJoin:
|
||||
case T_MergeJoin:
|
||||
case T_NestLoop:
|
||||
plan_node = (Plan *) create_join_node((JoinPath *) best_path, tlist);
|
||||
break;
|
||||
default:
|
||||
/* do nothing */
|
||||
break;
|
||||
}
|
||||
|
||||
plan_node->plan_size = size;
|
||||
@ -166,12 +166,12 @@ create_plan(Path * best_path)
|
||||
*
|
||||
* Returns the scan node.
|
||||
*/
|
||||
static Scan *
|
||||
static Scan *
|
||||
create_scan_node(Path * best_path, List * tlist)
|
||||
{
|
||||
|
||||
Scan *node = NULL;
|
||||
List *scan_clauses;
|
||||
Scan *node = NULL;
|
||||
List *scan_clauses;
|
||||
|
||||
/*
|
||||
* Extract the relevant clauses from the parent relation and replace
|
||||
@ -186,20 +186,20 @@ create_scan_node(Path * best_path, List * tlist)
|
||||
|
||||
switch (best_path->pathtype)
|
||||
{
|
||||
case T_SeqScan:
|
||||
node = (Scan *) create_seqscan_node(best_path, tlist, scan_clauses);
|
||||
break;
|
||||
case T_SeqScan:
|
||||
node = (Scan *) create_seqscan_node(best_path, tlist, scan_clauses);
|
||||
break;
|
||||
|
||||
case T_IndexScan:
|
||||
node = (Scan *) create_indexscan_node((IndexPath *) best_path,
|
||||
tlist,
|
||||
scan_clauses);
|
||||
break;
|
||||
case T_IndexScan:
|
||||
node = (Scan *) create_indexscan_node((IndexPath *) best_path,
|
||||
tlist,
|
||||
scan_clauses);
|
||||
break;
|
||||
|
||||
default:
|
||||
elog(WARN, "create_scan_node: unknown node type",
|
||||
best_path->pathtype);
|
||||
break;
|
||||
default:
|
||||
elog(WARN, "create_scan_node: unknown node type",
|
||||
best_path->pathtype);
|
||||
break;
|
||||
}
|
||||
|
||||
return node;
|
||||
@ -215,15 +215,15 @@ create_scan_node(Path * best_path, List * tlist)
|
||||
*
|
||||
* Returns the join node.
|
||||
*/
|
||||
static Join *
|
||||
static Join *
|
||||
create_join_node(JoinPath * best_path, List * tlist)
|
||||
{
|
||||
Plan *outer_node;
|
||||
List *outer_tlist;
|
||||
Plan *inner_node;
|
||||
List *inner_tlist;
|
||||
List *clauses;
|
||||
Join *retval = NULL;
|
||||
Plan *outer_node;
|
||||
List *outer_tlist;
|
||||
Plan *inner_node;
|
||||
List *inner_tlist;
|
||||
List *clauses;
|
||||
Join *retval = NULL;
|
||||
|
||||
outer_node = create_plan((Path *) best_path->outerjoinpath);
|
||||
outer_tlist = outer_node->targetlist;
|
||||
@ -235,45 +235,45 @@ create_join_node(JoinPath * best_path, List * tlist)
|
||||
|
||||
switch (best_path->path.pathtype)
|
||||
{
|
||||
case T_MergeJoin:
|
||||
retval = (Join *) create_mergejoin_node((MergePath *) best_path,
|
||||
tlist,
|
||||
clauses,
|
||||
outer_node,
|
||||
outer_tlist,
|
||||
inner_node,
|
||||
inner_tlist);
|
||||
break;
|
||||
case T_HashJoin:
|
||||
retval = (Join *) create_hashjoin_node((HashPath *) best_path,
|
||||
tlist,
|
||||
clauses,
|
||||
outer_node,
|
||||
outer_tlist,
|
||||
inner_node,
|
||||
inner_tlist);
|
||||
break;
|
||||
case T_NestLoop:
|
||||
retval = (Join *) create_nestloop_node((JoinPath *) best_path,
|
||||
tlist,
|
||||
clauses,
|
||||
outer_node,
|
||||
outer_tlist,
|
||||
inner_node,
|
||||
inner_tlist);
|
||||
break;
|
||||
default:
|
||||
/* do nothing */
|
||||
elog(WARN, "create_join_node: unknown node type",
|
||||
best_path->path.pathtype);
|
||||
case T_MergeJoin:
|
||||
retval = (Join *) create_mergejoin_node((MergePath *) best_path,
|
||||
tlist,
|
||||
clauses,
|
||||
outer_node,
|
||||
outer_tlist,
|
||||
inner_node,
|
||||
inner_tlist);
|
||||
break;
|
||||
case T_HashJoin:
|
||||
retval = (Join *) create_hashjoin_node((HashPath *) best_path,
|
||||
tlist,
|
||||
clauses,
|
||||
outer_node,
|
||||
outer_tlist,
|
||||
inner_node,
|
||||
inner_tlist);
|
||||
break;
|
||||
case T_NestLoop:
|
||||
retval = (Join *) create_nestloop_node((JoinPath *) best_path,
|
||||
tlist,
|
||||
clauses,
|
||||
outer_node,
|
||||
outer_tlist,
|
||||
inner_node,
|
||||
inner_tlist);
|
||||
break;
|
||||
default:
|
||||
/* do nothing */
|
||||
elog(WARN, "create_join_node: unknown node type",
|
||||
best_path->path.pathtype);
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
/*
|
||||
* * Expensive function pullups may have pulled local predicates *
|
||||
* into this path node. Put them in the qpqual of the plan node. *
|
||||
* -- JMH, 6/15/92
|
||||
* into this path node. Put them in the qpqual of the plan node. * --
|
||||
* JMH, 6/15/92
|
||||
*/
|
||||
if (get_locclauseinfo(best_path) != NIL)
|
||||
set_qpqual((Plan) retval,
|
||||
@ -300,9 +300,9 @@ create_join_node(JoinPath * best_path, List * tlist)
|
||||
static SeqScan *
|
||||
create_seqscan_node(Path * best_path, List * tlist, List * scan_clauses)
|
||||
{
|
||||
SeqScan *scan_node = (SeqScan *) NULL;
|
||||
Index scan_relid = -1;
|
||||
List *temp;
|
||||
SeqScan *scan_node = (SeqScan *) NULL;
|
||||
Index scan_relid = -1;
|
||||
List *temp;
|
||||
|
||||
temp = best_path->parent->relids;
|
||||
if (temp == NULL)
|
||||
@ -335,15 +335,15 @@ create_indexscan_node(IndexPath * best_path,
|
||||
* Extract the(first if conjunct, only if disjunct) clause from the
|
||||
* clauseinfo list.
|
||||
*/
|
||||
Expr *index_clause = (Expr *) NULL;
|
||||
List *indxqual = NIL;
|
||||
List *qpqual = NIL;
|
||||
List *fixed_indxqual = NIL;
|
||||
List *ixid;
|
||||
IndexScan *scan_node = (IndexScan *) NULL;
|
||||
bool lossy = FALSE;
|
||||
HeapTuple indexTuple;
|
||||
IndexTupleForm index;
|
||||
Expr *index_clause = (Expr *) NULL;
|
||||
List *indxqual = NIL;
|
||||
List *qpqual = NIL;
|
||||
List *fixed_indxqual = NIL;
|
||||
List *ixid;
|
||||
IndexScan *scan_node = (IndexScan *) NULL;
|
||||
bool lossy = FALSE;
|
||||
HeapTuple indexTuple;
|
||||
IndexTupleForm index;
|
||||
|
||||
/*
|
||||
* If an 'or' clause is to be used with this index, the indxqual field
|
||||
@ -358,7 +358,7 @@ create_indexscan_node(IndexPath * best_path,
|
||||
|
||||
if (or_clause((Node *) index_clause))
|
||||
{
|
||||
List *temp = NIL;
|
||||
List *temp = NIL;
|
||||
|
||||
foreach(temp, index_clause->args)
|
||||
indxqual = lappend(indxqual, lcons(lfirst(temp), NIL));
|
||||
@ -438,7 +438,7 @@ create_nestloop_node(JoinPath * best_path,
|
||||
Plan * inner_node,
|
||||
List * inner_tlist)
|
||||
{
|
||||
NestLoop *join_node = (NestLoop *) NULL;
|
||||
NestLoop *join_node = (NestLoop *) NULL;
|
||||
|
||||
if (IsA(inner_node, IndexScan))
|
||||
{
|
||||
@ -453,9 +453,9 @@ create_nestloop_node(JoinPath * best_path,
|
||||
* case of multi-column indices. - vadim 03/18/97
|
||||
*/
|
||||
|
||||
List *inner_indxqual = lfirst(((IndexScan *) inner_node)->indxqual);
|
||||
List *inner_qual;
|
||||
bool found = false;
|
||||
List *inner_indxqual = lfirst(((IndexScan *) inner_node)->indxqual);
|
||||
List *inner_qual;
|
||||
bool found = false;
|
||||
|
||||
foreach(inner_qual, inner_indxqual)
|
||||
{
|
||||
@ -479,7 +479,7 @@ create_nestloop_node(JoinPath * best_path,
|
||||
*/
|
||||
if (found)
|
||||
{
|
||||
List *new_inner_qual = NIL;
|
||||
List *new_inner_qual = NIL;
|
||||
|
||||
clauses = set_difference(clauses, inner_indxqual); /* XXX */
|
||||
new_inner_qual =
|
||||
@ -520,12 +520,12 @@ create_mergejoin_node(MergePath * best_path,
|
||||
Plan * inner_node,
|
||||
List * inner_tlist)
|
||||
{
|
||||
List *qpqual,
|
||||
*mergeclauses;
|
||||
RegProcedure opcode;
|
||||
Oid *outer_order,
|
||||
*inner_order;
|
||||
MergeJoin *join_node;
|
||||
List *qpqual,
|
||||
*mergeclauses;
|
||||
RegProcedure opcode;
|
||||
Oid *outer_order,
|
||||
*inner_order;
|
||||
MergeJoin *join_node;
|
||||
|
||||
|
||||
/*
|
||||
@ -564,11 +564,11 @@ create_mergejoin_node(MergePath * best_path,
|
||||
*/
|
||||
if (best_path->outersortkeys)
|
||||
{
|
||||
Temp *sorted_outer_node = make_temp(outer_tlist,
|
||||
Temp *sorted_outer_node = make_temp(outer_tlist,
|
||||
best_path->outersortkeys,
|
||||
outer_order,
|
||||
outer_node,
|
||||
TEMP_SORT);
|
||||
outer_order,
|
||||
outer_node,
|
||||
TEMP_SORT);
|
||||
|
||||
sorted_outer_node->plan.cost = outer_node->cost;
|
||||
outer_node = (Plan *) sorted_outer_node;
|
||||
@ -576,11 +576,11 @@ create_mergejoin_node(MergePath * best_path,
|
||||
|
||||
if (best_path->innersortkeys)
|
||||
{
|
||||
Temp *sorted_inner_node = make_temp(inner_tlist,
|
||||
Temp *sorted_inner_node = make_temp(inner_tlist,
|
||||
best_path->innersortkeys,
|
||||
inner_order,
|
||||
inner_node,
|
||||
TEMP_SORT);
|
||||
inner_order,
|
||||
inner_node,
|
||||
TEMP_SORT);
|
||||
|
||||
sorted_inner_node->plan.cost = outer_node->cost;
|
||||
inner_node = (Plan *) sorted_inner_node;
|
||||
@ -617,11 +617,11 @@ create_hashjoin_node(HashPath * best_path,
|
||||
Plan * inner_node,
|
||||
List * inner_tlist)
|
||||
{
|
||||
List *qpqual;
|
||||
List *hashclauses;
|
||||
HashJoin *join_node;
|
||||
Hash *hash_node;
|
||||
Var *innerhashkey;
|
||||
List *qpqual;
|
||||
List *hashclauses;
|
||||
HashJoin *join_node;
|
||||
Hash *hash_node;
|
||||
Var *innerhashkey;
|
||||
|
||||
/*
|
||||
* Separate the hashclauses from the other join qualification clauses
|
||||
@ -662,18 +662,18 @@ create_hashjoin_node(HashPath * best_path,
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
static Node *
|
||||
static Node *
|
||||
fix_indxqual_references(Node * clause, Path * index_path)
|
||||
{
|
||||
Node *newclause;
|
||||
Node *newclause;
|
||||
|
||||
if (IsA(clause, Var))
|
||||
{
|
||||
if (lfirsti(index_path->parent->relids) == ((Var *) clause)->varno)
|
||||
{
|
||||
int pos = 0;
|
||||
int varatt = ((Var *) clause)->varattno;
|
||||
int *indexkeys = ((IndexPath *) index_path)->indexkeys;
|
||||
int pos = 0;
|
||||
int varatt = ((Var *) clause)->varattno;
|
||||
int *indexkeys = ((IndexPath *) index_path)->indexkeys;
|
||||
|
||||
if (indexkeys)
|
||||
{
|
||||
@ -710,7 +710,7 @@ fix_indxqual_references(Node * clause, Path * index_path)
|
||||
is_funcclause((Node *) get_leftop((Expr *) clause)) &&
|
||||
((Func *) ((Expr *) get_leftop((Expr *) clause))->oper)->funcisindex)
|
||||
{
|
||||
Var *newvar =
|
||||
Var *newvar =
|
||||
makeVar((Index) lfirsti(index_path->parent->relids),
|
||||
1, /* func indices have one key */
|
||||
((Func *) ((Expr *) clause)->oper)->functype,
|
||||
@ -725,10 +725,10 @@ fix_indxqual_references(Node * clause, Path * index_path)
|
||||
}
|
||||
else if (IsA(clause, Expr))
|
||||
{
|
||||
Expr *expr = (Expr *) clause;
|
||||
List *new_subclauses = NIL;
|
||||
Node *subclause = NULL;
|
||||
List *i = NIL;
|
||||
Expr *expr = (Expr *) clause;
|
||||
List *new_subclauses = NIL;
|
||||
Node *subclause = NULL;
|
||||
List *i = NIL;
|
||||
|
||||
foreach(i, expr->args)
|
||||
{
|
||||
@ -757,10 +757,10 @@ fix_indxqual_references(Node * clause, Path * index_path)
|
||||
}
|
||||
else
|
||||
{
|
||||
List *oldclauses = (List *) clause;
|
||||
List *new_subclauses = NIL;
|
||||
Node *subclause = NULL;
|
||||
List *i = NIL;
|
||||
List *oldclauses = (List *) clause;
|
||||
List *new_subclauses = NIL;
|
||||
Node *subclause = NULL;
|
||||
List *i = NIL;
|
||||
|
||||
foreach(i, oldclauses)
|
||||
{
|
||||
@ -799,14 +799,14 @@ fix_indxqual_references(Node * clause, Path * index_path)
|
||||
*
|
||||
* XXX Shouldn't the operator be commuted?!
|
||||
*/
|
||||
static List *
|
||||
static List *
|
||||
switch_outer(List * clauses)
|
||||
{
|
||||
List *t_list = NIL;
|
||||
Expr *temp = NULL;
|
||||
List *i = NIL;
|
||||
Expr *clause;
|
||||
Node *op;
|
||||
List *t_list = NIL;
|
||||
Expr *temp = NULL;
|
||||
List *i = NIL;
|
||||
Expr *clause;
|
||||
Node *op;
|
||||
|
||||
foreach(i, clauses)
|
||||
{
|
||||
@ -843,13 +843,13 @@ switch_outer(List * clauses)
|
||||
*
|
||||
* Returns the modified target list.
|
||||
*/
|
||||
static List *
|
||||
static List *
|
||||
set_temp_tlist_operators(List * tlist, List * pathkeys, Oid * operators)
|
||||
{
|
||||
Node *keys = NULL;
|
||||
int keyno = 1;
|
||||
Resdom *resdom = (Resdom *) NULL;
|
||||
List *i = NIL;
|
||||
Node *keys = NULL;
|
||||
int keyno = 1;
|
||||
Resdom *resdom = (Resdom *) NULL;
|
||||
List *i = NIL;
|
||||
|
||||
foreach(i, pathkeys)
|
||||
{
|
||||
@ -891,15 +891,15 @@ set_temp_tlist_operators(List * tlist, List * pathkeys, Oid * operators)
|
||||
* 'plan-node' is the node which yields tuples for the sort
|
||||
* 'temptype' indicates which operation(sort or hash) to perform
|
||||
*/
|
||||
static Temp *
|
||||
static Temp *
|
||||
make_temp(List * tlist,
|
||||
List * keys,
|
||||
Oid * operators,
|
||||
Plan * plan_node,
|
||||
int temptype)
|
||||
{
|
||||
List *temp_tlist;
|
||||
Temp *retval = NULL;
|
||||
List *temp_tlist;
|
||||
Temp *retval = NULL;
|
||||
|
||||
/* Create a new target list for the temporary, with keys set. */
|
||||
temp_tlist = set_temp_tlist_operators(new_unsorted_tlist(tlist),
|
||||
@ -907,42 +907,42 @@ make_temp(List * tlist,
|
||||
operators);
|
||||
switch (temptype)
|
||||
{
|
||||
case TEMP_SORT:
|
||||
retval = (Temp *) make_seqscan(tlist,
|
||||
NIL,
|
||||
_TEMP_RELATION_ID_,
|
||||
(Plan *) make_sort(temp_tlist,
|
||||
case TEMP_SORT:
|
||||
retval = (Temp *) make_seqscan(tlist,
|
||||
NIL,
|
||||
_TEMP_RELATION_ID_,
|
||||
(Plan *) make_sort(temp_tlist,
|
||||
_TEMP_RELATION_ID_,
|
||||
plan_node,
|
||||
plan_node,
|
||||
length(keys)));
|
||||
break;
|
||||
break;
|
||||
|
||||
case TEMP_MATERIAL:
|
||||
retval = (Temp *) make_seqscan(tlist,
|
||||
NIL,
|
||||
_TEMP_RELATION_ID_,
|
||||
case TEMP_MATERIAL:
|
||||
retval = (Temp *) make_seqscan(tlist,
|
||||
NIL,
|
||||
_TEMP_RELATION_ID_,
|
||||
(Plan *) make_material(temp_tlist,
|
||||
_TEMP_RELATION_ID_,
|
||||
plan_node,
|
||||
length(keys)));
|
||||
break;
|
||||
break;
|
||||
|
||||
default:
|
||||
elog(WARN, "make_temp: unknown temp type %d", temptype);
|
||||
default:
|
||||
elog(WARN, "make_temp: unknown temp type %d", temptype);
|
||||
|
||||
}
|
||||
return (retval);
|
||||
}
|
||||
|
||||
|
||||
SeqScan *
|
||||
SeqScan *
|
||||
make_seqscan(List * qptlist,
|
||||
List * qpqual,
|
||||
Index scanrelid,
|
||||
Plan * lefttree)
|
||||
{
|
||||
SeqScan *node = makeNode(SeqScan);
|
||||
Plan *plan = &node->plan;
|
||||
SeqScan *node = makeNode(SeqScan);
|
||||
Plan *plan = &node->plan;
|
||||
|
||||
plan->cost = 0.0;
|
||||
plan->state = (EState *) NULL;
|
||||
@ -963,8 +963,8 @@ make_indexscan(List * qptlist,
|
||||
List * indxid,
|
||||
List * indxqual)
|
||||
{
|
||||
IndexScan *node = makeNode(IndexScan);
|
||||
Plan *plan = &node->scan.plan;
|
||||
IndexScan *node = makeNode(IndexScan);
|
||||
Plan *plan = &node->scan.plan;
|
||||
|
||||
plan->cost = 0.0;
|
||||
plan->state = (EState *) NULL;
|
||||
@ -987,8 +987,8 @@ make_nestloop(List * qptlist,
|
||||
Plan * lefttree,
|
||||
Plan * righttree)
|
||||
{
|
||||
NestLoop *node = makeNode(NestLoop);
|
||||
Plan *plan = &node->join;
|
||||
NestLoop *node = makeNode(NestLoop);
|
||||
Plan *plan = &node->join;
|
||||
|
||||
plan->cost = 0.0;
|
||||
plan->state = (EState *) NULL;
|
||||
@ -1008,8 +1008,8 @@ make_hashjoin(List * tlist,
|
||||
Plan * lefttree,
|
||||
Plan * righttree)
|
||||
{
|
||||
HashJoin *node = makeNode(HashJoin);
|
||||
Plan *plan = &node->join;
|
||||
HashJoin *node = makeNode(HashJoin);
|
||||
Plan *plan = &node->join;
|
||||
|
||||
plan->cost = 0.0;
|
||||
plan->state = (EState *) NULL;
|
||||
@ -1026,11 +1026,11 @@ make_hashjoin(List * tlist,
|
||||
return (node);
|
||||
}
|
||||
|
||||
static Hash *
|
||||
static Hash *
|
||||
make_hash(List * tlist, Var * hashkey, Plan * lefttree)
|
||||
{
|
||||
Hash *node = makeNode(Hash);
|
||||
Plan *plan = &node->plan;
|
||||
Hash *node = makeNode(Hash);
|
||||
Plan *plan = &node->plan;
|
||||
|
||||
plan->cost = 0.0;
|
||||
plan->state = (EState *) NULL;
|
||||
@ -1056,8 +1056,8 @@ make_mergesort(List * tlist,
|
||||
Plan * righttree,
|
||||
Plan * lefttree)
|
||||
{
|
||||
MergeJoin *node = makeNode(MergeJoin);
|
||||
Plan *plan = &node->join;
|
||||
MergeJoin *node = makeNode(MergeJoin);
|
||||
Plan *plan = &node->join;
|
||||
|
||||
plan->cost = 0.0;
|
||||
plan->state = (EState *) NULL;
|
||||
@ -1073,11 +1073,11 @@ 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;
|
||||
Sort *node = makeNode(Sort);
|
||||
Plan *plan = &node->plan;
|
||||
|
||||
plan->cost = 0.0;
|
||||
plan->state = (EState *) NULL;
|
||||
@ -1097,8 +1097,8 @@ make_material(List * tlist,
|
||||
Plan * lefttree,
|
||||
int keycount)
|
||||
{
|
||||
Material *node = makeNode(Material);
|
||||
Plan *plan = &node->plan;
|
||||
Material *node = makeNode(Material);
|
||||
Plan *plan = &node->plan;
|
||||
|
||||
plan->cost = 0.0;
|
||||
plan->state = (EState *) NULL;
|
||||
@ -1112,10 +1112,10 @@ make_material(List * tlist,
|
||||
return (node);
|
||||
}
|
||||
|
||||
Agg *
|
||||
Agg *
|
||||
make_agg(List * tlist, int nagg, Aggreg ** aggs)
|
||||
{
|
||||
Agg *node = makeNode(Agg);
|
||||
Agg *node = makeNode(Agg);
|
||||
|
||||
node->plan.cost = 0.0;
|
||||
node->plan.state = (EState *) NULL;
|
||||
@ -1129,14 +1129,14 @@ make_agg(List * tlist, int nagg, Aggreg ** aggs)
|
||||
return (node);
|
||||
}
|
||||
|
||||
Group *
|
||||
Group *
|
||||
make_group(List * tlist,
|
||||
bool tuplePerGroup,
|
||||
int ngrp,
|
||||
AttrNumber * grpColIdx,
|
||||
Sort * lefttree)
|
||||
{
|
||||
Group *node = makeNode(Group);
|
||||
Group *node = makeNode(Group);
|
||||
|
||||
node->plan.cost = 0.0;
|
||||
node->plan.state = (EState *) NULL;
|
||||
@ -1159,11 +1159,11 @@ make_group(List * tlist,
|
||||
* or "*"
|
||||
*/
|
||||
|
||||
Unique *
|
||||
Unique *
|
||||
make_unique(List * tlist, Plan * lefttree, char *uniqueAttr)
|
||||
{
|
||||
Unique *node = makeNode(Unique);
|
||||
Plan *plan = &node->plan;
|
||||
Unique *node = makeNode(Unique);
|
||||
Plan *plan = &node->plan;
|
||||
|
||||
plan->cost = 0.0;
|
||||
plan->state = (EState *) NULL;
|
||||
@ -1182,14 +1182,14 @@ make_unique(List * tlist, Plan * lefttree, char *uniqueAttr)
|
||||
return (node);
|
||||
}
|
||||
|
||||
List *
|
||||
List *
|
||||
generate_fjoin(List * tlist)
|
||||
{
|
||||
#if 0
|
||||
List tlistP;
|
||||
List newTlist = NIL;
|
||||
List fjoinList = NIL;
|
||||
int nIters = 0;
|
||||
List tlistP;
|
||||
List newTlist = NIL;
|
||||
List fjoinList = NIL;
|
||||
int nIters = 0;
|
||||
|
||||
/*
|
||||
* Break the target list into elements with Iter nodes, and those
|
||||
@ -1197,7 +1197,7 @@ generate_fjoin(List * tlist)
|
||||
*/
|
||||
foreach(tlistP, tlist)
|
||||
{
|
||||
List tlistElem;
|
||||
List tlistElem;
|
||||
|
||||
tlistElem = lfirst(tlistP);
|
||||
if (IsA(lsecond(tlistElem), Iter))
|
||||
@ -1216,11 +1216,11 @@ generate_fjoin(List * tlist)
|
||||
*/
|
||||
if (nIters > 0)
|
||||
{
|
||||
List *inner;
|
||||
List *tempList;
|
||||
Fjoin *fjoinNode;
|
||||
DatumPtr results = (DatumPtr) palloc(nIters * sizeof(Datum));
|
||||
BoolPtr alwaysDone = (BoolPtr) palloc(nIters * sizeof(bool));
|
||||
List *inner;
|
||||
List *tempList;
|
||||
Fjoin *fjoinNode;
|
||||
DatumPtr results = (DatumPtr) palloc(nIters * sizeof(Datum));
|
||||
BoolPtr alwaysDone = (BoolPtr) palloc(nIters * sizeof(bool));
|
||||
|
||||
inner = lfirst(fjoinList);
|
||||
fjoinList = lnext(fjoinList);
|
||||
|
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/initsplan.c,v 1.6 1997/09/07 04:44:00 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/initsplan.c,v 1.7 1997/09/08 02:24:36 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -33,16 +33,16 @@
|
||||
#include "optimizer/clauses.h"
|
||||
#include "optimizer/cost.h"
|
||||
|
||||
extern int Quiet;
|
||||
extern int Quiet;
|
||||
|
||||
static void add_clause_to_rels(Query * root, List * clause);
|
||||
static void add_clause_to_rels(Query * root, List * clause);
|
||||
static void
|
||||
add_join_clause_info_to_rels(Query * root, CInfo * clauseinfo,
|
||||
List * join_relids);
|
||||
static void add_vars_to_rels(Query * root, List * vars, List * join_relids);
|
||||
static void add_vars_to_rels(Query * root, List * vars, List * join_relids);
|
||||
|
||||
static MergeOrder *mergesortop(Expr * clause);
|
||||
static Oid hashjoinop(Expr * clause);
|
||||
static Oid hashjoinop(Expr * clause);
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
@ -63,13 +63,13 @@ static Oid hashjoinop(Expr * clause);
|
||||
void
|
||||
initialize_base_rels_list(Query * root, List * tlist)
|
||||
{
|
||||
List *tlist_vars = NIL;
|
||||
List *l = NIL;
|
||||
List *tvar = NIL;
|
||||
List *tlist_vars = NIL;
|
||||
List *l = NIL;
|
||||
List *tvar = NIL;
|
||||
|
||||
foreach(l, tlist)
|
||||
{
|
||||
TargetEntry *entry = (TargetEntry *) lfirst(l);
|
||||
TargetEntry *entry = (TargetEntry *) lfirst(l);
|
||||
|
||||
tlist_vars = append(tlist_vars, pull_var_clause(entry->expr));
|
||||
}
|
||||
@ -77,9 +77,9 @@ initialize_base_rels_list(Query * root, List * tlist)
|
||||
/* now, the target list only contains Var nodes */
|
||||
foreach(tvar, tlist_vars)
|
||||
{
|
||||
Var *var;
|
||||
Index varno;
|
||||
Rel *result;
|
||||
Var *var;
|
||||
Index varno;
|
||||
Rel *result;
|
||||
|
||||
var = (Var *) lfirst(tvar);
|
||||
varno = var->varno;
|
||||
@ -100,16 +100,16 @@ initialize_base_rels_list(Query * root, List * tlist)
|
||||
void
|
||||
add_missing_vars_to_base_rels(Query * root, List * tlist)
|
||||
{
|
||||
List *l;
|
||||
int varno;
|
||||
List *l;
|
||||
int varno;
|
||||
|
||||
varno = 1;
|
||||
foreach(l, root->rtable)
|
||||
{
|
||||
RangeTblEntry *rte = (RangeTblEntry *) lfirst(l);
|
||||
List *relids;
|
||||
Rel *result;
|
||||
Var *var;
|
||||
RangeTblEntry *rte = (RangeTblEntry *) lfirst(l);
|
||||
List *relids;
|
||||
Rel *result;
|
||||
Var *var;
|
||||
|
||||
relids = lconsi(varno, NIL);
|
||||
if (rte->inFromCl &&
|
||||
@ -147,7 +147,7 @@ add_missing_vars_to_base_rels(Query * root, List * tlist)
|
||||
void
|
||||
initialize_base_rels_jinfo(Query * root, List * clauses)
|
||||
{
|
||||
List *clause;
|
||||
List *clause;
|
||||
|
||||
foreach(clause, clauses)
|
||||
{
|
||||
@ -168,9 +168,9 @@ initialize_base_rels_jinfo(Query * root, List * clauses)
|
||||
static void
|
||||
add_clause_to_rels(Query * root, List * clause)
|
||||
{
|
||||
List *relids;
|
||||
List *vars;
|
||||
CInfo *clauseinfo = makeNode(CInfo);
|
||||
List *relids;
|
||||
List *vars;
|
||||
CInfo *clauseinfo = makeNode(CInfo);
|
||||
|
||||
/*
|
||||
* Retrieve all relids and vars contained within the clause.
|
||||
@ -189,7 +189,7 @@ add_clause_to_rels(Query * root, List * clause)
|
||||
|
||||
if (length(relids) == 1)
|
||||
{
|
||||
Rel *rel = get_base_rel(root, lfirsti(relids));
|
||||
Rel *rel = get_base_rel(root, lfirsti(relids));
|
||||
|
||||
/*
|
||||
* There is only one relation participating in 'clause', so
|
||||
@ -261,13 +261,13 @@ add_clause_to_rels(Query * root, List * clause)
|
||||
static void
|
||||
add_join_clause_info_to_rels(Query * root, CInfo * clauseinfo, List * join_relids)
|
||||
{
|
||||
List *join_relid;
|
||||
List *join_relid;
|
||||
|
||||
foreach(join_relid, join_relids)
|
||||
{
|
||||
JInfo *joininfo;
|
||||
List *other_rels = NIL;
|
||||
List *rel;
|
||||
JInfo *joininfo;
|
||||
List *other_rels = NIL;
|
||||
List *rel;
|
||||
|
||||
foreach(rel, join_relids)
|
||||
{
|
||||
@ -302,10 +302,10 @@ add_join_clause_info_to_rels(Query * root, CInfo * clauseinfo, List * join_relid
|
||||
static void
|
||||
add_vars_to_rels(Query * root, List * vars, List * join_relids)
|
||||
{
|
||||
Var *var;
|
||||
List *temp = NIL;
|
||||
Rel *rel = (Rel *) NULL;
|
||||
TargetEntry *tlistentry;
|
||||
Var *var;
|
||||
List *temp = NIL;
|
||||
Rel *rel = (Rel *) NULL;
|
||||
TargetEntry *tlistentry;
|
||||
|
||||
foreach(temp, vars)
|
||||
{
|
||||
@ -336,13 +336,13 @@ add_vars_to_rels(Query * root, List * vars, List * join_relids)
|
||||
void
|
||||
initialize_join_clause_info(List * rel_list)
|
||||
{
|
||||
List *x,
|
||||
*y,
|
||||
*z;
|
||||
Rel *rel;
|
||||
JInfo *joininfo;
|
||||
CInfo *clauseinfo;
|
||||
Expr *clause;
|
||||
List *x,
|
||||
*y,
|
||||
*z;
|
||||
Rel *rel;
|
||||
JInfo *joininfo;
|
||||
CInfo *clauseinfo;
|
||||
Expr *clause;
|
||||
|
||||
foreach(x, rel_list)
|
||||
{
|
||||
@ -356,8 +356,8 @@ initialize_join_clause_info(List * rel_list)
|
||||
clause = clauseinfo->clause;
|
||||
if (join_clause_p((Node *) clause))
|
||||
{
|
||||
MergeOrder *sortop = (MergeOrder *) NULL;
|
||||
Oid hashop = (Oid) NULL;
|
||||
MergeOrder *sortop = (MergeOrder *) NULL;
|
||||
Oid hashop = (Oid) NULL;
|
||||
|
||||
if (_enable_mergesort_)
|
||||
sortop = mergesortop(clause);
|
||||
@ -389,9 +389,9 @@ initialize_join_clause_info(List * rel_list)
|
||||
static MergeOrder *
|
||||
mergesortop(Expr * clause)
|
||||
{
|
||||
Oid leftOp,
|
||||
rightOp;
|
||||
bool sortable;
|
||||
Oid leftOp,
|
||||
rightOp;
|
||||
bool sortable;
|
||||
|
||||
sortable = op_mergesortable(((Oper *) clause->oper)->opno,
|
||||
(get_leftop(clause))->vartype,
|
||||
@ -401,7 +401,7 @@ mergesortop(Expr * clause)
|
||||
|
||||
if (sortable)
|
||||
{
|
||||
MergeOrder *morder = makeNode(MergeOrder);
|
||||
MergeOrder *morder = makeNode(MergeOrder);
|
||||
|
||||
morder->join_operator = ((Oper *) clause->oper)->opno;
|
||||
morder->left_operator = leftOp;
|
||||
@ -420,7 +420,7 @@ mergesortop(Expr * clause)
|
||||
* hashjoinable, i.e., both operands are single vars and the operator is
|
||||
* a hashjoinable operator.
|
||||
*/
|
||||
static Oid
|
||||
static Oid
|
||||
hashjoinop(Expr * clause)
|
||||
{
|
||||
return (op_hashjoinable(((Oper *) clause->oper)->opno,
|
||||
|
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planmain.c,v 1.5 1997/09/07 04:44:02 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planmain.c,v 1.6 1997/09/08 02:24:37 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -38,10 +38,10 @@
|
||||
#include "utils/mcxt.h"
|
||||
#include "utils/lsyscache.h"
|
||||
|
||||
static Plan *subplanner(Query * root, List * flat_tlist, List * qual);
|
||||
static Result *make_result(List * tlist, Node * resconstantqual, Plan * subplan);
|
||||
static Plan *subplanner(Query * root, List * flat_tlist, List * qual);
|
||||
static Result *make_result(List * tlist, Node * resconstantqual, Plan * subplan);
|
||||
|
||||
static Plan *
|
||||
static Plan *
|
||||
make_groupPlan(List ** tlist, bool tuplePerGroup,
|
||||
List * groupClause, Plan * subplan);
|
||||
|
||||
@ -62,17 +62,17 @@ make_groupPlan(List ** tlist, bool tuplePerGroup,
|
||||
*
|
||||
* Returns a query plan.
|
||||
*/
|
||||
Plan *
|
||||
Plan *
|
||||
query_planner(Query * root,
|
||||
int command_type,
|
||||
List * tlist,
|
||||
List * qual)
|
||||
{
|
||||
List *constant_qual = NIL;
|
||||
List *flattened_tlist = NIL;
|
||||
List *level_tlist = NIL;
|
||||
Plan *subplan = (Plan *) NULL;
|
||||
Agg *aggplan = NULL;
|
||||
List *constant_qual = NIL;
|
||||
List *flattened_tlist = NIL;
|
||||
List *level_tlist = NIL;
|
||||
Plan *subplan = (Plan *) NULL;
|
||||
Agg *aggplan = NULL;
|
||||
|
||||
/*
|
||||
* A command without a target list or qualification is an error,
|
||||
@ -132,36 +132,36 @@ query_planner(Query * root,
|
||||
|
||||
switch (command_type)
|
||||
{
|
||||
case CMD_SELECT:
|
||||
case CMD_INSERT:
|
||||
return ((Plan *) make_result(tlist,
|
||||
(Node *) constant_qual,
|
||||
(Plan *) NULL));
|
||||
break;
|
||||
case CMD_SELECT:
|
||||
case CMD_INSERT:
|
||||
return ((Plan *) make_result(tlist,
|
||||
(Node *) constant_qual,
|
||||
(Plan *) NULL));
|
||||
break;
|
||||
|
||||
case CMD_DELETE:
|
||||
case CMD_UPDATE:
|
||||
{
|
||||
SeqScan *scan = make_seqscan(tlist,
|
||||
case CMD_DELETE:
|
||||
case CMD_UPDATE:
|
||||
{
|
||||
SeqScan *scan = make_seqscan(tlist,
|
||||
(List *) NULL,
|
||||
root->resultRelation,
|
||||
(Plan *) NULL);
|
||||
|
||||
if (constant_qual != NULL)
|
||||
{
|
||||
return ((Plan *) make_result(tlist,
|
||||
(Node *) constant_qual,
|
||||
(Plan *) scan));
|
||||
if (constant_qual != NULL)
|
||||
{
|
||||
return ((Plan *) make_result(tlist,
|
||||
(Node *) constant_qual,
|
||||
(Plan *) scan));
|
||||
}
|
||||
else
|
||||
{
|
||||
return ((Plan *) scan);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return ((Plan *) scan);
|
||||
}
|
||||
}
|
||||
break;
|
||||
break;
|
||||
|
||||
default:
|
||||
return ((Plan *) NULL);
|
||||
default:
|
||||
return ((Plan *) NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@ -180,7 +180,7 @@ query_planner(Query * root,
|
||||
*/
|
||||
if (root->groupClause != NULL)
|
||||
{
|
||||
bool tuplePerGroup;
|
||||
bool tuplePerGroup;
|
||||
|
||||
/*
|
||||
* decide whether how many tuples per group the Group node needs
|
||||
@ -223,7 +223,7 @@ query_planner(Query * root,
|
||||
*/
|
||||
if (constant_qual)
|
||||
{
|
||||
Plan *plan;
|
||||
Plan *plan;
|
||||
|
||||
plan = (Plan *) make_result(tlist,
|
||||
(Node *) constant_qual,
|
||||
@ -277,13 +277,13 @@ query_planner(Query * root,
|
||||
* Returns a subplan.
|
||||
*
|
||||
*/
|
||||
static Plan *
|
||||
static Plan *
|
||||
subplanner(Query * root,
|
||||
List * flat_tlist,
|
||||
List * qual)
|
||||
{
|
||||
Rel *final_relation;
|
||||
List *final_relation_list;
|
||||
Rel *final_relation;
|
||||
List *final_relation_list;
|
||||
|
||||
/*
|
||||
* Initialize the targetlist and qualification, adding entries to
|
||||
@ -323,7 +323,7 @@ subplanner(Query * root,
|
||||
if (XfuncMode != XFUNC_OFF && XfuncMode != XFUNC_NOPM &&
|
||||
XfuncMode != XFUNC_NOPULL && !final_relation->pruneable)
|
||||
{
|
||||
List *pathnode;
|
||||
List *pathnode;
|
||||
|
||||
foreach(pathnode, final_relation->pathlist)
|
||||
{
|
||||
@ -353,13 +353,13 @@ subplanner(Query * root,
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
static Result *
|
||||
static Result *
|
||||
make_result(List * tlist,
|
||||
Node * resconstantqual,
|
||||
Plan * subplan)
|
||||
{
|
||||
Result *node = makeNode(Result);
|
||||
Plan *plan = &node->plan;
|
||||
Result *node = makeNode(Result);
|
||||
Plan *plan = &node->plan;
|
||||
|
||||
tlist = generate_fjoin(tlist);
|
||||
plan->cost = 0.0;
|
||||
@ -377,25 +377,25 @@ make_result(List * tlist,
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
static Plan *
|
||||
static Plan *
|
||||
make_groupPlan(List ** tlist,
|
||||
bool tuplePerGroup,
|
||||
List * groupClause,
|
||||
Plan * subplan)
|
||||
{
|
||||
List *sort_tlist;
|
||||
List *sl,
|
||||
*gl;
|
||||
List *glc = listCopy(groupClause);
|
||||
List *otles = NIL;/* list of removed non-GroupBy entries */
|
||||
List *otlvars = NIL; /* list of var in them */
|
||||
int otlvcnt;
|
||||
Sort *sortplan;
|
||||
Group *grpplan;
|
||||
int numCols;
|
||||
AttrNumber *grpColIdx;
|
||||
int keyno = 1;
|
||||
int last_resno = 1;
|
||||
List *sort_tlist;
|
||||
List *sl,
|
||||
*gl;
|
||||
List *glc = listCopy(groupClause);
|
||||
List *otles = NIL; /* list of removed non-GroupBy entries */
|
||||
List *otlvars = NIL; /* list of var in them */
|
||||
int otlvcnt;
|
||||
Sort *sortplan;
|
||||
Group *grpplan;
|
||||
int numCols;
|
||||
AttrNumber *grpColIdx;
|
||||
int keyno = 1;
|
||||
int last_resno = 1;
|
||||
|
||||
numCols = length(groupClause);
|
||||
grpColIdx = (AttrNumber *) palloc(sizeof(AttrNumber) * numCols);
|
||||
@ -412,12 +412,12 @@ make_groupPlan(List ** tlist,
|
||||
*/
|
||||
foreach(sl, sort_tlist)
|
||||
{
|
||||
Resdom *resdom = NULL;
|
||||
TargetEntry *te = (TargetEntry *) lfirst(sl);
|
||||
Resdom *resdom = NULL;
|
||||
TargetEntry *te = (TargetEntry *) lfirst(sl);
|
||||
|
||||
foreach(gl, glc)
|
||||
{
|
||||
GroupClause *grpcl = (GroupClause *) lfirst(gl);
|
||||
GroupClause *grpcl = (GroupClause *) lfirst(gl);
|
||||
|
||||
if (grpcl->entry->resdom->resno == te->resdom->resno)
|
||||
{
|
||||
@ -463,7 +463,7 @@ make_groupPlan(List ** tlist,
|
||||
otlvcnt = length(otlvars);
|
||||
foreach(gl, otlvars)
|
||||
{
|
||||
Var *v = (Var *) lfirst(gl);
|
||||
Var *v = (Var *) lfirst(gl);
|
||||
|
||||
if (tlist_member(v, sort_tlist) == NULL)
|
||||
{
|
||||
@ -490,15 +490,15 @@ make_groupPlan(List ** tlist,
|
||||
*/
|
||||
foreach(sl, sort_tlist)
|
||||
{
|
||||
TargetEntry *te = (TargetEntry *) lfirst(sl);
|
||||
Resdom *resdom = te->resdom;
|
||||
Node *expr = te->expr;
|
||||
TargetEntry *te = (TargetEntry *) lfirst(sl);
|
||||
Resdom *resdom = te->resdom;
|
||||
Node *expr = te->expr;
|
||||
|
||||
if (IsA(expr, Var))
|
||||
{
|
||||
#if 0 /* subplanVar->resdom->resno expected to
|
||||
* be = te->resdom->resno */
|
||||
TargetEntry *subplanVar;
|
||||
TargetEntry *subplanVar;
|
||||
|
||||
subplanVar = match_varid((Var *) expr, subplan->targetlist);
|
||||
((Var *) expr)->varattno = subplanVar->resdom->resno;
|
||||
@ -533,12 +533,12 @@ make_groupPlan(List ** tlist,
|
||||
sort_tlist = NIL; /* to be new parent TL */
|
||||
foreach(gl, *tlist)
|
||||
{
|
||||
List *temp = NIL;
|
||||
TargetEntry *te = (TargetEntry *) lfirst(gl);
|
||||
List *temp = NIL;
|
||||
TargetEntry *te = (TargetEntry *) lfirst(gl);
|
||||
|
||||
foreach(temp, otles) /* Is it removed non-GroupBy entry ? */
|
||||
{
|
||||
TargetEntry *ote = (TargetEntry *) lfirst(temp);
|
||||
TargetEntry *ote = (TargetEntry *) lfirst(temp);
|
||||
|
||||
if (ote->resdom->resno == te->resdom->resno)
|
||||
{
|
||||
@ -548,7 +548,7 @@ make_groupPlan(List ** tlist,
|
||||
}
|
||||
if (temp == NIL) /* It's "our" TLE - we're to return */
|
||||
{ /* it from Sort/Group plans */
|
||||
TargetEntry *my = (TargetEntry *) lfirst(sl); /* get it */
|
||||
TargetEntry *my = (TargetEntry *) lfirst(sl); /* get it */
|
||||
|
||||
sl = sl->next; /* prepare for the next "our" */
|
||||
my = copyObject(my);
|
||||
|
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.7 1997/09/07 04:44:03 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.8 1997/09/08 02:24:38 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -47,8 +47,8 @@
|
||||
|
||||
#include "executor/executor.h"
|
||||
|
||||
static Plan *make_sortplan(List * tlist, List * sortcls, Plan * plannode);
|
||||
static Plan *init_query_planner(Query * parse);
|
||||
static Plan *make_sortplan(List * tlist, List * sortcls, Plan * plannode);
|
||||
static Plan *init_query_planner(Query * parse);
|
||||
static Existential *make_existential(Plan * left, Plan * right);
|
||||
|
||||
/*****************************************************************************
|
||||
@ -68,18 +68,18 @@ static Existential *make_existential(Plan * left, Plan * right);
|
||||
* Returns a query plan.
|
||||
*
|
||||
*/
|
||||
Plan *
|
||||
Plan *
|
||||
planner(Query * parse)
|
||||
{
|
||||
List *tlist = parse->targetList;
|
||||
List *rangetable = parse->rtable;
|
||||
char *uniqueflag = parse->uniqueFlag;
|
||||
List *sortclause = parse->sortClause;
|
||||
Plan *special_plans = (Plan *) NULL;
|
||||
List *tlist = parse->targetList;
|
||||
List *rangetable = parse->rtable;
|
||||
char *uniqueflag = parse->uniqueFlag;
|
||||
List *sortclause = parse->sortClause;
|
||||
Plan *special_plans = (Plan *) NULL;
|
||||
|
||||
Plan *result_plan = (Plan *) NULL;
|
||||
Plan *result_plan = (Plan *) NULL;
|
||||
|
||||
int rt_index;
|
||||
int rt_index;
|
||||
|
||||
/*
|
||||
* plan inheritance
|
||||
@ -119,7 +119,7 @@ planner(Query * parse)
|
||||
|
||||
if (uniqueflag)
|
||||
{
|
||||
Plan *sortplan = make_sortplan(tlist, sortclause, result_plan);
|
||||
Plan *sortplan = make_sortplan(tlist, sortclause, result_plan);
|
||||
|
||||
return ((Plan *) make_unique(tlist, sortplan, uniqueflag));
|
||||
}
|
||||
@ -142,15 +142,15 @@ planner(Query * parse)
|
||||
* sortkeys: ( resdom1 resdom2 resdom3 ...)
|
||||
* sortops: (sortop1 sortop2 sortop3 ...)
|
||||
*/
|
||||
static Plan *
|
||||
static Plan *
|
||||
make_sortplan(List * tlist, List * sortcls, Plan * plannode)
|
||||
{
|
||||
Plan *sortplan = (Plan *) NULL;
|
||||
List *temp_tlist = NIL;
|
||||
List *i = NIL;
|
||||
Resdom *resnode = (Resdom *) NULL;
|
||||
Resdom *resdom = (Resdom *) NULL;
|
||||
int keyno = 1;
|
||||
Plan *sortplan = (Plan *) NULL;
|
||||
List *temp_tlist = NIL;
|
||||
List *i = NIL;
|
||||
Resdom *resnode = (Resdom *) NULL;
|
||||
Resdom *resdom = (Resdom *) NULL;
|
||||
int keyno = 1;
|
||||
|
||||
/*
|
||||
* First make a copy of the tlist so that we don't corrupt the the
|
||||
@ -161,7 +161,7 @@ make_sortplan(List * tlist, List * sortcls, Plan * plannode)
|
||||
|
||||
foreach(i, sortcls)
|
||||
{
|
||||
SortClause *sortcl = (SortClause *) lfirst(i);
|
||||
SortClause *sortcl = (SortClause *) lfirst(i);
|
||||
|
||||
resnode = sortcl->resdom;
|
||||
resdom = tlist_resdom(temp_tlist, resnode);
|
||||
@ -203,13 +203,13 @@ make_sortplan(List * tlist, List * sortcls, Plan * plannode)
|
||||
* MODIFIES: tlist,qual
|
||||
*
|
||||
*/
|
||||
static Plan *
|
||||
static Plan *
|
||||
init_query_planner(Query * root)
|
||||
{
|
||||
List *primary_qual;
|
||||
List *existential_qual;
|
||||
Existential *exist_plan;
|
||||
List *tlist = root->targetList;
|
||||
List *primary_qual;
|
||||
List *existential_qual;
|
||||
Existential *exist_plan;
|
||||
List *tlist = root->targetList;
|
||||
|
||||
tlist = preprocess_targetlist(tlist,
|
||||
root->commandType,
|
||||
@ -230,8 +230,8 @@ init_query_planner(Query * root)
|
||||
}
|
||||
else
|
||||
{
|
||||
int temp = root->commandType;
|
||||
Plan *existential_plan;
|
||||
int temp = root->commandType;
|
||||
Plan *existential_plan;
|
||||
|
||||
root->commandType = CMD_SELECT;
|
||||
existential_plan = query_planner(root,
|
||||
@ -256,7 +256,7 @@ init_query_planner(Query * root)
|
||||
static Existential *
|
||||
make_existential(Plan * left, Plan * right)
|
||||
{
|
||||
Existential *node = makeNode(Existential);
|
||||
Existential *node = makeNode(Existential);
|
||||
|
||||
node->lefttree = left;
|
||||
node->righttree = left;
|
||||
@ -275,17 +275,17 @@ make_existential(Plan * left, Plan * right)
|
||||
void
|
||||
pg_checkretval(Oid rettype, QueryTreeList * queryTreeList)
|
||||
{
|
||||
Query *parse;
|
||||
List *tlist;
|
||||
List *rt;
|
||||
int cmd;
|
||||
Type typ;
|
||||
Resdom *resnode;
|
||||
Relation reln;
|
||||
Oid relid;
|
||||
Oid tletype;
|
||||
int relnatts;
|
||||
int i;
|
||||
Query *parse;
|
||||
List *tlist;
|
||||
List *rt;
|
||||
int cmd;
|
||||
Type typ;
|
||||
Resdom *resnode;
|
||||
Relation reln;
|
||||
Oid relid;
|
||||
Oid tletype;
|
||||
int relnatts;
|
||||
int i;
|
||||
|
||||
/* find the final query */
|
||||
parse = queryTreeList->qtrees[queryTreeList->len - 1];
|
||||
@ -383,8 +383,8 @@ pg_checkretval(Oid rettype, QueryTreeList * queryTreeList)
|
||||
/* expect attributes 1 .. n in order */
|
||||
for (i = 1; i <= relnatts; i++)
|
||||
{
|
||||
TargetEntry *tle = lfirst(tlist);
|
||||
Node *thenode = tle->expr;
|
||||
TargetEntry *tle = lfirst(tlist);
|
||||
Node *thenode = tle->expr;
|
||||
|
||||
tlist = lnext(tlist);
|
||||
tletype = exprType(thenode);
|
||||
|
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/setrefs.c,v 1.5 1997/09/07 04:44:05 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/setrefs.c,v 1.6 1997/09/08 02:24:39 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -33,20 +33,20 @@
|
||||
#include "optimizer/var.h"
|
||||
#include "optimizer/tlist.h"
|
||||
|
||||
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 *
|
||||
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,
|
||||
List * outer_tlist, List * inner_tlist);
|
||||
static List *
|
||||
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);
|
||||
static void replace_result_clause(List * clause, List * subplanTargetList);
|
||||
static bool OperandIsInner(Node * opnd, int inner_relid);
|
||||
static void replace_agg_clause(Node * expr, List * targetlist);
|
||||
static Var *replace_joinvar_refs(Var * var, List * outer_tlist, List * inner_tlist);
|
||||
static List *tlist_temp_references(Oid tempid, List * tlist);
|
||||
static void replace_result_clause(List * clause, List * subplanTargetList);
|
||||
static bool OperandIsInner(Node * opnd, int inner_relid);
|
||||
static void replace_agg_clause(Node * expr, List * targetlist);
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
@ -94,7 +94,7 @@ set_tlist_references(Plan * plan)
|
||||
}
|
||||
else if (IsA(plan, Choose))
|
||||
{
|
||||
List *x;
|
||||
List *x;
|
||||
|
||||
foreach(x, ((Choose *) plan)->chooseplanlist)
|
||||
{
|
||||
@ -122,19 +122,19 @@ set_tlist_references(Plan * plan)
|
||||
static void
|
||||
set_join_tlist_references(Join * join)
|
||||
{
|
||||
Plan *outer = ((Plan *) join)->lefttree;
|
||||
Plan *inner = ((Plan *) join)->righttree;
|
||||
List *new_join_targetlist = NIL;
|
||||
TargetEntry *temp = (TargetEntry *) NULL;
|
||||
List *entry = NIL;
|
||||
List *inner_tlist = NULL;
|
||||
List *outer_tlist = NULL;
|
||||
TargetEntry *xtl = (TargetEntry *) NULL;
|
||||
List *qptlist = ((Plan *) join)->targetlist;
|
||||
Plan *outer = ((Plan *) join)->lefttree;
|
||||
Plan *inner = ((Plan *) join)->righttree;
|
||||
List *new_join_targetlist = NIL;
|
||||
TargetEntry *temp = (TargetEntry *) NULL;
|
||||
List *entry = NIL;
|
||||
List *inner_tlist = NULL;
|
||||
List *outer_tlist = NULL;
|
||||
TargetEntry *xtl = (TargetEntry *) NULL;
|
||||
List *qptlist = ((Plan *) join)->targetlist;
|
||||
|
||||
foreach(entry, qptlist)
|
||||
{
|
||||
List *joinvar;
|
||||
List *joinvar;
|
||||
|
||||
xtl = (TargetEntry *) lfirst(entry);
|
||||
inner_tlist = ((inner == NULL) ? NIL : inner->targetlist);
|
||||
@ -167,7 +167,7 @@ set_join_tlist_references(Join * join)
|
||||
static void
|
||||
set_tempscan_tlist_references(SeqScan * tempscan)
|
||||
{
|
||||
Temp *temp = (Temp *) ((Plan *) tempscan)->lefttree;
|
||||
Temp *temp = (Temp *) ((Plan *) tempscan)->lefttree;
|
||||
|
||||
((Plan *) tempscan)->targetlist =
|
||||
tlist_temp_references(temp->tempid,
|
||||
@ -189,7 +189,7 @@ set_tempscan_tlist_references(SeqScan * tempscan)
|
||||
static void
|
||||
set_temp_tlist_references(Temp * temp)
|
||||
{
|
||||
Plan *source = ((Plan *) temp)->lefttree;
|
||||
Plan *source = ((Plan *) temp)->lefttree;
|
||||
|
||||
if (source != NULL)
|
||||
{
|
||||
@ -217,7 +217,7 @@ set_temp_tlist_references(Temp * temp)
|
||||
* Returns the new join clauses.
|
||||
*
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
join_references(List * clauses,
|
||||
List * outer_tlist,
|
||||
List * inner_tlist)
|
||||
@ -243,15 +243,15 @@ join_references(List * clauses,
|
||||
* Returns the new list of clauses.
|
||||
*
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
index_outerjoin_references(List * inner_indxqual,
|
||||
List * outer_tlist,
|
||||
Index inner_relid)
|
||||
{
|
||||
List *t_list = NIL;
|
||||
Expr *temp = NULL;
|
||||
List *t_clause = NIL;
|
||||
Expr *clause = NULL;
|
||||
List *t_list = NIL;
|
||||
Expr *temp = NULL;
|
||||
List *t_clause = NIL;
|
||||
Expr *clause = NULL;
|
||||
|
||||
foreach(t_clause, inner_indxqual)
|
||||
{
|
||||
@ -262,7 +262,7 @@ index_outerjoin_references(List * inner_indxqual,
|
||||
*/
|
||||
if (OperandIsInner((Node *) get_rightop(clause), inner_relid))
|
||||
{
|
||||
Var *joinvar = (Var *)
|
||||
Var *joinvar = (Var *)
|
||||
replace_clause_joinvar_refs((Expr *) get_leftop(clause),
|
||||
outer_tlist,
|
||||
NIL);
|
||||
@ -275,7 +275,7 @@ index_outerjoin_references(List * inner_indxqual,
|
||||
else
|
||||
{
|
||||
/* inner scan on left */
|
||||
Var *joinvar = (Var *)
|
||||
Var *joinvar = (Var *)
|
||||
replace_clause_joinvar_refs((Expr *) get_rightop(clause),
|
||||
outer_tlist,
|
||||
NIL);
|
||||
@ -306,12 +306,12 @@ index_outerjoin_references(List * inner_indxqual,
|
||||
* Returns the new join clause.
|
||||
*
|
||||
*/
|
||||
static List *
|
||||
static List *
|
||||
replace_clause_joinvar_refs(Expr * clause,
|
||||
List * outer_tlist,
|
||||
List * inner_tlist)
|
||||
{
|
||||
List *temp = NULL;
|
||||
List *temp = NULL;
|
||||
|
||||
if (IsA(clause, Var))
|
||||
{
|
||||
@ -330,7 +330,7 @@ replace_clause_joinvar_refs(Expr * clause,
|
||||
}
|
||||
else if (or_clause((Node *) clause))
|
||||
{
|
||||
List *orclause =
|
||||
List *orclause =
|
||||
replace_subclause_joinvar_refs(((Expr *) clause)->args,
|
||||
outer_tlist,
|
||||
inner_tlist);
|
||||
@ -339,7 +339,7 @@ replace_clause_joinvar_refs(Expr * clause,
|
||||
}
|
||||
else if (IsA(clause, ArrayRef))
|
||||
{
|
||||
ArrayRef *aref = (ArrayRef *) clause;
|
||||
ArrayRef *aref = (ArrayRef *) clause;
|
||||
|
||||
temp = replace_subclause_joinvar_refs(aref->refupperindexpr,
|
||||
outer_tlist,
|
||||
@ -365,7 +365,7 @@ replace_clause_joinvar_refs(Expr * clause,
|
||||
}
|
||||
else if (is_funcclause((Node *) clause))
|
||||
{
|
||||
List *funcclause =
|
||||
List *funcclause =
|
||||
replace_subclause_joinvar_refs(((Expr *) clause)->args,
|
||||
outer_tlist,
|
||||
inner_tlist);
|
||||
@ -375,7 +375,7 @@ replace_clause_joinvar_refs(Expr * clause,
|
||||
}
|
||||
else if (not_clause((Node *) clause))
|
||||
{
|
||||
List *notclause =
|
||||
List *notclause =
|
||||
replace_clause_joinvar_refs(get_notclausearg(clause),
|
||||
outer_tlist,
|
||||
inner_tlist);
|
||||
@ -384,11 +384,11 @@ replace_clause_joinvar_refs(Expr * clause,
|
||||
}
|
||||
else if (is_opclause((Node *) clause))
|
||||
{
|
||||
Var *leftvar =
|
||||
Var *leftvar =
|
||||
(Var *) replace_clause_joinvar_refs((Expr *) get_leftop(clause),
|
||||
outer_tlist,
|
||||
inner_tlist);
|
||||
Var *rightvar =
|
||||
Var *rightvar =
|
||||
(Var *) replace_clause_joinvar_refs((Expr *) get_rightop(clause),
|
||||
outer_tlist,
|
||||
inner_tlist);
|
||||
@ -401,14 +401,14 @@ replace_clause_joinvar_refs(Expr * clause,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static List *
|
||||
static List *
|
||||
replace_subclause_joinvar_refs(List * clauses,
|
||||
List * outer_tlist,
|
||||
List * inner_tlist)
|
||||
{
|
||||
List *t_list = NIL;
|
||||
List *temp = NIL;
|
||||
List *clause = NIL;
|
||||
List *t_list = NIL;
|
||||
List *temp = NIL;
|
||||
List *clause = NIL;
|
||||
|
||||
foreach(clause, clauses)
|
||||
{
|
||||
@ -420,10 +420,10 @@ replace_subclause_joinvar_refs(List * clauses,
|
||||
return (t_list);
|
||||
}
|
||||
|
||||
static Var *
|
||||
static Var *
|
||||
replace_joinvar_refs(Var * var, List * outer_tlist, List * inner_tlist)
|
||||
{
|
||||
Resdom *outer_resdom = (Resdom *) NULL;
|
||||
Resdom *outer_resdom = (Resdom *) NULL;
|
||||
|
||||
outer_resdom = tlist_member(var, outer_tlist);
|
||||
|
||||
@ -437,7 +437,7 @@ replace_joinvar_refs(Var * var, List * outer_tlist, List * inner_tlist)
|
||||
}
|
||||
else
|
||||
{
|
||||
Resdom *inner_resdom;
|
||||
Resdom *inner_resdom;
|
||||
|
||||
inner_resdom = tlist_member(var, inner_tlist);
|
||||
if (inner_resdom != NULL && IsA(inner_resdom, Resdom))
|
||||
@ -466,18 +466,18 @@ replace_joinvar_refs(Var * var, List * outer_tlist, List * inner_tlist)
|
||||
* Returns new target list
|
||||
*
|
||||
*/
|
||||
static List *
|
||||
static List *
|
||||
tlist_temp_references(Oid tempid,
|
||||
List * tlist)
|
||||
{
|
||||
List *t_list = NIL;
|
||||
TargetEntry *temp = (TargetEntry *) NULL;
|
||||
TargetEntry *xtl = NULL;
|
||||
List *entry;
|
||||
List *t_list = NIL;
|
||||
TargetEntry *temp = (TargetEntry *) NULL;
|
||||
TargetEntry *xtl = NULL;
|
||||
List *entry;
|
||||
|
||||
foreach(entry, tlist)
|
||||
{
|
||||
AttrNumber oattno;
|
||||
AttrNumber oattno;
|
||||
|
||||
xtl = lfirst(entry);
|
||||
if (IsA(get_expr(xtl), Var))
|
||||
@ -513,12 +513,12 @@ tlist_temp_references(Oid tempid,
|
||||
void
|
||||
set_result_tlist_references(Result * resultNode)
|
||||
{
|
||||
Plan *subplan;
|
||||
List *resultTargetList;
|
||||
List *subplanTargetList;
|
||||
List *t;
|
||||
TargetEntry *entry;
|
||||
Expr *expr;
|
||||
Plan *subplan;
|
||||
List *resultTargetList;
|
||||
List *subplanTargetList;
|
||||
List *t;
|
||||
TargetEntry *entry;
|
||||
Expr *expr;
|
||||
|
||||
resultTargetList = ((Plan *) resultNode)->targetlist;
|
||||
|
||||
@ -564,9 +564,9 @@ replace_result_clause(List * clause,
|
||||
List * subplanTargetList) /* target list of the
|
||||
* subplan */
|
||||
{
|
||||
List *t;
|
||||
List *subClause;
|
||||
TargetEntry *subplanVar;
|
||||
List *t;
|
||||
List *subClause;
|
||||
TargetEntry *subplanVar;
|
||||
|
||||
if (IsA(clause, Var))
|
||||
{
|
||||
@ -598,7 +598,7 @@ replace_result_clause(List * clause,
|
||||
}
|
||||
else if (IsA(clause, ArrayRef))
|
||||
{
|
||||
ArrayRef *aref = (ArrayRef *) clause;
|
||||
ArrayRef *aref = (ArrayRef *) clause;
|
||||
|
||||
/*
|
||||
* This is an arrayref. Recursively call this routine for its
|
||||
@ -646,7 +646,7 @@ replace_result_clause(List * clause,
|
||||
}
|
||||
|
||||
static
|
||||
bool
|
||||
bool
|
||||
OperandIsInner(Node * opnd, int inner_relid)
|
||||
{
|
||||
|
||||
@ -663,7 +663,7 @@ OperandIsInner(Node * opnd, int inner_relid)
|
||||
}
|
||||
if (is_funcclause(opnd))
|
||||
{
|
||||
List *firstArg = lfirst(((Expr *) opnd)->args);
|
||||
List *firstArg = lfirst(((Expr *) opnd)->args);
|
||||
|
||||
if (IsA(firstArg, Var) &&
|
||||
(inner_relid == ((Var *) firstArg)->varno))
|
||||
@ -688,16 +688,16 @@ OperandIsInner(Node * opnd, int inner_relid)
|
||||
void
|
||||
set_agg_tlist_references(Agg * aggNode)
|
||||
{
|
||||
List *aggTargetList;
|
||||
List *subplanTargetList;
|
||||
List *tl;
|
||||
List *aggTargetList;
|
||||
List *subplanTargetList;
|
||||
List *tl;
|
||||
|
||||
aggTargetList = aggNode->plan.targetlist;
|
||||
subplanTargetList = aggNode->plan.lefttree->targetlist;
|
||||
|
||||
foreach(tl, aggTargetList)
|
||||
{
|
||||
TargetEntry *tle = lfirst(tl);
|
||||
TargetEntry *tle = lfirst(tl);
|
||||
|
||||
replace_agg_clause(tle->expr, subplanTargetList);
|
||||
}
|
||||
@ -706,9 +706,9 @@ set_agg_tlist_references(Agg * aggNode)
|
||||
void
|
||||
set_agg_agglist_references(Agg * aggNode)
|
||||
{
|
||||
List *subplanTargetList;
|
||||
Aggreg **aggs;
|
||||
int i;
|
||||
List *subplanTargetList;
|
||||
Aggreg **aggs;
|
||||
int i;
|
||||
|
||||
aggs = aggNode->aggs;
|
||||
subplanTargetList = aggNode->plan.lefttree->targetlist;
|
||||
@ -722,8 +722,8 @@ set_agg_agglist_references(Agg * aggNode)
|
||||
static void
|
||||
replace_agg_clause(Node * clause, List * subplanTargetList)
|
||||
{
|
||||
List *t;
|
||||
TargetEntry *subplanVar;
|
||||
List *t;
|
||||
TargetEntry *subplanVar;
|
||||
|
||||
if (IsA(clause, Var))
|
||||
{
|
||||
@ -757,7 +757,7 @@ replace_agg_clause(Node * clause, List * subplanTargetList)
|
||||
}
|
||||
else if (IsA(clause, ArrayRef))
|
||||
{
|
||||
ArrayRef *aref = (ArrayRef *) clause;
|
||||
ArrayRef *aref = (ArrayRef *) clause;
|
||||
|
||||
/*
|
||||
* This is an arrayref. Recursively call this routine for its
|
||||
@ -781,8 +781,8 @@ replace_agg_clause(Node * clause, List * subplanTargetList)
|
||||
* 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);
|
||||
Node *left = (Node *) get_leftop((Expr *) clause);
|
||||
Node *right = (Node *) get_rightop((Expr *) clause);
|
||||
|
||||
if (left != (Node *) NULL)
|
||||
replace_agg_clause(left, subplanTargetList);
|
||||
|
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/Attic/archive.c,v 1.2 1997/09/07 04:44:09 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/Attic/archive.c,v 1.3 1997/09/08 02:24:41 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -28,11 +28,11 @@
|
||||
void
|
||||
plan_archive(List * rt)
|
||||
{
|
||||
List *rtitem;
|
||||
RangeTblEntry *rte;
|
||||
TimeRange *trange;
|
||||
Relation r;
|
||||
Oid reloid;
|
||||
List *rtitem;
|
||||
RangeTblEntry *rte;
|
||||
TimeRange *trange;
|
||||
Relation r;
|
||||
Oid reloid;
|
||||
|
||||
foreach(rtitem, rt)
|
||||
{
|
||||
@ -55,11 +55,11 @@ plan_archive(List * rt)
|
||||
* find_archive_rels -- Given a particular relid, find the archive
|
||||
* relation's relid.
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
find_archive_rels(Oid relid)
|
||||
{
|
||||
Relation arel;
|
||||
char *arelName;
|
||||
Relation arel;
|
||||
char *arelName;
|
||||
|
||||
arelName = MakeArchiveName(relid);
|
||||
arel = RelationNameGetRelation(arelName);
|
||||
|
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepqual.c,v 1.4 1997/09/07 04:44:10 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepqual.c,v 1.5 1997/09/08 02:24:42 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -24,17 +24,17 @@
|
||||
|
||||
#include "utils/lsyscache.h"
|
||||
|
||||
static Expr *pull_args(Expr * qual);
|
||||
static List *pull_ors(List * orlist);
|
||||
static List *pull_ands(List * andlist);
|
||||
static Expr *find_nots(Expr * qual);
|
||||
static Expr *push_nots(Expr * qual);
|
||||
static Expr *normalize(Expr * qual);
|
||||
static List *or_normalize(List * orlist);
|
||||
static List *distribute_args(List * item, List * args);
|
||||
static List *qualcleanup(Expr * qual);
|
||||
static List *remove_ands(Expr * qual);
|
||||
static List *remove_duplicates(List * list);
|
||||
static Expr *pull_args(Expr * qual);
|
||||
static List *pull_ors(List * orlist);
|
||||
static List *pull_ands(List * andlist);
|
||||
static Expr *find_nots(Expr * qual);
|
||||
static Expr *push_nots(Expr * qual);
|
||||
static Expr *normalize(Expr * qual);
|
||||
static List *or_normalize(List * orlist);
|
||||
static List *distribute_args(List * item, List * args);
|
||||
static List *qualcleanup(Expr * qual);
|
||||
static List *remove_ands(Expr * qual);
|
||||
static List *remove_duplicates(List * list);
|
||||
|
||||
/*
|
||||
* preprocess-qualification--
|
||||
@ -47,10 +47,10 @@ static List *remove_duplicates(List * list);
|
||||
* preprocess-qualification simply converts the qual in conjunctive
|
||||
* normal form (see cnfify() below )
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
preprocess_qualification(Expr * qual, List * tlist, List ** existentialQualPtr)
|
||||
{
|
||||
List *cnf_qual = cnfify(qual, true);
|
||||
List *cnf_qual = cnfify(qual, true);
|
||||
|
||||
/*
|
||||
List *existential_qual =
|
||||
@ -100,10 +100,10 @@ preprocess_qualification(Expr * qual, List * tlist, List ** existentialQualPtr)
|
||||
* and from the rule manager (removeAndFlag = false).
|
||||
*
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
cnfify(Expr * qual, bool removeAndFlag)
|
||||
{
|
||||
Expr *newqual = NULL;
|
||||
Expr *newqual = NULL;
|
||||
|
||||
if (qual != NULL)
|
||||
{
|
||||
@ -133,7 +133,7 @@ cnfify(Expr * qual, bool removeAndFlag)
|
||||
* Returns the modified qualification.
|
||||
*
|
||||
*/
|
||||
static Expr *
|
||||
static Expr *
|
||||
pull_args(Expr * qual)
|
||||
{
|
||||
if (qual == NULL)
|
||||
@ -148,8 +148,8 @@ pull_args(Expr * qual)
|
||||
}
|
||||
else if (and_clause((Node *) qual))
|
||||
{
|
||||
List *temp = NIL;
|
||||
List *t_list = NIL;
|
||||
List *temp = NIL;
|
||||
List *t_list = NIL;
|
||||
|
||||
foreach(temp, qual->args)
|
||||
t_list = lappend(t_list, pull_args(lfirst(temp)));
|
||||
@ -157,8 +157,8 @@ pull_args(Expr * qual)
|
||||
}
|
||||
else if (or_clause((Node *) qual))
|
||||
{
|
||||
List *temp = NIL;
|
||||
List *t_list = NIL;
|
||||
List *temp = NIL;
|
||||
List *t_list = NIL;
|
||||
|
||||
foreach(temp, qual->args)
|
||||
t_list = lappend(t_list, pull_args(lfirst(temp)));
|
||||
@ -181,7 +181,7 @@ pull_args(Expr * qual)
|
||||
*
|
||||
* Returns the modified list.
|
||||
*/
|
||||
static List *
|
||||
static List *
|
||||
pull_ors(List * orlist)
|
||||
{
|
||||
if (orlist == NIL)
|
||||
@ -189,7 +189,7 @@ pull_ors(List * orlist)
|
||||
|
||||
if (or_clause(lfirst(orlist)))
|
||||
{
|
||||
List *args = ((Expr *) lfirst(orlist))->args;
|
||||
List *args = ((Expr *) lfirst(orlist))->args;
|
||||
|
||||
return (pull_ors(nconc(copyObject((Node *) args),
|
||||
copyObject((Node *) lnext(orlist)))));
|
||||
@ -207,7 +207,7 @@ pull_ors(List * orlist)
|
||||
*
|
||||
* Returns the modified list.
|
||||
*/
|
||||
static List *
|
||||
static List *
|
||||
pull_ands(List * andlist)
|
||||
{
|
||||
if (andlist == NIL)
|
||||
@ -215,7 +215,7 @@ pull_ands(List * andlist)
|
||||
|
||||
if (and_clause(lfirst(andlist)))
|
||||
{
|
||||
List *args = ((Expr *) lfirst(andlist))->args;
|
||||
List *args = ((Expr *) lfirst(andlist))->args;
|
||||
|
||||
return (pull_ands(nconc(copyObject((Node *) args),
|
||||
copyObject((Node *) lnext(andlist)))));
|
||||
@ -236,7 +236,7 @@ pull_ands(List * andlist)
|
||||
* Returns the modified qualification.
|
||||
*
|
||||
*/
|
||||
static Expr *
|
||||
static Expr *
|
||||
find_nots(Expr * qual)
|
||||
{
|
||||
if (qual == NULL)
|
||||
@ -251,8 +251,8 @@ find_nots(Expr * qual)
|
||||
}
|
||||
else if (and_clause((Node *) qual))
|
||||
{
|
||||
List *temp = NIL;
|
||||
List *t_list = NIL;
|
||||
List *temp = NIL;
|
||||
List *t_list = NIL;
|
||||
|
||||
foreach(temp, qual->args)
|
||||
{
|
||||
@ -263,8 +263,8 @@ find_nots(Expr * qual)
|
||||
}
|
||||
else if (or_clause((Node *) qual))
|
||||
{
|
||||
List *temp = NIL;
|
||||
List *t_list = NIL;
|
||||
List *temp = NIL;
|
||||
List *t_list = NIL;
|
||||
|
||||
foreach(temp, qual->args)
|
||||
{
|
||||
@ -285,7 +285,7 @@ find_nots(Expr * qual)
|
||||
* Returns the modified qualification.
|
||||
*
|
||||
*/
|
||||
static Expr *
|
||||
static Expr *
|
||||
push_nots(Expr * qual)
|
||||
{
|
||||
if (qual == NULL)
|
||||
@ -298,15 +298,15 @@ push_nots(Expr * qual)
|
||||
*/
|
||||
if (is_opclause((Node *) qual))
|
||||
{
|
||||
Oper *oper = (Oper *) ((Expr *) qual)->oper;
|
||||
Oid negator = get_negator(oper->opno);
|
||||
Oper *oper = (Oper *) ((Expr *) qual)->oper;
|
||||
Oid negator = get_negator(oper->opno);
|
||||
|
||||
if (negator)
|
||||
{
|
||||
Oper *op = (Oper *) makeOper(negator,
|
||||
InvalidOid,
|
||||
oper->opresulttype,
|
||||
0, NULL);
|
||||
Oper *op = (Oper *) makeOper(negator,
|
||||
InvalidOid,
|
||||
oper->opresulttype,
|
||||
0, NULL);
|
||||
|
||||
op->op_fcache = (FunctionCache *) NULL;
|
||||
return
|
||||
@ -325,8 +325,8 @@ push_nots(Expr * qual)
|
||||
* ("NOT" B)) ("NOT" ("OR" A B)) => ("AND" ("NOT" A) ("NOT" B))
|
||||
* i.e., continue negating down through the clause's descendants.
|
||||
*/
|
||||
List *temp = NIL;
|
||||
List *t_list = NIL;
|
||||
List *temp = NIL;
|
||||
List *t_list = NIL;
|
||||
|
||||
foreach(temp, qual->args)
|
||||
{
|
||||
@ -336,8 +336,8 @@ push_nots(Expr * qual)
|
||||
}
|
||||
else if (or_clause((Node *) qual))
|
||||
{
|
||||
List *temp = NIL;
|
||||
List *t_list = NIL;
|
||||
List *temp = NIL;
|
||||
List *t_list = NIL;
|
||||
|
||||
foreach(temp, qual->args)
|
||||
{
|
||||
@ -372,7 +372,7 @@ push_nots(Expr * qual)
|
||||
* Returns the modified qualification.
|
||||
*
|
||||
*/
|
||||
static Expr *
|
||||
static Expr *
|
||||
normalize(Expr * qual)
|
||||
{
|
||||
if (qual == NULL)
|
||||
@ -380,7 +380,7 @@ normalize(Expr * qual)
|
||||
|
||||
if (is_opclause((Node *) qual))
|
||||
{
|
||||
Expr *expr = (Expr *) qual;
|
||||
Expr *expr = (Expr *) qual;
|
||||
|
||||
return (make_clause(expr->opType, expr->oper,
|
||||
lcons(normalize((Expr *) get_leftop(qual)),
|
||||
@ -389,8 +389,8 @@ normalize(Expr * qual)
|
||||
}
|
||||
else if (and_clause((Node *) qual))
|
||||
{
|
||||
List *temp = NIL;
|
||||
List *t_list = NIL;
|
||||
List *temp = NIL;
|
||||
List *t_list = NIL;
|
||||
|
||||
foreach(temp, qual->args)
|
||||
{
|
||||
@ -401,9 +401,9 @@ normalize(Expr * qual)
|
||||
else if (or_clause((Node *) qual))
|
||||
{
|
||||
/* XXX - let form, maybe incorrect */
|
||||
List *orlist = NIL;
|
||||
List *temp = NIL;
|
||||
bool has_andclause = FALSE;
|
||||
List *orlist = NIL;
|
||||
List *temp = NIL;
|
||||
bool has_andclause = FALSE;
|
||||
|
||||
foreach(temp, qual->args)
|
||||
{
|
||||
@ -437,12 +437,12 @@ normalize(Expr * qual)
|
||||
* Returns the modified list.
|
||||
*
|
||||
*/
|
||||
static List *
|
||||
static List *
|
||||
or_normalize(List * orlist)
|
||||
{
|
||||
List *distributable = NIL;
|
||||
List *new_orlist = NIL;
|
||||
List *temp = NIL;
|
||||
List *distributable = NIL;
|
||||
List *new_orlist = NIL;
|
||||
List *temp = NIL;
|
||||
|
||||
if (orlist == NIL)
|
||||
return NIL;
|
||||
@ -476,13 +476,13 @@ or_normalize(List * orlist)
|
||||
* Returns an 'and' clause.
|
||||
*
|
||||
*/
|
||||
static List *
|
||||
static List *
|
||||
distribute_args(List * item, List * args)
|
||||
{
|
||||
List *or_list = NIL;
|
||||
List *n_list = NIL;
|
||||
List *temp = NIL;
|
||||
List *t_list = NIL;
|
||||
List *or_list = NIL;
|
||||
List *n_list = NIL;
|
||||
List *temp = NIL;
|
||||
List *t_list = NIL;
|
||||
|
||||
if (args == NULL)
|
||||
return (item);
|
||||
@ -506,7 +506,7 @@ distribute_args(List * item, List * args)
|
||||
* Returns the modified qualfication.
|
||||
*
|
||||
*/
|
||||
static List *
|
||||
static List *
|
||||
qualcleanup(Expr * qual)
|
||||
{
|
||||
if (qual == NULL)
|
||||
@ -521,9 +521,9 @@ qualcleanup(Expr * qual)
|
||||
}
|
||||
else if (and_clause((Node *) qual))
|
||||
{
|
||||
List *temp = NIL;
|
||||
List *t_list = NIL;
|
||||
List *new_and_args = NIL;
|
||||
List *temp = NIL;
|
||||
List *t_list = NIL;
|
||||
List *new_and_args = NIL;
|
||||
|
||||
foreach(temp, qual->args)
|
||||
t_list = lappend(t_list, qualcleanup(lfirst(temp)));
|
||||
@ -537,9 +537,9 @@ qualcleanup(Expr * qual)
|
||||
}
|
||||
else if (or_clause((Node *) qual))
|
||||
{
|
||||
List *temp = NIL;
|
||||
List *t_list = NIL;
|
||||
List *new_or_args = NIL;
|
||||
List *temp = NIL;
|
||||
List *t_list = NIL;
|
||||
List *new_or_args = NIL;
|
||||
|
||||
foreach(temp, qual->args)
|
||||
t_list = lappend(t_list, qualcleanup(lfirst(temp)));
|
||||
@ -567,10 +567,10 @@ qualcleanup(Expr * qual)
|
||||
* RETURNS : qual
|
||||
* MODIFIES: qual
|
||||
*/
|
||||
static List *
|
||||
static List *
|
||||
remove_ands(Expr * qual)
|
||||
{
|
||||
List *t_list = NIL;
|
||||
List *t_list = NIL;
|
||||
|
||||
if (qual == NULL)
|
||||
return (NIL);
|
||||
@ -583,7 +583,7 @@ remove_ands(Expr * qual)
|
||||
}
|
||||
else if (and_clause((Node *) qual))
|
||||
{
|
||||
List *temp = NIL;
|
||||
List *temp = NIL;
|
||||
|
||||
foreach(temp, qual->args)
|
||||
t_list = lappend(t_list, remove_ands(lfirst(temp)));
|
||||
@ -591,7 +591,7 @@ remove_ands(Expr * qual)
|
||||
}
|
||||
else if (or_clause((Node *) qual))
|
||||
{
|
||||
List *temp = NIL;
|
||||
List *temp = NIL;
|
||||
|
||||
foreach(temp, qual->args)
|
||||
t_list = lappend(t_list, remove_ands(lfirst(temp)));
|
||||
@ -620,7 +620,7 @@ remove_ands(Expr * qual)
|
||||
*
|
||||
*/
|
||||
#ifdef NOT_USED
|
||||
static List *
|
||||
static List *
|
||||
update_relations(List * tlist)
|
||||
{
|
||||
return (NIL);
|
||||
@ -634,13 +634,13 @@ update_relations(List * tlist)
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
static List *
|
||||
static List *
|
||||
remove_duplicates(List * list)
|
||||
{
|
||||
List *i;
|
||||
List *j;
|
||||
List *result = NIL;
|
||||
bool there_exists_duplicate = false;
|
||||
List *i;
|
||||
List *j;
|
||||
List *result = NIL;
|
||||
bool there_exists_duplicate = false;
|
||||
|
||||
if (length(list) == 1)
|
||||
return (list);
|
||||
|
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/preptlist.c,v 1.3 1997/09/07 04:44:13 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/preptlist.c,v 1.4 1997/09/08 02:24:44 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -33,13 +33,13 @@
|
||||
#include "optimizer/clauses.h"
|
||||
#include "optimizer/tlist.h"
|
||||
|
||||
static List *
|
||||
static List *
|
||||
expand_targetlist(List * tlist, Oid relid, int command_type,
|
||||
Index result_relation);
|
||||
static List *
|
||||
static List *
|
||||
replace_matching_resname(List * new_tlist,
|
||||
List * old_tlist);
|
||||
static List *
|
||||
static List *
|
||||
new_relation_targetlist(Oid relid, Index rt_index,
|
||||
NodeTag node_type);
|
||||
|
||||
@ -54,16 +54,16 @@ new_relation_targetlist(Oid relid, Index rt_index,
|
||||
*
|
||||
* Returns the new targetlist.
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
preprocess_targetlist(List * tlist,
|
||||
int command_type,
|
||||
Index result_relation,
|
||||
List * range_table)
|
||||
{
|
||||
List *expanded_tlist = NIL;
|
||||
Oid relid = InvalidOid;
|
||||
List *t_list = NIL;
|
||||
List *temp = NIL;
|
||||
List *expanded_tlist = NIL;
|
||||
Oid relid = InvalidOid;
|
||||
List *t_list = NIL;
|
||||
List *temp = NIL;
|
||||
|
||||
if (result_relation >= 1 && command_type != CMD_SELECT)
|
||||
{
|
||||
@ -82,7 +82,7 @@ preprocess_targetlist(List * tlist,
|
||||
/* was mapCAR */
|
||||
foreach(temp, expanded_tlist)
|
||||
{
|
||||
TargetEntry *tle = lfirst(temp);
|
||||
TargetEntry *tle = lfirst(temp);
|
||||
|
||||
if (tle->expr)
|
||||
fix_opid(tle->expr);
|
||||
@ -101,9 +101,9 @@ preprocess_targetlist(List * tlist,
|
||||
*/
|
||||
if (command_type == CMD_UPDATE || command_type == CMD_DELETE)
|
||||
{
|
||||
TargetEntry *ctid;
|
||||
Resdom *resdom;
|
||||
Var *var;
|
||||
TargetEntry *ctid;
|
||||
Resdom *resdom;
|
||||
Var *var;
|
||||
|
||||
resdom = makeResdom(length(t_list) + 1,
|
||||
27,
|
||||
@ -143,29 +143,29 @@ preprocess_targetlist(List * tlist,
|
||||
*
|
||||
* Returns the expanded target list, sorted in resno order.
|
||||
*/
|
||||
static List *
|
||||
static List *
|
||||
expand_targetlist(List * tlist,
|
||||
Oid relid,
|
||||
int command_type,
|
||||
Index result_relation)
|
||||
{
|
||||
NodeTag node_type = T_Invalid;
|
||||
NodeTag node_type = T_Invalid;
|
||||
|
||||
switch (command_type)
|
||||
{
|
||||
case CMD_INSERT:
|
||||
node_type = (NodeTag) T_Const;
|
||||
break;
|
||||
case CMD_UPDATE:
|
||||
node_type = (NodeTag) T_Var;
|
||||
break;
|
||||
case CMD_INSERT:
|
||||
node_type = (NodeTag) T_Const;
|
||||
break;
|
||||
case CMD_UPDATE:
|
||||
node_type = (NodeTag) T_Var;
|
||||
break;
|
||||
}
|
||||
|
||||
if (node_type != T_Invalid)
|
||||
{
|
||||
List *ntlist = new_relation_targetlist(relid,
|
||||
result_relation,
|
||||
node_type);
|
||||
List *ntlist = new_relation_targetlist(relid,
|
||||
result_relation,
|
||||
node_type);
|
||||
|
||||
return (replace_matching_resname(ntlist, tlist));
|
||||
}
|
||||
@ -177,21 +177,21 @@ expand_targetlist(List * tlist,
|
||||
}
|
||||
|
||||
|
||||
static List *
|
||||
static List *
|
||||
replace_matching_resname(List * new_tlist, List * old_tlist)
|
||||
{
|
||||
List *temp,
|
||||
*i;
|
||||
List *t_list = NIL;
|
||||
List *temp,
|
||||
*i;
|
||||
List *t_list = NIL;
|
||||
|
||||
foreach(i, new_tlist)
|
||||
{
|
||||
TargetEntry *new_tle = (TargetEntry *) lfirst(i);
|
||||
TargetEntry *matching_old_tl = NULL;
|
||||
TargetEntry *new_tle = (TargetEntry *) lfirst(i);
|
||||
TargetEntry *matching_old_tl = NULL;
|
||||
|
||||
foreach(temp, old_tlist)
|
||||
{
|
||||
TargetEntry *old_tle = (TargetEntry *) lfirst(temp);
|
||||
TargetEntry *old_tle = (TargetEntry *) lfirst(temp);
|
||||
|
||||
old_tle = lfirst(temp);
|
||||
if (!strcmp(old_tle->resdom->resname,
|
||||
@ -228,9 +228,9 @@ replace_matching_resname(List * new_tlist, List * old_tlist)
|
||||
*/
|
||||
foreach(temp, old_tlist)
|
||||
{
|
||||
TargetEntry *old_tle,
|
||||
*new_tl;
|
||||
Resdom *newresno;
|
||||
TargetEntry *old_tle,
|
||||
*new_tl;
|
||||
Resdom *newresno;
|
||||
|
||||
old_tle = lfirst(temp);
|
||||
if (old_tle->resdom->resno < 0)
|
||||
@ -253,15 +253,15 @@ replace_matching_resname(List * new_tlist, List * old_tlist)
|
||||
*
|
||||
* Returns the new targetlist.
|
||||
*/
|
||||
static List *
|
||||
static List *
|
||||
new_relation_targetlist(Oid relid, Index rt_index, NodeTag node_type)
|
||||
{
|
||||
AttrNumber attno;
|
||||
List *t_list = NIL;
|
||||
char *attname;
|
||||
Oid atttype = 0;
|
||||
int16 typlen = 0;
|
||||
bool attisset = false;
|
||||
AttrNumber attno;
|
||||
List *t_list = NIL;
|
||||
char *attname;
|
||||
Oid atttype = 0;
|
||||
int16 typlen = 0;
|
||||
bool attisset = false;
|
||||
|
||||
/* Oid type_id; */
|
||||
/* type_id = RelationIdGetTypeId(relid); */
|
||||
@ -287,59 +287,59 @@ new_relation_targetlist(Oid relid, Index rt_index, NodeTag node_type)
|
||||
|
||||
switch (node_type)
|
||||
{
|
||||
case T_Const:
|
||||
{
|
||||
struct varlena *typedefault = get_typdefault(atttype);
|
||||
int temp = 0;
|
||||
Const *temp2 = (Const *) NULL;
|
||||
TargetEntry *temp3 = (TargetEntry *) NULL;
|
||||
case T_Const:
|
||||
{
|
||||
struct varlena *typedefault = get_typdefault(atttype);
|
||||
int temp = 0;
|
||||
Const *temp2 = (Const *) NULL;
|
||||
TargetEntry *temp3 = (TargetEntry *) NULL;
|
||||
|
||||
if (typedefault == NULL)
|
||||
temp = 0;
|
||||
else
|
||||
temp = typlen;
|
||||
if (typedefault == NULL)
|
||||
temp = 0;
|
||||
else
|
||||
temp = typlen;
|
||||
|
||||
temp2 = makeConst(atttype,
|
||||
temp,
|
||||
(Datum) typedefault,
|
||||
temp2 = makeConst(atttype,
|
||||
temp,
|
||||
(Datum) typedefault,
|
||||
(typedefault == (struct varlena *) NULL),
|
||||
/* XXX this is bullshit */
|
||||
false,
|
||||
false, /* not a set */
|
||||
false);
|
||||
/* XXX this is bullshit */
|
||||
false,
|
||||
false, /* not a set */
|
||||
false);
|
||||
|
||||
temp3 = MakeTLE(makeResdom(attno,
|
||||
atttype,
|
||||
typlen,
|
||||
attname,
|
||||
0,
|
||||
(Oid) 0,
|
||||
0),
|
||||
(Node *) temp2);
|
||||
t_list = lappend(t_list, temp3);
|
||||
break;
|
||||
}
|
||||
case T_Var:
|
||||
{
|
||||
Var *temp_var = (Var *) NULL;
|
||||
TargetEntry *temp_list = NULL;
|
||||
|
||||
temp_var =
|
||||
makeVar(rt_index, attno, atttype, rt_index, attno);
|
||||
|
||||
temp_list = MakeTLE(makeResdom(attno,
|
||||
temp3 = MakeTLE(makeResdom(attno,
|
||||
atttype,
|
||||
typlen,
|
||||
attname,
|
||||
0,
|
||||
(Oid) 0,
|
||||
0),
|
||||
(Node *) temp_var);
|
||||
t_list = lappend(t_list, temp_list);
|
||||
(Node *) temp2);
|
||||
t_list = lappend(t_list, temp3);
|
||||
break;
|
||||
}
|
||||
case T_Var:
|
||||
{
|
||||
Var *temp_var = (Var *) NULL;
|
||||
TargetEntry *temp_list = NULL;
|
||||
|
||||
temp_var =
|
||||
makeVar(rt_index, attno, atttype, rt_index, attno);
|
||||
|
||||
temp_list = MakeTLE(makeResdom(attno,
|
||||
atttype,
|
||||
typlen,
|
||||
attname,
|
||||
0,
|
||||
(Oid) 0,
|
||||
0),
|
||||
(Node *) temp_var);
|
||||
t_list = lappend(t_list, temp_list);
|
||||
break;
|
||||
}
|
||||
default: /* do nothing */
|
||||
break;
|
||||
}
|
||||
default: /* do nothing */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.4 1997/09/07 04:44:14 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.5 1997/09/08 02:24:47 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -34,20 +34,20 @@
|
||||
#include "optimizer/planner.h"
|
||||
#include "optimizer/prep.h"
|
||||
|
||||
static List *
|
||||
static List *
|
||||
plan_union_query(List * relids, Index rt_index,
|
||||
RangeTblEntry * rt_entry, Query * parse, UnionFlag flag,
|
||||
List ** union_rtentriesPtr);
|
||||
static RangeTblEntry *
|
||||
new_rangetable_entry(Oid new_relid,
|
||||
RangeTblEntry * old_entry);
|
||||
static Query *
|
||||
static Query *
|
||||
subst_rangetable(Query * root, Index index,
|
||||
RangeTblEntry * new_entry);
|
||||
static void
|
||||
fix_parsetree_attnums(Index rt_index, Oid old_relid,
|
||||
Oid new_relid, Query * parsetree);
|
||||
static Append *
|
||||
static Append *
|
||||
make_append(List * unionplans, Index rt_index,
|
||||
List * union_rt_entries, List * tlist);
|
||||
|
||||
@ -58,20 +58,20 @@ make_append(List * unionplans, Index rt_index,
|
||||
* attributes from any relations listed in either of the argument relid
|
||||
* lists.
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
find_all_inheritors(List * unexamined_relids,
|
||||
List * examined_relids)
|
||||
{
|
||||
List *new_inheritors = NIL;
|
||||
List *new_examined_relids = NIL;
|
||||
List *new_unexamined_relids = NIL;
|
||||
List *new_inheritors = NIL;
|
||||
List *new_examined_relids = NIL;
|
||||
List *new_unexamined_relids = NIL;
|
||||
|
||||
/*
|
||||
* Find all relations which inherit from members of
|
||||
* 'unexamined-relids' and store them in 'new-inheritors'.
|
||||
*/
|
||||
List *rels = NIL;
|
||||
List *newrels = NIL;
|
||||
List *rels = NIL;
|
||||
List *newrels = NIL;
|
||||
|
||||
foreach(rels, unexamined_relids)
|
||||
{
|
||||
@ -105,25 +105,25 @@ find_all_inheritors(List * unexamined_relids,
|
||||
int
|
||||
first_matching_rt_entry(List * rangetable, UnionFlag flag)
|
||||
{
|
||||
int count = 0;
|
||||
List *temp = NIL;
|
||||
int count = 0;
|
||||
List *temp = NIL;
|
||||
|
||||
foreach(temp, rangetable)
|
||||
{
|
||||
RangeTblEntry *rt_entry = lfirst(temp);
|
||||
RangeTblEntry *rt_entry = lfirst(temp);
|
||||
|
||||
switch (flag)
|
||||
{
|
||||
case INHERITS_FLAG:
|
||||
if (rt_entry->inh)
|
||||
return count + 1;
|
||||
break;
|
||||
case ARCHIVE_FLAG:
|
||||
if (rt_entry->archive)
|
||||
return count + 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case INHERITS_FLAG:
|
||||
if (rt_entry->inh)
|
||||
return count + 1;
|
||||
break;
|
||||
case ARCHIVE_FLAG:
|
||||
if (rt_entry->archive)
|
||||
return count + 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
@ -141,50 +141,50 @@ first_matching_rt_entry(List * rangetable, UnionFlag flag)
|
||||
* entries to be inserted into an APPEND node.
|
||||
* XXX - what exactly does this mean, look for make_append
|
||||
*/
|
||||
Append *
|
||||
Append *
|
||||
plan_union_queries(Index rt_index,
|
||||
Query * parse,
|
||||
UnionFlag flag)
|
||||
{
|
||||
List *rangetable = parse->rtable;
|
||||
RangeTblEntry *rt_entry = rt_fetch(rt_index, rangetable);
|
||||
List *union_relids = NIL;
|
||||
List *union_plans = NIL;
|
||||
List *union_rt_entries = NIL;
|
||||
List *rangetable = parse->rtable;
|
||||
RangeTblEntry *rt_entry = rt_fetch(rt_index, rangetable);
|
||||
List *union_relids = NIL;
|
||||
List *union_plans = NIL;
|
||||
List *union_rt_entries = NIL;
|
||||
|
||||
switch (flag)
|
||||
{
|
||||
case INHERITS_FLAG:
|
||||
union_relids =
|
||||
find_all_inheritors(lconsi(rt_entry->relid,
|
||||
NIL),
|
||||
NIL);
|
||||
break;
|
||||
case INHERITS_FLAG:
|
||||
union_relids =
|
||||
find_all_inheritors(lconsi(rt_entry->relid,
|
||||
NIL),
|
||||
NIL);
|
||||
break;
|
||||
|
||||
#if 0
|
||||
case UNION_FLAG:
|
||||
{
|
||||
Index rt_index = 0;
|
||||
case UNION_FLAG:
|
||||
{
|
||||
Index rt_index = 0;
|
||||
|
||||
union_plans = handleunion(root, rangetable, tlist, qual);
|
||||
return (make_append(union_plans,
|
||||
rt_index, rangetable,
|
||||
union_plans = handleunion(root, rangetable, tlist, qual);
|
||||
return (make_append(union_plans,
|
||||
rt_index, rangetable,
|
||||
((Plan *) lfirst(union_plans))->targetlist));
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
case VERSION_FLAG:
|
||||
union_relids = VersionGetParents(rt_entry->relid);
|
||||
break;
|
||||
case VERSION_FLAG:
|
||||
union_relids = VersionGetParents(rt_entry->relid);
|
||||
break;
|
||||
|
||||
case ARCHIVE_FLAG:
|
||||
union_relids = find_archive_rels(rt_entry->relid);
|
||||
break;
|
||||
case ARCHIVE_FLAG:
|
||||
union_relids = find_archive_rels(rt_entry->relid);
|
||||
break;
|
||||
|
||||
default:
|
||||
/* do nothing */
|
||||
break;
|
||||
default:
|
||||
/* do nothing */
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -193,14 +193,14 @@ plan_union_queries(Index rt_index,
|
||||
*/
|
||||
switch (flag)
|
||||
{
|
||||
case INHERITS_FLAG:
|
||||
rt_fetch(rt_index, rangetable)->inh = false;
|
||||
break;
|
||||
case ARCHIVE_FLAG:
|
||||
rt_fetch(rt_index, rangetable)->archive = false;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case INHERITS_FLAG:
|
||||
rt_fetch(rt_index, rangetable)->inh = false;
|
||||
break;
|
||||
case ARCHIVE_FLAG:
|
||||
rt_fetch(rt_index, rangetable)->archive = false;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -225,7 +225,7 @@ plan_union_queries(Index rt_index,
|
||||
* Returns a list of plans for 'relids' and a list of range table entries
|
||||
* in union_rtentries.
|
||||
*/
|
||||
static List *
|
||||
static List *
|
||||
plan_union_query(List * relids,
|
||||
Index rt_index,
|
||||
RangeTblEntry * rt_entry,
|
||||
@ -233,18 +233,18 @@ plan_union_query(List * relids,
|
||||
UnionFlag flag,
|
||||
List ** union_rtentriesPtr)
|
||||
{
|
||||
List *i;
|
||||
List *union_plans = NIL;
|
||||
List *union_rtentries = NIL;
|
||||
List *i;
|
||||
List *union_plans = NIL;
|
||||
List *union_rtentries = NIL;
|
||||
|
||||
foreach(i, relids)
|
||||
{
|
||||
int relid = lfirsti(i);
|
||||
RangeTblEntry *new_rt_entry = new_rangetable_entry(relid,
|
||||
rt_entry);
|
||||
Query *new_root = subst_rangetable(root,
|
||||
rt_index,
|
||||
new_rt_entry);
|
||||
int relid = lfirsti(i);
|
||||
RangeTblEntry *new_rt_entry = new_rangetable_entry(relid,
|
||||
rt_entry);
|
||||
Query *new_root = subst_rangetable(root,
|
||||
rt_index,
|
||||
new_rt_entry);
|
||||
|
||||
/*
|
||||
* reset the uniqueflag and sortclause in parse tree root, so that
|
||||
@ -288,7 +288,7 @@ plan_union_query(List * relids,
|
||||
static RangeTblEntry *
|
||||
new_rangetable_entry(Oid new_relid, RangeTblEntry * old_entry)
|
||||
{
|
||||
RangeTblEntry *new_entry = copyObject(old_entry);
|
||||
RangeTblEntry *new_entry = copyObject(old_entry);
|
||||
|
||||
/* ??? someone tell me what the following is doing! - ay 11/94 */
|
||||
if (!strcmp(new_entry->refname, "*CURRENT*") ||
|
||||
@ -307,12 +307,12 @@ new_rangetable_entry(Oid new_relid, RangeTblEntry * old_entry)
|
||||
*
|
||||
* Returns a new copy of 'root'.
|
||||
*/
|
||||
static Query *
|
||||
static Query *
|
||||
subst_rangetable(Query * root, Index index, RangeTblEntry * new_entry)
|
||||
{
|
||||
Query *new_root = copyObject(root);
|
||||
List *temp = NIL;
|
||||
int i = 0;
|
||||
Query *new_root = copyObject(root);
|
||||
List *temp = NIL;
|
||||
int i = 0;
|
||||
|
||||
for (temp = new_root->rtable, i = 1; i < index; temp = lnext(temp), i++)
|
||||
;
|
||||
@ -332,54 +332,54 @@ fix_parsetree_attnums_nodes(Index rt_index,
|
||||
|
||||
switch (nodeTag(node))
|
||||
{
|
||||
case T_TargetEntry:
|
||||
{
|
||||
TargetEntry *tle = (TargetEntry *) node;
|
||||
case T_TargetEntry:
|
||||
{
|
||||
TargetEntry *tle = (TargetEntry *) node;
|
||||
|
||||
fix_parsetree_attnums_nodes(rt_index, old_relid, new_relid,
|
||||
tle->expr);
|
||||
}
|
||||
break;
|
||||
case T_Expr:
|
||||
{
|
||||
Expr *expr = (Expr *) node;
|
||||
fix_parsetree_attnums_nodes(rt_index, old_relid, new_relid,
|
||||
tle->expr);
|
||||
}
|
||||
break;
|
||||
case T_Expr:
|
||||
{
|
||||
Expr *expr = (Expr *) node;
|
||||
|
||||
fix_parsetree_attnums_nodes(rt_index, old_relid, new_relid,
|
||||
(Node *) expr->args);
|
||||
}
|
||||
break;
|
||||
case T_Var:
|
||||
{
|
||||
Var *var = (Var *) node;
|
||||
Oid old_typeid,
|
||||
fix_parsetree_attnums_nodes(rt_index, old_relid, new_relid,
|
||||
(Node *) expr->args);
|
||||
}
|
||||
break;
|
||||
case T_Var:
|
||||
{
|
||||
Var *var = (Var *) node;
|
||||
Oid old_typeid,
|
||||
new_typeid;
|
||||
|
||||
/* old_typeid = RelationIdGetTypeId(old_relid);*/
|
||||
/* new_typeid = RelationIdGetTypeId(new_relid);*/
|
||||
old_typeid = old_relid;
|
||||
new_typeid = new_relid;
|
||||
old_typeid = old_relid;
|
||||
new_typeid = new_relid;
|
||||
|
||||
if (var->varno == rt_index && var->varattno != 0)
|
||||
{
|
||||
var->varattno =
|
||||
get_attnum(new_typeid,
|
||||
get_attname(old_typeid, var->varattno));
|
||||
if (var->varno == rt_index && var->varattno != 0)
|
||||
{
|
||||
var->varattno =
|
||||
get_attnum(new_typeid,
|
||||
get_attname(old_typeid, var->varattno));
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case T_List:
|
||||
{
|
||||
List *l;
|
||||
break;
|
||||
case T_List:
|
||||
{
|
||||
List *l;
|
||||
|
||||
foreach(l, (List *) node)
|
||||
{
|
||||
fix_parsetree_attnums_nodes(rt_index, old_relid, new_relid,
|
||||
(Node *) lfirst(l));
|
||||
foreach(l, (List *) node)
|
||||
{
|
||||
fix_parsetree_attnums_nodes(rt_index, old_relid, new_relid,
|
||||
(Node *) lfirst(l));
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -407,13 +407,13 @@ fix_parsetree_attnums(Index rt_index,
|
||||
parsetree->qual);
|
||||
}
|
||||
|
||||
static Append *
|
||||
static Append *
|
||||
make_append(List * unionplans,
|
||||
Index rt_index,
|
||||
List * union_rt_entries,
|
||||
List * tlist)
|
||||
{
|
||||
Append *node = makeNode(Append);
|
||||
Append *node = makeNode(Append);
|
||||
|
||||
node->unionplans = unionplans;
|
||||
node->unionrelid = rt_index;
|
||||
|
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/Attic/clauseinfo.c,v 1.4 1997/09/07 04:44:17 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/Attic/clauseinfo.c,v 1.5 1997/09/08 02:24:48 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -44,12 +44,12 @@ 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;
|
||||
List *result = NIL;
|
||||
CInfo *clause = (CInfo *) NULL;
|
||||
List *temp = NIL;
|
||||
List *result = NIL;
|
||||
CInfo *clause = (CInfo *) NULL;
|
||||
|
||||
foreach(temp, clauseinfo_list)
|
||||
{
|
||||
@ -90,18 +90,18 @@ get_relattvals(List * clauseinfo_list,
|
||||
List ** values,
|
||||
List ** flags)
|
||||
{
|
||||
List *result1 = NIL;
|
||||
List *result2 = NIL;
|
||||
List *result3 = NIL;
|
||||
CInfo *temp = (CInfo *) NULL;
|
||||
List *i = NIL;
|
||||
List *result1 = NIL;
|
||||
List *result2 = NIL;
|
||||
List *result3 = NIL;
|
||||
CInfo *temp = (CInfo *) NULL;
|
||||
List *i = NIL;
|
||||
|
||||
foreach(i, clauseinfo_list)
|
||||
{
|
||||
int dummy;
|
||||
AttrNumber attno;
|
||||
Datum constval;
|
||||
int flag;
|
||||
int dummy;
|
||||
AttrNumber attno;
|
||||
Datum constval;
|
||||
int flag;
|
||||
|
||||
temp = (CInfo *) lfirst(i);
|
||||
get_relattval((Node *) temp->clause, &dummy, &attno, &constval, &flag);
|
||||
@ -137,15 +137,15 @@ get_joinvars(Oid relid,
|
||||
List ** values,
|
||||
List ** flags)
|
||||
{
|
||||
List *result1 = NIL;
|
||||
List *result2 = NIL;
|
||||
List *result3 = NIL;
|
||||
List *temp;
|
||||
List *result1 = NIL;
|
||||
List *result2 = NIL;
|
||||
List *result3 = NIL;
|
||||
List *temp;
|
||||
|
||||
foreach(temp, clauseinfo_list)
|
||||
{
|
||||
CInfo *clauseinfo = lfirst(temp);
|
||||
Expr *clause = clauseinfo->clause;
|
||||
CInfo *clauseinfo = lfirst(temp);
|
||||
Expr *clause = clauseinfo->clause;
|
||||
|
||||
if (IsA(get_leftop(clause), Var) &&
|
||||
(relid == (get_leftop(clause))->varno))
|
||||
@ -173,12 +173,12 @@ 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;
|
||||
List *result = NIL;
|
||||
List *i = NIL;
|
||||
CInfo *temp = (CInfo *) NULL;
|
||||
List *result = NIL;
|
||||
List *i = NIL;
|
||||
|
||||
foreach(i, clauseinfo_list)
|
||||
{
|
||||
|
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v 1.8 1997/09/07 04:44:20 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v 1.9 1997/09/08 02:24:52 momjian Exp $
|
||||
*
|
||||
* HISTORY
|
||||
* AUTHOR DATE MAJOR EVENT
|
||||
@ -34,16 +34,16 @@
|
||||
#include "optimizer/internal.h"
|
||||
#include "optimizer/var.h"
|
||||
|
||||
static bool agg_clause(Node * clause);
|
||||
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 ||
|
||||
type == OP_EXPR || type == FUNC_EXPR)
|
||||
{
|
||||
Expr *expr = makeNode(Expr);
|
||||
Expr *expr = makeNode(Expr);
|
||||
|
||||
/*
|
||||
* assume type checking already done and we don't need the type of
|
||||
@ -92,10 +92,10 @@ is_opclause(Node * clause)
|
||||
* operand (if it is non-null).
|
||||
*
|
||||
*/
|
||||
Expr *
|
||||
Expr *
|
||||
make_opclause(Oper * op, Var * leftop, Var * rightop)
|
||||
{
|
||||
Expr *expr = makeNode(Expr);
|
||||
Expr *expr = makeNode(Expr);
|
||||
|
||||
expr->typeOid = InvalidOid; /* assume type checking done */
|
||||
expr->opType = OP_EXPR;
|
||||
@ -111,7 +111,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)
|
||||
@ -126,7 +126,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)
|
||||
@ -139,7 +139,7 @@ get_rightop(Expr * clause)
|
||||
* AGG clause functions
|
||||
*****************************************************************************/
|
||||
|
||||
static bool
|
||||
static bool
|
||||
agg_clause(Node * clause)
|
||||
{
|
||||
return
|
||||
@ -171,10 +171,10 @@ is_funcclause(Node * clause)
|
||||
* arguments.
|
||||
*
|
||||
*/
|
||||
Expr *
|
||||
Expr *
|
||||
make_funcclause(Func * func, List * funcargs)
|
||||
{
|
||||
Expr *expr = makeNode(Expr);
|
||||
Expr *expr = makeNode(Expr);
|
||||
|
||||
expr->typeOid = InvalidOid; /* assume type checking done */
|
||||
expr->opType = FUNC_EXPR;
|
||||
@ -207,10 +207,10 @@ or_clause(Node * clause)
|
||||
* Creates an 'or' clause given a list of its subclauses.
|
||||
*
|
||||
*/
|
||||
Expr *
|
||||
Expr *
|
||||
make_orclause(List * orclauses)
|
||||
{
|
||||
Expr *expr = makeNode(Expr);
|
||||
Expr *expr = makeNode(Expr);
|
||||
|
||||
expr->typeOid = InvalidOid; /* assume type checking done */
|
||||
expr->opType = OR_EXPR;
|
||||
@ -243,10 +243,10 @@ not_clause(Node * clause)
|
||||
* Create a 'not' clause given the expression to be negated.
|
||||
*
|
||||
*/
|
||||
Expr *
|
||||
Expr *
|
||||
make_notclause(Expr * notclause)
|
||||
{
|
||||
Expr *expr = makeNode(Expr);
|
||||
Expr *expr = makeNode(Expr);
|
||||
|
||||
expr->typeOid = InvalidOid; /* assume type checking done */
|
||||
expr->opType = NOT_EXPR;
|
||||
@ -261,7 +261,7 @@ make_notclause(Expr * notclause)
|
||||
* Retrieve the clause within a 'not' clause
|
||||
*
|
||||
*/
|
||||
Expr *
|
||||
Expr *
|
||||
get_notclausearg(Expr * notclause)
|
||||
{
|
||||
return (lfirst(notclause->args));
|
||||
@ -292,10 +292,10 @@ and_clause(Node * clause)
|
||||
* Create an 'and' clause given its arguments in a list.
|
||||
*
|
||||
*/
|
||||
Expr *
|
||||
Expr *
|
||||
make_andclause(List * andclauses)
|
||||
{
|
||||
Expr *expr = makeNode(Expr);
|
||||
Expr *expr = makeNode(Expr);
|
||||
|
||||
expr->typeOid = InvalidOid; /* assume type checking done */
|
||||
expr->opType = AND_EXPR;
|
||||
@ -320,12 +320,12 @@ make_andclause(List * andclauses)
|
||||
* quals as the return value.
|
||||
*
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
pull_constant_clauses(List * quals, List ** constantQual)
|
||||
{
|
||||
List *q;
|
||||
List *constqual = NIL;
|
||||
List *restqual = NIL;
|
||||
List *q;
|
||||
List *constqual = NIL;
|
||||
List *restqual = NIL;
|
||||
|
||||
foreach(q, quals)
|
||||
{
|
||||
@ -358,15 +358,15 @@ pull_constant_clauses(List * quals, List ** constantQual)
|
||||
void
|
||||
clause_relids_vars(Node * clause, List ** relids, List ** vars)
|
||||
{
|
||||
List *clvars = pull_var_clause(clause);
|
||||
List *var_list = NIL;
|
||||
List *varno_list = NIL;
|
||||
List *i = NIL;
|
||||
List *clvars = pull_var_clause(clause);
|
||||
List *var_list = NIL;
|
||||
List *varno_list = NIL;
|
||||
List *i = NIL;
|
||||
|
||||
foreach(i, clvars)
|
||||
{
|
||||
Var *var = (Var *) lfirst(i);
|
||||
List *vi;
|
||||
Var *var = (Var *) lfirst(i);
|
||||
List *vi;
|
||||
|
||||
if (!intMember(var->varno, varno_list))
|
||||
{
|
||||
@ -374,7 +374,7 @@ clause_relids_vars(Node * clause, List ** relids, List ** vars)
|
||||
}
|
||||
foreach(vi, var_list)
|
||||
{
|
||||
Var *in_list = (Var *) lfirst(vi);
|
||||
Var *in_list = (Var *) lfirst(vi);
|
||||
|
||||
if (in_list->varno == var->varno &&
|
||||
in_list->varattno == var->varattno)
|
||||
@ -398,13 +398,13 @@ clause_relids_vars(Node * clause, List ** relids, List ** vars)
|
||||
int
|
||||
NumRelids(Node * clause)
|
||||
{
|
||||
List *vars = pull_var_clause(clause);
|
||||
List *i = NIL;
|
||||
List *var_list = NIL;
|
||||
List *vars = pull_var_clause(clause);
|
||||
List *i = NIL;
|
||||
List *var_list = NIL;
|
||||
|
||||
foreach(i, vars)
|
||||
{
|
||||
Var *var = (Var *) lfirst(i);
|
||||
Var *var = (Var *) lfirst(i);
|
||||
|
||||
if (!intMember(var->varno, var_list))
|
||||
{
|
||||
@ -433,7 +433,7 @@ contains_not(Node * clause)
|
||||
|
||||
if (or_clause(clause))
|
||||
{
|
||||
List *a;
|
||||
List *a;
|
||||
|
||||
foreach(a, ((Expr *) clause)->args)
|
||||
{
|
||||
@ -454,8 +454,8 @@ contains_not(Node * clause)
|
||||
bool
|
||||
join_clause_p(Node * clause)
|
||||
{
|
||||
Node *leftop,
|
||||
*rightop;
|
||||
Node *leftop,
|
||||
*rightop;
|
||||
|
||||
if (!is_opclause(clause))
|
||||
return false;
|
||||
@ -528,7 +528,7 @@ fix_opid(Node * clause)
|
||||
}
|
||||
else if (IsA(clause, ArrayRef))
|
||||
{
|
||||
ArrayRef *aref = (ArrayRef *) clause;
|
||||
ArrayRef *aref = (ArrayRef *) clause;
|
||||
|
||||
fix_opids(aref->refupperindexpr);
|
||||
fix_opids(aref->reflowerindexpr);
|
||||
@ -559,10 +559,10 @@ fix_opid(Node * clause)
|
||||
* Returns its argument.
|
||||
*
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
fix_opids(List * clauses)
|
||||
{
|
||||
List *clause;
|
||||
List *clause;
|
||||
|
||||
foreach(clause, clauses)
|
||||
fix_opid(lfirst(clause));
|
||||
@ -601,8 +601,8 @@ get_relattval(Node * clause,
|
||||
Datum * constval,
|
||||
int *flag)
|
||||
{
|
||||
Var *left = get_leftop((Expr *) clause);
|
||||
Var *right = get_rightop((Expr *) clause);
|
||||
Var *left = get_leftop((Expr *) clause);
|
||||
Var *right = get_rightop((Expr *) clause);
|
||||
|
||||
if (is_opclause(clause) && IsA(left, Var) &&
|
||||
IsA(right, Const))
|
||||
@ -641,7 +641,7 @@ get_relattval(Node * clause,
|
||||
is_funcclause((Node *) left) &&
|
||||
IsA(right, Const))
|
||||
{
|
||||
List *args = ((Expr *) left)->args;
|
||||
List *args = ((Expr *) left)->args;
|
||||
|
||||
|
||||
*relid = ((Var *) lfirst(args))->varno;
|
||||
@ -662,7 +662,7 @@ get_relattval(Node * clause,
|
||||
is_funcclause((Node *) right) &&
|
||||
IsA(left, Const))
|
||||
{
|
||||
List *args = ((Expr *) right)->args;
|
||||
List *args = ((Expr *) right)->args;
|
||||
|
||||
*relid = ((Var *) lfirst(args))->varno;
|
||||
*attno = InvalidAttrNumber;
|
||||
@ -732,13 +732,13 @@ get_rels_atts(Node * clause,
|
||||
int *relid2,
|
||||
AttrNumber * attno2)
|
||||
{
|
||||
Var *left = get_leftop((Expr *) clause);
|
||||
Var *right = get_rightop((Expr *) clause);
|
||||
bool var_left = (IsA(left, Var));
|
||||
bool var_right = (IsA(right, Var));
|
||||
bool varexpr_left = (bool) ((IsA(left, Func) || IsA(left, Oper)) &&
|
||||
contain_var_clause((Node *) left));
|
||||
bool varexpr_right = (bool) ((IsA(right, Func) || IsA(right, Oper)) &&
|
||||
Var *left = get_leftop((Expr *) clause);
|
||||
Var *right = get_rightop((Expr *) clause);
|
||||
bool var_left = (IsA(left, Var));
|
||||
bool var_right = (IsA(right, Var));
|
||||
bool varexpr_left = (bool) ((IsA(left, Func) || IsA(left, Oper)) &&
|
||||
contain_var_clause((Node *) left));
|
||||
bool varexpr_right = (bool) ((IsA(right, Func) || IsA(right, Oper)) &&
|
||||
contain_var_clause((Node *) right));
|
||||
|
||||
if (is_opclause(clause))
|
||||
@ -782,10 +782,10 @@ get_rels_atts(Node * clause,
|
||||
void
|
||||
CommuteClause(Node * clause)
|
||||
{
|
||||
Node *temp;
|
||||
Oper *commu;
|
||||
Node *temp;
|
||||
Oper *commu;
|
||||
OperatorTupleForm commuTup;
|
||||
HeapTuple heapTup;
|
||||
HeapTuple heapTup;
|
||||
|
||||
if (!is_opclause(clause))
|
||||
return;
|
||||
|
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/Attic/indexnode.c,v 1.3 1997/09/07 04:44:22 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/Attic/indexnode.c,v 1.4 1997/09/08 02:24:54 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -24,7 +24,7 @@
|
||||
#include "optimizer/pathnode.h" /* where the decls go */
|
||||
|
||||
|
||||
static List *find_secondary_index(Query * root, Oid relid);
|
||||
static List *find_secondary_index(Query * root, Oid relid);
|
||||
|
||||
/*
|
||||
* find-relation-indices--
|
||||
@ -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)
|
||||
@ -56,16 +56,16 @@ find_relation_indices(Query * root, Rel * rel)
|
||||
* Returns a list of new index nodes.
|
||||
*
|
||||
*/
|
||||
static List *
|
||||
static List *
|
||||
find_secondary_index(Query * root, Oid relid)
|
||||
{
|
||||
IdxInfoRetval indexinfo;
|
||||
List *indexes = NIL;
|
||||
bool first = TRUE;
|
||||
IdxInfoRetval indexinfo;
|
||||
List *indexes = NIL;
|
||||
bool first = TRUE;
|
||||
|
||||
while (index_info(root, first, relid, &indexinfo))
|
||||
{
|
||||
Rel *indexnode = makeNode(Rel);
|
||||
Rel *indexnode = makeNode(Rel);
|
||||
|
||||
indexnode->relids = lconsi(indexinfo.relid, NIL);
|
||||
indexnode->relam = indexinfo.relam;
|
||||
|
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/Attic/internal.c,v 1.4 1997/09/07 04:44:24 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/Attic/internal.c,v 1.5 1997/09/08 02:24:56 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -38,17 +38,17 @@
|
||||
|
||||
/* the following should probably be moved elsewhere -ay */
|
||||
|
||||
TargetEntry *
|
||||
TargetEntry *
|
||||
MakeTLE(Resdom * resdom, Node * expr)
|
||||
{
|
||||
TargetEntry *rt = makeNode(TargetEntry);
|
||||
TargetEntry *rt = makeNode(TargetEntry);
|
||||
|
||||
rt->resdom = resdom;
|
||||
rt->expr = 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.3 1997/09/07 04:44:27 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/joininfo.c,v 1.4 1997/09/08 02:24:57 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -35,11 +35,11 @@
|
||||
* exists.
|
||||
*
|
||||
*/
|
||||
JInfo *
|
||||
JInfo *
|
||||
joininfo_member(List * join_relids, List * joininfo_list)
|
||||
{
|
||||
List *i = NIL;
|
||||
List *other_rels = NIL;
|
||||
List *i = NIL;
|
||||
List *other_rels = NIL;
|
||||
|
||||
foreach(i, joininfo_list)
|
||||
{
|
||||
@ -61,11 +61,11 @@ 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,
|
||||
this_rel->joininfo);
|
||||
JInfo *joininfo = joininfo_member(join_relids,
|
||||
this_rel->joininfo);
|
||||
|
||||
if (joininfo == NULL)
|
||||
{
|
||||
@ -88,12 +88,12 @@ 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;
|
||||
Var *l,
|
||||
*r;
|
||||
Var *retval;
|
||||
Var *l,
|
||||
*r;
|
||||
|
||||
retval = (Var *) NULL;
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/Attic/keys.c,v 1.3 1997/09/07 04:44:28 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/Attic/keys.c,v 1.4 1997/09/08 02:24:58 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -22,8 +22,8 @@
|
||||
#include "optimizer/tlist.h"
|
||||
|
||||
|
||||
static Expr *matching2_tlvar(int var, List * tlist, bool(*test) ());
|
||||
static bool equal_indexkey_var(int index_key, Var * var);
|
||||
static Expr *matching2_tlvar(int var, List * tlist, bool(*test) ());
|
||||
static bool equal_indexkey_var(int index_key, Var * var);
|
||||
|
||||
/*
|
||||
* 1. index key
|
||||
@ -70,7 +70,7 @@ match_indexkey_operand(int indexkey, Var * operand, Rel * rel)
|
||||
* fields of var node 'var'.
|
||||
*
|
||||
*/
|
||||
static bool
|
||||
static bool
|
||||
equal_indexkey_var(int index_key, Var * var)
|
||||
{
|
||||
if (index_key == var->varattno)
|
||||
@ -85,22 +85,22 @@ equal_indexkey_var(int index_key, Var * var)
|
||||
* lelation.
|
||||
*
|
||||
*/
|
||||
Var *
|
||||
Var *
|
||||
extract_subkey(JoinKey * jk, int which_subkey)
|
||||
{
|
||||
Var *retval;
|
||||
Var *retval;
|
||||
|
||||
switch (which_subkey)
|
||||
{
|
||||
case OUTER:
|
||||
retval = jk->outer;
|
||||
break;
|
||||
case INNER:
|
||||
retval = jk->inner;
|
||||
break;
|
||||
default: /* do nothing */
|
||||
elog(DEBUG, "extract_subkey with neither INNER or OUTER");
|
||||
retval = NULL;
|
||||
case OUTER:
|
||||
retval = jk->outer;
|
||||
break;
|
||||
case INNER:
|
||||
retval = jk->inner;
|
||||
break;
|
||||
default: /* do nothing */
|
||||
elog(DEBUG, "extract_subkey with neither INNER or OUTER");
|
||||
retval = NULL;
|
||||
}
|
||||
return (retval);
|
||||
}
|
||||
@ -120,9 +120,9 @@ extract_subkey(JoinKey * jk, int which_subkey)
|
||||
bool
|
||||
samekeys(List * keys1, List * keys2)
|
||||
{
|
||||
bool allmember = true;
|
||||
List *key1,
|
||||
*key2;
|
||||
bool allmember = true;
|
||||
List *key1,
|
||||
*key2;
|
||||
|
||||
for (key1 = keys1, key2 = keys2; key1 != NIL && key2 != NIL;
|
||||
key1 = lnext(key1), key2 = lnext(key2))
|
||||
@ -152,14 +152,14 @@ samekeys(List * keys1, List * keys2)
|
||||
/* This function is identical to matching_tlvar and tlistentry_member.
|
||||
* They should be merged.
|
||||
*/
|
||||
static Expr *
|
||||
static Expr *
|
||||
matching2_tlvar(int var, List * tlist, bool(*test) ())
|
||||
{
|
||||
TargetEntry *tlentry = NULL;
|
||||
TargetEntry *tlentry = NULL;
|
||||
|
||||
if (var)
|
||||
{
|
||||
List *temp;
|
||||
List *temp;
|
||||
|
||||
foreach(temp, tlist)
|
||||
{
|
||||
@ -178,16 +178,16 @@ matching2_tlvar(int var, List * tlist, bool(*test) ())
|
||||
}
|
||||
|
||||
|
||||
List *
|
||||
List *
|
||||
collect_index_pathkeys(int *index_keys, List * tlist)
|
||||
{
|
||||
List *retval = NIL;
|
||||
List *retval = NIL;
|
||||
|
||||
Assert(index_keys != NULL);
|
||||
|
||||
while (index_keys[0] != 0)
|
||||
{
|
||||
Expr *mvar;
|
||||
Expr *mvar;
|
||||
|
||||
mvar = matching2_tlvar(index_keys[0],
|
||||
tlist,
|
||||
|
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/Attic/ordering.c,v 1.4 1997/09/07 04:44:30 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/Attic/ordering.c,v 1.5 1997/09/08 02:24:58 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -18,7 +18,7 @@
|
||||
#include "optimizer/internal.h"
|
||||
#include "optimizer/ordering.h"
|
||||
|
||||
static bool equal_sortops_order(Oid * ordering1, Oid * ordering2);
|
||||
static bool equal_sortops_order(Oid * ordering1, Oid * ordering2);
|
||||
|
||||
/*
|
||||
* equal-path-path-ordering--
|
||||
@ -110,10 +110,10 @@ equal_merge_merge_ordering(MergeOrder * merge_ordering1,
|
||||
* equal_sort_ops_order -
|
||||
* Returns true iff the sort operators are in the same order.
|
||||
*/
|
||||
static bool
|
||||
static bool
|
||||
equal_sortops_order(Oid * ordering1, Oid * ordering2)
|
||||
{
|
||||
int i = 0;
|
||||
int i = 0;
|
||||
|
||||
if (ordering1 == NULL || ordering2 == NULL)
|
||||
return (ordering1 == ordering2);
|
||||
|
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/pathnode.c,v 1.4 1997/09/07 04:44:30 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/pathnode.c,v 1.5 1997/09/08 02:24:59 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -29,7 +29,7 @@
|
||||
|
||||
#include "parser/parsetree.h" /* for getrelid() */
|
||||
|
||||
static Path *better_path(Path * new_path, List * unique_paths, bool * noOther);
|
||||
static Path *better_path(Path * new_path, List * unique_paths, bool * noOther);
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
@ -44,8 +44,8 @@ static Path *better_path(Path * new_path, List * unique_paths, bool * noOther
|
||||
bool
|
||||
path_is_cheaper(Path * path1, Path * path2)
|
||||
{
|
||||
Cost cost1 = path1->path_cost;
|
||||
Cost cost2 = path2->path_cost;
|
||||
Cost cost1 = path1->path_cost;
|
||||
Cost cost2 = path2->path_cost;
|
||||
|
||||
return ((bool) (cost1 < cost2));
|
||||
}
|
||||
@ -61,11 +61,11 @@ path_is_cheaper(Path * path1, Path * path2)
|
||||
* is minimum.
|
||||
*
|
||||
*/
|
||||
Path *
|
||||
Path *
|
||||
set_cheapest(Rel * parent_rel, List * pathlist)
|
||||
{
|
||||
List *p;
|
||||
Path *cheapest_so_far;
|
||||
List *p;
|
||||
Path *cheapest_so_far;
|
||||
|
||||
Assert(pathlist != NIL);
|
||||
Assert(IsA(parent_rel, Rel));
|
||||
@ -74,7 +74,7 @@ set_cheapest(Rel * parent_rel, List * pathlist)
|
||||
|
||||
foreach(p, lnext(pathlist))
|
||||
{
|
||||
Path *path = (Path *) lfirst(p);
|
||||
Path *path = (Path *) lfirst(p);
|
||||
|
||||
if (path_is_cheaper(path, cheapest_so_far))
|
||||
{
|
||||
@ -100,13 +100,13 @@ 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;
|
||||
Path *new_path;
|
||||
Path *old_path;
|
||||
bool noOther;
|
||||
List *x;
|
||||
Path *new_path;
|
||||
Path *old_path;
|
||||
bool noOther;
|
||||
|
||||
foreach(x, new_paths)
|
||||
{
|
||||
@ -153,13 +153,13 @@ add_pathlist(Rel * parent_rel, List * unique_paths, List * new_paths)
|
||||
* t - if there is no path in the list with the same ordering and keys
|
||||
*
|
||||
*/
|
||||
static Path *
|
||||
static Path *
|
||||
better_path(Path * new_path, List * unique_paths, bool * noOther)
|
||||
{
|
||||
Path *old_path = (Path *) NULL;
|
||||
Path *path = (Path *) NULL;
|
||||
List *temp = NIL;
|
||||
Path *retval = NULL;
|
||||
Path *old_path = (Path *) NULL;
|
||||
Path *path = (Path *) NULL;
|
||||
List *temp = NIL;
|
||||
Path *retval = NULL;
|
||||
|
||||
/*
|
||||
* XXX - added the following two lines which weren't int the lisp
|
||||
@ -207,12 +207,12 @@ better_path(Path * new_path, List * unique_paths, bool * noOther)
|
||||
* pathnode.
|
||||
*
|
||||
*/
|
||||
Path *
|
||||
Path *
|
||||
create_seqscan_path(Rel * rel)
|
||||
{
|
||||
int relid = 0;
|
||||
int relid = 0;
|
||||
|
||||
Path *pathnode = makeNode(Path);
|
||||
Path *pathnode = makeNode(Path);
|
||||
|
||||
pathnode->pathtype = T_SeqScan;
|
||||
pathnode->parent = rel;
|
||||
@ -257,14 +257,14 @@ create_seqscan_path(Rel * rel)
|
||||
* Returns the new path node.
|
||||
*
|
||||
*/
|
||||
IndexPath *
|
||||
IndexPath *
|
||||
create_index_path(Query * root,
|
||||
Rel * rel,
|
||||
Rel * index,
|
||||
List * restriction_clauses,
|
||||
bool is_join_scan)
|
||||
{
|
||||
IndexPath *pathnode = makeNode(IndexPath);
|
||||
IndexPath *pathnode = makeNode(IndexPath);
|
||||
|
||||
pathnode->path.pathtype = T_IndexScan;
|
||||
pathnode->path.parent = rel;
|
||||
@ -344,12 +344,12 @@ create_index_path(Query * root,
|
||||
* Compute scan cost for the case when 'index' is used with a
|
||||
* restriction clause.
|
||||
*/
|
||||
List *attnos;
|
||||
List *values;
|
||||
List *flags;
|
||||
float npages;
|
||||
float selec;
|
||||
Cost clausesel;
|
||||
List *attnos;
|
||||
List *values;
|
||||
List *flags;
|
||||
float npages;
|
||||
float selec;
|
||||
Cost clausesel;
|
||||
|
||||
get_relattvals(restriction_clauses,
|
||||
&attnos,
|
||||
@ -417,14 +417,14 @@ create_index_path(Query * root,
|
||||
* Returns the resulting path node.
|
||||
*
|
||||
*/
|
||||
JoinPath *
|
||||
JoinPath *
|
||||
create_nestloop_path(Rel * joinrel,
|
||||
Rel * outer_rel,
|
||||
Path * outer_path,
|
||||
Path * inner_path,
|
||||
List * keys)
|
||||
{
|
||||
JoinPath *pathnode = makeNode(JoinPath);
|
||||
JoinPath *pathnode = makeNode(JoinPath);
|
||||
|
||||
pathnode->path.pathtype = T_NestLoop;
|
||||
pathnode->path.parent = joinrel;
|
||||
@ -494,7 +494,7 @@ create_nestloop_path(Rel * joinrel,
|
||||
* 'innersortkeys' are the sort varkeys for the inner relation
|
||||
*
|
||||
*/
|
||||
MergePath *
|
||||
MergePath *
|
||||
create_mergesort_path(Rel * joinrel,
|
||||
int outersize,
|
||||
int innersize,
|
||||
@ -508,7 +508,7 @@ create_mergesort_path(Rel * joinrel,
|
||||
List * outersortkeys,
|
||||
List * innersortkeys)
|
||||
{
|
||||
MergePath *pathnode = makeNode(MergePath);
|
||||
MergePath *pathnode = makeNode(MergePath);
|
||||
|
||||
pathnode->jpath.path.pathtype = T_MergeJoin;
|
||||
pathnode->jpath.path.parent = joinrel;
|
||||
@ -560,7 +560,7 @@ create_mergesort_path(Rel * joinrel,
|
||||
* 'innerkeys' are the sort varkeys for the inner relation
|
||||
*
|
||||
*/
|
||||
HashPath *
|
||||
HashPath *
|
||||
create_hashjoin_path(Rel * joinrel,
|
||||
int outersize,
|
||||
int innersize,
|
||||
@ -574,7 +574,7 @@ create_hashjoin_path(Rel * joinrel,
|
||||
List * outerkeys,
|
||||
List * innerkeys)
|
||||
{
|
||||
HashPath *pathnode = makeNode(HashPath);
|
||||
HashPath *pathnode = makeNode(HashPath);
|
||||
|
||||
pathnode->jpath.path.pathtype = T_HashJoin;
|
||||
pathnode->jpath.path.parent = joinrel;
|
||||
|
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/plancat.c,v 1.7 1997/09/07 04:44:31 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/plancat.c,v 1.8 1997/09/08 02:25:01 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -59,9 +59,9 @@ void
|
||||
relation_info(Query * root, Index relid,
|
||||
bool * hasindex, int *pages, int *tuples)
|
||||
{
|
||||
HeapTuple relationTuple;
|
||||
Form_pg_class relation;
|
||||
Oid relationObjectId;
|
||||
HeapTuple relationTuple;
|
||||
Form_pg_class relation;
|
||||
Oid relationObjectId;
|
||||
|
||||
relationObjectId = getrelid(relid, root->rtable);
|
||||
relationTuple = SearchSysCacheTuple(RELOID,
|
||||
@ -103,14 +103,14 @@ relation_info(Query * root, Index relid,
|
||||
bool
|
||||
index_info(Query * root, bool first, int relid, IdxInfoRetval * info)
|
||||
{
|
||||
register i;
|
||||
HeapTuple indexTuple,
|
||||
amopTuple;
|
||||
IndexTupleForm index;
|
||||
Relation indexRelation;
|
||||
uint16 amstrategy;
|
||||
Oid relam;
|
||||
Oid indrelid;
|
||||
register i;
|
||||
HeapTuple indexTuple,
|
||||
amopTuple;
|
||||
IndexTupleForm index;
|
||||
Relation indexRelation;
|
||||
uint16 amstrategy;
|
||||
Oid relam;
|
||||
Oid indrelid;
|
||||
|
||||
static Relation relation = (Relation) NULL;
|
||||
static HeapScanDesc scan = (HeapScanDesc) NULL;
|
||||
@ -183,7 +183,7 @@ index_info(Query * root, bool first, int relid, IdxInfoRetval * info)
|
||||
* which is all within a command, so the automatic pfree at end of
|
||||
* transaction should be ok.
|
||||
*/
|
||||
char *predString;
|
||||
char *predString;
|
||||
|
||||
predString = fmgr(F_TEXTOUT, &index->indpred);
|
||||
info->indpred = (Node *) stringToNode(predString);
|
||||
@ -256,15 +256,15 @@ index_selectivity(Oid indid,
|
||||
float *idxPages,
|
||||
float *idxSelec)
|
||||
{
|
||||
Oid *opno_array;
|
||||
int *attno_array,
|
||||
*flag_array;
|
||||
char **value_array;
|
||||
int i = 0;
|
||||
List *xopno,
|
||||
*xattno,
|
||||
*value,
|
||||
*flag;
|
||||
Oid *opno_array;
|
||||
int *attno_array,
|
||||
*flag_array;
|
||||
char **value_array;
|
||||
int i = 0;
|
||||
List *xopno,
|
||||
*xattno,
|
||||
*value,
|
||||
*flag;
|
||||
|
||||
if (length(opnos) != nkeys || length(attnos) != nkeys ||
|
||||
length(values) != nkeys || length(flags) != nkeys)
|
||||
@ -339,7 +339,7 @@ restriction_selectivity(Oid functionObjectId,
|
||||
char *constValue,
|
||||
int32 constFlag)
|
||||
{
|
||||
float64 result;
|
||||
float64 result;
|
||||
|
||||
result = (float64) fmgr(functionObjectId,
|
||||
(char *) operatorObjectId,
|
||||
@ -378,7 +378,7 @@ join_selectivity(Oid functionObjectId,
|
||||
Oid relationObjectId2,
|
||||
AttrNumber attributeNumber2)
|
||||
{
|
||||
float64 result;
|
||||
float64 result;
|
||||
|
||||
result = (float64) fmgr(functionObjectId,
|
||||
(char *) operatorObjectId,
|
||||
@ -403,18 +403,18 @@ 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] = {
|
||||
{0, Anum_pg_inherits_inhparent, F_OIDEQ}
|
||||
};
|
||||
|
||||
HeapTuple inheritsTuple;
|
||||
Relation relation;
|
||||
HeapScanDesc scan;
|
||||
List *list = NIL;
|
||||
Oid inhrelid;
|
||||
HeapTuple inheritsTuple;
|
||||
Relation relation;
|
||||
HeapScanDesc scan;
|
||||
List *list = NIL;
|
||||
Oid inhrelid;
|
||||
|
||||
fmgr_info(F_OIDEQ, &key[0].sk_func, &key[0].sk_nargs);
|
||||
|
||||
@ -439,18 +439,18 @@ 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] = {
|
||||
{0, Anum_pg_version_verrelid, F_OIDEQ}
|
||||
};
|
||||
|
||||
HeapTuple versionTuple;
|
||||
Relation relation;
|
||||
HeapScanDesc scan;
|
||||
Oid verbaseid;
|
||||
List *list = NIL;
|
||||
HeapTuple versionTuple;
|
||||
Relation relation;
|
||||
HeapScanDesc scan;
|
||||
Oid verbaseid;
|
||||
List *list = NIL;
|
||||
|
||||
fmgr_info(F_OIDEQ, &key[0].sk_func, &key[0].sk_nargs);
|
||||
relation = heap_openr(VersionRelationName);
|
||||
@ -512,21 +512,21 @@ IndexSelectivity(Oid indexrelid,
|
||||
float *idxPages,
|
||||
float *idxSelec)
|
||||
{
|
||||
register i,
|
||||
n;
|
||||
HeapTuple indexTuple,
|
||||
amopTuple,
|
||||
indRel;
|
||||
IndexTupleForm index;
|
||||
Form_pg_amop amop;
|
||||
Oid indclass;
|
||||
float64data npages,
|
||||
select;
|
||||
float64 amopnpages,
|
||||
amopselect;
|
||||
Oid relam;
|
||||
bool nphack = false;
|
||||
float64data fattr_select = 1.0;
|
||||
register i,
|
||||
n;
|
||||
HeapTuple indexTuple,
|
||||
amopTuple,
|
||||
indRel;
|
||||
IndexTupleForm index;
|
||||
Form_pg_amop amop;
|
||||
Oid indclass;
|
||||
float64data npages,
|
||||
select;
|
||||
float64 amopnpages,
|
||||
amopselect;
|
||||
Oid relam;
|
||||
bool nphack = false;
|
||||
float64data fattr_select = 1.0;
|
||||
|
||||
indRel = SearchSysCacheTuple(RELOID,
|
||||
ObjectIdGetDatum(indexrelid),
|
||||
|
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/relnode.c,v 1.2 1997/09/07 04:44:32 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/relnode.c,v 1.3 1997/09/08 02:25:02 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -27,11 +27,11 @@
|
||||
* necessary. This is for base relations.
|
||||
*
|
||||
*/
|
||||
Rel *
|
||||
Rel *
|
||||
get_base_rel(Query * root, int relid)
|
||||
{
|
||||
List *relids;
|
||||
Rel *rel;
|
||||
List *relids;
|
||||
Rel *rel;
|
||||
|
||||
relids = lconsi(relid, NIL);
|
||||
rel = rel_member(relids, root->base_relation_list_);
|
||||
@ -77,9 +77,9 @@ get_base_rel(Query * root, int relid)
|
||||
}
|
||||
else
|
||||
{
|
||||
bool hasindex;
|
||||
int pages,
|
||||
tuples;
|
||||
bool hasindex;
|
||||
int pages,
|
||||
tuples;
|
||||
|
||||
/*
|
||||
* Otherwise, retrieve relation characteristics from the
|
||||
@ -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,11 +114,11 @@ 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;
|
||||
List *temprelid = NIL;
|
||||
List *temp = NIL;
|
||||
List *temprelid = NIL;
|
||||
|
||||
if (relid != NIL && rels != NIL)
|
||||
{
|
||||
|
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/tlist.c,v 1.5 1997/09/07 04:44:33 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/tlist.c,v 1.6 1997/09/08 02:25:03 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -28,7 +28,7 @@
|
||||
#include "nodes/makefuncs.h"
|
||||
#include "parser/catalog_utils.h"
|
||||
|
||||
static Node *flatten_tlistentry(Node * tlistentry, List * flat_tlist);
|
||||
static Node *flatten_tlistentry(Node * tlistentry, List * flat_tlist);
|
||||
|
||||
/*****************************************************************************
|
||||
* ---------- RELATION node target list routines ----------
|
||||
@ -44,12 +44,12 @@ static Node *flatten_tlistentry(Node * tlistentry, List * flat_tlist);
|
||||
* var = valid var-node
|
||||
* targetlist = valid sequence
|
||||
*/
|
||||
TargetEntry *
|
||||
TargetEntry *
|
||||
tlistentry_member(Var * var, List * targetlist)
|
||||
{
|
||||
if (var)
|
||||
{
|
||||
List *temp = NIL;
|
||||
List *temp = NIL;
|
||||
|
||||
foreach(temp, targetlist)
|
||||
{
|
||||
@ -69,10 +69,10 @@ tlistentry_member(Var * var, List * targetlist)
|
||||
* REQUIRES: "test" operates on lispval unions,
|
||||
*
|
||||
*/
|
||||
Expr *
|
||||
Expr *
|
||||
matching_tlvar(Var * var, List * targetlist)
|
||||
{
|
||||
TargetEntry *tlentry;
|
||||
TargetEntry *tlentry;
|
||||
|
||||
tlentry = tlistentry_member(var, targetlist);
|
||||
if (tlentry)
|
||||
@ -96,7 +96,7 @@ matching_tlvar(Var * var, List * targetlist)
|
||||
void
|
||||
add_tl_element(Rel * rel, Var * var)
|
||||
{
|
||||
Expr *oldvar = (Expr *) NULL;
|
||||
Expr *oldvar = (Expr *) NULL;
|
||||
|
||||
oldvar = matching_tlvar(var, rel->targetlist);
|
||||
|
||||
@ -105,12 +105,12 @@ add_tl_element(Rel * rel, Var * var)
|
||||
*/
|
||||
if (oldvar == NULL)
|
||||
{
|
||||
List *tlist = rel->targetlist;
|
||||
Var *newvar = makeVar(var->varno,
|
||||
var->varattno,
|
||||
var->vartype,
|
||||
var->varno,
|
||||
var->varoattno);
|
||||
List *tlist = rel->targetlist;
|
||||
Var *newvar = makeVar(var->varno,
|
||||
var->varattno,
|
||||
var->vartype,
|
||||
var->varno,
|
||||
var->varoattno);
|
||||
|
||||
rel->targetlist =
|
||||
lappend(tlist,
|
||||
@ -129,10 +129,10 @@ add_tl_element(Rel * rel, Var * var)
|
||||
* RETURNS: newly created tlist-entry
|
||||
* CREATES: new targetlist entry (always).
|
||||
*/
|
||||
TargetEntry *
|
||||
TargetEntry *
|
||||
create_tl_element(Var * var, int resdomno)
|
||||
{
|
||||
TargetEntry *tlelement = makeNode(TargetEntry);
|
||||
TargetEntry *tlelement = makeNode(TargetEntry);
|
||||
|
||||
tlelement->resdom =
|
||||
makeResdom(resdomno,
|
||||
@ -152,7 +152,7 @@ create_tl_element(Var * var, int resdomno)
|
||||
* Returns the targetlist elements from a relation tlist.
|
||||
*
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
get_actual_tlist(List * tlist)
|
||||
{
|
||||
|
||||
@ -160,8 +160,8 @@ get_actual_tlist(List * tlist)
|
||||
* this function is not making sense. - ay 10/94
|
||||
*/
|
||||
#if 0
|
||||
List *element = NIL;
|
||||
List *result = NIL;
|
||||
List *element = NIL;
|
||||
List *result = NIL;
|
||||
|
||||
if (tlist == NULL)
|
||||
{
|
||||
@ -199,12 +199,12 @@ 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;
|
||||
TargetEntry *temp_tle = (TargetEntry *) NULL;
|
||||
TargetEntry *tl_elt = (TargetEntry *) NULL;
|
||||
List *i = NIL;
|
||||
TargetEntry *temp_tle = (TargetEntry *) NULL;
|
||||
TargetEntry *tl_elt = (TargetEntry *) NULL;
|
||||
|
||||
if (var)
|
||||
{
|
||||
@ -229,12 +229,12 @@ 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;
|
||||
List *i = NIL;
|
||||
TargetEntry *temp_tle = (TargetEntry *) NULL;
|
||||
Resdom *resdom = (Resdom *) NULL;
|
||||
List *i = NIL;
|
||||
TargetEntry *temp_tle = (TargetEntry *) NULL;
|
||||
|
||||
foreach(i, tlist)
|
||||
{
|
||||
@ -264,18 +264,18 @@ tlist_resdom(List * tlist, Resdom * resnode)
|
||||
* [what used to be varid is now broken up into two fields varnoold and
|
||||
* varoattno. Also, nested attnos are long gone. - ay 2/95]
|
||||
*/
|
||||
TargetEntry *
|
||||
TargetEntry *
|
||||
match_varid(Var * test_var, List * tlist)
|
||||
{
|
||||
List *tl;
|
||||
Oid type_var;
|
||||
List *tl;
|
||||
Oid type_var;
|
||||
|
||||
type_var = (Oid) test_var->vartype;
|
||||
|
||||
foreach(tl, tlist)
|
||||
{
|
||||
TargetEntry *entry;
|
||||
Var *tlvar;
|
||||
TargetEntry *entry;
|
||||
Var *tlvar;
|
||||
|
||||
entry = lfirst(tl);
|
||||
tlvar = get_expr(entry);
|
||||
@ -310,15 +310,15 @@ 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);
|
||||
List *x = NIL;
|
||||
List *new_targetlist = (List *) copyObject((Node *) targetlist);
|
||||
List *x = NIL;
|
||||
|
||||
foreach(x, new_targetlist)
|
||||
{
|
||||
TargetEntry *tle = (TargetEntry *) lfirst(x);
|
||||
TargetEntry *tle = (TargetEntry *) lfirst(x);
|
||||
|
||||
tle->resdom->reskey = 0;
|
||||
tle->resdom->reskeyop = (Oid) 0;
|
||||
@ -338,18 +338,18 @@ new_unsorted_tlist(List * targetlist)
|
||||
* Returns a new target list.
|
||||
*
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
copy_vars(List * target, List * source)
|
||||
{
|
||||
List *result = NIL;
|
||||
List *src = NIL;
|
||||
List *dest = NIL;
|
||||
List *result = NIL;
|
||||
List *src = NIL;
|
||||
List *dest = NIL;
|
||||
|
||||
for (src = source, dest = target; src != NIL &&
|
||||
dest != NIL; src = lnext(src), dest = lnext(dest))
|
||||
{
|
||||
TargetEntry *temp = MakeTLE(((TargetEntry *) lfirst(dest))->resdom,
|
||||
(Node *) get_expr(lfirst(src)));
|
||||
TargetEntry *temp = MakeTLE(((TargetEntry *) lfirst(dest))->resdom,
|
||||
(Node *) get_expr(lfirst(src)));
|
||||
|
||||
result = lappend(result, temp);
|
||||
}
|
||||
@ -366,18 +366,18 @@ copy_vars(List * target, List * source)
|
||||
* Returns the "flattened" new target list.
|
||||
*
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
flatten_tlist(List * tlist)
|
||||
{
|
||||
int last_resdomno = 1;
|
||||
List *new_tlist = NIL;
|
||||
List *tlist_vars = NIL;
|
||||
List *temp;
|
||||
int last_resdomno = 1;
|
||||
List *new_tlist = NIL;
|
||||
List *tlist_vars = NIL;
|
||||
List *temp;
|
||||
|
||||
foreach(temp, tlist)
|
||||
{
|
||||
TargetEntry *temp_entry = NULL;
|
||||
List *vars;
|
||||
TargetEntry *temp_entry = NULL;
|
||||
List *vars;
|
||||
|
||||
temp_entry = lfirst(temp);
|
||||
vars = pull_var_clause((Node *) get_expr(temp_entry));
|
||||
@ -389,11 +389,11 @@ flatten_tlist(List * tlist)
|
||||
|
||||
foreach(temp, tlist_vars)
|
||||
{
|
||||
Var *var = lfirst(temp);
|
||||
Var *var = lfirst(temp);
|
||||
|
||||
if (!(tlist_member(var, new_tlist)))
|
||||
{
|
||||
Resdom *r;
|
||||
Resdom *r;
|
||||
|
||||
r = makeResdom(last_resdomno,
|
||||
var->vartype,
|
||||
@ -422,15 +422,15 @@ flatten_tlist(List * tlist)
|
||||
* Returns the modified actual target list.
|
||||
*
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
flatten_tlist_vars(List * full_tlist, List * flat_tlist)
|
||||
{
|
||||
List *x = NIL;
|
||||
List *result = NIL;
|
||||
List *x = NIL;
|
||||
List *result = NIL;
|
||||
|
||||
foreach(x, full_tlist)
|
||||
{
|
||||
TargetEntry *tle = lfirst(x);
|
||||
TargetEntry *tle = lfirst(x);
|
||||
|
||||
result =
|
||||
lappend(result,
|
||||
@ -453,7 +453,7 @@ flatten_tlist_vars(List * full_tlist, List * flat_tlist)
|
||||
* Returns the (modified) target_list entry from the target list.
|
||||
*
|
||||
*/
|
||||
static Node *
|
||||
static Node *
|
||||
flatten_tlistentry(Node * tlistentry, List * flat_tlist)
|
||||
{
|
||||
if (tlistentry == NULL)
|
||||
@ -486,9 +486,9 @@ flatten_tlistentry(Node * tlistentry, List * flat_tlist)
|
||||
}
|
||||
else if (is_funcclause(tlistentry))
|
||||
{
|
||||
Expr *expr = (Expr *) tlistentry;
|
||||
List *temp_result = NIL;
|
||||
List *elt = NIL;
|
||||
Expr *expr = (Expr *) tlistentry;
|
||||
List *temp_result = NIL;
|
||||
List *elt = NIL;
|
||||
|
||||
foreach(elt, expr->args)
|
||||
temp_result = lappend(temp_result,
|
||||
@ -506,9 +506,9 @@ flatten_tlistentry(Node * tlistentry, List * flat_tlist)
|
||||
}
|
||||
else if (IsA(tlistentry, ArrayRef))
|
||||
{
|
||||
ArrayRef *aref = (ArrayRef *) tlistentry;
|
||||
List *temp = NIL;
|
||||
List *elt = NIL;
|
||||
ArrayRef *aref = (ArrayRef *) tlistentry;
|
||||
List *temp = NIL;
|
||||
List *elt = NIL;
|
||||
|
||||
foreach(elt, aref->refupperindexpr)
|
||||
temp = lappend(temp, flatten_tlistentry(lfirst(elt), flat_tlist));
|
||||
@ -529,11 +529,11 @@ flatten_tlistentry(Node * tlistentry, List * flat_tlist)
|
||||
}
|
||||
else
|
||||
{
|
||||
Expr *expr = (Expr *) tlistentry;
|
||||
Var *left =
|
||||
Expr *expr = (Expr *) tlistentry;
|
||||
Var *left =
|
||||
(Var *) flatten_tlistentry((Node *) get_leftop(expr),
|
||||
flat_tlist);
|
||||
Var *right =
|
||||
Var *right =
|
||||
(Var *) flatten_tlistentry((Node *) get_rightop(expr),
|
||||
flat_tlist);
|
||||
|
||||
@ -543,17 +543,17 @@ flatten_tlistentry(Node * tlistentry, List * flat_tlist)
|
||||
}
|
||||
|
||||
|
||||
TargetEntry *
|
||||
TargetEntry *
|
||||
MakeTLE(Resdom * resdom, Node * expr)
|
||||
{
|
||||
TargetEntry *rt = makeNode(TargetEntry);
|
||||
TargetEntry *rt = makeNode(TargetEntry);
|
||||
|
||||
rt->resdom = resdom;
|
||||
rt->expr = expr;
|
||||
return rt;
|
||||
}
|
||||
|
||||
Var *
|
||||
Var *
|
||||
get_expr(TargetEntry * tle)
|
||||
{
|
||||
Assert(tle != NULL);
|
||||
@ -576,17 +576,17 @@ get_expr(TargetEntry * tle)
|
||||
void
|
||||
AddGroupAttrToTlist(List * tlist, List * grpCl)
|
||||
{
|
||||
List *gl;
|
||||
int last_resdomno = length(tlist) + 1;
|
||||
List *gl;
|
||||
int last_resdomno = length(tlist) + 1;
|
||||
|
||||
foreach(gl, grpCl)
|
||||
{
|
||||
GroupClause *gc = (GroupClause *) lfirst(gl);
|
||||
Var *var = gc->grpAttr;
|
||||
GroupClause *gc = (GroupClause *) lfirst(gl);
|
||||
Var *var = gc->grpAttr;
|
||||
|
||||
if (!(tlist_member(var, tlist)))
|
||||
{
|
||||
Resdom *r;
|
||||
Resdom *r;
|
||||
|
||||
r = makeResdom(last_resdomno,
|
||||
var->vartype,
|
||||
@ -608,9 +608,9 @@ AddGroupAttrToTlist(List * tlist, List * grpCl)
|
||||
int
|
||||
exec_tlist_length(List * targetlist)
|
||||
{
|
||||
int len;
|
||||
List *tl;
|
||||
TargetEntry *curTle;
|
||||
int len;
|
||||
List *tl;
|
||||
TargetEntry *curTle;
|
||||
|
||||
len = 0;
|
||||
foreach(tl, targetlist)
|
||||
|
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/var.c,v 1.4 1997/09/07 04:44:35 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/var.c,v 1.5 1997/09/08 02:25:07 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -34,35 +34,35 @@
|
||||
* 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,
|
||||
*result = NIL;
|
||||
List *i,
|
||||
*result = NIL;
|
||||
|
||||
if (me == NULL)
|
||||
return (NIL);
|
||||
|
||||
switch (nodeTag(me))
|
||||
{
|
||||
case T_List:
|
||||
foreach(i, (List *) me)
|
||||
{
|
||||
result = nconc(result, pull_varnos(lfirst(i)));
|
||||
}
|
||||
break;
|
||||
case T_ArrayRef:
|
||||
foreach(i, ((ArrayRef *) me)->refupperindexpr)
|
||||
result = nconc(result, pull_varnos(lfirst(i)));
|
||||
foreach(i, ((ArrayRef *) me)->reflowerindexpr)
|
||||
result = nconc(result, pull_varnos(lfirst(i)));
|
||||
result = nconc(result, pull_varnos(((ArrayRef *) me)->refassgnexpr));
|
||||
break;
|
||||
case T_Var:
|
||||
result = lconsi(((Var *) me)->varno, NIL);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case T_List:
|
||||
foreach(i, (List *) me)
|
||||
{
|
||||
result = nconc(result, pull_varnos(lfirst(i)));
|
||||
}
|
||||
break;
|
||||
case T_ArrayRef:
|
||||
foreach(i, ((ArrayRef *) me)->refupperindexpr)
|
||||
result = nconc(result, pull_varnos(lfirst(i)));
|
||||
foreach(i, ((ArrayRef *) me)->reflowerindexpr)
|
||||
result = nconc(result, pull_varnos(lfirst(i)));
|
||||
result = nconc(result, pull_varnos(((ArrayRef *) me)->refassgnexpr));
|
||||
break;
|
||||
case T_Var:
|
||||
result = lconsi(((Var *) me)->varno, NIL);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return (result);
|
||||
}
|
||||
@ -87,7 +87,7 @@ contain_var_clause(Node * clause)
|
||||
return FALSE;
|
||||
else if (or_clause(clause))
|
||||
{
|
||||
List *temp;
|
||||
List *temp;
|
||||
|
||||
foreach(temp, ((Expr *) clause)->args)
|
||||
{
|
||||
@ -98,7 +98,7 @@ contain_var_clause(Node * clause)
|
||||
}
|
||||
else if (is_funcclause(clause))
|
||||
{
|
||||
List *temp;
|
||||
List *temp;
|
||||
|
||||
foreach(temp, ((Expr *) clause)->args)
|
||||
{
|
||||
@ -109,7 +109,7 @@ contain_var_clause(Node * clause)
|
||||
}
|
||||
else if (IsA(clause, ArrayRef))
|
||||
{
|
||||
List *temp;
|
||||
List *temp;
|
||||
|
||||
foreach(temp, ((ArrayRef *) clause)->refupperindexpr)
|
||||
{
|
||||
@ -143,10 +143,10 @@ contain_var_clause(Node * clause)
|
||||
*
|
||||
* Returns list of varnodes found.
|
||||
*/
|
||||
List *
|
||||
List *
|
||||
pull_var_clause(Node * clause)
|
||||
{
|
||||
List *retval = NIL;
|
||||
List *retval = NIL;
|
||||
|
||||
if (clause == NULL)
|
||||
return (NIL);
|
||||
@ -158,14 +158,14 @@ pull_var_clause(Node * clause)
|
||||
retval = NIL;
|
||||
else if (or_clause(clause))
|
||||
{
|
||||
List *temp;
|
||||
List *temp;
|
||||
|
||||
foreach(temp, ((Expr *) clause)->args)
|
||||
retval = nconc(retval, pull_var_clause(lfirst(temp)));
|
||||
}
|
||||
else if (is_funcclause(clause))
|
||||
{
|
||||
List *temp;
|
||||
List *temp;
|
||||
|
||||
foreach(temp, ((Expr *) clause)->args)
|
||||
retval = nconc(retval, pull_var_clause(lfirst(temp)));
|
||||
@ -176,7 +176,7 @@ pull_var_clause(Node * clause)
|
||||
}
|
||||
else if (IsA(clause, ArrayRef))
|
||||
{
|
||||
List *temp;
|
||||
List *temp;
|
||||
|
||||
foreach(temp, ((ArrayRef *) clause)->refupperindexpr)
|
||||
retval = nconc(retval, pull_var_clause(lfirst(temp)));
|
||||
|
Reference in New Issue
Block a user