postgresql/src/backend/optimizer/path
Tom Lane 6c8656409b Fix PARAM_EXEC assignment mechanism to be safe in the presence of WITH.
The planner previously assumed that parameter Vars having the same absolute
query level, varno, and varattno could safely be assigned the same runtime
PARAM_EXEC slot, even though they might be different Vars appearing in
different subqueries.  This was (probably) safe before the introduction of
CTEs, but the lazy-evalution mechanism used for CTEs means that a CTE can
be executed during execution of some other subquery, causing the lifespan
of Params at the same syntactic nesting level as the CTE to overlap with
use of the same slots inside the CTE.  In 9.1 we created additional hazards
by using the same parameter-assignment technology for nestloop inner scan
parameters, but it was broken before that, as illustrated by the added
regression test.

To fix, restructure the planner's management of PlannerParamItems so that
items having different semantic lifespans are kept rigorously separated.
This will probably result in complex queries using more runtime PARAM_EXEC
slots than before, but the slots are cheap enough that this hardly matters.
Also, stop generating PlannerParamItems containing Params for subquery
outputs: all we really need to do is reserve the PARAM_EXEC slot number,
and that now only takes incrementing a counter.  The planning code is
simpler and probably faster than before, as well as being more correct.

Per report from Vik Reykja.

Back-patch of commit 46c508fbcf into all
branches that support WITH.
2012-09-07 20:38:28 -04:00
..
allpaths.c Fix PARAM_EXEC assignment mechanism to be safe in the presence of WITH. 2012-09-07 20:38:28 -04:00
clausesel.c Fix planner to pass correct collation to operator selectivity estimators. 2012-07-08 23:51:13 -04:00
costsize.c Account for SRFs in targetlists in planner rowcount estimates. 2012-07-21 17:45:15 -04:00
equivclass.c Run pgindent on 9.2 source tree in preparation for first 9.3 2012-06-10 15:20:04 -04:00
indxpath.c Allow create_index_paths() to consider multiple join bitmapscan paths. 2012-08-16 13:04:03 -04:00
joinpath.c Run pgindent on 9.2 source tree in preparation for first 9.3 2012-06-10 15:20:04 -04:00
joinrels.c Resurrect the "last ditch" code path in join_search_one_level(). 2012-08-15 00:08:42 -04:00
Makefile Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00
orindxpath.c Run pgindent on 9.2 source tree in preparation for first 9.3 2012-06-10 15:20:04 -04:00
pathkeys.c Run pgindent on 9.2 source tree in preparation for first 9.3 2012-06-10 15:20:04 -04:00
tidpath.c Update copyright notices for year 2012. 2012-01-01 18:01:58 -05:00