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.94.2) (envelope-from ) id 1uqVjk-007b33-Pt for pgsql-hackers@arkaria.postgresql.org; Mon, 25 Aug 2025 11:51:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uqVjj-008niP-NU for pgsql-hackers@arkaria.postgresql.org; Mon, 25 Aug 2025 11:51:44 +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.94.2) (envelope-from ) id 1uqVjj-008niH-A2 for pgsql-hackers@lists.postgresql.org; Mon, 25 Aug 2025 11:51:44 +0000 Received: from mail-lf1-x135.google.com ([2a00:1450:4864:20::135]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uqVjh-001eXC-0Z for pgsql-hackers@postgresql.org; Mon, 25 Aug 2025 11:51:42 +0000 Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-55f3533fd05so2516482e87.0 for ; Mon, 25 Aug 2025 04:51:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1756122700; x=1756727500; darn=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=z5C4dYH4gepcNA8uo5ztE2yXBJ4MqlwEtR0mG4Pw0kM=; b=i5uuIueh5a3d8jUoo25k8gfL4vLMuD5E1SYHHsT2146t9vGvyQsWs/oq7TOYuCLeEb PipD/qR73x2kSMYRBXX656czIVH9WFU/AxJU9L9loEX9uu4lrmsVB7wErhdqPpUINOGE z8yqlb7RIRE2KOYJbtWoiltJgmJxnXPsUw272k+o+gIL8SB9m2EJ6DtobXisylxdNYIn 9VInfWBYzalMNjX8HfI36Lgg9dd3kbKNQb4lcuE9jLkDqY6zkIwHiSR7EE5cMRs3VRxW auLCcxlyhivpYZraHh/WRFKGnVIT6ydXKULS5QazVTMK0vFWPkz+KZP4nS4ZuvHPYtbv yJFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756122700; x=1756727500; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=z5C4dYH4gepcNA8uo5ztE2yXBJ4MqlwEtR0mG4Pw0kM=; b=ZshDJy2Qi5m2dxnzAqI26dliPXbv0tUNmXGYdUzLkfXPy/WDTby6NhdR0xZpcW2wPd O0SGdEEyHjqcGph2Nk/K7h/i2XpVtFYz0r8dVpcJxDYpGml9cskQhGwoC+V80UOFPCN9 2UNsl6pVE8MOYDfyccaTfNi4+9/w5XQ9xlDqC2IqbmiiJ5KC61xWoTpB4b+Y0x8ovaaw rubijhRNKqM9DPZpRrYUPKUBK1R/l8RGeg2UWZLEm3kgyIjFLgPpqXOXALITGkahRk5w zH3HRQBt+pHYKfI4EUca3S8Rz+wa+1dSq6ipnmlHg2fHbrc1F4Vg9FHeRmH44YCn05Vc udNA== X-Forwarded-Encrypted: i=1; AJvYcCVXWgZbyWhRhn77QEB1Ia5MhmFE8TT78aEAghgECJLX+iOWjJKiOsM1qZhOdL3yuD6fNecNsB6SC+1BR2ng@postgresql.org X-Gm-Message-State: AOJu0YzSwDMckLYwdluukP5orI5xpo/4V75zEMWjzBN2GfsknqX8DSLn vwxD7mgj7ZSYKtXNXaIWKuJr8/SyRPyi3xrm94C91033PagzoZUBVfFyLi7NfKqzIduyws2Z0gw 08/DoS5FVkA8P7gJ4P/FZyJa4OT6VBCs= X-Gm-Gg: ASbGncujkn9ERemuTQ3r13jop5g6JnmBsL86uHaMk3Danp5pIaN4VXB22TieUns45H6 aCdlynn27cvY71ZIZ5JGxYzfPg80vcXQ6HsGMGQuCbzga00fJgc6r8oHlDvZQiOLpIKwOThljtf 1y2Krbfx2Y5lCqBfp1vNwLBUZFJyy6Q98526oe4Tam549h8yhLV70gAJM3s3hoXjzL0cHdJ3sj9 hkT35fdQQ== X-Google-Smtp-Source: AGHT+IEH42YR0i1YWjGMrk8rXsrT3UJex/q13+qoLtYMlHHg2i3Zm3/h56PuCa94nlG1v3RlwTYoXmmsSBxPZSKFcVg= X-Received: by 2002:a05:6512:1244:b0:55f:4400:f2f6 with SMTP id 2adb3069b0e04-55f4400f686mr1240667e87.42.1756122699938; Mon, 25 Aug 2025 04:51:39 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Amit Kapila Date: Mon, 25 Aug 2025 17:21:27 +0530 X-Gm-Features: Ac12FXylWmUFU5RkJEfRGnFnNLhjl5rzmW8aNzK1WIz5-GFeqWVDh5cpN73WVP0 Message-ID: Subject: Re: [BUG?] check_exclusion_or_unique_constraint false negative To: Mihail Nikalayeu Cc: "Zhijie Hou (Fujitsu)" , Peter Geoghegan , "Hayato Kuroda (Fujitsu)" , PostgreSQL Hackers , Andres Freund 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 Mon, Aug 25, 2025 at 4:19=E2=80=AFPM Mihail Nikalayeu wrote: > > > Why only by luck? > > I mean last_write_win provides the same results in the following cases: > * we found the tuple, detected a conflict, and decided to ignore the > update coming from the publisher > * we were unable to find the tuple, logged an error about it, and > ignored the update coming from the publisher > > In both cases, the result is the same: the subscriber version remains > in the table. > Right, so we can say that it will be consistent. > > Then these may not lead to eventual consistency for such cases. So, > > not sure one should anyway rely on these. > > But with the fixed snapshot dirty scan, it becomes possible to > implement such strategies. > Also, some strategies require some kind of merge function for tuples. > In my understanding, even last_write_win should probably compare > timestamps to determine which version is "newer" because time in > distributed systems can be tricky. > Therefore, we have to find the tuple if it exists. > > > BTW, then isn't it possible that INSERT happens on a different page? > > Yes, it is possible - in that case, the bug does not occur. It only > happens if a new TID of some logical tuple is added to the same page. > What if the new insert happens in a page prior to the current page? I mean that the scan won't encounter the page where Insert happens. > Just to clarify, this is about B-tree pages, not the heap. > > > I think this questions whether we consider the SnapshotDirty results > > correct or not. > > In my understanding, this is clearly wrong: > * such behavior is not documented anywhere > I agree. This is where we need inputs. > * usage patterns assume that such things cannot happen > * new features struggle with it. For example, the new update_deleted > logging may fail to behave correctly > (038_update_missing_with_retain.pl in the patch) - so how should it be > used? It might be correct, but it also might not be... > > Another option is to document the behavior and rename it to SnapshotMaybe= :) > By the way, SnapshotSelf is also affected. > BTW, do we know the reason behind using SnapshotDirty in the first place? I don't see any comments in the nearby code unless I am missing something. > > The case of logical replication giving wrong results > > [0] is the behavior from the beginning of logical replication. > > Logical replication was mainly focused on replication without any > concurrent updates on the subscriber side. So, I think this is why the > issue was overlooked. > The other possibility is that as this is a rare scenario so we didn't consider it. --=20 With Regards, Amit Kapila.