Обсуждение: update behavior

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

update behavior

От
Scott Ribe
Дата:
I believe that if I UPDATE a row with the same values that it already has, this still dirties pages, writes the row,
generatesa WAL entry. There is no shortcut in the processing that's "hey, there's not really a change here, we'll just
leavestorage alone". 

Is this correct?

--
Scott Ribe
scott_ribe@elevated-dev.com
https://www.linkedin.com/in/scottribe/






Re: update behavior

От
"David G. Johnston"
Дата:
On Thu, Jun 19, 2025 at 10:24 AM Scott Ribe <scott_ribe@elevated-dev.com> wrote:
I believe that if I UPDATE a row with the same values that it already has, this still dirties pages, writes the row, generates a WAL entry. There is no shortcut in the processing that's "hey, there's not really a change here, we'll just leave storage alone".

Is this correct?


Correct.  You need a trigger to prevent the update.  There is one provided: suppress_redundant_updates_trigger()


David J.

Re: update behavior

От
Scott Ribe
Дата:
> On Jun 19, 2025, at 11:31 AM, David G. Johnston <david.g.johnston@gmail.com> wrote:
>
> Correct.  You need a trigger to prevent the update.  There is one provided: suppress_redundant_updates_trigger()

Or, in my case that prompted this question, I need a WHERE clause for the ON CONFLICT UPDATE...





Re: update behavior

От
Tom Lane
Дата:
Scott Ribe <scott_ribe@elevated-dev.com> writes:
> I believe that if I UPDATE a row with the same values that it already has, this still dirties pages, writes the row,
generatesa WAL entry. There is no shortcut in the processing that's "hey, there's not really a change here, we'll just
leavestorage alone". 

> Is this correct?

It is.  We do offer a trigger you can add to suppress zero-change
updates [1], but that's not the default behavior.  We judged that
checking for that would add more cycles than it removes, for most
applications most of the time.

            regards, tom lane

[1] https://www.postgresql.org/docs/current/functions-trigger.html