Re: Indexes on partitioned tables and foreign partitions

From: Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>
To: Michael Paquier <michael(at)paquier(dot)xyz>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Simon Riggs <simon(at)2ndquadrant(dot)com>, Arseny Sher <a(dot)sher(at)postgrespro(dot)ru>, "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Indexes on partitioned tables and foreign partitions
Date: 2018-05-10 03:00:13
Message-ID: 211ee61d-f91a-9cbd-7b9b-6cd81cb8d08d@lab.ntt.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2018/05/10 10:02, Michael Paquier wrote:
> Something
> that I find confusing on HEAD though is that DefineIndex calls itself
> around line 1006 and cascades through each children but there is no
> context about the error.
>
> For example if I have this partition layer:
> CREATE TABLE measurement (
> logdate date not null,
> peaktemp int,
> unitsales int
> ) PARTITION BY RANGE (logdate);
> CREATE FOREIGN TABLE measurement_y2016m07
> PARTITION OF measurement FOR VALUES FROM ('2016-07-01') TO
> ('2016-08-01')
> SERVER postgres_server;
>
> Then by creating an index on the parent I get that:
> =# create index measurement_idx on measurement (peaktemp);
> ERROR: 42809: cannot create index on foreign table "measurement_y2016m07"
> LOCATION: DefineIndex, indexcmds.c:442
>
> This may be confusing for the user as the DDL does not complain directly
> about the relation worked on. Perhaps we could add an error context?
> We surely don't want multiple contexts either when working on long
> chains, but we could build a chained list of relation names in the error
> message.

How about we error out even *before* calling DefineIndex for the 1st time?
I see that ProcessUtilitySlow() gets a list of all partitions when
locking them for index creation before calling DefineIndex. Maybe, just
go through the list and error out if one of them is a partition that we
don't support creating an index on?

For example, with the attached patch doing the above, I get:

create table p (a int) partition by range (a);
create table p1 partition of p for values from (minvalue) to (1);
create foreign table p2 partition of p for values from (1) to (maxvalue)
server loopback options (table_name 'p2base');
create index on p (a);
ERROR: cannot create index on partitioned table containing foreign partitions

Thanks,
Amit

Attachment Content-Type Size
partitioned-table-index-prevent-1.patch text/plain 1.4 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message David Rowley 2018-05-10 03:55:02 Needless additional partition check in INSERT?
Previous Message Amit Langote 2018-05-10 02:20:56 Re: Indexes on partitioned tables and foreign partitions