pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pg_indexes doesn't show indexes for partitioned tables - bug or intended?
5+ messages / 4 participants
[nested] [flat]

* pg_indexes doesn't show indexes for partitioned tables - bug or intended?
@ 2019-04-10 12:39  Thomas Kellerer <spam_eater@gmx.net>
  0 siblings, 1 reply; 5+ messages in thread

From: Thomas Kellerer @ 2019-04-10 12:39 UTC (permalink / raw)
  To: 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






^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: pg_indexes doesn't show indexes for partitioned tables - bug or intended?
@ 2019-04-10 15:57  David Rowley <david.rowley@2ndquadrant.com>
  parent: Thomas Kellerer <spam_eater@gmx.net>
  0 siblings, 2 replies; 5+ messages in thread

From: David Rowley @ 2019-04-10 15:57 UTC (permalink / raw)
  To: Thomas Kellerer <spam_eater@gmx.net>; +Cc: pgsql-general

On Thu, 11 Apr 2019 at 00:39, Thomas Kellerer <spam_eater@gmx.net> wrote:
>
> 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).

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

Overlooked for PG11. You'll see them in PG12 per [1]. It's not really
possible to backpatch a fix for that since these views are created
during initdb.

[1] https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=f94cec64476f2752e91b10d7928a2fcd105e9...

-- 
 David Rowley                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services





^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: pg_indexes doesn't show indexes for partitioned tables - bug or intended?
@ 2019-04-10 16:04  Alvaro Herrera <alvherre@2ndquadrant.com>
  parent: David Rowley <david.rowley@2ndquadrant.com>
  1 sibling, 0 replies; 5+ messages in thread

From: Alvaro Herrera @ 2019-04-10 16:04 UTC (permalink / raw)
  To: David Rowley <david.rowley@2ndquadrant.com>; +Cc: Thomas Kellerer <spam_eater@gmx.net>; pgsql-general

On 2019-Apr-11, David Rowley wrote:

> On Thu, 11 Apr 2019 at 00:39, Thomas Kellerer <spam_eater@gmx.net> wrote:
> >
> > 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).
> 
> > Is leaving out the indexes defined on the partitioned table intended or a bug?
> 
> Overlooked for PG11. You'll see them in PG12 per [1]. It's not really
> possible to backpatch a fix for that since these views are created
> during initdb.

(You can, of course, adjust the view definition yourself.)

-- 
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services





^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: pg_indexes doesn't show indexes for partitioned tables - bug or intended?
@ 2019-04-10 16:20  Thomas Kellerer <spam_eater@gmx.net>
  parent: David Rowley <david.rowley@2ndquadrant.com>
  1 sibling, 1 reply; 5+ messages in thread

From: Thomas Kellerer @ 2019-04-10 16:20 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

David Rowley schrieb am 10.04.2019 um 17:57:
>> 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).
>
>> Is leaving out the indexes defined on the partitioned table intended or a bug?
>
> Overlooked for PG11. You'll see them in PG12 per [1]. It's not really
> possible to backpatch a fix for that since these views are created
> during initdb.

Thanks.

I don't undertand though why it's not back patched - at least that would fix the bug for new installations

Thomas





^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: pg_indexes doesn't show indexes for partitioned tables - bug or intended?
@ 2019-04-10 20:04  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Thomas Kellerer <spam_eater@gmx.net>
  0 siblings, 0 replies; 5+ messages in thread

From: Tom Lane @ 2019-04-10 20:04 UTC (permalink / raw)
  To: Thomas Kellerer <spam_eater@gmx.net>; +Cc: pgsql-general@lists.postgresql.org

Thomas Kellerer <spam_eater@gmx.net> writes:
> David Rowley schrieb am 10.04.2019 um 17:57:
>> Overlooked for PG11. You'll see them in PG12 per [1]. It's not really
>> possible to backpatch a fix for that since these views are created
>> during initdb.

> I don't undertand though why it's not back patched - at least that would fix the bug for new installations

David overstated the situation --- it'd be *possible* to back-patch a
fix for that, if we thought that the bug was of sufficient importance.
But the costs of such changes are way way higher than "change a couple
of lines in system_views.sql".  We would also have to write documentation
about how to fix it manually, along the lines of the first bullet point in
[1], and then users would either have to jump through that hoop or decide
that it wasn't worth it to them (which it wouldn't be, for most).  And,
having different behaviors in different "v11" installations is not really
all that nice, especially for something that's only debatably a bug.
So I concur with the decision not to back-patch.

			regards, tom lane

[1] https://www.postgresql.org/docs/9.6/release-9-6-5.html





^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2019-04-10 20:04 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-04-10 12:39 pg_indexes doesn't show indexes for partitioned tables - bug or intended? Thomas Kellerer <spam_eater@gmx.net>
2019-04-10 15:57 ` David Rowley <david.rowley@2ndquadrant.com>
2019-04-10 16:04   ` Alvaro Herrera <alvherre@2ndquadrant.com>
2019-04-10 16:20   ` Thomas Kellerer <spam_eater@gmx.net>
2019-04-10 20:04     ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox