Re: Using Expanded Objects other than Arrays from plpgsql

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andrey Borodin <x4mmm(at)yandex-team(dot)ru>
Cc: Michel Pelletier <pelletier(dot)michel(at)gmail(dot)com>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Using Expanded Objects other than Arrays from plpgsql
Date: 2025-01-26 19:04:41
Message-ID: 46876.1737918281@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

Andrey Borodin <x4mmm(at)yandex-team(dot)ru> writes:
> On 26 Jan 2025, at 20:37, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> Maybe we should recast it as an action. What do you think of
>> "mark_expr_as_assignment_source"?

> Sounds better to me. I found no examples of similar functions nether in pl_gram.y, nor in gram.y, so IMO mark_expr_as_assignment_source() is the best candidate.

WFM, I'll make it so in next version.

> Got it, many thanks for the explanation.

I'll see about incorporating more of that in the comments, too.

> I wonder if you plan similar optimizations for array_cat(), array_remove() etc?
> + a := a || a; -- not optimizable
> Why is it not optimizable? Because there is no support function, because array_cat() has no support function, or something else?

plpgsql won't attempt to optimize it because "a" is referenced twice
and there is no support function that might say it's safe anyway.

array_cat doesn't currently have any special smarts about expanded
arrays, so it's all moot because the arrays would get flattened
on the way into it. If we did improve it to be able to cope with
expanded arrays, I'm not real sure that it could safely manage an
in-place update where the two inputs are the same array --- at
the least, some extreme care would be needed to get the right
answers.

I'm not real excited about optimizing additional array operations
anyway. Maybe some more will get done at some point, but I don't
see that as part of this work.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message jian he 2025-01-27 08:16:26 Re: Emitting JSON to file using COPY TO
Previous Message Adrian Klaver 2025-01-26 17:33:06 Re: FATAL: could not send data to WAL stream: lost synchronization with server: got message type "0", length 892351284

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2025-01-26 19:23:47 Re: MAX_BACKENDS size (comment accuracy)
Previous Message Andres Freund 2025-01-26 18:15:11 Re: MAX_BACKENDS size (comment accuracy)