Re: UPDATE on Domain Array that is based on a composite key crashes

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Zhihong Yu <zyu(at)yugabyte(dot)com>
Cc: Onder Kalaci <onderk(at)microsoft(dot)com>, "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: UPDATE on Domain Array that is based on a composite key crashes
Date: 2021-10-19 17:04:39
Message-ID: 1871897.1634663079@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

[ please do not quote the entire thread when replying ]

Zhihong Yu <zyu(at)yugabyte(dot)com> writes:
> Here is the patch.

This patch seems quite misguided to me. The proximate cause of
the crash is that we're arriving at ExecEvalFieldStoreDeForm with
*op->resnull and *op->resvalue both zero, which is a completely
invalid situation for a pass-by-reference datatype; so something
upstream of this messed up. Even if there were an argument for
acting as though that were a valid NULL value, this patch fails to
do so; that'd require setting all the output fieldstore.nulls[]
entries to true, which you didn't.

Moreover, experiment quickly shows that the problem only shows up with
an array of domain over composite, not an array of plain composite.
The proposed patch doesn't seem to have anything to do with that
observation.

After some digging around, I see where the issue actually is:
the expression tree we're dealing with looks like

{SUBSCRIPTINGREF
:refexpr
{VAR
}
:refassgnexpr
{COERCETODOMAIN
:arg
{FIELDSTORE
:arg
{CASETESTEXPR
}
}
}
}

The array element we intend to replace has to be passed down to
the CaseTestExpr, but that isn't happening. That's because
isAssignmentIndirectionExpr fails to recognize a tree like
this, so ExecInitSubscriptingRef doesn't realize it needs to
arrange for that.

I believe the attached is a correct fix.

regards, tom lane

Attachment Content-Type Size
fix-assignment-to-array-of-domain-over-composite.patch text/x-diff 3.6 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Zhihong Yu 2021-10-19 17:29:40 Re: UPDATE on Domain Array that is based on a composite key crashes
Previous Message Japin Li 2021-10-19 16:38:31 Re: UPDATE on Domain Array that is based on a composite key crashes