Commit 4a6e3a6a authored by Vadim B. Mikheev's avatar Vadim B. Mikheev

Old planner() becomes union_planner(); new planner() makes initialization

of some global variables to support subselects and calls union_planner().
Calls to SS_replace_correlation_vars() and SS_process_sublinks() in
query_planner() before planning.
Get rid of #ifdef INDEXSCAN_PATCH in createplan.c.
parent a3f1c367
......@@ -4,7 +4,7 @@
# Makefile for optimizer/plan
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/backend/optimizer/plan/Makefile,v 1.5 1997/12/20 00:24:31 scrappy Exp $
# $Header: /cvsroot/pgsql/src/backend/optimizer/plan/Makefile,v 1.6 1998/02/13 03:36:51 vadim Exp $
#
#-------------------------------------------------------------------------
......@@ -15,7 +15,7 @@ INCLUDE_OPT = -I../..
CFLAGS+=$(INCLUDE_OPT)
OBJS = createplan.o initsplan.o planmain.o planner.o setrefs.o
OBJS = createplan.o initsplan.o planmain.o planner.o setrefs.o subselect.o
# not ready yet: predmig.o xfunc.o
......
......@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.25 1998/02/10 04:01:09 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.26 1998/02/13 03:36:54 vadim Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -685,13 +685,11 @@ fix_indxqual_references(Node *clause, Path *index_path)
else if (IsA(clause, Const))
{
return (clause);
#ifdef INDEXSCAN_PATCH
}
else if (IsA(clause, Param))
{
/* Function parameter used as index scan arg. DZ - 27-8-1996 */
return (clause);
#endif
}
else if (is_opclause(clause) &&
is_funcclause((Node *) get_leftop((Expr *) clause)) &&
......
......@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planmain.c,v 1.18 1998/02/10 04:01:12 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planmain.c,v 1.19 1998/02/13 03:36:57 vadim Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -22,7 +22,9 @@
#include "nodes/makefuncs.h"
#include "optimizer/planmain.h"
#include "optimizer/subselect.h"
#include "optimizer/internal.h"
#include "optimizer/prep.h"
#include "optimizer/paths.h"
#include "optimizer/clauses.h"
#include "optimizer/keys.h"
......@@ -72,7 +74,18 @@ query_planner(Query *root,
List *var_only_tlist = NIL;
List *level_tlist = NIL;
Plan *subplan = NULL;
if ( PlannerQueryLevel > 1 )
{
/* should copy be made ? */
tlist = (List *) SS_replace_correlation_vars ((Node*)tlist);
qual = (List *) SS_replace_correlation_vars ((Node*)qual);
}
if (root->hasSubLinks)
qual = (List *) SS_process_sublinks ((Node*) qual);
qual = cnfify((Expr *) qual, true);
/*
* A command without a target list or qualification is an error,
* except for "delete foo".
......@@ -145,7 +158,7 @@ query_planner(Query *root,
if (constant_qual != NULL)
{
return ((Plan *) make_result(tlist,
(Node *) constant_qual,
(Node *) constant_qual,
(Plan *) scan));
}
else
......
......@@ -7,11 +7,12 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.21 1998/01/15 18:59:48 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.22 1998/02/13 03:36:59 vadim Exp $
*
*-------------------------------------------------------------------------
*/
#include <sys/types.h>
#include <string.h>
#include "postgres.h"
......@@ -30,6 +31,7 @@
#include "optimizer/plancat.h"
#include "optimizer/prep.h"
#include "optimizer/planmain.h"
#include "optimizer/subselect.h"
#include "optimizer/paths.h"
#include "optimizer/cost.h"
......@@ -56,10 +58,32 @@ extern Plan *make_groupPlan(List **tlist, bool tuplePerGroup,
*
*****************************************************************************/
Plan*
planner(Query *parse)
{
Plan *result_plan;
PlannerQueryLevel = 1;
PlannerVarParam = NULL;
PlannerParamVar = NULL;
PlannerInitPlan = NULL;
PlannerPlanId = 0;
result_plan = union_planner (parse);
Assert (PlannerQueryLevel == 1);
if ( PlannerPlanId > 0 )
{
result_plan->initPlan = PlannerInitPlan;
(void) SS_finalize_plan (result_plan);
}
result_plan->nParamExec = length (PlannerParamVar);
return (result_plan);
}
/*
* planner--
* Main query optimizer routine.
* union_planner--
*
* Invokes the planner on union queries if there are any left,
* recursing if necessary to get them all, then processes normal plans.
......@@ -68,14 +92,13 @@ extern Plan *make_groupPlan(List **tlist, bool tuplePerGroup,
*
*/
Plan *
planner(Query *parse)
union_planner(Query *parse)
{
List *tlist = parse->targetList;
List *rangetable = parse->rtable;
Plan *result_plan = (Plan *) NULL;
List *primary_qual;
Index rt_index;
......@@ -100,17 +123,25 @@ planner(Query *parse)
}
else
{
List **vpm = NULL;
tlist = preprocess_targetlist(tlist,
parse->commandType,
parse->resultRelation,
parse->rtable);
primary_qual = cnfify((Expr *) parse->qual, true);
if ( parse->rtable != NULL )
{
vpm = (List **) palloc (length (parse->rtable) * sizeof (List*));
memset (vpm, 0, length (parse->rtable) * sizeof (List*));
}
PlannerVarParam = lcons (vpm, PlannerVarParam);
result_plan = query_planner(parse,
parse->commandType,
tlist,
primary_qual);
parse->commandType,
tlist,
(List*) parse->qual);
PlannerVarParam = lnext (PlannerVarParam);
if ( vpm != NULL )
pfree (vpm);
}
/*
......
......@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/setrefs.c,v 1.17 1998/02/10 04:01:13 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/setrefs.c,v 1.18 1998/02/13 03:37:02 vadim Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -405,7 +405,21 @@ replace_clause_joinvar_refs(Expr *clause,
leftvar,
rightvar));
}
else if (is_subplan(clause))
{
((Expr*) clause)->args =
replace_subclause_joinvar_refs(((Expr*) clause)->args,
outer_tlist,
inner_tlist);
((SubPlan*) ((Expr*) clause)->oper)->sublink->oper =
replace_subclause_joinvar_refs(((SubPlan*) ((Expr*) clause)->oper)->sublink->oper,
outer_tlist,
inner_tlist);
return ((List*) clause);
}
/* shouldn't reach here */
elog (ERROR, "replace_clause_joinvar_refs: unsupported clause %d",
nodeTag (clause));
return NULL;
}
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment