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 1s6Gft-00B8xm-67 for pgsql-hackers@arkaria.postgresql.org; Sun, 12 May 2024 21:24:05 +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 1s6Gfr-00DGvZ-25 for pgsql-hackers@arkaria.postgresql.org; Sun, 12 May 2024 21:24:03 +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 1s6Gfq-00DGvR-Nu for pgsql-hackers@lists.postgresql.org; Sun, 12 May 2024 21:24:03 +0000 Received: from mail-yb1-xb2f.google.com ([2607:f8b0:4864:20::b2f]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1s6Gfj-000iX6-9G for pgsql-hackers@lists.postgresql.org; Sun, 12 May 2024 21:24:02 +0000 Received: by mail-yb1-xb2f.google.com with SMTP id 3f1490d57ef6-de60a51fe21so3860130276.0 for ; Sun, 12 May 2024 14:23:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715549034; x=1716153834; darn=lists.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=qVkVxYY0gu0t/qcceryo8zadjhekhed4PflRKo8NKQk=; b=em3XPg4BAz1RCLkz45TCDXzGQkNHPFc2F9REOSloMYYLMBsPRSNAuLAofBsWjIFo1Q 6BbiHYXFn4qBXm94zfY2kpoSZ9nQHnDSy9nuSK3rW/Siq6a7UbUCn0kteR55fBvjplGp B6DqTnjCFfU3tesGdBZp2mRyFo8dcp/N3bf9t4/ZD9xcO6aiOnD5cdRpjdCixYWZNqvh qcpwdsmoWxHyPYBvgNm/gmqot4Mes2LW5RWMIvcQsIg1txF1+u8Q/PRFRuaL6SUETSf5 +lPioUGwW2GShvOHYVOWGqnfKdugLt4zvIPFftVRfZa87ctXWwqK7DARAN/ecQCMV0i+ 90xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715549034; x=1716153834; 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=qVkVxYY0gu0t/qcceryo8zadjhekhed4PflRKo8NKQk=; b=M8FtcUgFvqqP10axO2eZahmifP7AD5xDmbsaBJPVLc7fwNiJwJ7x35ZUUi05TC/c1/ 9CEmYuZoLd52zZ9dVZk1YORzmyrnSsAyUuoWfW4HRkg09615typZNpc6lK0+HtnsWXuE F69kGayUZmD+fzjig5nok/E+nCcrlwyd2njhstH8PbXI1sMZt+X72dgoreAddRZ4eXpT bUC5B+szQc9kRMtGTeTmPKt/XYU3TIi6WkVOCdU+Bb6k939jaGdeKbovOWstZLjBpkF7 W0zZiOx+VvnW0NVOhTDvJd9sb49r5YMV03XTIMkYKO3RsPWW8blWL9TPR76SM/n0MVJL pozw== X-Forwarded-Encrypted: i=1; AJvYcCWCxhG3nxfH9pjKfHcKkPPwIA7/hSL9+Us2d+lfib22yDvIqEqUfEIrvttonnFxYMRky3ji8x4qVV0ZOk0vqfLy0SugfZ7Itm8xbPBEzipuvIHm X-Gm-Message-State: AOJu0YwGkdRjnD6kial44DrjzjTBleJMmnoHkyOrWN5BFdz7RAXfjZkq hKmUh9c2ev/7p1hJkIDKNu0vW6oUlnnt+MoBCpMS69Um9IZYrmjUNA3LJ3PwMTFsQDpu7kS4CMl 2beXortvCFuoZzgWbsfhMJW1TW/M= X-Google-Smtp-Source: AGHT+IEtDHaUj+2cC4qb8dgJZmgXheIBrvgMYLSowKSDO7y7B0yOEJf9Y9c27xAcTDTfNYYquDANTiA7CL3hEd5bMe0= X-Received: by 2002:a25:29c1:0:b0:dcd:5187:a032 with SMTP id 3f1490d57ef6-dee4f4c2b87mr10907968276.43.1715549034090; Sun, 12 May 2024 14:23:54 -0700 (PDT) MIME-Version: 1.0 References: <20220922151328.lakwdytvwnyyif3b@awork3.anarazel.de> <8c74cc5e-4b97-4cd7-9aaf-67886822a78c@eisentraut.org> <20240501022412.85@rfd.leadboat.com> <1375614.1715301775@sss.pgh.pa.us> <8635D8B1-45B7-4D67-86C7-D6ECB4F10B11@enterprisedb.com> In-Reply-To: From: Alexander Korotkov Date: Mon, 13 May 2024 00:23:42 +0300 Message-ID: Subject: Re: [PATCH] Improve amcheck to also check UNIQUE constraint in btree index. To: Mark Dilger Cc: Pavel Borisov , Tom Lane , Noah Misch , Peter Eisentraut , Aleksander Alekseev , Postgres hackers , Maxim Orlov , Andres Freund , Greg Stark , Julien Rouhaud , David Steele , Peter Geoghegan , Maxim Orlov , lubennikovaav@gmail.com 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 Sat, May 11, 2024 at 4:13=E2=80=AFAM Mark Dilger wrote: > > On May 10, 2024, at 12:05 PM, Alexander Korotkov = wrote: > > The only bt_target_page_check() caller is > > bt_check_level_from_leftmost(), which overrides state->target in the > > next iteration anyway. I think the patch is just refactoring to > > eliminate the confusion pointer by Peter Geoghegan upthread. > > I find your argument unconvincing. > > After bt_target_page_check() returns at line 919, and before bt_check_lev= el_from_leftmost() overrides state->target in the next iteration, bt_check_= level_from_leftmost() conditionally fetches an item from the page reference= d by state->target. See line 963. > > I'm left with four possibilities: > > > 1) bt_target_page_check() never gets to the code that uses "rightpage" r= ather than "state->target" in the same iteration where bt_check_level_from_= leftmost() conditionally fetches an item from state->target, so the change = you're making doesn't matter. > > 2) The code prior to v2-0003 was wrong, having changed state->target in = an inappropriate way, causing the wrong thing to happen at what is now line= 963. The patch fixes the bug, because state->target no longer gets overwr= itten where you are now using "rightpage" for the value. > > 3) The code used to work, having set up state->target correctly in the p= lace where you are now using "rightpage", but v2-0003 has broken that. > > 4) It's been broken all along and your patch just changes from wrong to = wrong. > > > If you believe (1) is true, then I'm complaining that you are relying far= to much on action at a distance, and that you are not documenting it. Eve= n with documentation of this interrelationship, I'd be unhappy with how bri= ttle the code is. I cannot easily discern that the two don't ever happen i= n the same iteration, and I'm not at all convinced one way or the other. I= tried to set up some Asserts about that, but none of the test cases actual= ly reach the new code, so adding Asserts doesn't help to investigate the qu= estion. > > If (2) is true, then I'm complaining that the commit message doesn't ment= ion the fact that this is a bug fix. Bug fixes should be clearly documente= d as such, otherwise future work might assume the commit can be reverted wi= th only stylistic consequences. > > If (3) is true, then I'm complaining that the patch is flat busted. > > If (4) is true, then maybe we should revert the entire feature, or have a= discussion of mitigation efforts that are needed. > > Regardless of which of 1..4 you pick, I think it could all do with more r= egression test coverage. > > > For reference, I said something similar earlier today in another email to= this thread: > > This patch introduces a change that stores a new page into variable "righ= tpage" rather than overwriting "state->target", which the old implementatio= n most certainly did. That means that after returning from bt_target_page_= check() into the calling function bt_check_level_from_leftmost() the value = in state->target is not what it would have been prior to this patch. Now, = that'd be irrelevant if nobody goes on to consult that value, but just 44 l= ines further down in bt_check_level_from_leftmost() state->target is clearl= y used. So the behavior at that point is changing between the old and new = versions of the code, and I think I'm within reason to ask if it was wrong = before the patch, wrong after the patch, or something else? Is this a bug = being introduced, being fixed, or ... ? Thank you for your analysis. I'm inclined to believe in 2, but not yet completely sure. It's really pity that our tests don't cover this. I'm investigating this area. ------ Regards, Alexander Korotkov