Skip to content

Commit ad480bd

Browse files
committed
Ignore extra subquery outputs in set_subquery_size_estimates().
In commit 0f61d4d, I added code to copy up column width estimates for each column of a subquery. That code supposed that the subquery couldn't have any output columns that didn't correspond to known columns of the current query level --- which is true when a query is parsed from scratch, but the assumption fails when planning a view that depends on another view that's been redefined (adding output columns) since the upper view was made. This results in an assertion failure or even a crash, as per bug #8025 from lindebg. Remove the Assert and instead skip the column if its resno is out of the expected range.
1 parent 861aac5 commit ad480bd

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/backend/optimizer/path/costsize.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3261,6 +3261,15 @@ set_subquery_size_estimates(PlannerInfo *root, RelOptInfo *rel,
32613261
if (te->resjunk)
32623262
continue;
32633263

3264+
/*
3265+
* The subquery could be an expansion of a view that's had columns
3266+
* added to it since the current query was parsed, so that there are
3267+
* non-junk tlist columns in it that don't correspond to any column
3268+
* visible at our query level. Ignore such columns.
3269+
*/
3270+
if (te->resno < rel->min_attr || te->resno > rel->max_attr)
3271+
continue;
3272+
32643273
/*
32653274
* XXX This currently doesn't work for subqueries containing set
32663275
* operations, because the Vars in their tlists are bogus references
@@ -3282,7 +3291,6 @@ set_subquery_size_estimates(PlannerInfo *root, RelOptInfo *rel,
32823291

32833292
item_width = subrel->attr_widths[var->varattno - subrel->min_attr];
32843293
}
3285-
Assert(te->resno >= rel->min_attr && te->resno <= rel->max_attr);
32863294
rel->attr_widths[te->resno - rel->min_attr] = item_width;
32873295
}
32883296

0 commit comments

Comments
 (0)