Re: Bug with 'iscachable' attribute (Was: Index selection bug)

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andriy I Pilipenko <bamby(at)marka(dot)net(dot)ua>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: Bug with 'iscachable' attribute (Was: Index selection bug)
Date: 2000-07-27 23:56:21
Message-ID: 14770.964742181@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Andriy I Pilipenko <bamby(at)marka(dot)net(dot)ua> writes:
> create function f() returns int as '
> select a
> from a
> where a = (select max(b) from b)
> ' language 'sql'
> with (iscachable)

> select f()

> ERROR: replace_vars_with_subplan_refs: variable not in subplan target list

Fixed by the attached patch. Thanks for the report!

regards, tom lane

*** src/backend/optimizer/plan/planner.c.orig Wed Apr 12 13:15:22 2000
--- src/backend/optimizer/plan/planner.c Thu Jul 27 19:53:29 2000
***************
*** 53,58 ****
--- 53,74 ----
planner(Query *parse)
{
Plan *result_plan;
+ Index save_PlannerQueryLevel;
+ List *save_PlannerInitPlan;
+ List *save_PlannerParamVar;
+ int save_PlannerPlanId;
+
+ /*
+ * The planner can be called recursively (an example is when
+ * eval_const_expressions tries to simplify an SQL function).
+ * So, global state variables must be saved and restored.
+ *
+ * (Perhaps these should be moved into the Query structure instead?)
+ */
+ save_PlannerQueryLevel = PlannerQueryLevel;
+ save_PlannerInitPlan = PlannerInitPlan;
+ save_PlannerParamVar = PlannerParamVar;
+ save_PlannerPlanId = PlannerPlanId;

/* Initialize state for subselects */
PlannerQueryLevel = 1;
***************
*** 80,85 ****
--- 96,107 ----

/* final cleanup of the plan */
set_plan_references(result_plan);
+
+ /* restore state for outer planner, if any */
+ PlannerQueryLevel = save_PlannerQueryLevel;
+ PlannerInitPlan = save_PlannerInitPlan;
+ PlannerParamVar = save_PlannerParamVar;
+ PlannerPlanId = save_PlannerPlanId;

return result_plan;
}

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Radek Kanovsky 2000-07-28 13:02:35 float8 comparison failure
Previous Message Bruce Momjian 2000-07-27 19:43:58 Re: [PATCHES] Libpq++ memory leak