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

Commit14ffaec

Browse files
committed
amcheck: Add gin_index_check() to verify GIN index
Adds a new function, validating two kinds of invariants on a GIN index:- parent-child consistency: Paths in a GIN graph have to contain consistent keys. Tuples on parent pages consistently include tuples from child pages; parent tuples do not require any adjustments.- balanced-tree / graph: Each internal page has at least one downlink, and can reference either only leaf pages or only internal pages.The GIN verification is based on work by Grigory Kryachko, reworked byHeikki Linnakangas and with various improvements by Andrey Borodin.Investigation and fixes for multiple bugs by Kirill Reshke.Author: Grigory Kryachko <GSKryachko@gmail.com>Author: Heikki Linnakangas <hlinnaka@iki.fi>Author: Andrey Borodin <amborodin@acm.org>Reviewed-By: José Villanova <jose.arthur@gmail.com>Reviewed-By: Aleksander Alekseev <aleksander@timescale.com>Reviewed-By: Nikolay Samokhvalov <samokhvalov@gmail.com>Reviewed-By: Andres Freund <andres@anarazel.de>Reviewed-By: Tomas Vondra <tomas.vondra@enterprisedb.com>Reviewed-By: Kirill Reshke <reshkekirill@gmail.com>Reviewed-By: Mark Dilger <mark.dilger@enterprisedb.com>Reviewed-By: Peter Geoghegan <pg@bowt.ie>Discussion:https://postgr.es/m/45AC9B0A-2B45-40EE-B08F-BDCF5739D1E1%40yandex-team.ru
1 parent53a2a15 commit14ffaec

File tree

9 files changed

+946
-3
lines changed

9 files changed

+946
-3
lines changed

‎contrib/amcheck/Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ MODULE_big= amcheck
44
OBJS =\
55
$(WIN32RES)\
66
verify_common.o\
7+
verify_gin.o\
78
verify_heapam.o\
89
verify_nbtree.o
910

1011
EXTENSION = amcheck
11-
DATA = 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
12+
DATA = amcheck--1.2--1.3.sql amcheck--1.1--1.2.sql amcheck--1.0--1.1.sql amcheck--1.0.sql\
13+
amcheck--1.3--1.4.sql amcheck--1.4--1.5.sql
1214
PGFILEDESC = "amcheck - function for verifying relation integrity"
1315

14-
REGRESS = check check_btree check_heap
16+
REGRESS = check check_btreecheck_gincheck_heap
1517

1618
EXTRA_INSTALL = contrib/pg_walinspect
1719
TAP_TESTS = 1

‎contrib/amcheck/amcheck--1.4--1.5.sql

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* contrib/amcheck/amcheck--1.4--1.5.sql*/
2+
3+
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
4+
\echo Use"ALTER EXTENSION amcheck UPDATE TO '1.5'" to load this file. \quit
5+
6+
7+
-- gin_index_check()
8+
--
9+
CREATEFUNCTIONgin_index_check(index regclass)
10+
RETURNS VOID
11+
AS'MODULE_PATHNAME','gin_index_check'
12+
LANGUAGE C STRICT;
13+
14+
REVOKE ALLON FUNCTION gin_index_check(regclass)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.4'
3+
default_version = '1.5'
44
module_pathname = '$libdir/amcheck'
55
relocatable = true
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
-- Test of index bulk load
2+
SELECT setseed(1);
3+
setseed
4+
---------
5+
6+
(1 row)
7+
8+
CREATE TABLE "gin_check"("Column1" int[]);
9+
-- posting trees (frequently used entries)
10+
INSERT INTO gin_check select array_agg(round(random()*255) ) from generate_series(1, 100000) as i group by i % 10000;
11+
-- posting leaves (sparse entries)
12+
INSERT INTO gin_check select array_agg(255 + round(random()*100)) from generate_series(1, 100) as i group by i % 100;
13+
CREATE INDEX gin_check_idx on "gin_check" USING GIN("Column1");
14+
SELECT gin_index_check('gin_check_idx');
15+
gin_index_check
16+
-----------------
17+
18+
(1 row)
19+
20+
-- cleanup
21+
DROP TABLE gin_check;
22+
-- Test index inserts
23+
SELECT setseed(1);
24+
setseed
25+
---------
26+
27+
(1 row)
28+
29+
CREATE TABLE "gin_check"("Column1" int[]);
30+
CREATE INDEX gin_check_idx on "gin_check" USING GIN("Column1");
31+
ALTER INDEX gin_check_idx SET (fastupdate = false);
32+
-- posting trees
33+
INSERT INTO gin_check select array_agg(round(random()*255) ) from generate_series(1, 100000) as i group by i % 10000;
34+
-- posting leaves
35+
INSERT INTO gin_check select array_agg(100 + round(random()*255)) from generate_series(1, 100) as i group by i % 100;
36+
SELECT gin_index_check('gin_check_idx');
37+
gin_index_check
38+
-----------------
39+
40+
(1 row)
41+
42+
-- cleanup
43+
DROP TABLE gin_check;
44+
-- Test GIN over text array
45+
SELECT setseed(1);
46+
setseed
47+
---------
48+
49+
(1 row)
50+
51+
CREATE TABLE "gin_check_text_array"("Column1" text[]);
52+
-- posting trees
53+
INSERT INTO gin_check_text_array select array_agg(md5(round(random()*300)::text)::text) from generate_series(1, 100000) as i group by i % 10000;
54+
-- posting leaves
55+
INSERT INTO gin_check_text_array select array_agg(md5(round(random()*300 + 300)::text)::text) from generate_series(1, 10000) as i group by i % 100;
56+
CREATE INDEX gin_check_text_array_idx on "gin_check_text_array" USING GIN("Column1");
57+
SELECT gin_index_check('gin_check_text_array_idx');
58+
gin_index_check
59+
-----------------
60+
61+
(1 row)
62+
63+
-- cleanup
64+
DROP TABLE gin_check_text_array;

