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 1upTu0-0060ir-OB for pgsql-hackers@arkaria.postgresql.org; Fri, 22 Aug 2025 15:42:06 +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 1upTu0-007B0x-6z for pgsql-hackers@arkaria.postgresql.org; Fri, 22 Aug 2025 15:42:04 +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 1upTtz-007B0p-Sv for pgsql-hackers@lists.postgresql.org; Fri, 22 Aug 2025 15:42:04 +0000 Received: from mail-vk1-xa35.google.com ([2607:f8b0:4864:20::a35]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1upTtx-001DPQ-2g for pgsql-hackers@postgresql.org; Fri, 22 Aug 2025 15:42:03 +0000 Received: by mail-vk1-xa35.google.com with SMTP id 71dfb90a1353d-53b174ac3e5so817397e0c.2 for ; Fri, 22 Aug 2025 08:42:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1755877322; x=1756482122; 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=wD/229f4AsGBKDL5MDcVZ/lprIfmEN6Lp1Xpew6WQ8k=; b=YHHl4FbCJhyA89lPbgYAcECZP3O3QwLL0bR+hwwpmpg0y+CTuGvrcnnY5JHCr0csfm XwjtZ1Rsu3GboZ2072SbMalm/6IdVcwryav/E/edZayC23xbbHeAzDDeBdAoA3+2tcCs taLP97Cbmq98y4ZvqbOdKg71f5qA0hQIWW2Y/a1/FFJnXZD+ppAy/zWgmGWbkEI83Tr5 u5PKNpWdFcX+O7EQL8md4BXqTWfu9Hci4TlH94GkEAeqSF+yJrXzu5bhx8JckZdfZrvM Fl2x2oEpiejNhByRxbnE+alIuVPDeL14zDHSehrH75/ShvaWYomhaThgFvERc5kFNh2p rdUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755877322; x=1756482122; 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=wD/229f4AsGBKDL5MDcVZ/lprIfmEN6Lp1Xpew6WQ8k=; b=EvIkNjGP9xRemDcCzxfIJkuCmtst683DUM28mGdxkOdEaf53Ie+aYkWwnWlbDzF6b3 3YGr8TSODKYEIHJI18BYB5P8aFA+53iSxysXxItaZ9WOXCEN1iM0MRjl6lFjjl03ZjcH j5bzQmZH+DdRpOZfEv4f07aj8Hgcl2y3X45smU3hLrSFuXrz7SNgQ0E23in729UIr40v rm+BfRloEyepHJELXUwt0qj/AhyLuIEqBfNOLcuogRNrmjh9UIY5Ul+g7j2sk0x/3iVT ore6IHze8fGYTnNcyymnZEG/U3vT8Q8ppqHoXi4WdyaXPyuVsm1RDwR5YnD+gELQnv6/ htDg== X-Forwarded-Encrypted: i=1; AJvYcCX/WUUsp5GSclgHWsVPRmfW+i7PIwyqNlUHVK7kPBoPwcPzcnVZlcRjhPQHnKAOyGn4YYMU0qLhuWt+7cu4@postgresql.org X-Gm-Message-State: AOJu0YxPWazOrfreUwEZTejkUQu/vVc7WEwxzwkbbEC7Sqs1QWauWIQI xkK/lzut1viQ1xa2exj6++MAHDjwcPynxTSN2oq3eaczcRNgl0eDZ8EBmkbz4cCT9OgUR8zxMc0 wXIBkH5s6bCdkSEoJzva1G7k3SNymJw4= X-Gm-Gg: ASbGncuDhINfYVrGYeBx6lKQ7nKIaFY/ZN8acjZlT/4g0wu3Vofo242McEnpkYoU+0o UxPMLnoYy0MH4KFLYbwlEmI42r6chCkCgCkacTrBT6pZHT9uzFkNJuut/IqSzuHvpjIcGoEMjIl CYW2iaihjVqdC3ePgiBORS2Lae8tw9pK4dS/IYI0616uBgnEHR7ODUDhFB6PUu0uB76HRInpjRO lQ/eGBNHjzs85FJB70= X-Google-Smtp-Source: AGHT+IHKdk8SBSvyP4AyeKr9R5gdjgPyJsS/7XAHpuk6KPzR0QcW/YzUPTTcCc+GIzcXjng3L+8aRVGp5zHctGyam+w= X-Received: by 2002:a05:6122:2008:b0:52f:47de:3700 with SMTP id 71dfb90a1353d-53c8a2daae4mr987340e0c.5.1755877321525; Fri, 22 Aug 2025 08:42:01 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Mihail Nikalayeu Date: Fri, 22 Aug 2025 17:41:25 +0200 X-Gm-Features: Ac12FXxIHwBXRzaI7TK85XwG9bO9QKystA41uY2t6es6M1mS1nXLl3-AbNfsYqs 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" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Amit, a few more explanations related to your message. > IIUC, the problem you are worried about can happen with DELETE+INSERT > in the same transaction on the subscriber, right? Technically, yes - this can occur during a single UPDATE, as well as a DELETE followed by an INSERT of the same key within the same transaction (which is effectively equivalent to an UPDATE). However, it should NOT occur, because at no point in the timeline does a row with that key fail to exist; therefore, no scan should return =E2=80=9Cther= e is no such row in the index.=E2=80=9D > If so, this should > happen with DELETE and INSERT in a separate transaction as well. Yes, it may happen - and in that case, it is correct. This is because there is a moment between the DELETE and the INSERT when the row does not exist. Therefore, it is acceptable for a scan to check the index at that particular moment and find nothing. > BTW, as the update (or DELETE+INSERT) happens at a later time than the > publisher's update/delete, so once we have the last_write_win > resolution strategy implemented, it is the subscriber operation that > will win. So, the current behavior shouldn't cause any problem. For the last_write_win and UPDATE vs UPDATE case - yes, probably, but only by luck. However, there are many scenarios that cannot be implemented correctly, for example: * DELETE always wins * UPDATE with a higher version (column value) wins * first_write_win * etc. Also, the cases from [0] are clearly wrong without any conflict resolution. In particular, case 2 - there are no real conflicts at all (since different sets of columns are involved), but an incorrect result may still be produced. [0]: https://www.postgresql.org/message-id/flat/CADzfLwWC49oanFSGPTf%3D6FJo= Tw-kAnpPZV8nVqAyR5KL68LrHQ%40mail.gmail.com#5f6b3be849f8d95c166decfae541df0= 9