aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/selfuncs.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2012-10-03 13:37:53 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2012-10-03 13:37:53 -0400
commit1f91c8ca1d2edc66c688ee719eded79ecd0e8f1b (patch)
tree81431c90c1f5eb62ad847492881f56e0158781da /src/backend/utils/adt/selfuncs.c
parentfe3b5eb08a16c391478e305bd9ea40f4f5979689 (diff)
downloadpostgresql-1f91c8ca1d2edc66c688ee719eded79ecd0e8f1b.tar.gz
postgresql-1f91c8ca1d2edc66c688ee719eded79ecd0e8f1b.zip
Avoid planner crash/Assert failure with joins to unflattened subqueries.
examine_simple_variable supposed that any RTE_SUBQUERY rel it gets pointed at must have been planned already. However, this isn't a safe assumption because we must do selectivity estimation while generating indexscan paths, and that code might look at join clauses involving a rel that the loop in set_base_rel_sizes() hasn't reached yet. The simplest fix is to play dumb in such a situation, that is give up trying to extract any stats for the Var. This could possibly be improved by making a separate pass over the RTE list to plan each unflattened subquery before we start the main planning work --- but that would be pretty invasive and it doesn't seem worth it, for now at least. (We couldn't just break set_base_rel_sizes() into two loops: the prescan would need to handle all subquery rels in the query, not only those in the current join subproblem.) This bug was introduced in commit 1cb108efb0e60d87e4adec38e7636b6e8efbeb57, although I think that subsequent changes may have exposed it more than it was originally. Per bug #7580 from Maxim Boguk.
Diffstat (limited to 'src/backend/utils/adt/selfuncs.c')
-rw-r--r--src/backend/utils/adt/selfuncs.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c
index 2ab26dea290..61100aec4ae 100644
--- a/src/backend/utils/adt/selfuncs.c
+++ b/src/backend/utils/adt/selfuncs.c
@@ -4518,8 +4518,10 @@ examine_simple_variable(PlannerInfo *root, Var *var,
*/
rel = find_base_rel(root, var->varno);
- /* Subquery should have been planned already */
- Assert(rel->subroot && IsA(rel->subroot, PlannerInfo));
+ /* If the subquery hasn't been planned yet, we have to punt */
+ if (rel->subroot == NULL)
+ return;
+ Assert(IsA(rel->subroot, PlannerInfo));
/*
* Switch our attention to the subquery as mangled by the planner. It