Fix a confusing amcheck corruption message.
authorRobert Haas <[email protected]>
Tue, 16 Mar 2021 19:42:20 +0000 (15:42 -0400)
committerRobert Haas <[email protected]>
Tue, 16 Mar 2021 19:42:50 +0000 (15:42 -0400)
Don't complain about the last TOAST chunk number being different
from what we expected if there are no TOAST chunks at all.
In such a case, saying that the final chunk number is 0 is not
really accurate, and the fact the value is missing from the
TOAST table is reported separately anyway.

Mark Dilger

Discussion: http://postgr.es/m/AA5506CE-7D2A-42E4-A51D-358635E3722D@enterprisedb.com

contrib/amcheck/verify_heapam.c
src/bin/pg_amcheck/t/004_verify_heapam.pl

index 49f5ca0ef2c8f6d83aa35dfadd997a3da72c7574..e614c12a14a5a3fdf75bfff004d40731179bcce2 100644 (file)
@@ -1100,14 +1100,14 @@ check_tuple_attribute(HeapCheckContext *ctx)
        check_toast_tuple(toasttup, ctx);
        ctx->chunkno++;
    }
-   if (ctx->chunkno != (ctx->endchunk + 1))
-       report_corruption(ctx,
-                         psprintf("final toast chunk number %u differs from expected value %u",
-                                  ctx->chunkno, (ctx->endchunk + 1)));
    if (!found_toasttup)
        report_corruption(ctx,
                          psprintf("toasted value for attribute %u missing from toast table",
                                   ctx->attnum));
+   else if (ctx->chunkno != (ctx->endchunk + 1))
+       report_corruption(ctx,
+                         psprintf("final toast chunk number %u differs from expected value %u",
+                                  ctx->chunkno, (ctx->endchunk + 1)));
    systable_endscan_ordered(toastscan);
 
    return true;
index 9f7114cd62250e8c0938b6898e6029eb5607fdbc..16574cb1f8606951742e49552ffbd337f631f788 100644 (file)
@@ -296,7 +296,7 @@ close($file)
 $node->start;
 
 # Ok, Xids and page layout look ok.  We can run corruption tests.
-plan tests => 20;
+plan tests => 19;
 
 # Check that pg_amcheck runs against the uncorrupted table without error.
 $node->command_ok(['pg_amcheck', '-p', $port, 'postgres'],
@@ -489,7 +489,6 @@ for (my $tupidx = 0; $tupidx < ROWCOUNT; $tupidx++)
 
        $header = header(0, $offnum, 2);
        push @expected,
-           qr/${header}final toast chunk number 0 differs from expected value \d+/,
            qr/${header}toasted value for attribute 2 missing from toast table/;
    }
    elsif ($offnum == 14)