Remove useless memory context switch in ExecHashTableCreate()

Started by cca55073 days ago3 messageshackers

Thread notes

1 note#refactor
hackorum-bot#refactor
hackorum-bot
2 days ago

@global #refactor

#refactor
Jump to latest
#1cca5507
cca5507@qq.com

Hi,

After adf97c1562, the "MemoryContextSwitchTo(hashtable->hashCxt)" in ExecHashTableCreate()
is useless, so attach a patch to remove it. While at it, rename "oldctx" to "oldcxt" to keep consistent
and fix a stale comment.

Now PrepareTempTablespaces() will not be called within hashCxt, but I think it's ok.

--
Regards,
ChangAo Chen

Attachments:

t260209_1
v1-0001-Remove-useless-memory-context-switch-in-ExecHashT.patchapplication/octet-stream; charset=utf-8; name=v1-0001-Remove-useless-memory-context-switch-in-ExecHashT.patchDownload+7-13
#2Nathan Bossart
nathandbossart@gmail.com
In reply to: cca5507 (#1)
Re: Remove useless memory context switch in ExecHashTableCreate()

On Thu, Dec 03, 2026 at 05:50:01PM +0800, cca5507 wrote:

After adf97c1562, the "MemoryContextSwitchTo(hashtable->hashCxt)" in
ExecHashTableCreate() is useless, so attach a patch to remove it. While
at it, rename "oldctx" to "oldcxt" to keep consistent and fix a stale
comment.

Seems generally reasonable.

Now PrepareTempTablespaces() will not be called within hashCxt, but I
think it's ok.

I do, too, but only after inspecting the code to be sure
PrepareTempTablespaces() doesn't ever leak memory. While that's pretty old
code that is unlikely to withstand too many changes in the future, IMHO
it'd be a good idea to note that some callers depend on it not leaking
memory. That way, future patch authors will be more likely to free
everything they allocated.

--
nathan

#3cca5507
cca5507@qq.com
In reply to: Nathan Bossart (#2)
Re: Remove useless memory context switch in ExecHashTableCreate()

Hi,

 Now PrepareTempTablespaces() will not be called within hashCxt, but I
 think it's ok.

I do, too, but only after inspecting the code to be sure
PrepareTempTablespaces() doesn't ever leak memory.  While that's pretty old
code that is unlikely to withstand too many changes in the future, IMHO
it'd be a good idea to note that some callers depend on it not leaking
memory.  That way, future patch authors will be more likely to free
everything they allocated.

I think it's harmless even if it leaks some memory because we only need
to call it once within a transaction, so the memory won’t grow indefinitely.

--
Regards,
ChangAo Chen