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 1uqUls-007HjS-D8 for pgsql-hackers@arkaria.postgresql.org; Mon, 25 Aug 2025 10:49:53 +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 1uqUlr-008KMR-JD for pgsql-hackers@arkaria.postgresql.org; Mon, 25 Aug 2025 10:49:52 +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.94.2) (envelope-from ) id 1uqUlr-008KMJ-9S for pgsql-hackers@lists.postgresql.org; Mon, 25 Aug 2025 10:49:51 +0000 Received: from mail-vk1-xa32.google.com ([2607:f8b0:4864:20::a32]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uqUlp-001kIN-2Q for pgsql-hackers@postgresql.org; Mon, 25 Aug 2025 10:49:51 +0000 Received: by mail-vk1-xa32.google.com with SMTP id 71dfb90a1353d-53b174dbfceso1320315e0c.2 for ; Mon, 25 Aug 2025 03:49:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1756118988; x=1756723788; darn=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=lH8AghX0poq6H8t4F1SEpIzazbu95yVpEtOBDxWjg2c=; b=kxcxQxlB+6r7/WRn4fzTmYlmoYSOACpxKxyd8bcW164bDZlF/b99Y/9eQn4CNvbI5K kbOaejx15QiISRCX9j/DGAqGzckKMw/whFMjbc6DxJG9tvkyNTtXI5F+4G9fI6JvshbB RYEJjfQlKR8LBCapTnEn/t/IzeR/UtyvFPZbsWNGNN9s3/G5TDrHFwCcTqNqa/wDV8ri TO4bkirF7IZgPXQlpRWJ5PsKPtK1a5l3dhOdrjLQz+QDe+hRNHv0zu2r3zgj8/dKb0dE yaHqQk0nKBKpjGnIbqnynnFyujTengwSLhk6FgzWYXpHLDE3BgXAMXRaCBNj/jIla7y9 y7jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756118988; x=1756723788; h=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=lH8AghX0poq6H8t4F1SEpIzazbu95yVpEtOBDxWjg2c=; b=xT9iLvZPWO5ElfEXASHrCz8H8osVZWyUY4ggzQLWjNFdb9t8F79lWPmEd4ZEDFwV/v DZgPjmyJaC38YiINeUVzvO7hlI26UN3RkrVViIRFiIMNo7435aTnZsfHM2GznaMaDKho j4/scv0WuhHYwqqoSuV2aRjB5yPiCYHgu/N/ojgz8KGV1UCXtpXHPUrjEoaamorElJqs lP/vwWtP+U0shp//GqsK7D3wF4LStf0ktOsIIccetEpVfKKxl36qq2Ijvj4YTCZBx+k1 UaCyBDyc7z1YmgT9CkO2ll93bEAVnsadvIpZ8i462zPH8JF6YUqzqiJjlfuu1/E6jE0y vaWg== X-Forwarded-Encrypted: i=1; AJvYcCUQo6Ttc0bUybrVLJ3A2V77RTCwZ2a1MWu7A6wa/roa8+mrti+9KrWvSQ2Amoset8caj01Fj+j39KR61IaZ@postgresql.org X-Gm-Message-State: AOJu0YwNwHzWczRYmYSQKUi2joC2Ugo2u2oCRyenyE8HeizrfKrnmDeq Cm9w5oeo6Ldv5EGyMCSdqfpvXBFlWL19lh6zH7U/rsWM2/3WGHdEjx8odYYBUEmVGgKYwzTx5s6 elrAvLrQSUDNiQ8Qbx+EEhpKPAdH44ks= X-Gm-Gg: ASbGnctPnhFF7P4rF60k5KBhAgCZumTFzxMSwT7/+Oxpat2NqkMxiVGw40yxZcUcNJm pc+9bdmrWKiUfoFZif8ZuanTy8SCOZM8CXVQS60Ok24NKmZTJZUdPz6s8bmi3QuE7khfLvNzR9J G+ZuGKZSe0sPWfuBzM/ilrYxaBl6/HBKABvomzWBV6hMsUWagSFsnNUXRR5aqxJSlDRqMisugIa xhywqNoupgcgDgdAlFZkJTO6r1f3D6rDjICk8qIVzkPnL/ZFX/I X-Google-Smtp-Source: AGHT+IEjg2z37yY7LuQAKE5CLD2MNnI9C6oMH0ySQ/mPkNTAyB2OyMJheY/fsTZizVN6G3Da28mP/Vo5BgsWN1oWTT0= X-Received: by 2002:a05:6122:1d41:b0:53c:6d68:1cd3 with SMTP id 71dfb90a1353d-53c8a43609bmr3305439e0c.13.1756118987735; Mon, 25 Aug 2025 03:49:47 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Mihail Nikalayeu Date: Mon, 25 Aug 2025 12:49:10 +0200 X-Gm-Features: Ac12FXweRLeuO77hcCSdgUELpG1Dpflx39AUfeUsb4r7LbwZGP0Yw1GWSShrUxs Message-ID: Subject: Re: [BUG?] check_exclusion_or_unique_constraint false negative To: Amit Kapila Cc: "Zhijie Hou (Fujitsu)" , Peter Geoghegan , "Hayato Kuroda (Fujitsu)" , PostgreSQL Hackers , Andres Freund Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello! > 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. > 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. 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 * 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. > 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. Best regards, Mikhail.