Re: a thinko in b676ac443b6

From: Tomas Vondra <tomas(dot)vondra(at)enterprisedb(dot)com>
To: Amit Langote <amitlangote09(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: a thinko in b676ac443b6
Date: 2021-07-27 16:07:54
Message-ID: a6aee4d9-3fea-d620-6622-5e5776177d99@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 7/27/21 4:28 AM, Amit Langote wrote:
> Hi,
>
> I noticed $subject while rebasing my patch at [1] to enable batching
> for the inserts used in cross-partition UPDATEs.
>
> b676ac443b6 did this:
>
> - resultRelInfo->ri_PlanSlots[resultRelInfo->ri_NumSlots] =
> - MakeSingleTupleTableSlot(planSlot->tts_tupleDescriptor,
> - planSlot->tts_ops);
> ...
> + {
> + TupleDesc tdesc =
> CreateTupleDescCopy(slot->tts_tupleDescriptor);
> +
> + resultRelInfo->ri_Slots[resultRelInfo->ri_NumSlots] =
> + MakeSingleTupleTableSlot(tdesc, slot->tts_ops);
> ...
> + resultRelInfo->ri_PlanSlots[resultRelInfo->ri_NumSlots] =
> + MakeSingleTupleTableSlot(tdesc, planSlot->tts_ops);
>
> I think it can be incorrect to use the same TupleDesc for both the
> slots in ri_Slots (for ready-to-be-inserted tuples) and ri_PlanSlots
> (for subplan output tuples). Especially if you consider what we did
> in 86dc90056df that was committed into v14. In that commit, we
> changed the way a subplan under ModifyTable produces its output for an
> UPDATE statement. Previously, it would produce a tuple matching the
> target table's TupleDesc exactly (plus any junk columns), but now it
> produces only a partial tuple containing the values for the changed
> columns.
>
> So it's better to revert to using planSlot->tts_tupleDescriptor for
> the slots in ri_PlanSlots. Attached a patch to do so.
>

Yeah, this seems like a clear mistake - thanks for noticing it! Clearly
no regression test triggered the issue, so I wonder what's the best way
to test it - any idea what would the test need to do?

I did some quick experiments with batched INSERTs with RETURNING clauses
and/or subplans, but I haven't succeeded in triggering the issue :-(

regards

--
Tomas Vondra
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2021-07-27 16:12:12 Re: Skip temporary table schema name from explain-verbose output.
Previous Message Dagfinn Ilmari Mannsåker 2021-07-27 16:06:19 perlcritic: prohibit map and grep in void conext