0003-Covering-amcheck-v8.patch
text/x-patch
Filename: 0003-Covering-amcheck-v8.patch
Type: text/x-patch
Part: 2
Message:
Re: WIP: Covering + unique indexes.
Patch
Format: unified
Series: patch v8-0003
| File | + | − |
|---|---|---|
| contrib/amcheck/expected/check_btree.out | 19 | 0 |
| contrib/amcheck/sql/check_btree.sql | 10 | 0 |
| contrib/amcheck/verify_nbtree.c | 6 | 6 |
commit 4fed19a3329ac7ac3c9966ae25afb2d13ca2216e
Author: Anastasia <a.lubennikova@postgrespro.ru>
Date: Wed Mar 28 17:50:53 2018 +0300
0003-Covering-amcheck-v8.patch
diff --git a/contrib/amcheck/expected/check_btree.out b/contrib/amcheck/expected/check_btree.out
index df3741e..9e4ddef 100644
--- a/contrib/amcheck/expected/check_btree.out
+++ b/contrib/amcheck/expected/check_btree.out
@@ -1,10 +1,14 @@
-- minimal test, basically just verifying that amcheck
CREATE TABLE bttest_a(id int8);
CREATE TABLE bttest_b(id int8);
+CREATE TABLE bttest_multi(id int8, data int8);
INSERT INTO bttest_a SELECT * FROM generate_series(1, 100000);
INSERT INTO bttest_b SELECT * FROM generate_series(100000, 1, -1);
+INSERT INTO bttest_multi SELECT i, i%2 FROM generate_series(1, 100000) as i;
CREATE INDEX bttest_a_idx ON bttest_a USING btree (id);
CREATE INDEX bttest_b_idx ON bttest_b USING btree (id);
+CREATE UNIQUE INDEX bttest_multi_idx ON bttest_multi
+USING btree (id) INCLUDE (data);
CREATE ROLE bttest_role;
-- verify permissions are checked (error due to function not callable)
SET ROLE bttest_role;
@@ -85,8 +89,23 @@ WHERE relation = ANY(ARRAY['bttest_a', 'bttest_a_idx', 'bttest_b', 'bttest_b_idx
(0 rows)
COMMIT;
+-- normal check outside of xact for index with included columns
+SELECT bt_index_check('bttest_multi_idx');
+ bt_index_check
+----------------
+
+(1 row)
+
+-- more expansive test for index with included columns
+SELECT bt_index_parent_check('bttest_multi_idx');
+ bt_index_parent_check
+-----------------------
+
+(1 row)
+
-- cleanup
DROP TABLE bttest_a;
DROP TABLE bttest_b;
+DROP TABLE bttest_multi;
DROP OWNED BY bttest_role; -- permissions
DROP ROLE bttest_role;
diff --git a/contrib/amcheck/sql/check_btree.sql b/contrib/amcheck/sql/check_btree.sql
index fd90531..9ea250b 100644
--- a/contrib/amcheck/sql/check_btree.sql
+++ b/contrib/amcheck/sql/check_btree.sql
@@ -1,12 +1,16 @@
-- minimal test, basically just verifying that amcheck
CREATE TABLE bttest_a(id int8);
CREATE TABLE bttest_b(id int8);
+CREATE TABLE bttest_multi(id int8, data int8);
INSERT INTO bttest_a SELECT * FROM generate_series(1, 100000);
INSERT INTO bttest_b SELECT * FROM generate_series(100000, 1, -1);
+INSERT INTO bttest_multi SELECT i, i%2 FROM generate_series(1, 100000) as i;
CREATE INDEX bttest_a_idx ON bttest_a USING btree (id);
CREATE INDEX bttest_b_idx ON bttest_b USING btree (id);
+CREATE UNIQUE INDEX bttest_multi_idx ON bttest_multi
+USING btree (id) INCLUDE (data);
CREATE ROLE bttest_role;
@@ -54,8 +58,14 @@ WHERE relation = ANY(ARRAY['bttest_a', 'bttest_a_idx', 'bttest_b', 'bttest_b_idx
AND pid = pg_backend_pid();
COMMIT;
+-- normal check outside of xact for index with included columns
+SELECT bt_index_check('bttest_multi_idx');
+-- more expansive test for index with included columns
+SELECT bt_index_parent_check('bttest_multi_idx');
+
-- cleanup
DROP TABLE bttest_a;
DROP TABLE bttest_b;
+DROP TABLE bttest_multi;
DROP OWNED BY bttest_role; -- permissions
DROP ROLE bttest_role;
diff --git a/contrib/amcheck/verify_nbtree.c b/contrib/amcheck/verify_nbtree.c
index da518da..fb472b3 100644
--- a/contrib/amcheck/verify_nbtree.c
+++ b/contrib/amcheck/verify_nbtree.c
@@ -1102,10 +1102,10 @@ static inline bool
invariant_leq_offset(BtreeCheckState *state, ScanKey key,
OffsetNumber upperbound)
{
- int16 natts = state->rel->rd_rel->relnatts;
+ int16 nkeyatts = IndexRelationGetNumberOfKeyAttributes(state->rel);
int32 cmp;
- cmp = _bt_compare(state->rel, natts, key, state->target, upperbound);
+ cmp = _bt_compare(state->rel, nkeyatts, key, state->target, upperbound);
return cmp <= 0;
}
@@ -1121,10 +1121,10 @@ static inline bool
invariant_geq_offset(BtreeCheckState *state, ScanKey key,
OffsetNumber lowerbound)
{
- int16 natts = state->rel->rd_rel->relnatts;
+ int16 nkeyatts = IndexRelationGetNumberOfKeyAttributes(state->rel);
int32 cmp;
- cmp = _bt_compare(state->rel, natts, key, state->target, lowerbound);
+ cmp = _bt_compare(state->rel, nkeyatts, key, state->target, lowerbound);
return cmp >= 0;
}
@@ -1144,10 +1144,10 @@ invariant_leq_nontarget_offset(BtreeCheckState *state,
Page nontarget, ScanKey key,
OffsetNumber upperbound)
{
- int16 natts = state->rel->rd_rel->relnatts;
+ int16 nkeyatts = IndexRelationGetNumberOfKeyAttributes(state->rel);
int32 cmp;
- cmp = _bt_compare(state->rel, natts, key, nontarget, upperbound);
+ cmp = _bt_compare(state->rel, nkeyatts, key, nontarget, upperbound);
return cmp <= 0;
}