]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
doc: warn about the use of "ctid" queries beyond the examples
authorBruce Momjian <bruce@momjian.us>
Fri, 26 Dec 2025 22:34:17 +0000 (17:34 -0500)
committerBruce Momjian <bruce@momjian.us>
Fri, 26 Dec 2025 22:34:17 +0000 (17:34 -0500)
Also be more assertive that "ctid" should not be used for long-term
storage.

Reported-by: Bernice Southey
Discussion: https://postgr.es/m/CAEDh4nyn5swFYuSfcnGAbpQrKOc47Hh_ZyKVSPYJcu2P=51Luw@mail.gmail.com

Backpatch-through: 17

doc/src/sgml/ddl.sgml
doc/src/sgml/ref/delete.sgml
doc/src/sgml/ref/update.sgml

index a00e496798f99eefbbd6aba4dca8e12e6cea11b7..45aba2113393a0b2661773725ad68d7c4311764b 100644 (file)
@@ -1468,7 +1468,7 @@ CREATE TABLE circles (
       locate the row version very quickly, a row's
       <structfield>ctid</structfield> will change if it is
       updated or moved by <command>VACUUM FULL</command>.  Therefore
-      <structfield>ctid</structfield> is useless as a long-term row
+      <structfield>ctid</structfield> should not be used as a row
       identifier.  A primary key should be used to identify logical rows.
      </para>
     </listitem>
index 7717855bc9ef4877307b8bde1857ab010c5ff7aa..f61ecc7881b85e93e92af021dbc74a5e8ba2935d 100644 (file)
@@ -285,6 +285,9 @@ DELETE FROM user_logs AS dl
   USING delete_batch AS del
   WHERE dl.ctid = del.ctid;
 </programlisting>
+   This use of <structfield>ctid</structfield> is only safe because
+   the query is repeatedly run, avoiding the problem of changed
+   <structfield>ctid</structfield>s.
   </para>
  </refsect1>
 
index 1c433bec2bb8efcfd848af367c34c4f93daea761..456d03a0104bced10f597d870c4caff1802008fc 100644 (file)
@@ -470,6 +470,9 @@ UPDATE work_item SET status = 'failed'
   WHERE work_item.ctid = emr.ctid;
 </programlisting>
    This command will need to be repeated until no rows remain to be updated.
+   (This use of <structfield>ctid</structfield> is only safe because
+   the query is repeatedly run, avoiding the problem of changed
+   <structfield>ctid</structfield>s.)
    Use of an <literal>ORDER BY</literal> clause allows the command to
    prioritize which rows will be updated; it can also prevent deadlock
    with other update operations if they use the same ordering.