Commit 4eaf7eac authored by Teodor Sigaev's avatar Teodor Sigaev

Add missing and dangling downlink checks to amcheck

When bt_index_parent_check() is called with the heapallindexed option,
allocate a second Bloom filter to fingerprint block numbers that appear
in the downlinks of internal pages.  Use Bloom filter probes when
walking the B-Tree to detect missing downlinks.  This can detect subtle
problems with page deletion/VACUUM, such as corruption caused by the bug
just fixed in commit 6db4b499.

The downlink Bloom filter is bound in size by work_mem.  Its optimal
size is typically far smaller than that of the regular heapallindexed
Bloom filter, especially when the index has high fan-out.

Author: Peter Geoghegan
Reviewer: Teodor Sigaev
Discussion: https://postgr.es/m/CAH2-WznUzY4fWTjm1tBB3JpVz8cCfz7k_qVp5BhuPyhivmWJFg@mail.gmail.com
parent 7f58f666
This diff is collapsed.
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
<function>bt_index_check</function> tests that its target, a <function>bt_index_check</function> tests that its target, a
B-Tree index, respects a variety of invariants. Example usage: B-Tree index, respects a variety of invariants. Example usage:
<screen> <screen>
test=# SELECT bt_index_check(index =&gt; c.oid, heapallindexed =&gt; i.indisunique) test=# SELECT bt_index_check(index =&gt; c.oid, heapallindexed =&gt; i.indisunique),
c.relname, c.relname,
c.relpages c.relpages
FROM pg_index i FROM pg_index i
...@@ -67,7 +67,7 @@ WHERE am.amname = 'btree' AND n.nspname = 'pg_catalog' ...@@ -67,7 +67,7 @@ WHERE am.amname = 'btree' AND n.nspname = 'pg_catalog'
-- Don't check temp tables, which may be from another session: -- Don't check temp tables, which may be from another session:
AND c.relpersistence != 't' AND c.relpersistence != 't'
-- Function may throw an error when this is omitted: -- Function may throw an error when this is omitted:
AND i.indisready AND i.indisvalid AND c.relkind = 'i' AND i.indisready AND i.indisvalid
ORDER BY c.relpages DESC LIMIT 10; ORDER BY c.relpages DESC LIMIT 10;
bt_index_check | relname | relpages bt_index_check | relname | relpages
----------------+---------------------------------+---------- ----------------+---------------------------------+----------
...@@ -126,7 +126,8 @@ ORDER BY c.relpages DESC LIMIT 10; ...@@ -126,7 +126,8 @@ ORDER BY c.relpages DESC LIMIT 10;
Optionally, when the <parameter>heapallindexed</parameter> Optionally, when the <parameter>heapallindexed</parameter>
argument is <literal>true</literal>, the function verifies the argument is <literal>true</literal>, the function verifies the
presence of all heap tuples that should be found within the presence of all heap tuples that should be found within the
index. The checks that can be performed by index, and that there are no missing downlinks in the index
structure. The checks that can be performed by
<function>bt_index_parent_check</function> are a superset of the <function>bt_index_parent_check</function> are a superset of the
checks that can be performed by <function>bt_index_check</function>. checks that can be performed by <function>bt_index_check</function>.
<function>bt_index_parent_check</function> can be thought of as <function>bt_index_parent_check</function> can be thought of as
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment