Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lGp71-0004Oj-Fa for pgsql-hackers@arkaria.postgresql.org; Mon, 01 Mar 2021 20:25:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lGp70-0007Dy-BL for pgsql-hackers@arkaria.postgresql.org; Mon, 01 Mar 2021 20:25:50 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lGp4s-00043k-Mm for pgsql-hackers@lists.postgresql.org; Mon, 01 Mar 2021 20:23:38 +0000 Received: from mail-vs1-xe35.google.com ([2607:f8b0:4864:20::e35]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lGp4q-0006aU-6m for pgsql-hackers@lists.postgresql.org; Mon, 01 Mar 2021 20:23:37 +0000 Received: by mail-vs1-xe35.google.com with SMTP id d25so2345488vsr.11 for ; Mon, 01 Mar 2021 12:23:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=NySM6p6+rwiHsn6KPt84G7mX88e7R7KAx+/hBl/CB30=; b=U1RMvX0NbpZikI/gq6RbzJr3tBgNh5jSr7IH4iApfQy9EbwpRI3M6KDjItLq4ICV84 YrR0GBqAGMQZC2N6j4Ax/bO6vBNDBgLskK03IpJi5wV1OHKPpt6N6xm+NOZqA5xuOpOY VeprKtx3y9jY6HK9T9brNaEf3mJdz/grtuPOU/zn5Ez2zJcnnGGIiPCGCfIruWjk8Fx3 utJBQAWTk35/0nITdgRSEmsrn4CWXhirgORfhXNqPXllL/BUZvKQCXvUu3VBiNDDg+kn 0OuJH3KmDlmkHHJ1eqIOWH1wtKdMIxCIlw1oXqKsWjVrYHv+h7eJ7KJXOWDVTsyfDw2c /N5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=NySM6p6+rwiHsn6KPt84G7mX88e7R7KAx+/hBl/CB30=; b=HQ8SMYt1wIlIL96ZOtTAP20xQM12BiAvhwvLzwXSmw977+ryEfnNUr4Oop5b/EUkqC xEqzipQIZ45Ye1HKzQmrSd99mkhwaq7+LS3iSo1YEcmkJc/PigDWL3LSjdzqjazAI0Nr VBq0Z1xfoXMrjSmLUvAKC/+x1ynRfhDOkgWo45japhddoDY1L9MZJQRFIE2dNkj9zMDK kXCvoSUqrhrHSZ+C6OdDIGCHu6YJtjeOUL7JVWlOPOqzHZy03TkPLS5nVn3GxBPE5xN1 WAjwh5AUijZip+6Mi3Pl7jhRxbgKrxIskRijfrLFdmImD2BDq45WSV2VY5xiCoLOhwhK XkDw== X-Gm-Message-State: AOAM532BBPHNm18/unVkuSemekjVDvDtgOAt7zJWOFhE6Q/GAe0g6SQj gqfKgNMJR3ucmQvGRCT7hPRvPDD6/lHcgHO8I9k= X-Google-Smtp-Source: ABdhPJzhxEvz0m9WiF/Rrfr3QsqTieMaVQwPyUyNlr6mhFnO5P+YZbTgcTvoTLou8GMKUR2OQfqgWCNl8WtPTzgYBSU= X-Received: by 2002:a67:2c86:: with SMTP id s128mr379845vss.12.1614630215353; Mon, 01 Mar 2021 12:23:35 -0800 (PST) MIME-Version: 1.0 References: <6A958AE0-CFB9-4B1F-8EF8-BF6E729AFB59@enterprisedb.com> In-Reply-To: <6A958AE0-CFB9-4B1F-8EF8-BF6E729AFB59@enterprisedb.com> From: Pavel Borisov Date: Tue, 2 Mar 2021 00:23:23 +0400 Message-ID: Subject: Re: [PATCH] Improve amcheck to also check UNIQUE constraint in btree index. To: Mark Dilger Cc: Anastasia Lubennikova , Postgres hackers , Peter Geoghegan Content-Type: multipart/alternative; boundary="0000000000006e08f805bc7f6487" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --0000000000006e08f805bc7f6487 Content-Type: text/plain; charset="UTF-8" > > If bt_index_check() and bt_index_parent_check() are to have this > functionality, shouldn't there be an option controlling it much as the > option (heapallindexed boolean) controls checking whether all entries in > the heap are indexed in the btree? It seems inconsistent to have an option > to avoid checking the heap for that, but not for this. Alternately, this > might even be better coded as its own function, named something like > bt_unique_index_check() perhaps. I hope Peter might advise? > As for heap checking, my reasoning was that we can not check whether a unique constraint violated by the index, without checking heap tuple visibility. I.e. we can have many identical index entries without uniqueness violated if only one of them corresponds to a visible heap tuple. So heap checking included in my patch is _necessary_ for unique constraint checking, it should not have an option to be disabled, otherwise, the only answer we can get is that unique constraint MAY be violated and may not be, which is quite useless. If you meant something different, please elaborate. I can try to rewrite unique constraint checking to be done after all others check but I suppose it's the performance considerations are that made previous amcheck routines to do many checks simultaneously. I tried to stick to this practice. It's also not so elegant to duplicate much code to make uniqueness checks independently and the resulting patch will be much bigger and harder to review. Anyway, your and Peter's further considerations are always welcome. -- Best regards, Pavel Borisov Postgres Professional: http://postgrespro.com --0000000000006e08f805bc7f6487 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
If bt_index_check() and bt_index_parent_check() are to h= ave this functionality, shouldn't there be an option controlling it muc= h as the option (heapallindexed boolean) controls checking whether all entr= ies in the heap are indexed in the btree?=C2=A0 It seems inconsistent to ha= ve an option to avoid checking the heap for that, but not for this.=C2=A0 A= lternately, this might even be better coded as its own function, named some= thing like bt_unique_index_check() perhaps.=C2=A0 I hope Peter might advise= ?
=C2=A0
As for heap checking, my reasoning = was that we can not check whether a unique constraint violated by the index= , without checking heap tuple visibility. I.e. we can have many identical i= ndex entries without uniqueness violated if only one of them corresponds to= a visible heap tuple. So heap checking included in my patch is _necessary_= for unique constraint checking, it should not have an option to be disable= d, otherwise, the only answer we can get is that unique=C2=A0constraint MAY= be violated and may not be, which is quite useless. If you meant something= different, please elaborate.=C2=A0

I can try to r= ewrite unique constraint checking to be done after all others check but I s= uppose it's the performance considerations are that made previous amche= ck routines to do many checks simultaneously. I tried to stick to this prac= tice. It's also not so elegant to duplicate much code to make uniquenes= s checks independently and the resulting patch will be much bigger and hard= er to review.

Anyway, your and Peter's further= considerations are always welcome.

--
Best regards,
Pavel Borisov

Postgres Professio= nal: http://postgrespro.com
--0000000000006e08f805bc7f6487--