Re: BUG #16213: segfault when running a query

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Cc: matt(dot)jibson(at)gmail(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #16213: segfault when running a query
Date: 2020-01-17 18:29:54
Message-ID: 31142.1579285794@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

I wrote:
> PG Bug reporting form <noreply(at)postgresql(dot)org> writes:
>> The above query produces an error in the server log:
>> LOG: server process (PID 108) was terminated by signal 11: Segmentation
>> fault

> The direct cause of the crash is that by the time we get to ExecutorEnd,
> there are dangling pointers in the es_tupleTable list.

After further reflection, I'm totally dissatisfied with the quick-hack
patch I posted last night. I think that what this example demonstrates
is that my fix (in commit 9b63c13f0) for bug #14924 in fact does not
work: the subPlan list is not the only way in which a SubPlan connects
up to the outer plan level. I have no faith that the es_tupleTable list
is the only other way, either, or that we won't create more in future.

I think what we have to do here is revert 9b63c13f0, going back to
the previous policy of passing down parent = NULL to the transient
subexpressions, so that there is a strong guarantee that there aren't
any unwanted connections between short-lived and longer-lived state.
And then we need some other solution for making SubPlans in VALUES
lists work. The best bet seems to be what I speculated about in that
commit message: initialize the expressions for VALUES rows that contain
SubPlans normally at executor startup, and use the trick with
short-lived expression state only for VALUES rows that don't contain any
SubPlans. I think that the case we're worried about with long VALUES
lists is not likely to involve any SubPlans, so that this shouldn't be
too awful for memory consumption.

Another benefit of doing it like this is that SubPlans in the VALUES
lists are reported normally by EXPLAIN, while the previous hack caused
them to be missing from the output.

Objections, better ideas?

regards, tom lane

Attachment Content-Type Size
fix-for-hashed-subplan-in-VALUES-2.patch text/x-diff 9.2 KB

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Alvaro Herrera 2020-01-17 21:12:16 Re: Reorderbuffer crash during recovery
Previous Message Tom Lane 2020-01-17 15:29:52 Re: BUG #16216: the result of to_date function with negative year number not same as BC year number

Browse pgsql-hackers by date

  From Date Subject
Next Message Karl O. Pinc 2020-01-17 18:46:59 Re: Patch to document base64 encoding
Previous Message Karl O. Pinc 2020-01-17 18:22:19 Re: Patch to document base64 encoding