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 @@ ...@@ -4,7 +4,7 @@
# Makefile for optimizer/plan # Makefile for optimizer/plan
# #
# IDENTIFICATION # 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../.. ...@@ -15,7 +15,7 @@ INCLUDE_OPT = -I../..
CFLAGS+=$(INCLUDE_OPT) 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 # not ready yet: predmig.o xfunc.o
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * 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) ...@@ -685,13 +685,11 @@ fix_indxqual_references(Node *clause, Path *index_path)
else if (IsA(clause, Const)) else if (IsA(clause, Const))
{ {
return (clause); return (clause);
#ifdef INDEXSCAN_PATCH
} }
else if (IsA(clause, Param)) else if (IsA(clause, Param))
{ {
/* Function parameter used as index scan arg. DZ - 27-8-1996 */ /* Function parameter used as index scan arg. DZ - 27-8-1996 */
return (clause); return (clause);
#endif
} }
else if (is_opclause(clause) && else if (is_opclause(clause) &&
is_funcclause((Node *) get_leftop((Expr *) clause)) && is_funcclause((Node *) get_leftop((Expr *) clause)) &&
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * 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 @@ ...@@ -22,7 +22,9 @@
#include "nodes/makefuncs.h" #include "nodes/makefuncs.h"
#include "optimizer/planmain.h" #include "optimizer/planmain.h"
#include "optimizer/subselect.h"
#include "optimizer/internal.h" #include "optimizer/internal.h"
#include "optimizer/prep.h"
#include "optimizer/paths.h" #include "optimizer/paths.h"
#include "optimizer/clauses.h" #include "optimizer/clauses.h"
#include "optimizer/keys.h" #include "optimizer/keys.h"
...@@ -72,7 +74,18 @@ query_planner(Query *root, ...@@ -72,7 +74,18 @@ query_planner(Query *root,
List *var_only_tlist = NIL; List *var_only_tlist = NIL;
List *level_tlist = NIL; List *level_tlist = NIL;
Plan *subplan = NULL; 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, * A command without a target list or qualification is an error,
* except for "delete foo". * except for "delete foo".
...@@ -145,7 +158,7 @@ query_planner(Query *root, ...@@ -145,7 +158,7 @@ query_planner(Query *root,
if (constant_qual != NULL) if (constant_qual != NULL)
{ {
return ((Plan *) make_result(tlist, return ((Plan *) make_result(tlist,
(Node *) constant_qual, (Node *) constant_qual,
(Plan *) scan)); (Plan *) scan));
} }
else else
......
...@@ -7,11 +7,12 @@ ...@@ -7,11 +7,12 @@
* *
* *
* IDENTIFICATION * 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 <sys/types.h>
#include <string.h>
#include "postgres.h" #include "postgres.h"
...@@ -30,6 +31,7 @@ ...@@ -30,6 +31,7 @@
#include "optimizer/plancat.h" #include "optimizer/plancat.h"
#include "optimizer/prep.h" #include "optimizer/prep.h"
#include "optimizer/planmain.h" #include "optimizer/planmain.h"
#include "optimizer/subselect.h"
#include "optimizer/paths.h" #include "optimizer/paths.h"
#include "optimizer/cost.h" #include "optimizer/cost.h"
...@@ -56,10 +58,32 @@ extern Plan *make_groupPlan(List **tlist, bool tuplePerGroup, ...@@ -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-- * union_planner--
* Main query optimizer routine.
* *
* Invokes the planner on union queries if there are any left, * Invokes the planner on union queries if there are any left,
* recursing if necessary to get them all, then processes normal plans. * recursing if necessary to get them all, then processes normal plans.
...@@ -68,14 +92,13 @@ extern Plan *make_groupPlan(List **tlist, bool tuplePerGroup, ...@@ -68,14 +92,13 @@ extern Plan *make_groupPlan(List **tlist, bool tuplePerGroup,
* *
*/ */
Plan * Plan *
planner(Query *parse) union_planner(Query *parse)
{ {
List *tlist = parse->targetList; List *tlist = parse->targetList;
List *rangetable = parse->rtable; List *rangetable = parse->rtable;
Plan *result_plan = (Plan *) NULL; Plan *result_plan = (Plan *) NULL;
List *primary_qual;
Index rt_index; Index rt_index;
...@@ -100,17 +123,25 @@ planner(Query *parse) ...@@ -100,17 +123,25 @@ planner(Query *parse)
} }
else else
{ {
List **vpm = NULL;
tlist = preprocess_targetlist(tlist, tlist = preprocess_targetlist(tlist,
parse->commandType, parse->commandType,
parse->resultRelation, parse->resultRelation,
parse->rtable); parse->rtable);
if ( parse->rtable != NULL )
primary_qual = cnfify((Expr *) parse->qual, true); {
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, result_plan = query_planner(parse,
parse->commandType, parse->commandType,
tlist, tlist,
primary_qual); (List*) parse->qual);
PlannerVarParam = lnext (PlannerVarParam);
if ( vpm != NULL )
pfree (vpm);
} }
/* /*
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * 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, ...@@ -405,7 +405,21 @@ replace_clause_joinvar_refs(Expr *clause,
leftvar, leftvar,
rightvar)); 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 */ /* shouldn't reach here */
elog (ERROR, "replace_clause_joinvar_refs: unsupported clause %d",
nodeTag (clause));
return NULL; 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