mirror of
https://github.com/postgres/postgres.git
synced 2025-07-27 12:41:57 +03:00
Indexes with INCLUDE columns and their support in B-tree
This patch introduces INCLUDE clause to index definition. This clause specifies a list of columns which will be included as a non-key part in the index. The INCLUDE columns exist solely to allow more queries to benefit from index-only scans. Also, such columns don't need to have appropriate operator classes. Expressions are not supported as INCLUDE columns since they cannot be used in index-only scans. Index access methods supporting INCLUDE are indicated by amcaninclude flag in IndexAmRoutine. For now, only B-tree indexes support INCLUDE clause. In B-tree indexes INCLUDE columns are truncated from pivot index tuples (tuples located in non-leaf pages and high keys). Therefore, B-tree indexes now might have variable number of attributes. This patch also provides generic facility to support that: pivot tuples contain number of their attributes in t_tid.ip_posid. Free 13th bit of t_info is used for indicating that. This facility will simplify further support of index suffix truncation. The changes of above are backward-compatible, pg_upgrade doesn't need special handling of B-tree indexes for that. Bump catalog version Author: Anastasia Lubennikova with contribition by Alexander Korotkov and me Reviewed by: Peter Geoghegan, Tomas Vondra, Antonin Houska, Jeff Janes, David Rowley, Alexander Korotkov Discussion: https://www.postgresql.org/message-id/flat/56168952.4010101@postgrespro.ru
This commit is contained in:
@ -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;
|
||||
|
||||
@ -57,8 +61,23 @@ 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', true);
|
||||
SELECT bt_index_parent_check('bttest_multi_idx', true);
|
||||
|
||||
-- repeat same checks with index made by insertions
|
||||
TRUNCATE bttest_multi;
|
||||
INSERT INTO bttest_multi SELECT i, i%2 FROM generate_series(1, 100000) as i;
|
||||
SELECT bt_index_check('bttest_multi_idx');
|
||||
SELECT bt_index_parent_check('bttest_multi_idx', true);
|
||||
SELECT bt_index_parent_check('bttest_multi_idx', true);
|
||||
|
||||
|
||||
-- cleanup
|
||||
DROP TABLE bttest_a;
|
||||
DROP TABLE bttest_b;
|
||||
DROP TABLE bttest_multi;
|
||||
DROP OWNED BY bttest_role; -- permissions
|
||||
DROP ROLE bttest_role;
|
||||
|
Reference in New Issue
Block a user