Avoid copying MinimalTuple twice in ExecHashSkewTableInsert()
Thread notes
1 note#performance#minor#enhancement
hackorum-bot#performance#minor#enhancement
@global #performance #minor #enhancement
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
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/