Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vYVLE-005O6d-1Y for pgsql-docs@arkaria.postgresql.org; Wed, 24 Dec 2025 20:20:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vYVLD-005bPV-17 for pgsql-docs@arkaria.postgresql.org; Wed, 24 Dec 2025 20:20:16 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vYVLD-005bPM-04 for pgsql-docs@lists.postgresql.org; Wed, 24 Dec 2025 20:20:15 +0000 Received: from mail-ua1-x92b.google.com ([2607:f8b0:4864:20::92b]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vYVLB-002RoX-1p for pgsql-docs@lists.postgresql.org; Wed, 24 Dec 2025 20:20:14 +0000 Received: by mail-ua1-x92b.google.com with SMTP id a1e0cc1a2514c-94124140e02so3909286241.1 for ; Wed, 24 Dec 2025 12:20:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xzilla-net.20230601.gappssmtp.com; s=20230601; t=1766607612; x=1767212412; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=IigYlmd8dMQGFw3rDvwsDqMyZOdXyYif7qr3kf+F5sU=; b=DH/KDmnPoLCJiYEKv4693RpV7k8gNn7kmDXbqf+p52JkENxEaBrAOKv0hH2AZqGrO4 Md6mAdd7hXv7SvLEr3Jx+Wh6ukM8KV68ofwa3F5svHZy57+bRMhBAHWXS6BwCvARisO/ TF/T8XYkZhAI5ba2B2OijerBRD3AvLN8a1tZiE6J/4vshhZo/OhPxYTeopnNyEzwob73 OZ9gikAtwQfQjht5EauimLYcuPRHvcvdMMxr9IJh0JXAIiPsveAPkGrad1/4nzZ+SxZR LNq40bjCmYlcuiRNCHVfx621gY/JKgrta7W529xb3U8uZ19qca4HwOvOatLTrLjMdZuT +Dmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766607612; x=1767212412; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=IigYlmd8dMQGFw3rDvwsDqMyZOdXyYif7qr3kf+F5sU=; b=tU8E4+ZKg6jAKE4mtH1ExA82GqrvGcTFR+pMroEztS3MMJ2vBKl1AFOgywHzz9TdBF bSBF2kNQOARXnDVFUB9OprbbE27stmR/ITX90pk1ZbO1wtEU6/zL3FdEItthb/jKwtWy VlolqM5u/tGJZQyHFaN/w1G/WJ2Nwkb1J0Yz6jrpUf2hif5mZmx5IuNgccCErixKN++9 yy3fC9SBK0yVonW8/JrCc66rbc1vSErCEsm2lTj6LL5vxAZk8xQ+FXuQPkhp3Q2GSyBq sTg19XsJTfkaVJq2nculVUcEAmBdzGozxubkQ73tal8f7y69ehIDbl90QnJtjTF9qUjZ GPow== X-Forwarded-Encrypted: i=1; AJvYcCWK5jz3xXY+6tyBKeH7qKXZbLIi1sd8oZVIFKvKg5/6UUrWu8ZzpuuvUqQLeLmXYqqo/hzyztPY+PGA@lists.postgresql.org X-Gm-Message-State: AOJu0YwNjaAgEYaAsFWyZkHnprPbwdI/4CVomvmrfRlKk4asTvcmmH7I WTm7O7CuMvaORkYmpH3Vn+uN5wbimpx7m189QlPd97I7E6ULg2RirQm/k1SCQgVMH9jjiy6IwBG EJ/jDy1X4e+aHyzcCChzt6aXdPZkMkwDPIX8huLSGSg== X-Gm-Gg: AY/fxX5O16OH6LaLJmaPlyCUp7veOK41rOj49CESE3+KcQN3F3iC8e0aUAn1cBX5Jox NfwcWX3E/FpKSrx+WGMIErXuMjJYlyDrrZ4V8DtFt404m/7zeQZJZ+KnJ0DDP0CLApuZocr0Zbo 8c/2feWSuMHUsLELw0miIuPqL+NjxTw9g5xV9SqnfsFRrPGFHAw3tOPqFP8uJA4mRZErjMfeRam gPmxhC0stLZArjXLeq29zcdv5IE2HEdkmAfDf+5JSEG/VgNJYgicsZtCSF71CBwXzlT1nI= X-Google-Smtp-Source: AGHT+IGyIBCVyYxCPcCzyRf1G+08tlgqqqbQsm0AqrzLmaY3AplENxdc16IValYYVF5GAlDcHX1nJnNSXB/Zlw2pia8= X-Received: by 2002:a05:6102:5489:b0:5df:c4ec:661e with SMTP id ada2fe7eead31-5eb1a853f35mr6446856137.43.1766607612201; Wed, 24 Dec 2025 12:20:12 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Robert Treat Date: Wed, 24 Dec 2025 15:20:00 -0500 X-Gm-Features: AQt7F2r5-g7X58dtvDPpfrmn3gw2A9aB0SIjASNZ-84qqbB4N0pgQ0BlU3PuDEg Message-ID: Subject: Re: More guidance on ctid To: Bruce Momjian Cc: Bernice Southey , pgsql-docs@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Dec 24, 2025 at 2:47=E2=80=AFPM Bruce Momjian wr= ote: > On Wed, Dec 24, 2025 at 07:38:07PM +0000, Bernice Southey wrote: > > Bruce Momjian wrote: > > > We could go in the direction you suggested, but it seems out-of-place= in > > > the UPDATE/DELETE docs since it gets into a lot of details. Maybe in > > > the locking chapter? > > How about if the UPDATE and DELETE examples only show how to get limit > > and order by with a cte, and remove all references to locking. No for > > update, deadlocks etc. The examples use primary keys and not ctid. > > Anyone just trying to do simple limit and order by without locking > > problems will get what they need, and won't be confused by the locking > > complexity. Anyone trying to solve lock contention needs to understand > > locking and should be looking at that chapter. The explanation for > > deadlock avoidance should be there as you suggest. Perhaps the update > > and delete examples can link to them. If you think this is the right > > approach I'm willing to give it a go? > > I am not the author of the original ctid doc patch, but I believe the > goal was to use ctid so we don't need to use needless index lookups for > primary keys. > I think there were multiple goals at play, but IMHO they resulted in an example that was too clever by half. While I have used multiple versions of the technique they were trying to highlight myself, I think it is out of place to add such complex examples in the documentation where we are relying on the behavioral side-effects (locking and ordering) of what is essentially an implementation detail (ctid) and a detail which we really do not recommend users interact with in any general way. If we just focus on the original goal of providing an UPDATE with LIMIT alternative, there are multiple ways to achieve that with much simpler (non-CTE event) syntax. To the degree people feel those solutions don't scale, that's entirely dependent on a combination of factors like schema design, size of data, overall read and write throughputs, among others; things that feel fairly out of scope for what is essentially the grammar portion of the documentation. If people want to add caveats around working at scale, I think Bernice is on the right path by suggesting those things be written about in various other sections of the documentation. While it may seem better to jam all those bits together, it is easy to forget it comes at a cost of complexity for most users, again, which Bernice is a good example of. Robert Treat https://xzilla.net