Avoid copying MinimalTuple twice in ExecHashSkewTableInsert()

Started by cca550710 days ago2 messageshackers

Thread notes

1 note#performance#minor#enhancement
hackorum-bot#performance#minor#enhancement
hackorum-bot
2 days ago

@global #performance #minor #enhancement

#performance#minor#enhancement
Jump to latest
#1cca5507
cca5507@qq.com

Hi,

We currently copy MinimalTuple twice in ExecHashSkewTableInsert() if the input
slot is not a MinimalTupleTableSlot. We can avoid this by using
ExecCopySlotMinimalTupleExtra().

Patch attached.

--
Regards,
ChangAo Chen

Attachments:

t259357_1
v1-0001-Avoid-copying-MinimalTuple-twice-in-ExecHashSkewT.patchapplication/octet-stream; charset=utf-8; name=v1-0001-Avoid-copying-MinimalTuple-twice-in-ExecHashSkewT.patchDownload+7-10
#2Chao Li
li.evan.chao@gmail.com
In reply to: cca5507 (#1)
Re: Avoid copying MinimalTuple twice in ExecHashSkewTableInsert()

On Nov 18, 2026, at 22:56, cca5507 <cca5507@qq.com> wrote:

Hi,

We currently copy MinimalTuple twice in ExecHashSkewTableInsert() if the input
slot is not a MinimalTupleTableSlot. We can avoid this by using
ExecCopySlotMinimalTupleExtra().

Patch attached.

--
Regards,
ChangAo Chen
<v1-0001-Avoid-copying-MinimalTuple-twice-in-ExecHashSkewT.patch>

The current code does:

* ExecFetchSlotMinimalTuple(slot, &shouldFree)
* if slot->tts_ops->get_minimal_tuple is not NULL, slot->tts_ops->get_minimal_tuple(slot);
* else slot->tts_ops->copy_minimal_tuple(slot, 0);
* hashTuple = (HashJoinTuple) MemoryContextAlloc()
* memcpy(HJTUPLE_MINTUPLE(hashTuple), tuple, tuple->t_len);
* if (shouldFree) heap_free_minimal_tuple(tuple);

The patch does:

* tuple = ExecCopySlotMinimalTupleExtra(slot, HJTUPLE_OVERHEAD);
* slot->tts_ops->copy_minimal_tuple(slot, extra);
* hashTuple = (HashJoinTuple) ((char *) tuple - HJTUPLE_OVERHEAD);

When slot->tts_ops->get_minimal_tuple is not NULL, the old and new code do almost the same amount of work. But when slot->tts_ops->get_minimal_tuple is NULL, this patch saves an allocation, a memcpy(), and a pfree().

So, this patch can improve performance a little bit. Plus, it simplifies the code, so I think it's an improvement.

In summary, v1 looks good to me. I also tried to build and run tests, everything passed.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/