pgpartman / pg_partman

Partition management extension for PostgreSQL
Other
2.05k stars 279 forks source link

Non-key index columns are not properlly inherited from template table #674

Open C0mbatwombat opened 2 months ago

C0mbatwombat commented 2 months ago

Hi team,

First of all, thank you for this great extension! I noticed that non-key index columns (using the INCLUDE keyword) are inherited as normal index columns.

A minimal example:

create table example_table (
    id        BIGINT not null,
    some_other_column BIGINT not null,

    insertTime              TIMESTAMPTZ NOT NULL DEFAULT now()

) PARTITION BY RANGE (insertTime);

CREATE TABLE example_table_template (LIKE example_table);
ALTER TABLE public.example_table_template ADD PRIMARY KEY (id) INCLUDE (some_other_column);

SELECT partman.create_parent('public.example_table', 'inserttime', '1 month', p_template_table := 'public.example_table_template', p_premake := 2);

postgres=# \d example_table_template
                     Table "public.example_table_template"
      Column       |           Type           | Collation | Nullable | Default 
-------------------+--------------------------+-----------+----------+---------
 id                | bigint                   |           | not null | 
 some_other_column | bigint                   |           | not null | 
 inserttime        | timestamp with time zone |           | not null | 
Indexes:
    "example_table_template_pkey" PRIMARY KEY, btree (id) INCLUDE (some_other_column)  <-------

postgres=# \d example_table_p20240501
                    Table "public.example_table_p20240501"
      Column       |           Type           | Collation | Nullable | Default 
-------------------+--------------------------+-----------+----------+---------
 id                | bigint                   |           | not null | 
 some_other_column | bigint                   |           | not null | 
 inserttime        | timestamp with time zone |           | not null | now()
Partition of: example_table FOR VALUES FROM ('2024-05-01 00:00:00+00') TO ('2024-06-01 00:00:00+00')
Indexes:
    *example_table_p20240501_pkey" PRIMARY KEY, btree (id, some_other_column) <-------

I would have expected the index of example_table_p20240501 to be the same as the index on the example_table_template table. Not a huge issue but I thought you might want to know about it.

Thanks!

keithf4 commented 2 months ago

Thanks for the report. Looks like a valid issue but I'll need to investigate more when I get back to working on the next version of partman.