Re: Eval expression R/O once time (src/backend/executor/execExpr.c)

From: Andres Freund <andres(at)anarazel(dot)de>
To: Ranier Vilela <ranier(dot)vf(at)gmail(dot)com>
Cc: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Eval expression R/O once time (src/backend/executor/execExpr.c)
Date: 2021-09-21 20:19:32
Message-ID: 20210921201932.ou2rnz6yikpwgpbg@alap3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On 2021-09-21 15:09:11 -0300, Ranier Vilela wrote:
> Currently when determining where CoerceToDomainValue can be read,
> it evaluates every step in a loop.
> But, I think that the expression is immutable and should be solved only
> once.

What is immutable here?

> Otherwise the logic is wrong since by the rules of C, even though the
> variable is
> being initialized in the declaration, it still receives initialization at
> each repetition.
> What causes palloc running multiple times.
>
> In other words:
> Datum *domainval = NULL;
>
> is the same:
> Datum *domainval;
> domainval = NULL;

Obviously?

> Thoughts?

I don't see what this is supposed to achieve. The allocation of
domainval/domainnull happens on every loop iteration with/without your patch.

And it has to, the allocation intentionally is separate for each
constraint. As the comment even explicitly says:
/*
* Since value might be read multiple times, force to R/O
* - but only if it could be an expanded datum.
*/
Greetings,

Andres Freund

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jeremy Schneider 2021-09-21 20:47:54 Re: relation OID in ReorderBufferToastReplace error message
Previous Message Andrew Dunstan 2021-09-21 20:13:55 Re: windows build slow due to windows.h includes