doc: warn about the use of "ctid" queries beyond the examples

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
pull/259/head
Bruce Momjian 2 weeks ago
parent f8a4cad8f4
commit e82e9aaa6a
  1. 2
      doc/src/sgml/ddl.sgml
  2. 3
      doc/src/sgml/ref/delete.sgml
  3. 3
      doc/src/sgml/ref/update.sgml

@ -1558,7 +1558,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>

@ -323,6 +323,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>

@ -503,6 +503,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.

Loading…
Cancel
Save