mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
Improve psql's \d command to show whether index columns are key columns.
This is essential information when looking at an index that has "included" columns. Per discussion, follow the style used in \dC and some other places: column header is "Key?" and values are "yes" or "no" (all translatable). While at it, revise describeOneTableDetails to be a bit more maintainable: avoid hard-wired column numbers and multiple repetitions of what needs to be identical test logic. This also results in the emitted catalog query corresponding more closely to what we print, which should be a benefit to users of ECHO_HIDDEN mode, and perhaps a bit faster too (the old logic sometimes asked for values it would not print, even ones that are fairly expensive to get). Discussion: https://postgr.es/m/21724.1531943735@sss.pgh.pa.us
This commit is contained in:
@ -111,12 +111,12 @@ ERROR: cannot alter statistics on non-expression column "a" of index "attmp_idx
|
||||
HINT: Alter statistics on table column instead.
|
||||
ALTER INDEX attmp_idx ALTER COLUMN 2 SET STATISTICS 1000;
|
||||
\d+ attmp_idx
|
||||
Index "public.attmp_idx"
|
||||
Column | Type | Definition | Storage | Stats target
|
||||
--------+------------------+------------+---------+--------------
|
||||
a | integer | a | plain |
|
||||
expr | double precision | (d + e) | plain | 1000
|
||||
b | cstring | b | plain |
|
||||
Index "public.attmp_idx"
|
||||
Column | Type | Key? | Definition | Storage | Stats target
|
||||
--------+------------------+------+------------+---------+--------------
|
||||
a | integer | yes | a | plain |
|
||||
expr | double precision | yes | (d + e) | plain | 1000
|
||||
b | cstring | yes | b | plain |
|
||||
btree, for table "public.attmp"
|
||||
|
||||
ALTER INDEX attmp_idx ALTER COLUMN 3 SET STATISTICS 1000;
|
||||
|
@ -2362,10 +2362,10 @@ DROP TABLE array_gin_test;
|
||||
CREATE INDEX gin_relopts_test ON array_index_op_test USING gin (i)
|
||||
WITH (FASTUPDATE=on, GIN_PENDING_LIST_LIMIT=128);
|
||||
\d+ gin_relopts_test
|
||||
Index "public.gin_relopts_test"
|
||||
Column | Type | Definition | Storage | Stats target
|
||||
--------+---------+------------+---------+--------------
|
||||
i | integer | i | plain |
|
||||
Index "public.gin_relopts_test"
|
||||
Column | Type | Key? | Definition | Storage | Stats target
|
||||
--------+---------+------+------------+---------+--------------
|
||||
i | integer | yes | i | plain |
|
||||
gin, for table "public.array_index_op_test"
|
||||
Options: fastupdate=on, gin_pending_list_limit=128
|
||||
|
||||
@ -2582,11 +2582,11 @@ Indexes:
|
||||
"cwi_uniq_idx" PRIMARY KEY, btree (a, b)
|
||||
|
||||
\d cwi_uniq_idx
|
||||
Index "public.cwi_uniq_idx"
|
||||
Column | Type | Definition
|
||||
--------+-----------------------+------------
|
||||
a | integer | a
|
||||
b | character varying(10) | b
|
||||
Index "public.cwi_uniq_idx"
|
||||
Column | Type | Key? | Definition
|
||||
--------+-----------------------+------+------------
|
||||
a | integer | yes | a
|
||||
b | character varying(10) | yes | b
|
||||
primary key, btree, for table "public.cwi_test"
|
||||
|
||||
CREATE UNIQUE INDEX cwi_uniq2_idx ON cwi_test(b , a);
|
||||
@ -2605,11 +2605,11 @@ Indexes:
|
||||
"cwi_replaced_pkey" PRIMARY KEY, btree (b, a)
|
||||
|
||||
\d cwi_replaced_pkey
|
||||
Index "public.cwi_replaced_pkey"
|
||||
Column | Type | Definition
|
||||
--------+-----------------------+------------
|
||||
b | character varying(10) | b
|
||||
a | integer | a
|
||||
Index "public.cwi_replaced_pkey"
|
||||
Column | Type | Key? | Definition
|
||||
--------+-----------------------+------+------------
|
||||
b | character varying(10) | yes | b
|
||||
a | integer | yes | a
|
||||
primary key, btree, for table "public.cwi_test"
|
||||
|
||||
DROP INDEX cwi_replaced_pkey; -- Should fail; a constraint depends on it
|
||||
|
@ -20,13 +20,13 @@ WHERE i.indrelid = 'tbl_include_reg'::regclass ORDER BY c.relname;
|
||||
(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
|
||||
Index "public.tbl_include_reg_idx"
|
||||
Column | Type | Key? | Definition
|
||||
--------+---------+------+------------
|
||||
c1 | integer | yes | c1
|
||||
c2 | integer | yes | c2
|
||||
c3 | integer | no | c3
|
||||
c4 | box | no | c4
|
||||
btree, for table "public.tbl_include_reg"
|
||||
|
||||
-- Unique index and unique constraint
|
||||
|
@ -67,17 +67,17 @@ INSERT INTO testschema.test_default_tab VALUES (1);
|
||||
CREATE INDEX test_index1 on testschema.test_default_tab (id);
|
||||
CREATE INDEX test_index2 on testschema.test_default_tab (id) TABLESPACE regress_tblspace;
|
||||
\d testschema.test_index1
|
||||
Index "testschema.test_index1"
|
||||
Column | Type | Definition
|
||||
--------+--------+------------
|
||||
id | bigint | id
|
||||
Index "testschema.test_index1"
|
||||
Column | Type | Key? | Definition
|
||||
--------+--------+------+------------
|
||||
id | bigint | yes | id
|
||||
btree, for table "testschema.test_default_tab"
|
||||
|
||||
\d testschema.test_index2
|
||||
Index "testschema.test_index2"
|
||||
Column | Type | Definition
|
||||
--------+--------+------------
|
||||
id | bigint | id
|
||||
Index "testschema.test_index2"
|
||||
Column | Type | Key? | Definition
|
||||
--------+--------+------+------------
|
||||
id | bigint | yes | id
|
||||
btree, for table "testschema.test_default_tab"
|
||||
Tablespace: "regress_tblspace"
|
||||
|
||||
@ -86,17 +86,17 @@ SET default_tablespace TO regress_tblspace;
|
||||
-- tablespace should not change if no rewrite
|
||||
ALTER TABLE testschema.test_default_tab ALTER id TYPE bigint;
|
||||
\d testschema.test_index1
|
||||
Index "testschema.test_index1"
|
||||
Column | Type | Definition
|
||||
--------+--------+------------
|
||||
id | bigint | id
|
||||
Index "testschema.test_index1"
|
||||
Column | Type | Key? | Definition
|
||||
--------+--------+------+------------
|
||||
id | bigint | yes | id
|
||||
btree, for table "testschema.test_default_tab"
|
||||
|
||||
\d testschema.test_index2
|
||||
Index "testschema.test_index2"
|
||||
Column | Type | Definition
|
||||
--------+--------+------------
|
||||
id | bigint | id
|
||||
Index "testschema.test_index2"
|
||||
Column | Type | Key? | Definition
|
||||
--------+--------+------+------------
|
||||
id | bigint | yes | id
|
||||
btree, for table "testschema.test_default_tab"
|
||||
Tablespace: "regress_tblspace"
|
||||
|
||||
@ -109,17 +109,17 @@ SELECT * FROM testschema.test_default_tab;
|
||||
-- tablespace should not change even if there is an index rewrite
|
||||
ALTER TABLE testschema.test_default_tab ALTER id TYPE int;
|
||||
\d testschema.test_index1
|
||||
Index "testschema.test_index1"
|
||||
Column | Type | Definition
|
||||
--------+---------+------------
|
||||
id | integer | id
|
||||
Index "testschema.test_index1"
|
||||
Column | Type | Key? | Definition
|
||||
--------+---------+------+------------
|
||||
id | integer | yes | id
|
||||
btree, for table "testschema.test_default_tab"
|
||||
|
||||
\d testschema.test_index2
|
||||
Index "testschema.test_index2"
|
||||
Column | Type | Definition
|
||||
--------+---------+------------
|
||||
id | integer | id
|
||||
Index "testschema.test_index2"
|
||||
Column | Type | Key? | Definition
|
||||
--------+---------+------+------------
|
||||
id | integer | yes | id
|
||||
btree, for table "testschema.test_default_tab"
|
||||
Tablespace: "regress_tblspace"
|
||||
|
||||
@ -134,34 +134,34 @@ SET default_tablespace TO '';
|
||||
-- tablespace should not change if no rewrite
|
||||
ALTER TABLE testschema.test_default_tab ALTER id TYPE int;
|
||||
\d testschema.test_index1
|
||||
Index "testschema.test_index1"
|
||||
Column | Type | Definition
|
||||
--------+---------+------------
|
||||
id | integer | id
|
||||
Index "testschema.test_index1"
|
||||
Column | Type | Key? | Definition
|
||||
--------+---------+------+------------
|
||||
id | integer | yes | id
|
||||
btree, for table "testschema.test_default_tab"
|
||||
|
||||
\d testschema.test_index2
|
||||
Index "testschema.test_index2"
|
||||
Column | Type | Definition
|
||||
--------+---------+------------
|
||||
id | integer | id
|
||||
Index "testschema.test_index2"
|
||||
Column | Type | Key? | Definition
|
||||
--------+---------+------+------------
|
||||
id | integer | yes | id
|
||||
btree, for table "testschema.test_default_tab"
|
||||
Tablespace: "regress_tblspace"
|
||||
|
||||
-- tablespace should not change even if there is an index rewrite
|
||||
ALTER TABLE testschema.test_default_tab ALTER id TYPE bigint;
|
||||
\d testschema.test_index1
|
||||
Index "testschema.test_index1"
|
||||
Column | Type | Definition
|
||||
--------+--------+------------
|
||||
id | bigint | id
|
||||
Index "testschema.test_index1"
|
||||
Column | Type | Key? | Definition
|
||||
--------+--------+------+------------
|
||||
id | bigint | yes | id
|
||||
btree, for table "testschema.test_default_tab"
|
||||
|
||||
\d testschema.test_index2
|
||||
Index "testschema.test_index2"
|
||||
Column | Type | Definition
|
||||
--------+--------+------------
|
||||
id | bigint | id
|
||||
Index "testschema.test_index2"
|
||||
Column | Type | Key? | Definition
|
||||
--------+--------+------+------------
|
||||
id | bigint | yes | id
|
||||
btree, for table "testschema.test_default_tab"
|
||||
Tablespace: "regress_tblspace"
|
||||
|
||||
@ -174,18 +174,18 @@ ALTER TABLE testschema.test_tab ADD CONSTRAINT test_tab_unique UNIQUE (id);
|
||||
SET default_tablespace TO '';
|
||||
ALTER TABLE testschema.test_tab ADD CONSTRAINT test_tab_pkey PRIMARY KEY (id);
|
||||
\d testschema.test_tab_unique
|
||||
Index "testschema.test_tab_unique"
|
||||
Column | Type | Definition
|
||||
--------+---------+------------
|
||||
id | integer | id
|
||||
Index "testschema.test_tab_unique"
|
||||
Column | Type | Key? | Definition
|
||||
--------+---------+------+------------
|
||||
id | integer | yes | id
|
||||
unique, btree, for table "testschema.test_tab"
|
||||
Tablespace: "regress_tblspace"
|
||||
|
||||
\d testschema.test_tab_pkey
|
||||
Index "testschema.test_tab_pkey"
|
||||
Column | Type | Definition
|
||||
--------+---------+------------
|
||||
id | integer | id
|
||||
Index "testschema.test_tab_pkey"
|
||||
Column | Type | Key? | Definition
|
||||
--------+---------+------+------------
|
||||
id | integer | yes | id
|
||||
primary key, btree, for table "testschema.test_tab"
|
||||
|
||||
SELECT * FROM testschema.test_tab;
|
||||
|
Reference in New Issue
Block a user