CREATETABLE bttest_a(id int8); CREATETABLE bttest_b(id int8); CREATETABLE bttest_multi(id int8, data int8); CREATETABLE delete_test_table (a bigint, b bigint, c bigint, d bigint);
-- Stabilize tests ALTERTABLE bttest_a SET (autovacuum_enabled = false); ALTERTABLE bttest_b SET (autovacuum_enabled = false); ALTERTABLE bttest_multi SET (autovacuum_enabled = false); ALTERTABLE delete_test_table SET (autovacuum_enabled = false);
INSERTINTO bttest_a SELECT * FROM generate_series(1, 100000); INSERTINTO bttest_b SELECT * FROM generate_series(100000, 1, -1); INSERTINTO bttest_multi SELECT i, i%2FROM generate_series(1, 100000) as i;
CREATEINDEX bttest_a_idx ON bttest_a USING btree (id) WITH (deduplicate_items = ON); CREATEINDEX bttest_b_idx ON bttest_b USING btree (id); CREATEUNIQUEINDEX bttest_multi_idx ON bttest_multi USING btree (id) INCLUDE (data);
CREATE ROLE regress_bttest_role;
-- verify permissions are checked (error due to function not callable) SET ROLE regress_bttest_role; SELECT bt_index_check('bttest_a_idx'::regclass); SELECT bt_index_parent_check('bttest_a_idx'::regclass);
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 regress_bttest_role; GRANT EXECUTE ON FUNCTION bt_index_parent_check(regclass) TO regress_bttest_role; GRANT EXECUTE ON FUNCTION bt_index_check(regclass, boolean) TO regress_bttest_role; GRANT EXECUTE ON FUNCTION bt_index_parent_check(regclass, boolean) TO regress_bttest_role; SET ROLE regress_bttest_role; SELECT bt_index_check('bttest_a_idx'); SELECT bt_index_parent_check('bttest_a_idx');
RESET ROLE;
-- verify wrong index types are rejected (error)
BEGIN; CREATEINDEX bttest_a_brin_idx ON bttest_a USING brin(id); SELECT bt_index_parent_check('bttest_a_brin_idx');
ROLLBACK;
-- normal check outside of xact SELECT bt_index_check('bttest_a_idx'); -- more expansive tests SELECT bt_index_check('bttest_a_idx', true); SELECT bt_index_parent_check('bttest_b_idx', true);
BEGIN; SELECT bt_index_check('bttest_a_idx'); SELECT bt_index_parent_check('bttest_b_idx'); -- make sure we don't have any leftover locks SELECT * FROM pg_locks WHERE relation = ANY(ARRAY['bttest_a', 'bttest_a_idx', 'bttest_b', 'bttest_b_idx']::regclass[]) 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 tests for index with included columns SELECT bt_index_parent_check('bttest_multi_idx', true, true);
-- repeat expansive tests for index built using insertions
TRUNCATE bttest_multi; INSERTINTO bttest_multi SELECT i, i%2FROM generate_series(1, 100000) as i; SELECT bt_index_parent_check('bttest_multi_idx', true, true);
-- -- Test for multilevel page deletion/downlink present checks, and rootdescend -- checks -- INSERTINTO delete_test_table SELECT i, 1, 2, 3FROM generate_series(1,80000) i; ALTERTABLE delete_test_table ADDPRIMARYKEY (a,b,c,d); -- Delete most entries, and vacuum, deleting internal pages and creating "fast -- root" DELETEFROM delete_test_table WHERE a < 79990;
VACUUM delete_test_table; SELECT bt_index_parent_check('delete_test_table_pkey', true);
-- -- BUG #15597: must not assume consistent input toasting state when forming -- tuple. Bloom filter must fingerprint normalized index tuple representation. -- CREATETABLE toast_bug(buggy text); ALTERTABLE toast_bug ALTERCOLUMN buggy SET STORAGE extended; CREATEINDEX toasty ON toast_bug(buggy);
-- pg_attribute entry for toasty.buggy (the index) will have plain storage: UPDATE pg_attribute SET attstorage = 'p' WHERE attrelid = 'toasty'::regclass AND attname = 'buggy';
-- Whereas pg_attribute entry for toast_bug.buggy (the table) still has extended storage: SELECT attstorage FROM pg_attribute WHERE attrelid = 'toast_bug'::regclass AND attname = 'buggy';
-- Insert compressible heap tuple (comfortably exceeds TOAST_TUPLE_THRESHOLD): INSERTINTO toast_bug SELECTrepeat('a', 2200); -- Should not get false positive report of corruption: SELECT bt_index_check('toasty', true);
-- -- Check that index expressions and predicates are run as the table's owner --
TRUNCATE bttest_a; INSERTINTO bttest_a SELECT * FROM generate_series(1, 1000); ALTERTABLE bttest_a OWNER TO regress_bttest_role; -- A dummy index function checking current_user CREATE FUNCTION ifun(int8) RETURNS int8AS $$
BEGIN
ASSERT current_user = 'regress_bttest_role',
format('ifun(%s) called by %s', $1, current_user); RETURN $1;
END;
$$ LANGUAGE plpgsql IMMUTABLE;
CREATEINDEX bttest_a_expr_idx ON bttest_a ((ifun(id) + ifun(0))) WHERE ifun(id + 10) > ifun(10);
-- Check that null values in an unique index are not treated as equal CREATETABLE bttest_unique_nulls (a serial, b int, c intUNIQUE); INSERTINTO bttest_unique_nulls VALUES (generate_series(1, 10000), 2, default); SELECT bt_index_check('bttest_unique_nulls_c_key', heapallindexed => true, checkunique => true); CREATEINDEXon bttest_unique_nulls (b,c); SELECT bt_index_check('bttest_unique_nulls_b_c_idx', heapallindexed => true, checkunique => true);
-- Check support of both 1B and 4B header sizes of short varlena datum CREATETABLE varlena_bug (v text); ALTERTABLE varlena_bug ALTERcolumn v SET storage plain; INSERTINTO varlena_bug VALUES ('x');
COPY varlena_bug from stdin;
x
\. CREATEINDEX varlena_bug_idx on varlena_bug(v); SELECT bt_index_check('varlena_bug_idx', true);
-- Also check that we compress varlena values, which were previously stored -- uncompressed in index. INSERTINTO varlena_bug VALUES (repeat('Test', 250)); ALTERTABLE varlena_bug ALTERCOLUMN v SET STORAGE extended; SELECT bt_index_check('varlena_bug_idx', true);
-- cleanup DROPTABLE bttest_a; DROPTABLE bttest_b; DROPTABLE bttest_multi; DROPTABLE delete_test_table; DROPTABLE toast_bug; DROP FUNCTION ifun(int8); DROPTABLE bttest_unique_nulls; DROP OWNED BY regress_bttest_role; -- permissions DROP ROLE regress_bttest_role; DROPTABLE varlena_bug;
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.1 Sekunden
(vorverarbeitet am 2026-08-08)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.