mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-01-12 18:34:36 +08:00
91 lines
2.9 KiB
Plaintext
91 lines
2.9 KiB
Plaintext
|
-- minimal test, basically just verifying that amcheck
|
||
|
CREATE TABLE bttest_a(id int8);
|
||
|
CREATE TABLE bttest_b(id int8);
|
||
|
INSERT INTO bttest_a SELECT * FROM generate_series(1, 100000);
|
||
|
INSERT INTO bttest_b SELECT * FROM generate_series(100000, 1, -1);
|
||
|
CREATE INDEX bttest_a_idx ON bttest_a USING btree (id);
|
||
|
CREATE INDEX bttest_b_idx ON bttest_b USING btree (id);
|
||
|
CREATE ROLE bttest_role;
|
||
|
-- verify permissions are checked (error due to function not callable)
|
||
|
SET ROLE bttest_role;
|
||
|
SELECT bt_index_check('bttest_a_idx'::regclass);
|
||
|
ERROR: permission denied for function bt_index_check
|
||
|
SELECT bt_index_parent_check('bttest_a_idx'::regclass);
|
||
|
ERROR: permission denied for function bt_index_parent_check
|
||
|
RESET ROLE;
|
||
|
-- we, intentionally, don't check relation permissions - it's useful
|
||
|
-- to run this cluster-wide with a restricted account, and as tested
|
||
|
-- above explicit permission has to be granted for that.
|
||
|
GRANT EXECUTE ON FUNCTION bt_index_check(regclass) TO bttest_role;
|
||
|
GRANT EXECUTE ON FUNCTION bt_index_parent_check(regclass) TO bttest_role;
|
||
|
SET ROLE bttest_role;
|
||
|
SELECT bt_index_check('bttest_a_idx');
|
||
|
bt_index_check
|
||
|
----------------
|
||
|
|
||
|
(1 row)
|
||
|
|
||
|
SELECT bt_index_parent_check('bttest_a_idx');
|
||
|
bt_index_parent_check
|
||
|
-----------------------
|
||
|
|
||
|
(1 row)
|
||
|
|
||
|
RESET ROLE;
|
||
|
-- verify plain tables are rejected (error)
|
||
|
SELECT bt_index_check('bttest_a');
|
||
|
ERROR: "bttest_a" is not an index
|
||
|
SELECT bt_index_parent_check('bttest_a');
|
||
|
ERROR: "bttest_a" is not an index
|
||
|
-- verify non-existing indexes are rejected (error)
|
||
|
SELECT bt_index_check(17);
|
||
|
ERROR: could not open relation with OID 17
|
||
|
SELECT bt_index_parent_check(17);
|
||
|
ERROR: could not open relation with OID 17
|
||
|
-- verify wrong index types are rejected (error)
|
||
|
BEGIN;
|
||
|
CREATE INDEX bttest_a_brin_idx ON bttest_a USING brin(id);
|
||
|
SELECT bt_index_parent_check('bttest_a_brin_idx');
|
||
|
ERROR: only B-Tree indexes are supported as targets for verification
|
||
|
DETAIL: Relation "bttest_a_brin_idx" is not a B-Tree index.
|
||
|
ROLLBACK;
|
||
|
-- normal check outside of xact
|
||
|
SELECT bt_index_check('bttest_a_idx');
|
||
|
bt_index_check
|
||
|
----------------
|
||
|
|
||
|
(1 row)
|
||
|
|
||
|
-- more expansive test
|
||
|
SELECT bt_index_parent_check('bttest_b_idx');
|
||
|
bt_index_parent_check
|
||
|
-----------------------
|
||
|
|
||
|
(1 row)
|
||
|
|
||
|
BEGIN;
|
||
|
SELECT bt_index_check('bttest_a_idx');
|
||
|
bt_index_check
|
||
|
----------------
|
||
|
|
||
|
(1 row)
|
||
|
|
||
|
SELECT bt_index_parent_check('bttest_b_idx');
|
||
|
bt_index_parent_check
|
||
|
-----------------------
|
||
|
|
||
|
(1 row)
|
||
|
|
||
|
-- make sure we don't have any leftover locks
|
||
|
SELECT * FROM pg_locks WHERE relation IN ('bttest_a_idx'::regclass, 'bttest_b_idx'::regclass);
|
||
|
locktype | database | relation | page | tuple | virtualxid | transactionid | classid | objid | objsubid | virtualtransaction | pid | mode | granted | fastpath
|
||
|
----------+----------+----------+------+-------+------------+---------------+---------+-------+----------+--------------------+-----+------+---------+----------
|
||
|
(0 rows)
|
||
|
|
||
|
COMMIT;
|
||
|
-- cleanup
|
||
|
DROP TABLE bttest_a;
|
||
|
DROP TABLE bttest_b;
|
||
|
DROP OWNED BY bttest_role; -- permissions
|
||
|
DROP ROLE bttest_role;
|