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 1sZS4I-0015y3-E9 for pgsql-hackers@arkaria.postgresql.org; Thu, 01 Aug 2024 09:25:54 +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 1sZS4G-006B0i-7I for pgsql-hackers@arkaria.postgresql.org; Thu, 01 Aug 2024 09:25: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 1sZS4F-006B0a-Sy for pgsql-hackers@lists.postgresql.org; Thu, 01 Aug 2024 09:25:51 +0000 Received: from mail-ed1-x529.google.com ([2a00:1450:4864:20::529]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sZS4D-002aGS-Si for pgsql-hackers@postgresql.org; Thu, 01 Aug 2024 09:25:51 +0000 Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-5a156557029so10820501a12.2 for ; Thu, 01 Aug 2024 02:25:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722504348; x=1723109148; 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=N1y4YmhWNAaGCWbPjrKUiakWZlHsaD1xUhRVkmKDjhI=; b=HxN4eBsR5anxI5RuwLLNY7qEUiaKhIZjQmwouzKJF/rWtkF+m5cx0kZC/a3SwqgXcY UN+wfZSlNe/4aCbDjbbw3UbB2YwvRkpWvWlxzFA3X3NcG+iBD7c0q1N66RLiBd5v8aHv SJuAzkgW2bfKk2In+MjSQhQe/GgqrBinVGf99aQq/aJUZhevLaXKmrjN3ABdK7iPUdyK P1+dNJkXQCW5YjHJ/x2txKRwzO5ORZIwtj4XYh1H24TopENV8iW73dm0AnAhQNb3zqKq BVGREll0Cy3/EtLiLMm0Bs7X91pKmPPkMDI8MsNh+OWKLM9j/gN3l3p05jOay3D2uuoX w95g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722504348; x=1723109148; 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=N1y4YmhWNAaGCWbPjrKUiakWZlHsaD1xUhRVkmKDjhI=; b=NEgRgbIgY9PjXEVCWHAysck10wDTyNbBV0EUyJCk9AeCdL8kBNI+LMekWCDn1v286I L0nXwu+ZeV1M8uQBNHP/sPFvuLI/BkfDrQprxqQgkGjNA73Hj9ER2gWVGVdSYbbHqfo3 ThjQaW8Ap2zTO3rV4D+4qvNDX+egjuP7WaBgu8ISsqfi9/t+vayx3YsG+Ccmgj981fRj lZoHol+g1siHc3up9zM93mplueVDAe1k0/1ucSpS2E+3DPzkrq4TNVl7YPDfsiGusZ0d WdwqitzfRm29aDdkE8aVDCWrV3PIhK79Jk6A5duWNGdI5OYAldvYRpFcvXvmRElzWyW/ /9+A== X-Gm-Message-State: AOJu0YxQftZQPYXWEvsctki1wgnq+QrEf2xO1t54QzqVARTrd2QAOXLp YAFrV2dOYSpVazldoH7rvgt/P+XbvRtppLVWNTUASWehga7Up7QVrTYQ1Pjv103pOsfgvveJDuI vIxVPFF/RYx1TcqK5bEpx47F9So4= X-Google-Smtp-Source: AGHT+IHdKYuUU83hKWPF6MCjC/wOg+VU0kvI3D027t32Utmz784hIJrYSDAVXaf3xPJ6MJWJ6Y2gGbMrM2voIyYhsZg= X-Received: by 2002:a17:907:9488:b0:a77:e55a:9e8c with SMTP id a640c23a62f3a-a7daf65a041mr128964166b.47.1722504348321; Thu, 01 Aug 2024 02:25:48 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Michail Nikolaev Date: Thu, 1 Aug 2024 11:25:36 +0200 Message-ID: Subject: Re: [BUG?] check_exclusion_or_unique_constraint false negative To: "Hayato Kuroda (Fujitsu)" Cc: PostgreSQL Hackers , Andres Freund , Amit Kapila Content-Type: multipart/alternative; boundary="000000000000ce5232061e9bcbf1" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000ce5232061e9bcbf1 Content-Type: text/plain; charset="UTF-8" Hello, Hayato! > Thanks for pointing out the issue! Thanks for your attention! > IIUC, the issue can happen when two concurrent transactions using DirtySnapshot access > the same tuples, which is not specific to the parallel apply Not exactly, it happens for any DirtySnapshot scan over a B-tree index with some other transaction updating the same index page (even using the MVCC snapshot). So, logical replication related scenario looks like this: * subscriber worker receives a tuple update\delete from the publisher * it calls RelationFindReplTupleByIndex to find the tuple in the local table * some other transaction updates the tuple in the local table (on subscriber side) in parallel * RelationFindReplTupleByIndex may not find the tuple because it uses DirtySnapshot * update\delete is lost Parallel apply mode looks like more dangerous because it uses multiple workers on the subscriber side, so the probability of the issue is higher. In that case, "some other transaction" is just another worker applying changes of different transaction in parallel. Best regards, Mikhail. --000000000000ce5232061e9bcbf1 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hello, Hayato!

> Thanks for pointing out the iss= ue!

Thanks for your attention!

> IIUC, the issue can happe= n when two concurrent transactions using DirtySnapshot access
> the s= ame tuples, which is not specific to the parallel apply

Not exactly,= it happens for any DirtySnapshot scan over a B-tree index with some other = transaction updating the same index page (even using the MVCC snapshot).
So, logical replication related scenario looks like this:

* sub= scriber worker receives a tuple update\delete from the publisher
* it ca= lls RelationFindReplTupleByIndex to find the tuple in the local table
* = some other transaction updates the tuple in the local table (on subscriber = side) in parallel
* RelationFindReplTupleByIndex may not find the tuple = because it uses DirtySnapshot
* update\delete is lost

Parallel ap= ply=C2=A0mode looks like more dangerous because it uses multiple workers on= the subscriber=C2=A0side, so the probability of the issue is higher.
In= that case, "some other transaction" is just another worker apply= ing changes of different transaction in parallel.

Best regards,
M= ikhail.
=C2=A0
--000000000000ce5232061e9bcbf1--