‎contrib/amcheck/meson.build

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
amcheck_sources=files(
44
'verify_common.c',
5+
'verify_gin.c',
56
'verify_heapam.c',
67
'verify_nbtree.c',
78
)
@@ -25,6 +26,7 @@ install_data(
2526
'amcheck--1.1--1.2.sql',
2627
'amcheck--1.2--1.3.sql',
2728
'amcheck--1.3--1.4.sql',
29+
'amcheck--1.4--1.5.sql',
2830
kwargs: contrib_data_args,
2931
)
3032

@@ -36,6 +38,7 @@ tests += {
3638
'sql': [
3739
'check',
3840
'check_btree',
41+
'check_gin',
3942
'check_heap',
4043
],
4144
},

‎contrib/amcheck/sql/check_gin.sql

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
-- Test of index bulk load
2+
SELECT setseed(1);
3+
CREATETABLE "gin_check"("Column1"int[]);
4+
-- posting trees (frequently used entries)
5+
INSERT INTO gin_checkselect array_agg(round(random()*255) )from generate_series(1,100000)as igroup by i %10000;
6+
-- posting leaves (sparse entries)
7+
INSERT INTO gin_checkselect array_agg(255+ round(random()*100))from generate_series(1,100)as igroup by i %100;
8+
CREATEINDEXgin_check_idxon"gin_check" USING GIN("Column1");
9+
SELECT gin_index_check('gin_check_idx');
10+
11+
-- cleanup
12+
DROPTABLE gin_check;
13+
14+
-- Test index inserts
15+
SELECT setseed(1);
16+
CREATETABLE "gin_check"("Column1"int[]);
17+
CREATEINDEXgin_check_idxon"gin_check" USING GIN("Column1");
18+
ALTERINDEX gin_check_idxSET (fastupdate= false);
19+
-- posting trees
20+
INSERT INTO gin_checkselect array_agg(round(random()*255) )from generate_series(1,100000)as igroup by i %10000;
21+
-- posting leaves
22+
INSERT INTO gin_checkselect array_agg(100+ round(random()*255))from generate_series(1,100)as igroup by i %100;
23+
24+
SELECT gin_index_check('gin_check_idx');
25+
26+
-- cleanup
27+
DROPTABLE gin_check;
28+
29+
-- Test GIN over text array
30+
SELECT setseed(1);
31+
CREATETABLE "gin_check_text_array"("Column1"text[]);
32+
-- posting trees
33+
INSERT INTO gin_check_text_arrayselect array_agg(md5(round(random()*300)::text)::text)from generate_series(1,100000)as igroup by i %10000;
34+
-- posting leaves
35+
INSERT INTO gin_check_text_arrayselect array_agg(md5(round(random()*300+300)::text)::text)from generate_series(1,10000)as igroup by i %100;
36+
CREATEINDEXgin_check_text_array_idxon"gin_check_text_array" USING GIN("Column1");
37+
SELECT gin_index_check('gin_check_text_array_idx');
38+
39+
-- cleanup
40+
DROPTABLE gin_check_text_array;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp