Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7f563c0

Browse files
committed
Add amcheck verification of heap relations belonging to btree indexes.
Add a new, optional, capability to bt_index_check() andbt_index_parent_check(): check that each heap tuple that should have anindex entry does in fact have one. The extra checking is performed atthe end of the existing nbtree checks.This is implemented by using a Bloom filter data structure. Theimplementation performs set membership tests within a callback (the sametype of callback that each index AM registers for CREATE INDEX). TheBloom filter is populated during the initial index verification scan.Reusing the CREATE INDEX infrastructure allows the new verificationoption to automatically benefit from the heap consistency checks thatCREATE INDEX already performs. CREATE INDEX does thorough sanitychecking of HOT chains, so the new check actually manages to detectproblems in heap-only tuples.Author: Peter GeogheganReviewed-By: Pavan Deolasee, Andres FreundDiscussion:https://postgr.es/m/CAH2-Wzm5VmG7cu1N-H=nnS57wZThoSDQU+F5dewx3o84M+jY=g@mail.gmail.com
1 parent51bc271 commit7f563c0

File tree

7 files changed

+458
-63
lines changed

7 files changed

+458
-63
lines changed

‎contrib/amcheck/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ MODULE_big= amcheck
44
OBJS= verify_nbtree.o$(WIN32RES)
55

66
EXTENSION = amcheck
7-
DATA = amcheck--1.0.sql
7+
DATA = amcheck--1.0--1.1.sql amcheck--1.0.sql
88
PGFILEDESC = "amcheck - function for verifying relation integrity"
99

1010
REGRESS = check check_btree

‎contrib/amcheck/amcheck--1.0--1.1.sql

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/* contrib/amcheck/amcheck--1.0--1.1.sql*/
2+
3+
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
4+
\echo Use"ALTER EXTENSION amcheck UPDATE TO '1.1'" to load this file. \quit
5+
6+
-- In order to avoid issues with dependencies when updating amcheck to 1.1,
7+
-- create new, overloaded versions of the 1.0 functions
8+
9+
--
10+
-- bt_index_check()
11+
--
12+
CREATEFUNCTIONbt_index_check(index regclass,
13+
heapallindexedboolean)
14+
RETURNS VOID
15+
AS'MODULE_PATHNAME','bt_index_check'
16+
LANGUAGE C STRICT PARALLEL RESTRICTED;
17+
18+
--
19+
-- bt_index_parent_check()
20+
--
21+
CREATEFUNCTIONbt_index_parent_check(index regclass,
22+
heapallindexedboolean)
23+
RETURNS VOID
24+
AS'MODULE_PATHNAME','bt_index_parent_check'
25+
LANGUAGE C STRICT PARALLEL RESTRICTED;
26+
27+
-- Don't want these to be available to public
28+
REVOKE ALLON FUNCTION bt_index_check(regclass,boolean)FROM PUBLIC;
29+
REVOKE ALLON FUNCTION bt_index_parent_check(regclass,boolean)FROM PUBLIC;

‎contrib/amcheck/amcheck.control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# amcheck extension
22
comment = 'functions for verifying relation integrity'
3-
default_version = '1.0'
3+
default_version = '1.1'
44
module_pathname = '$libdir/amcheck'
55
relocatable = true

‎contrib/amcheck/expected/check_btree.out

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ RESET ROLE;
1818
-- above explicit permission has to be granted for that.
1919
GRANT EXECUTE ON FUNCTION bt_index_check(regclass) TO bttest_role;
2020
GRANT EXECUTE ON FUNCTION bt_index_parent_check(regclass) TO bttest_role;
21+
GRANT EXECUTE ON FUNCTION bt_index_check(regclass, boolean) TO bttest_role;
22+
GRANT EXECUTE ON FUNCTION bt_index_parent_check(regclass, boolean) TO bttest_role;
2123
SET ROLE bttest_role;
2224
SELECT bt_index_check('bttest_a_idx');
2325
bt_index_check
@@ -56,8 +58,14 @@ SELECT bt_index_check('bttest_a_idx');
5658

5759
(1 row)
5860

59-
-- more expansive test
60-
SELECT bt_index_parent_check('bttest_b_idx');
61+
-- more expansive tests
62+
SELECT bt_index_check('bttest_a_idx', true);
63+
bt_index_check
64+
----------------
65+
66+
(1 row)
67+
68+
SELECT bt_index_parent_check('bttest_b_idx', true);
6169
bt_index_parent_check
6270
-----------------------
6371

‎contrib/amcheck/sql/check_btree.sql

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ RESET ROLE;
2121
-- above explicit permission has to be granted for that.
2222
GRANT EXECUTEON FUNCTION bt_index_check(regclass) TO bttest_role;
2323
GRANT EXECUTEON FUNCTION bt_index_parent_check(regclass) TO bttest_role;
24+
GRANT EXECUTEON FUNCTION bt_index_check(regclass,boolean) TO bttest_role;
25+
GRANT EXECUTEON FUNCTION bt_index_parent_check(regclass,boolean) TO bttest_role;
2426
SET ROLE bttest_role;
2527
SELECT bt_index_check('bttest_a_idx');
2628
SELECT bt_index_parent_check('bttest_a_idx');
@@ -42,8 +44,9 @@ ROLLBACK;
4244

4345
-- normal check outside of xact
4446
SELECT bt_index_check('bttest_a_idx');
45-
-- more expansive test
46-
SELECT bt_index_parent_check('bttest_b_idx');
47+
-- more expansive tests
48+
SELECT bt_index_check('bttest_a_idx', true);
49+
SELECT bt_index_parent_check('bttest_b_idx', true);
4750

4851
BEGIN;
4952
SELECT bt_index_check('bttest_a_idx');

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp