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 1k2Qyn-0005zn-8f for pgsql-hackers@arkaria.postgresql.org; Mon, 03 Aug 2020 03:17:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1k2Qym-0003AT-6r for pgsql-hackers@arkaria.postgresql.org; Mon, 03 Aug 2020 03:17: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 1k2Qyl-00039j-SM for pgsql-hackers@lists.postgresql.org; Mon, 03 Aug 2020 03:17:36 +0000 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1k2Qye-0005GK-V5 for pgsql-hackers@postgresql.org; Mon, 03 Aug 2020 03:17:34 +0000 Received: by mail-pl1-x631.google.com with SMTP id o1so20047422plk.1 for ; Sun, 02 Aug 2020 20:17:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb-com.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=KLSD2t/TF777YR5oCExQPHrKpFh0wa5QWX5FD0NOS+c=; b=BwpJyeReqfnFpj6TphjUTX3rkLcUKHBEboP4APTBwzipLXMiySmbUSAgU9tp22DmWp N4ZUpjXxAo5Olvds+gIl/aD1fci7dA2W1vwYyY/yRuZZO5UeVKOwr8WaVQto/kaGb2Er 3zw9AMm45mbGRFch0hlKW0V99T8yRUan1Jh3MSPCJUlwikum4c5X7lYpPd2GBRhSF239 OzkFi/TXk02u8EyFQqRGkeMhErxjMxiz7NYwhkZ3vzbW5hzTvVuspjXyYxM1pY3sf+qa PeGdYZIFjbLvwOOFJoVKG3AJqIlxIVj3PEeaxqMA9CKQV2PkcQcesTF0g6rRw8/ldRK/ 63YA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=KLSD2t/TF777YR5oCExQPHrKpFh0wa5QWX5FD0NOS+c=; b=hsnkNhvBtEp+zMZP1rQmKeoU1hRnaAmyvmSkkh9UTQlojbFdMWwUgTP2gxnos9oLBw xHNrkIYlVjBQH/9MKBd13+G39kfpA4dbmxm76TBBmfWH0WydLprWIHV+xjPHR0pYP4iO Epy38x79NmdxTpUqjywVFCMsIHWb/p5pf8uTfhyuVYfyR4yRRCYNbVquEvzmY5adhgH7 DhCATMU3EdTfNoWlnw6kEE+rS/7AHFYpkQaXNoFeN7mO23bnnqHzlXotBZdkVlRrckd0 L49mK2kmyIQt+v/HRWBJP01gomCMH2FLw8d/89zSxkQZZnLUCFXRZmWoHFIVNV9lWBXQ uyIw== X-Gm-Message-State: AOAM533ZiRNVf3MU3VlBRx1bUhZzCI8Fpqyz5gdtngrDElCtJ3IhKNJO jhbz2BaatqDKQ9DX+uHB4iSWZ0IKGu0JPQteWHVMtO8rWcZp5WBK4EY3J57bLqlZJ69j9cMnf3a WNsErt2ntZ1zXm/Qr6fC8hODijJLi5ss8RXMzEqf74goLUKpUBKfV9uR37IYru9D37mpMraEjI9 yA1Xcg83tCEURR3yXun0kZWayxWmXN8qDB4zBA X-Google-Smtp-Source: ABdhPJx/T+wm4rL1kMsRsSjgVJj+J+IKLrn9nSEVtSyxBAjC+fRuaQ9Cd3BmOBvblXoRF5FLtEDyCw== X-Received: by 2002:a17:902:525:: with SMTP id 34mr13464872plf.80.1596424647719; Sun, 02 Aug 2020 20:17:27 -0700 (PDT) Received: from [192.168.0.29] (24-113-193-150.wavecable.com. [24.113.193.150]) by smtp.gmail.com with ESMTPSA id k4sm13443940pjg.48.2020.08.02.20.17.26 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 02 Aug 2020 20:17:26 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.80.23.2.2\)) Subject: Re: new heapcheck contrib module From: Mark Dilger In-Reply-To: Date: Sun, 2 Aug 2020 20:17:25 -0700 Cc: Amul Sul , Dilip Kumar , Peter Geoghegan , Andres Freund , PostgreSQL-development Content-Transfer-Encoding: quoted-printable Message-Id: <53B5B281-81BF-40FD-9903-EBAA5193506B@enterprisedb.com> References: <12ED3DA8-25F0-4B68-937D-D907CFBF08E7@enterprisedb.com> <20200420194210.sevnpi4lyghoanxi@alap3.anarazel.de> <23E60C3C-C20A-4508-84AC-E0CEA59E784A@enterprisedb.com> <5F743835-3399-419C-8324-2D424237E999@enterprisedb.com> <885D2EC9-7D06-4903-A17D-72C184A1E1C5@enterprisedb.com> <5CC85F28-F210-47AC-8DA8-EC4E82AF3FD5@enterprisedb.com> <0C0349EB-DD85-4DA8-82C7-DF70AB714592@enterprisedb.com> <9DF93B83-FE46-4EC4-A99D-77A60729FD2D@enterprisedb.com> To: Robert Haas X-Mailer: Apple Mail (2.3608.80.23.2.2) 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: Precedence: bulk > On Jul 30, 2020, at 10:59 AM, Robert Haas = wrote: >=20 > + curchunk =3D DatumGetInt32(fastgetattr(toasttup, 2, > + ctx->toast_rel->rd_att, &isnull)); >=20 > Should we be worrying about the possibility of fastgetattr crapping > out if the TOAST tuple is corrupted? I think we should, but I'm not sure we should be worrying about it at = this location. If the toast index is corrupt, systable_getnext_ordered = could trip over the index corruption in the process of retrieving the = toast tuple, so checking the toast tuple only helps if the toast index = does not cause a crash first. I think the toast index should be checked = before this point, ala verify_nbtree, so that we don't need to worry = about that here. It might also make more sense to verify the toast = table ala verify_heapam prior to here, so we don't have to worry about = that here either. But that raises questions about whose responsibility = this all is. If verify_heapam checks the toast table and toast index = before the main table, that takes care of it, but makes a mess of the = idea of verify_heapam taking a start and end block, since verifying the = toast index is an all or nothing proposition, not something to be done = in incremental pieces. If we leave verify_heapam as it is, then it is = up to the caller to check the toast before the main relation, which is = more flexible, but is more complicated and requires the user to remember = to do it. We could split the difference by having verify_heapam do = nothing about toast, leaving it up to the caller, but make pg_amcheck = handle it by default, making it easier for users to not think about the = issue. Users who want to do incremental checking could still keep track = of the chunks that have already been checked, not just for the main = relation, but for the toast relation, too, and give start and end block = arguments to verify_heapam for the toast table check and then again for = the main table check. That doesn't fix the question of incrementally = checking the index, though. Looking at it a slightly different way, I think what is being checked at = the point in the code you mention is the logical structure of the = toasted value related to the current main table tuple, not the lower = level tuple structure of the toast table. We already have a function = for checking a heap, namely verify_heapam, and we (or the caller, = really) should be using that. The clean way to do things is verify_heapam(toast_rel) verify_btreeam(toast_idx) verify_heapam(main_rel) and then depending on how fast and loose you want to be, you can use the = start and end block arguments, which are inherently a bit half-baked, = given the lack of any way to be sure you check precisely the right range = of blocks, and also you can be fast and loose about skipping the index = check or not, as you see fit. Thoughts? =E2=80=94 Mark Dilger EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company