mirror of
https://github.com/postgres/postgres.git
synced 2025-07-15 19:21:59 +03:00
Fix pg_get_indexdef()'s behavior for included index columns.
The multi-argument form of pg_get_indexdef() failed to print anything when asked to print a single index column that is an included column rather than a key column. This seems an unintentional result of someone having tried to take a short-cut and use the attrsOnly flag for two different purposes. To fix, split said flag into two flags, attrsOnly which suppresses non-attribute info, and keysOnly which suppresses included columns. Add a test case using psql's \d command, which relies on that function. (It's mighty tempting at this point to replace pg_get_indexdef_worker's mess of boolean flag arguments with a single bitmask-of-flags argument, which would allow making the call sites much more self-documenting. But I refrained for the moment.) Discussion: https://postgr.es/m/21724.1531943735@sss.pgh.pa.us
This commit is contained in:
@ -19,6 +19,16 @@ WHERE i.indrelid = 'tbl_include_reg'::regclass ORDER BY c.relname;
|
||||
CREATE INDEX tbl_include_reg_idx ON public.tbl_include_reg USING btree (c1, c2) INCLUDE (c3, c4)
|
||||
(2 rows)
|
||||
|
||||
\d tbl_include_reg_idx
|
||||
Index "public.tbl_include_reg_idx"
|
||||
Column | Type | Definition
|
||||
--------+---------+------------
|
||||
c1 | integer | c1
|
||||
c2 | integer | c2
|
||||
c3 | integer | c3
|
||||
c4 | box | c4
|
||||
btree, for table "public.tbl_include_reg"
|
||||
|
||||
-- Unique index and unique constraint
|
||||
CREATE TABLE tbl_include_unique1 (c1 int, c2 int, c3 int, c4 box);
|
||||
INSERT INTO tbl_include_unique1 SELECT x, 2*x, 3*x, box('4,4,4,4') FROM generate_series(1,10) AS x;
|
||||
|
@ -14,6 +14,7 @@ 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;
|
||||
\d tbl_include_reg_idx
|
||||
|
||||
-- Unique index and unique constraint
|
||||
CREATE TABLE tbl_include_unique1 (c1 int, c2 int, c3 int, c4 box);
|
||||
|
Reference in New Issue
Block a user