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 1sVYT1-00AS4s-9I for pgsql-hackers@arkaria.postgresql.org; Sun, 21 Jul 2024 15:27:19 +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 1sVYSz-00A3Kr-9d for pgsql-hackers@arkaria.postgresql.org; Sun, 21 Jul 2024 15:27:17 +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 1sVYSy-00A3Kj-Vq for pgsql-hackers@lists.postgresql.org; Sun, 21 Jul 2024 15:27:17 +0000 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sVYSx-000iwB-7W for pgsql-hackers@postgresql.org; Sun, 21 Jul 2024 15:27:16 +0000 Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-367963ea053so2183871f8f.2 for ; Sun, 21 Jul 2024 08:27:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721575633; x=1722180433; darn=postgresql.org; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=K9mNUcEnNtgcRn79DrRwdnToUD+VSyiQU6HpLDPwP8U=; b=HEAd3gv3tmflp73bYS77RLWfsKAOg39JvSRmTuusbgyYyzx1jkSJCNTJs05t3vvLg3 ikk8s/fdTkE4Qkr4U3/c7esS5UO0GzygCxNRztXEAMKY27LVFYfQaydKYT7/ivPPR9iv uehhuw4eZBkpo4tSM402I+3rtDd2/OMdLdPBQzXvVMhHIpI/uV1Bv9c63hofBxcEvWAb iIAR9lnxn5zLo06ukgqL5D0HCT2BAwBhr75YBxiYy279BhQsKab+FBkwJ/9qfe7S6I84 jmJxpBJ0U3dtu/Xlwab68749976gYy3BaEmVYt2fJAwQ084G+lFdPcikMdi25LpsTkOA MmcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721575633; x=1722180433; h=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=K9mNUcEnNtgcRn79DrRwdnToUD+VSyiQU6HpLDPwP8U=; b=kPJ4BSdgD/SgDWTKjLt0m+zknRI47in+6QQI5IgLnxExcddk0cVL8tmpZxrYsQ8sGE EH1ZTnSkBHH6FI4nXBu+d8HK0sd9hRInSiXL7VrOnP3T5wt9YwbmPRwf0pRlAu0W2I/r Ew1zOhFPPmMoBq9DQExF9BXWjHw6SCwb4E0SUiY9pxhxKu1/L9rcxWmVBK7U9oDyvOaN 9yOqKARQX7NGm9OWTFCfM3Q+ulU+9NZ5isc6gFtVEau7A6JIVk+pzeFp8rhlw9CU7UxW EYm+5w1S28KjmISe17Vr5GEvn/myWzupPA0hhAegs8CYOZrGjzZCla04ec63geY6875P zYmg== X-Gm-Message-State: AOJu0YzlAgIfYYr60yZHMlvsxrDBksirlgnlA1nMqg3EdeZjYaivs1cS GTauzB5TcEBJ5mk+fhHFjDX4M0aqB9/DpCMzxlup+lQ5CZ1chB2sGXkpdkzu2A1KzVmWaBY1rlW qVwH3qx8Ddqo81+4OlyFbii9cwRvsyDon X-Google-Smtp-Source: AGHT+IGCyjVRFQgm6LyGF9sxKstQEV0s/TI2vFy62yIm19TWLBDIj2tJZe4Efu+w1RHh0098oUeczw4IwxwFHV5SjCo= X-Received: by 2002:adf:f947:0:b0:368:6596:edba with SMTP id ffacd0b85a97d-369bae67475mr2784887f8f.39.1721575633397; Sun, 21 Jul 2024 08:27:13 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Michail Nikolaev Date: Sun, 21 Jul 2024 17:27:01 +0200 Message-ID: Subject: Re: [BUG?] check_exclusion_or_unique_constraint false negative To: PostgreSQL Hackers , Andres Freund Content-Type: multipart/alternative; boundary="0000000000001532f2061dc39096" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000001532f2061dc39096 Content-Type: text/plain; charset="UTF-8" Hello, Andres. Sorry to bother you, but I feel it's necessary to validate the possible issue regarding someone who can decide whether it is okay or not. The issue is reproducible with the first UPSERT implementation (your commit 168d5805e4c08bed7b95d351bf097cff7c07dd65 from 2015) and up to now. The problem appears as follows: * A unique index contains a specific value (in the test, it is the only value for the entire index). * check_exclusion_or_unique_constraint returns FALSE for that value in some random cases. * Technically, this means index_getnext finds 0 records, even though we know the value exists in the index. I was able to reproduce this only with an UNLOGGED table. I can't find any scenarios that are actually broken (since the issue is resolved by speculative insertion later), but this looks suspicious to me. It could be a symptom of some tricky race condition in the btree. Best regards, Mikhail > --0000000000001532f2061dc39096 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hello, Andres.

Sorry to bother you= , but I feel it's necessary to validate the possible issue regarding so= meone who can decide whether it is okay or not.
The issue is reproducibl= e with the first UPSERT implementation (your commit 168d5805e4c08bed7b95d35= 1bf097cff7c07dd65 from 2015) and up to now.

The problem appears as f= ollows:
* A unique index contains a specific value (in the test, it is t= he only value for the entire index).
* check_exclusion_or_unique_constra= int returns FALSE for that value in some random cases.
* Technically, th= is means index_getnext finds 0 records, even though we know the value exist= s in the index.

I was able to reproduce this only with an UNLOGGED t= able.
I can't find any scenarios that are actually broken (since the= issue is resolved by speculative insertion later), but this looks suspicio= us to me. It could be a symptom of some tricky race condition in the btree.=

Best regards,
Mikhail
--0000000000001532f2061dc39096--