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 1vYSxZ-004AaL-0s for pgsql-docs@arkaria.postgresql.org; Wed, 24 Dec 2025 17:47:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vYSxW-005HmU-01 for pgsql-docs@arkaria.postgresql.org; Wed, 24 Dec 2025 17:47:38 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vYSxV-005HmM-2R for pgsql-docs@lists.postgresql.org; Wed, 24 Dec 2025 17:47:38 +0000 Received: from mail-yx1-xb12f.google.com ([2607:f8b0:4864:20::b12f]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vYSxT-002YTh-2Q for pgsql-docs@lists.postgresql.org; Wed, 24 Dec 2025 17:47:37 +0000 Received: by mail-yx1-xb12f.google.com with SMTP id 956f58d0204a3-6447743ce90so5700595d50.2 for ; Wed, 24 Dec 2025 09:47:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766598453; x=1767203253; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=HvJgafweQMyJewlGJJLVk5RbL05lAs81VSSCf0YUHFs=; b=aWBrMQRXbHUhaMkmTV8m60EmVYkLcUkppktfb70vtv+4gAiC88Pv9deElZz/JwHzbN uPxMFcZeo3DOdfeOCo2yOqSonPKZGOuexZLagh+oq3fM9idtFwzIvXTPnaam++fB0n94 7PNWXt3zBKRRDYoKWnRU+DYR2YSiOFsmXrQyFEKVycnR21V0k8jRU1994LvUE/E0e2hn YRCwKENtjUM2cnAhB2jmgVSyRNvxlq/j6M7M9mcqSx86qGQaeHWz+W6HWjV9+cTun/MI GjR0qYdWd80dLkU7fFVxy1/Tqix9++IJTXr+LOoN1+78yRLZUNvElUfTzBsZBFAndwOL /A8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766598453; x=1767203253; h=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=HvJgafweQMyJewlGJJLVk5RbL05lAs81VSSCf0YUHFs=; b=nVnZNh3xd4OMaDbvrRZ1rt2YelerMzBo08r41F23uHwfFBE10riWk+RpzzDukCGsyN 9E0g7r5u2nZbglBeTaPPCMFZSGmfGTcuFb0ZuWmcPqYfGSyw0gXj1HT2eoVnnoo6fQYV aNAejsll0H02kQgTv118HqL71zMr/gx0p1lvTZXI0GqEiCWM2t8FEpZdvGUO8m7ThJ7B 04PKZX1EgI6KJl5ICJbp1jdrxvzruc0rkadzf16XWPpgcyNs2CngNwFWfnOYBihFPQ1o dE8/fpXXxbthhoChC+VQcEmZOVkUx0as4l4fPUVuLLOBf4/jws+lE09fPVU5Cg6JJUH+ dkSw== X-Gm-Message-State: AOJu0YxmEluitr1Oaptiy6WvIOsFjF79zmXuifnwG9mBZ3rObVHvDDAi EIkvQAubXdzf1Xz+EkG2iRKNy/oi4VaSMCGAe+2PEJrEJ3YoZIyCw1UBbP8pSO3z3FEOc5/v65k qQgLxn9/VxGX7Kl4yiTSIHzE4uDGhW64= X-Gm-Gg: AY/fxX4rp9+1tP6lrbHWOL1NY7j39aTwLSFSZnLeEJe+DvYJIZ3TNCPbwwiZVpjYM8K xQcKFT/AsuQew0Aj8IXXPRL2I/khnI/CClKyknVAW+ZKmDXlG6JETUaOrT24Jgy3uycowJdNsBc uT7uK86/y6UwLHblKHwLZIiwWdDDWqiW+iTAmZNAPqCf9auCkmFSgwYj/jxQ3XpXcKOzZoYahlJ hQ3MusuyRBsWKyIvRcwkUIOy7DTsfusGwokjNLry/JTpm4s3vH5rIB2jrmYWC1pNy5j009gHRbe lBGwQRIBzpr22LhE1yr+ X-Google-Smtp-Source: AGHT+IFdr2fg5//Q7LWCBmrT2X3v6lzGm/QqmLBJQktWt761/DMoSYRyHCqLI/BnWpFXseAWx/uPIr1VM3RzuZme/c8= X-Received: by 2002:a05:690e:13c8:b0:645:527b:bc11 with SMTP id 956f58d0204a3-6466a83234bmr13878447d50.3.1766598453549; Wed, 24 Dec 2025 09:47:33 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Bernice Southey Date: Wed, 24 Dec 2025 17:46:57 +0000 X-Gm-Features: AQt7F2otZl7rejvYnsNLuASOQCHMR9d6KvFBxS30StvJH1d-RghhIMX6CY9uBD0 Message-ID: Subject: Re: More guidance on ctid To: Bruce Momjian Cc: pgsql-docs@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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? hmmmmm...the original examples were introduced to show people how to work around no order by and limit for update and delete. That capability would of course be the simplest solution for everyone to understand and would hide all this locking trouble. If only it was simple to add. But in the absence of this, the cte select pattern does work as a substitute. Since the complexity cat is already out the bag with these examples in UPDATE and DELETE, showing how to use the work-around properly seems responsible and worth it. The hard part is keeping it simple. In a different life when I was a service developer, my excellent SQL Server data architect told me the only way to avoid deadlocks on multirow updates was retries. This didn't work. Deadlocks were the bane of our system. A couple of years ago my very experienced partner rearchitected part of his Postgres system after deadlocks killed the performance. He was unaware deadlocks were caused by ordering. (It was his fist postgres system.) I expect many systems prematurely avoid batching because of deadlocks, when all they need is ordering. This is a pity because batching is brilliant for performance when done right. This history is why I'm keen on properly explaining how to avoid deadlocks. I ran headlong into the locking issues using this cte select pattern because I had an improper understanding of the locking. One of the last things I added in my patch was the link to the MMVC doc and maybe this level of detail is unnecessary. Maybe there's a way to phrase this all that's less intimidating. The rule of thumb is use skip locked with ctid and otherwise your primary key, and then you should be fine with this pattern. To introduce these examples where your rows can change underneath you without some warning, is problematic. Those are my Christmas eve thoughts because I go eat my delicious dinner. Have a lovely holiday! Thanks, Bernice