Avoid copying MinimalTuple twice in ExecHashSkewTableInsert()

Поиск
Список
Период
Сортировка
Искать

Avoid copying MinimalTuple twice in ExecHashSkewTableInsert()

От:
"cca5507" <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

Re: Avoid copying MinimalTuple twice in ExecHashSkewTableInsert()

От:
Chao Li <li.evan.chao@gmail.com>
Дата:


> On Nov 18, 2026, at 22:56, cca5507  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
> 

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/






FAQ