pg_indexes doesn't show indexes for partitioned tables - bug or intended?

From: Thomas Kellerer <spam_eater(at)gmx(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: pg_indexes doesn't show indexes for partitioned tables - bug or intended?
Date: 2019-04-10 12:39:22
Message-ID: q8ko5q$3t72$1@blaine.gmane.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

In Postgres 11.2, indexes defined on partitioned tables do not show up in pg_indexes (the actual indexes for the partitions however do show up).

E.g.:

CREATE TABLE base_table
(
column1 varchar(50) NOT NULL,
column2 integer NOT NULL,
column3 integer not null,
part_key bigint NOT NULL
)
PARTITION BY HASH (part_key);

CREATE UNIQUE INDEX idx_one ON base_table (column1, column2, part_key);

The following select returns nothing:

select *
from pg_indexes
where tablename = 'base_table';

This is caused by the fact that pg_indexes only returns information for regular tables and materialized views ("relkind in ('r','m')") and regular indexes (relkind = 'i')

If the conditions on the relkind for the "table class" to include 'p' as well, and the relkind for the "index class" is changed to return 'i' and 'I', then those indexes are listed in pg_indexes as well:

SELECT n.nspname AS schemaname,
c.relname AS tablename,
i.relname AS indexname,
t.spcname AS tablespace,
pg_get_indexdef(i.oid) AS indexdef
FROM pg_index x
JOIN pg_class c ON c.oid = x.indrelid
JOIN pg_class i ON i.oid = x.indexrelid
LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
LEFT JOIN pg_tablespace t ON t.oid = i.reltablespace
WHERE (c.relkind in ('r','m','p')) --<< add 'p' to the list
AND i.relkind in ('i', 'I') --<< add 'I' to the list

Is leaving out the indexes defined on the partitioned table intended or a bug?

Regards
Thomas

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Олег Самойлов 2019-04-10 14:08:46 Re: PK and FK using Hash index
Previous Message Jess Wren 2019-04-10 08:57:22 Re: How to use full-text search URL parser to filter query results by domain name?