mirror of
https://github.com/postgres/postgres.git
synced 2025-07-15 19:21:59 +03:00
Drop the rule against included index columns duplicating key columns.
The initial version of the included-index-column feature stated that included columns couldn't be the same as any key column of the index. While it'd be pretty silly to do that, since the included column would be entirely redundant, we've never prohibited redundant index columns before so it's not very consistent to do so here. Moreover, the prohibition was itself badly implemented, so that it failed to reject columns that were effectively identical but not spelled quite alike, as reported by Aditya Toshniwal. (Moreover, it's not hard to imagine that for some non-btree index types, such cases would be non-silly anyhow: the index might use a lossy representation for key columns but be able to support retrieval of the original form of included columns.) Hence, let's just drop the prohibition. In passing, do some copy-editing on the documentation for the included-column feature. Yugo Nagata; documentation and test corrections by me Discussion: https://postgr.es/m/CAM9w-_mhBCys4fQNfaiQKTRrVWtoFrZ-wXmDuE9Nj5y-Y7aDKQ@mail.gmail.com
This commit is contained in:
@ -7,17 +7,17 @@
|
||||
-- Regular index with included columns
|
||||
CREATE TABLE tbl_include_reg (c1 int, c2 int, c3 int, c4 box);
|
||||
INSERT INTO tbl_include_reg SELECT x, 2*x, 3*x, box('4,4,4,4') FROM generate_series(1,10) AS x;
|
||||
CREATE INDEX tbl_include_reg_idx ON tbl_include_reg using btree (c1, c2) INCLUDE (c3,c4);
|
||||
-- must fail because of intersection of key and included columns
|
||||
CREATE INDEX tbl_include_reg_idx ON tbl_include_reg using btree (c1, c2) INCLUDE (c1,c3);
|
||||
ERROR: included columns must not intersect with key columns
|
||||
CREATE INDEX tbl_include_reg_idx ON tbl_include_reg (c1, c2) INCLUDE (c3, c4);
|
||||
-- duplicate column is pretty pointless, but we allow it anyway
|
||||
CREATE INDEX ON tbl_include_reg (c1, c2) INCLUDE (c1, c3);
|
||||
SELECT pg_get_indexdef(i.indexrelid)
|
||||
FROM pg_index i JOIN pg_class c ON i.indexrelid = c.oid
|
||||
WHERE i.indrelid = 'tbl_include_reg'::regclass ORDER BY c.relname;
|
||||
pg_get_indexdef
|
||||
--------------------------------------------------------------------------------------------------
|
||||
pg_get_indexdef
|
||||
---------------------------------------------------------------------------------------------------------------
|
||||
CREATE INDEX tbl_include_reg_c1_c2_c11_c3_idx ON public.tbl_include_reg USING btree (c1, c2) INCLUDE (c1, c3)
|
||||
CREATE INDEX tbl_include_reg_idx ON public.tbl_include_reg USING btree (c1, c2) INCLUDE (c3, c4)
|
||||
(1 row)
|
||||
(2 rows)
|
||||
|
||||
-- Unique index and unique constraint
|
||||
CREATE TABLE tbl_include_unique1 (c1 int, c2 int, c3 int, c4 box);
|
||||
|
@ -8,9 +8,9 @@
|
||||
-- Regular index with included columns
|
||||
CREATE TABLE tbl_include_reg (c1 int, c2 int, c3 int, c4 box);
|
||||
INSERT INTO tbl_include_reg SELECT x, 2*x, 3*x, box('4,4,4,4') FROM generate_series(1,10) AS x;
|
||||
CREATE INDEX tbl_include_reg_idx ON tbl_include_reg using btree (c1, c2) INCLUDE (c3,c4);
|
||||
-- must fail because of intersection of key and included columns
|
||||
CREATE INDEX tbl_include_reg_idx ON tbl_include_reg using btree (c1, c2) INCLUDE (c1,c3);
|
||||
CREATE INDEX tbl_include_reg_idx ON tbl_include_reg (c1, c2) INCLUDE (c3, c4);
|
||||
-- duplicate column is pretty pointless, but we allow it anyway
|
||||
CREATE INDEX ON tbl_include_reg (c1, c2) INCLUDE (c1, c3);
|
||||
SELECT pg_get_indexdef(i.indexrelid)
|
||||
FROM pg_index i JOIN pg_class c ON i.indexrelid = c.oid
|
||||
WHERE i.indrelid = 'tbl_include_reg'::regclass ORDER BY c.relname;
|
||||
|
Reference in New Issue
Block a user