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 1sZkLZ-003NHm-KV for pgsql-hackers@arkaria.postgresql.org; Fri, 02 Aug 2024 04:56:57 +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 1sZkLY-00FCIh-6D for pgsql-hackers@arkaria.postgresql.org; Fri, 02 Aug 2024 04:56:56 +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 1sZkLX-00FCIZ-Sn for pgsql-hackers@lists.postgresql.org; Fri, 02 Aug 2024 04:56:55 +0000 Received: from mail-oa1-x31.google.com ([2001:4860:4864:20::31]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sZkLV-002elW-9B for pgsql-hackers@postgresql.org; Fri, 02 Aug 2024 04:56:54 +0000 Received: by mail-oa1-x31.google.com with SMTP id 586e51a60fabf-260dde65a68so4865433fac.2 for ; Thu, 01 Aug 2024 21:56:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722574613; x=1723179413; 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=mAUW+SqUozLiT+QtSiXtx9Fzu9V1oZVX4CkKnSBFDQs=; b=j4wYqR/bcXM1cCt0hhzGs1l/tijpv1nhlAi805DGKpBlFjKZ3UsFpwKNU02Ucgqqef hRDavggmhPFGyFI+QN+k12i+ELSotfenumqavbLahQ8UZB1wU/Yhvvjke64zjRTiao7m F4pH+0Vmq4XZcTNmIP3BNOdRDBJJJk8Pu6znJYO1PDg4jpjXHrvzic44fib9HNvhkNq5 V2gnyOTLa2lbCF6/PeXAldhKIAfkJXZb9n9YxLrQIWN/39rua+4z5yB2QnpwwXIbqjGF 4JRq6WGAOv2FwRDbKILvotVsTZC45yKGBr+786/4fSeWgp9s3vEbh1dTluiJ3UyJHOf/ h11A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722574613; x=1723179413; 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=mAUW+SqUozLiT+QtSiXtx9Fzu9V1oZVX4CkKnSBFDQs=; b=e7bXK5FjOJnp2TBW/oipI5NyH32AT8WBj6YydoLqyH1KnUOnZMNn4KvSoelzcPsAcq Djo7D/o3eSZbPVQBr/xXJMu3trWzbbi26MbGXfPrBjF6uWBk57sSZ+UbTxpqcglfVmX3 9EU4dAyHcYxLB927exksVRl9tgTqpgxmJjr2nfsUHG+bZdsQe5CXXO3ZtWm4P0Fo9TCJ H8KQEWqlcOIyNDrLNZYMucTTg2vgUF8OM4fwj1rivqyaBD6N6Gp9nkvJkIkmNpHpWUB+ MLvM83pzgHoXdid3ET2vLZV0+ouF/B3Rk4Mgq5AlKrGqB7tX09V0undNuBc9o513ng3H 20sA== X-Forwarded-Encrypted: i=1; AJvYcCX8PP2z8FImGTsgtfdSuJAI/ZjTGNoobHoA1O0oDjU5KgxBWK8BJ5OcRX2+DzSRX+YGwYEoC0qs5CO3n6PwT4kOfnC7FUDZ0P99z0id X-Gm-Message-State: AOJu0Yx3g4NiDID6g/jPlVbQdobRF6m95SXK5hp3VBK2hIk4V/RjVsij mPJbZcUWTesHdLnUCHzHoU2BZPmtntIb3g6f52kTrMDfUCycuk+TZscOgX9uo6w1i9d27vQBmGT T7IzT8ThnTmjpr/hjOiPHDVLsupeSKanN X-Google-Smtp-Source: AGHT+IEo1y5RgmCRkFEweuEI5dBC0yhBAdBVRf33Okjz27eXwo2/H6ht2lLRFmSm6vPo5c+HPUi07VBB3QSsWaesPp4= X-Received: by 2002:a05:6871:9285:b0:268:952b:d2a4 with SMTP id 586e51a60fabf-268952be27amr1579223fac.32.1722574612558; Thu, 01 Aug 2024 21:56:52 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Amit Kapila Date: Fri, 2 Aug 2024 10:26:40 +0530 Message-ID: Subject: Re: [BUG?] check_exclusion_or_unique_constraint false negative To: Michail Nikolaev Cc: "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 Thu, Aug 1, 2024 at 2:55=E2=80=AFPM Michail Nikolaev wrote: > > > Thanks for pointing out the issue! > > Thanks for your attention! > > > IIUC, the issue can happen when two concurrent transactions using Dirty= Snapshot 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 wi= th 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 ta= ble > * some other transaction updates the tuple in the local table (on subscri= ber side) in parallel > * RelationFindReplTupleByIndex may not find the tuple because it uses Dir= tySnapshot > * update\delete is lost > > Parallel apply mode looks like more dangerous because it uses multiple wo= rkers on the subscriber side, so the probability of the issue is higher. > In that case, "some other transaction" is just another worker applying ch= anges of different transaction in parallel. > I think it is rather less likely or not possible in a parallel apply case because such conflicting updates (updates on the same tuple) should be serialized at the publisher itself. So one of the updates will be after the commit that has the second update. I haven't tried the test based on your description of the general problem with DirtySnapshot scan. In case of logical replication, we will LOG update_missing type of conflict and the user may need to take some manual action based on that. I have not tried a test so I could be wrong as well. I am not sure we can do anything specific to logical replication for this but feel free to suggest if you have ideas to solve this problem in general or specific to logical replication. --=20 With Regards, Amit Kapila.