pgsql: Add stack-overflow guards in set-operation planning.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Add stack-overflow guards in set-operation planning.
Date: 2018-01-28 18:39:31
Message-ID: E1efrrX-0000fF-Tk@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Add stack-overflow guards in set-operation planning.

create_plan_recurse lacked any stack depth check. This is not per
our normal coding rules, but I'd supposed it was safe because earlier
planner processing is more complex and presumably should eat more
stack. But bug #15033 from Andrew Grossman shows this isn't true,
at least not for queries having the form of a many-thousand-way
INTERSECT stack.

Further testing showed that recurse_set_operations is also capable
of being crashed in this way, since it likewise will recurse to the
bottom of a parsetree before calling any support functions that
might themselves contain any stack checks. However, its stack
consumption is only perhaps a third of create_plan_recurse's.

It's possible that this particular problem with create_plan_recurse can
only manifest in 9.6 and later, since before that we didn't build a Path
tree for set operations. But having seen this example, I now have no
faith in the proposition that create_plan_recurse doesn't need a stack
check, so back-patch to all supported branches.

Discussion: https://postgr.es/m/20180127050845.28812.58244@wrigleys.postgresql.org

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/35a528062cc8ccdb51bde6c672991ae64e970847

Modified Files
--------------
src/backend/optimizer/plan/createplan.c | 3 +++
src/backend/optimizer/prep/prepunion.c | 3 +++
2 files changed, 6 insertions(+)

Browse pgsql-committers by date

  From Date Subject
Next Message Amit Langote 2018-01-29 08:04:40 Re: pgsql: Local partitioned indexes
Previous Message Simon Riggs 2018-01-28 16:15:58 pgsql: Default monitoring roles - errata