Is a clearer memory lifespan for outerTuple and innerTuple useful?

From: Andy Fan <zhihuifan1213(at)163(dot)com>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Is a clearer memory lifespan for outerTuple and innerTuple useful?
Date: 2023-12-15 07:35:15
Message-ID: 87edfnc3nh.fsf@163.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


Hi,

When I am working on "shared detoast value"[0], where I want to avoid
detoast the same datum over and over again, I have to decide which
memory context should be used to hold the detoast value. later I
found I have to use different MemoryContexts for the OuterTuple and
innerTuple since OuterTuple usually have a longer lifespan.

I found the following code in nodeMergeJoin.c which has pretty similar
situation, just that it uses ExprContext rather than MemoryContext.

MergeJoinState *
ExecInitMergeJoin(MergeJoin *node, EState *estate, int eflags)

/*
* we need two additional econtexts in which we can compute the join
* expressions from the left and right input tuples. The node's regular
* econtext won't do because it gets reset too often.
*/
mergestate->mj_OuterEContext = CreateExprContext(estate);
mergestate->mj_InnerEContext = CreateExprContext(estate);

IIUC, we needs a MemoryContext rather than ExprContext in fact. In the
attachment, I just use two MemoryContext instead of the two ExprContexts
which should be less memory and more precise semantics, and works
fine. shall we go in this direction? I attached the 2 MemoryContext in
JoinState rather than MergeJoinState, which is for the "shared detoast
value"[0] more or less.

[0] https://www.postgresql.org/message-id/87ttoyihgm.fsf@163.com

Attachment Content-Type Size
v1-0001-Use-MemoryContext-instead-of-ExprContext-for-node.patch text/x-diff 4.4 KB
unknown_filename text/plain 27 bytes

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andy Fan 2023-12-15 07:51:10 Re: Is a clearer memory lifespan for outerTuple and innerTuple useful?
Previous Message wenhui qiu 2023-12-15 06:40:31 Support "Right Semi Join" plan shapes