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 1vJ7DW-00B7uC-28 for pgsql-hackers@arkaria.postgresql.org; Wed, 12 Nov 2025 09:32:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vJ7DU-00AbCS-0I for pgsql-hackers@arkaria.postgresql.org; Wed, 12 Nov 2025 09:32:40 +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 1vJ7DT-00AbCK-2S for pgsql-hackers@lists.postgresql.org; Wed, 12 Nov 2025 09:32:39 +0000 Received: from mail-pg1-x534.google.com ([2607:f8b0:4864:20::534]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vJ7DR-007Jje-0h for pgsql-hackers@lists.postgresql.org; Wed, 12 Nov 2025 09:32:39 +0000 Received: by mail-pg1-x534.google.com with SMTP id 41be03b00d2f7-b553412a19bso396683a12.1 for ; Wed, 12 Nov 2025 01:32:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762939954; x=1763544754; darn=lists.postgresql.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=ZzL0D5fKfRWjcGhtFEdEcr/lKyWGy4jAlwe6NbIa7cA=; b=cAxh1LYJKkfwKamlR0d6aJ3dk2Sq+LeLgsrUSCdAuenoVUSJ8MzhRLxuQdLs/p7Cfk EHjy52RrJwyd3YvF9sb+hpxWm5lWqsrtCCRkndVwpxhG0g6VtZIIs5upxkugSPxpIYRV b0nOQQJPYLo62p8a3TPFf0I/GLJpPx8iKjdYNvNHX5YcPe18s5zPA5T9swyiAcS88tQR zwNzXSJ+mUOG7j1c8G2WSSWQ2T3Y4okaCJryvbqm4G0bUz6fdK3ZbAfrpSLk0Od/dOh2 OCSFPfiKaUgQsq5KuVQa0tqn4w49gohPj7hoEs1mr/XloodmuNQz+NkCPwayT+79v3J/ BKMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762939954; x=1763544754; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=ZzL0D5fKfRWjcGhtFEdEcr/lKyWGy4jAlwe6NbIa7cA=; b=JO5/xccpN0munQThuEHIb2kkFKkCIz+Xfq2eSWkhrYWAWaMNDK7ciL8Ud/+YYYwCYa vP1VBS63AFmOmoPyAfvZwJWC4xzjTHn6vptX73BTeE7qU9EeO/veQIAqUGpDBb8M2v/h 6DBqQAFcTfEqPsfMIcrkrf+zRR3oJirUA4tsfd5vz4ok4z4T9vpvtee3UqErFB9U9b8M BnhLvJEzjkvs1biS28qVDodA8C+336wpIWltT/H6cqI5e2hEKxKR/jfvNXL0slDId8L+ rz8D2fDvgfzzZ14X6f5XWzyqUxQkpt2GqT+RTi5Bbs8m4mZY9vnWV7kdTl0Hr9BRy1Rx wiGQ== X-Forwarded-Encrypted: i=1; AJvYcCWSOSuRQShcfr14exBmIirnedu3RPJg8VJevmHKCuOaPnlJ1uLZ/RahSq3YVjqaghAl5zf7OuSwyySvpZdH@lists.postgresql.org X-Gm-Message-State: AOJu0Yyct1LalQpWK2QpWk8VayJCgp9YI6Y3e288cUAxJZqaOhCtlEkB m0YN+0pRWd0pVbOwGdHZXCVXOIu9MlPaN9nS2QKEm2hiHSP4kURv2fwN X-Gm-Gg: ASbGncv0Q9l9tmBcZF4EOMoGXvKOpTYobwB8ZJAuh27tGJP7NezAWaVu+0i9iKiyWzN ZSNSkyEwBsVLBIhf/PhEbAYcQ+nyRrlFDSRqbpXPoZ2xKBtVmTzhGQHo+FxtQl3+WahFVxJ0TNh TRRkKFPA6arNcz7nYAKorq/Ja8Obz/eZ48/SjWQkLH6+LcR2o1hoazA6slqSAf9XnHYeCts0Jow OyKFoumsDUn2ozMGWlC12NaZNEvVJ0hCjuSoPtA1EyDr4i6i/GXHXvlu1hZC7o+/ceQdY+qk6KW uZU79PywjFZqqb8ShfoGqTiN1QGj06XyCGXzskfQDNwdFLR4MpeiMBxg8kqCmWDkNh6QmkEpZLT gv4uFCu81pXS9XYcmc0da3BM4KzxqVb7ivp13O+db1msYeyQ/4pi1qN0o6icJuldI7BMfrlElbg 30mblm7c9aPw== X-Google-Smtp-Source: AGHT+IFyw1rm5513uU3JqWUf8bGB1k+5ZVqQEG9aMgL2MvQNiZBPoHyPtcwxr1eIJ4U9PqKj+C/7Zw== X-Received: by 2002:a17:902:d60b:b0:295:557e:7476 with SMTP id d9443c01a7336-2984ed27f76mr30583605ad.7.1762939954194; Wed, 12 Nov 2025 01:32:34 -0800 (PST) Received: from smtpclient.apple ([209.127.78.222]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2984dbf13a3sm24110585ad.35.2025.11.12.01.32.30 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Nov 2025 01:32:33 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.700.81\)) Subject: Re: SQL:2011 Application Time Update & Delete From: Chao Li In-Reply-To: Date: Wed, 12 Nov 2025 17:31:53 +0800 Cc: Peter Eisentraut , PostgreSQL Hackers Content-Transfer-Encoding: quoted-printable Message-Id: <7A20FF56-1A90-4221-A95E-5A605E36410A@gmail.com> References: <2f5364f3-a1d3-4410-98f3-d788b11e6525@eisentraut.org> To: Paul A Jungwirth X-Mailer: Apple Mail (2.3826.700.81) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Nov 5, 2025, at 03:12, Paul A Jungwirth = wrote: >=20 > On Wed, Oct 29, 2025 at 11:02=E2=80=AFPM Paul A Jungwirth > wrote: >>=20 >> On Tue, Oct 28, 2025 at 3:49=E2=80=AFAM Peter Eisentraut = wrote: >>> On 24.10.25 19:08, Paul A Jungwirth wrote: >>>> The first 3 doc patches all apply to features that we released in = v18, >>>> so it would be nice to get those reviewed/merged soon if possible. >>>=20 >>> I have looked through the documentation patches 0001 through 0003. >>=20 >> Thanks for taking a look! New patches attached; details below. >=20 > Hi Hackers, >=20 > Here is another set of patches. I added isolation tests for FOR > PORTION OF. In REPEATABLE READ and SERIALIZABLE you get > easy-to-predict results. In READ COMMITTED you get a lot of lost > updates/deletes, because the second operation doesn't see the > leftovers created by the first (and sometimes the first operation > changes the start/end times in a way that EvalPlanQual no longer sees > the being-changed row either). I think those results make sense, if > you think step-by-step what Postgres is doing, but they are not really > what a user wants. >=20 > I tested the same sequences in MariaDB, and they also gave nonsense > results, although not always the same nonsense as Postgres. At > UNCOMMITTED READ it actually gave the results you'd want, but at that > level I assume you will have other problems. >=20 > I also tested DB2. It doesn't have READ COMMITTED, but I think READ > STABILITY is the closest. At that level (as well as CURSOR STABILITY > and REPEATABLE READ), you get correct results. >=20 > Back to Postgres, you can get "desired" results IN READ COMMITTED by > explicitly locking rows (with SELECT FOR UPDATE) just before > updating/deleting them. Since you acquire the lock before the > update/delete starts, there can be no new leftovers created within > that span of history, and the update/delete sees everything that is > there. The same approach also gives correct results in MariaDB. I > think it is just the way you have to do things with temporal tables in > READ COMMITTED whenever you expect concurrent updates to the same > history. >=20 > I considered whether we should make EvalPlanQual (or something else) > automatically rescan for leftovers when it's a temporal operation. > Then you wouldn't have to explicitly lock anything. But it seems like > that is more than the isolation level "contract", and maybe even plain > violates it (but arguably not, if you say the update shouldn't *start* > until the other session commits). But since there is a workaround, and > since other RDBMSes also scramble temporal data in READ COMMITTED, and > since it is a lot of work and seems tricky, I didn't attempt it. >=20 > Another idea (or maybe nearly the same thing) would be to > automatically do the same thing that SELECT FOR UPDATE is doing, > whenever we see a FOR PORTION OF DML command---i.e. scan for rows and > lock them first, then do the update. But that has similar issues. If > it adds locks the user doesn't expect, is it really the right thing? > And it means users pay the cost even when no concurrency is expected. > It offers strictly fewer options than requiring users to do SELECT FOR > UPDATE explicitly. >=20 > The isolation tests are a separate patch for now, because they felt > like a significant chunk, and I wanted to emphasize them, but really > they should be part of the main FOR PORTION OF commit. Probably I'll > squash them in future submissions. That patch also makes some small > updates to a comment in ExecForPortionOf and the docs for > UPDATE/DELETE FOR PORTION OF, to raise awareness of the READ COMMITTED > issues. >=20 > Rebased to 65f4976189. >=20 > Yours, >=20 > --=20 > Paul ~{:-) > pj@illuminatedcomputing.com > = I tried to review this patch. Though I =E2=80=9Cgit reset=E2=80=9D to = commit 65f4976189, =E2=80=9Cgit am=E2=80=9D still failed at 0009. Today I only reviewed 0001, it was a happy reading. I found a small typo = and got a suggestion: 1 - 0001 ``` + entity described by a table. In a typical non-temporal table, there = is + single row for each entity. In a temporal table, an entity may have=20= ``` =E2=80=9CThere is single row=E2=80=9D should be =E2=80=9Cthere is a = single row=E2=80=9D. 2 - 0001 - The doc mentions rangetypes which is the key factor for = defining a temporal table, can we add a hyper link on =E2=80=9Crangetype=E2= =80=9D so that readers can easily jump to learn which rangetypes can be = used. I will continue to review the rest of commits tomorrow. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/