forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit1f542a2
committed
Prevent planagg.c from failing on queries containing CTEs.
The existing tests in preprocess_minmax_aggregates() usually prevent itfrom trying to do anything with queries containing CTEs, but there's anexception: a CTE could be present as a member of an appendrel, if weflattened a UNION ALL that contains CTE references. If it did try togenerate an optimized path for a query using a CTE, it failed with"could not find plan for CTE", as reported by Torsten Förtsch.The proximate cause is an unwise decision in commit3fc6e2d to clearsubroot->cte_plan_ids in build_minmax_path(). That left the subroot'scte_plan_ids list out of step with its parse->cteList.Removing the "subroot->cte_plan_ids = NIL;" assignment is enough to letthe case work again, but really it's pretty silly to be expending anycycles at all in this module when there are CTEs: we always treat theiroutputs as unordered so there's no way for the optimization to win.Hence, also add an early-exit test so we don't waste time like that.Back-patch to 9.6 where the misbehavior was introduced.Report:https://postgr.es/m/CAKkG4_=gjY5QiHtqSZyWMwDuTd_CftKoTaCqxjJ7uUz1-Gw=qw@mail.gmail.com1 parent501c7b9 commit1f542a2
1 file changed
+8
-1
lines changedLines changed: 8 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
103 | 103 |
| |
104 | 104 |
| |
105 | 105 |
| |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
106 | 114 |
| |
107 | 115 |
| |
108 | 116 |
| |
| |||
360 | 368 |
| |
361 | 369 |
| |
362 | 370 |
| |
363 |
| - | |
364 | 371 |
| |
365 | 372 |
| |
366 | 373 |
| |
|
0 commit comments
Comments
(0)