Re: BUG #15724: Can't create foreign table as partition

From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Amit Langote <amitlangote09(at)gmail(dot)com>
Cc: Pavan Deolasee <pavan(dot)deolasee(at)gmail(dot)com>, stepya(at)ukr(dot)net, PostgreSQL mailing lists <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #15724: Can't create foreign table as partition
Date: 2019-06-25 12:56:57
Message-ID: 20190625125657.GA27674@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hi Amit, thanks for reviewing.

On 2019-Jun-25, Amit Langote wrote:

> @@ -15705,6 +15721,32 @@ AttachPartitionEnsureIndexes(Relation rel,
> Relation attachrel)
> i++;
> }
>
> + /*
> + * If we're attaching a foreign table, we must fail if any of the indexes
> + * is a constraint index; otherwise, there's nothing to do here.
> + */
> + if (attachrel->rd_rel->relkind == RELKIND_FOREIGN_TABLE)
> + {
> + foreach(cell, idxes)
> + {
> + Oid idx = lfirst_oid(cell);
>
> Why not add the is-foreign-table check in the loop that already exists
> just below the above added code? That's what the patch does for
> DefineRelation() and if you do so, there's no need for the goto label
> that's also added by the patch.

Because if you do that, you might build a few indexes on regular
partitions before coming across a foreign one, which is very unfriendly.
I'll add a comment to this effect.

> (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
> errmsg("cannot create index
> on partitioned table \"%s\"",
> stmt->relation->relname),
> + errdetail("Table \"%s\"
> contains weird partitions or something.",
> + stmt->relation->relname)));

> The "...weird partitions or something" message wouldn't be very
> useful, but maybe you intended to rewrite it before committing?

Hah, yeah, I did :-)

> I suppose we could turn that particular ereport into elog(ERROR, ...),
> because finding children of a partitioned that are neither of
> RELATION, PARTITIONED_TABLE, FOREIGN_TABLE should be an internal
> error.

Yeah, an elog() sounds a good idea. I suppose "unexpected relkind
\"%c\" on partition \"%s\"" should be good.

BTW I'm now thinking that those ERRCODE_INVALID_OBJECT_DEFINITION codes
are not really the correct ones; I mean, it would be the right one to
use for the unexpected relkind condition, but for the other cases I
think we should use ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE instead.

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

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Alvaro Herrera 2019-06-25 13:52:43 Re: BUG #15789: libpq compilation with OpenSSL 1.1.1b fails on Windows with Visual Studio 2017
Previous Message PG Bug reporting form 2019-06-25 11:09:47 BUG #15872: copy command does not skip special character