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 1mzMze-0002v1-09 for pgsql-hackers@arkaria.postgresql.org; Mon, 20 Dec 2021 18:02:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mzMzc-0001Dv-TD for pgsql-hackers@arkaria.postgresql.org; Mon, 20 Dec 2021 18:02:36 +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 1mzMzc-00017o-7K for pgsql-hackers@lists.postgresql.org; Mon, 20 Dec 2021 18:02:36 +0000 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mzMzV-0004xZ-6Z for pgsql-hackers@lists.postgresql.org; Mon, 20 Dec 2021 18:02:35 +0000 Received: by mail-pl1-x634.google.com with SMTP id v19so8696417plo.7 for ; Mon, 20 Dec 2021 10:02:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=iKFnBfva9piRfa4SuQnmgiwFRRuDw4RRnHdGGmjSLqo=; b=YCYo/f3jNkzkyY+0odxwoSlkQPywa6/2eF6OfWW7iDbi0dM53DX7h8Ayp0cmIwXQMX 23muww/ue0J5+R6YAiLzJSi3/RqQwN4zj20GL/7C3IYzpBur7axC7vF5kIA3yAuG2gcv Dg1klW6G+PNZg3w06fjBXFbKl0Yqz6KIi2oBypsapxs0gqOxRLtWnxne2YIz8WbbT1nZ HXjX21lrMe63//pcJKcSUeV2mE8Sdvt01Tux18V/DPMlnJk18BHw2lDLmCFE6NWg5lFm avz7YEYxnHNloRv4ltWtQpTW+ZJ+G9c+eskHAxYwAlgPzfXpMA4Vns9MQE8zel5t+o5x QPbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=iKFnBfva9piRfa4SuQnmgiwFRRuDw4RRnHdGGmjSLqo=; b=thIw0frUPnHIo95A3nuKwPmf6p8ZbzlWo3cCSsTnKYwRGBqdDXQnVz0/oxO+d7KUhi acEhv5zez/SXZ4dy2zcTM1oOD+TAmSQEnjqxQS8a+TYUi78wmBAdbQFUwD22D3Zd3JzR nwjUQgQCBZRfLURDwIEn4PGGfYqnO1hZDhY2yC5nGArJ/0hON65bdhEqlniE51a+rNc6 p/OftY0ln9P8DTXo8nrn6QqdTz6tDSjn8aVvmZje0C7oZ3wjye54aRlqDV2QPTd/SC+s 3dPq8Zl8dpTF1CQR6RvRUofQjIoLJzGUBWNX54NLmH4k5i/G+LhqV0/njff8qWdUxZ7W Fu/w== X-Gm-Message-State: AOAM531Y9fLFHk4FA2/2LvXQwSX/G6+CU0i9P327O6sxEx6KoiunrTBo fIhAG4perp07xzOmMEW0JD3pAvBf5ox5um80Jl46HyEp52/36kQfE0mBsi4xyzlaI0wRVt7Fjsp g9qZTEnM74bDIUYhmXBorvdVll7LsMUbcKcoUoI1yAO6s6TkkXDGUef6Xqi5hWK9gsNSG38LB5p 5Eb8yRC4iQ4Q9o2/UVd352esNgUWCBY0PCTBs8VaDpvB5GkugdLmC/ X-Google-Smtp-Source: ABdhPJxAqkt9p6DrA5ZNjNY0Q7HZRpmI3tASpgb7cuFSjHDFvXjK6OFnB/UGnyJgEvo5gyJehVud9A== X-Received: by 2002:a17:90a:e7c2:: with SMTP id kb2mr142445pjb.200.1640023340446; Mon, 20 Dec 2021 10:02:20 -0800 (PST) Received: from ?IPv6:2600:6c50:157f:eb87:85a3:28b6:8fb8:d7cd? ([2600:6c50:157f:eb87:85a3:28b6:8fb8:d7cd]) by smtp.gmail.com with ESMTPSA id ip5sm60236pjb.1.2021.12.20.10.02.19 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Dec 2021 10:02:20 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.7\)) Subject: Re: [PATCH] Improve amcheck to also check UNIQUE constraint in btree index. From: Mark Dilger In-Reply-To: Date: Mon, 20 Dec 2021 10:02:18 -0800 Cc: David Steele , Anastasia Lubennikova , Postgres hackers , Peter Geoghegan , Maxim Orlov Content-Transfer-Encoding: quoted-printable Message-Id: References: <6A958AE0-CFB9-4B1F-8EF8-BF6E729AFB59@enterprisedb.com> <6FED9A6F-9AB3-4711-A5F7-55535ADF736B@enterprisedb.com> <4A5C6A8E-8C8C-4D9B-8FFA-DFAA697E7A53@enterprisedb.com> To: Pavel Borisov X-Mailer: Apple Mail (2.3608.120.23.2.7) X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Dec 20, 2021, at 7:37 AM, Pavel Borisov = wrote: >=20 > The patch is pgindented and rebased on the current PG master code. Thank you, Pavel. The tests in check_btree.sql no longer create a bttest_unique table, so = the DROP TABLE is surplusage: +DROP TABLE bttest_unique; +ERROR: table "bttest_unique" does not exist The changes in pg_amcheck.c to pass the new checkunique parameter will = likely need to be based on a amcheck version check. The implementation = of prepare_btree_command() in pg_amcheck.c should be kept compatible = with older versions of amcheck, because it connects to remote servers = and you can't know in advance that the remote servers are as up-to-date = as the machine where pg_amcheck is installed. I'm thinking specifically = about this change: @@ -871,7 +877,8 @@ prepare_btree_command(PQExpBuffer sql, RelationInfo = *rel, PGconn *conn) if (opts.parent_check) appendPQExpBuffer(sql, "SELECT %s.bt_index_parent_check(" - "index :=3D c.oid, heapallindexed :=3D %s, = rootdescend :=3D %s)" + "index :=3D c.oid, heapallindexed :=3D %s, = rootdescend :=3D %s, " + "checkunique :=3D %s)" "\nFROM pg_catalog.pg_class c, = pg_catalog.pg_index i " "WHERE c.oid =3D %u " "AND c.oid =3D i.indexrelid " If the user calls pg_amcheck with --checkunique, and one or more remote = servers have an amcheck version < 1.4, at a minimum you'll need to avoid = calling bt_index_parent_check with that parameter, and probably also = you'll either need to raise a warning or perhaps an error telling the = user that such a check cannot be performed. You've forgotten to include contrib/amcheck/amcheck--1.3--1.4.sql in the = v5 patch, resulting in a failed install: /usr/bin/install -c -m 644 ./amcheck--1.3--1.4.sql = ./amcheck--1.2--1.3.sql ./amcheck--1.1--1.2.sql ./amcheck--1.0--1.1.sql = ./amcheck--1.0.sql = '/Users/mark.dilger/hydra/unique_review.5/tmp_install/Users/mark.dilger/pg= test/test_install/share/postgresql/extension/' install: ./amcheck--1.3--1.4.sql: No such file or directory make[2]: *** [install] Error 71 make[1]: *** [checkprep] Error 2 Using the one from the v4 patch fixes the problem. Please include this = file in v6, to simplify the review process. The changes to t/005_opclass_damage.pl look ok. The creation of a new = table for the new test seems unnecessary, but only problematic in that = it makes the test slightly longer to read. I recommend changing the = test to use the same table that the prior test uses, but that is just a = recommendation, not a requirement. You should add coverage for --checkunique to t/003_check.pl. You should add coverage for multiple PostgreSQL::Test::Cluster instances = running differing versions of amcheck, perhaps some on version 1.3 and = some on version 1.4. Then test that the --checkunique option works = adequately. I have not reviewed the changes to verify_nbtree.c. I'll leave that to = Peter. =E2=80=94 Mark Dilger EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company