mirror of
https://github.com/postgres/postgres.git
synced 2025-06-17 17:02:08 +03:00
Fix problems with ParamListInfo serialization mechanism.
Commit d1b7c1ffe7
introduced a mechanism
for serializing a ParamListInfo structure to be passed to a parallel
worker. However, this mechanism failed to handle external expanded
values, as pointed out by Noah Misch. Repair.
Moreover, plpgsql_param_fetch requires adjustment because the
serialization mechanism needs it to skip evaluating unused parameters
just as we would do when it is called from copyParamList, but params
== estate->paramLI in that case. To fix, make the bms_is_member test
in that function unconditional.
Finally, have setup_param_list set a new ParamListInfo field,
paramMask, to the parameters actually used in the expression, so that
we don't try to fetch those that are not needed when serializing a
parameter list. This isn't necessary for correctness, but it makes
the performance of the parallel executor code comparable to what we
do for cases involving cursors.
Design suggestions and extensive review by Noah Misch. Patch by me.
This commit is contained in:
@ -264,6 +264,11 @@ datumEstimateSpace(Datum value, bool isnull, bool typByVal, int typLen)
|
||||
/* no need to use add_size, can't overflow */
|
||||
if (typByVal)
|
||||
sz += sizeof(Datum);
|
||||
else if (VARATT_IS_EXTERNAL_EXPANDED(value))
|
||||
{
|
||||
ExpandedObjectHeader *eoh = DatumGetEOHP(value);
|
||||
sz += EOH_get_flat_size(eoh);
|
||||
}
|
||||
else
|
||||
sz += datumGetSize(value, typByVal, typLen);
|
||||
}
|
||||
@ -292,6 +297,7 @@ void
|
||||
datumSerialize(Datum value, bool isnull, bool typByVal, int typLen,
|
||||
char **start_address)
|
||||
{
|
||||
ExpandedObjectHeader *eoh = NULL;
|
||||
int header;
|
||||
|
||||
/* Write header word. */
|
||||
@ -299,6 +305,11 @@ datumSerialize(Datum value, bool isnull, bool typByVal, int typLen,
|
||||
header = -2;
|
||||
else if (typByVal)
|
||||
header = -1;
|
||||
else if (VARATT_IS_EXTERNAL_EXPANDED(value))
|
||||
{
|
||||
eoh = DatumGetEOHP(value);
|
||||
header = EOH_get_flat_size(eoh);
|
||||
}
|
||||
else
|
||||
header = datumGetSize(value, typByVal, typLen);
|
||||
memcpy(*start_address, &header, sizeof(int));
|
||||
@ -312,6 +323,11 @@ datumSerialize(Datum value, bool isnull, bool typByVal, int typLen,
|
||||
memcpy(*start_address, &value, sizeof(Datum));
|
||||
*start_address += sizeof(Datum);
|
||||
}
|
||||
else if (eoh)
|
||||
{
|
||||
EOH_flatten_into(eoh, (void *) *start_address, header);
|
||||
*start_address += header;
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(*start_address, DatumGetPointer(value), header);
|
||||
|
Reference in New Issue
Block a user