Re: Document efficient self-joins / UPDATE LIMIT techniques.

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Corey Huinker <corey(dot)huinker(at)gmail(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Document efficient self-joins / UPDATE LIMIT techniques.
Date: 2023-09-25 06:04:02
Message-ID: CACJufxFA0DyqCf2RFusP5-ArpRaNQAFTDEozgejZZ1EX3M0viQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi.
-----------------------------------------
In cases where a DML operation involving many rows must be performed,
and that table experiences numerous other simultaneous DML operations,
a FOR UPDATE clause used in conjunction with SKIP LOCKED can be useful
for performing partial DML operations:

WITH mods AS (SELECT ctid FROM mytable
WHERE status = 'active' AND retries > 10
ORDER BY id FOR UPDATE SKIP LOCKED)
UPDATE mytable SET status = 'failed'
FROM mods WHERE mytable.ctid = mods.ctid

This allows the DML operation to be performed in parts, avoiding
locking, until such time as the set of rows that remain to be modified
is small enough that the locking will not affect overall performance,
at which point the same statement can be issued without the SKIP
LOCKED clause to ensure that no rows were overlooked.
----------------------------------
mods found out the ctids to be updated, update mytable actually do the update.
I didn't get "This allows the DML operation to be performed in parts".

omit "at which point", the last sentence still makes sense. so I
didn't get "at which point"?

I am not native english speaker.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2023-09-25 06:13:41 Re: pg_upgrade and logical replication
Previous Message Michael Paquier 2023-09-25 05:58:42 Re: pg_upgrade and logical replication