Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hfl0X-0006Aa-9q for pgsql-bugs@arkaria.postgresql.org; Tue, 25 Jun 2019 12:57:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hfl0V-0007oM-Ml for pgsql-bugs@arkaria.postgresql.org; Tue, 25 Jun 2019 12:57:07 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hfl0V-0007fJ-5u for pgsql-bugs@lists.postgresql.org; Tue, 25 Jun 2019 12:57:07 +0000 Received: from mail-qt1-x844.google.com ([2607:f8b0:4864:20::844]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hfl0S-0005eI-0D for pgsql-bugs@lists.postgresql.org; Tue, 25 Jun 2019 12:57:05 +0000 Received: by mail-qt1-x844.google.com with SMTP id p15so18232096qtl.3 for ; Tue, 25 Jun 2019 05:57:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=UKaxdKP/+FnSDmvjJ5l3d3NL98XhRHTGBmMx5GuPr9Y=; b=OUecvFCyUF4Y1Q0TgzTl3yaTw++rpipZPrLGySLJbmg+Bs+uDpMpSxKMnj2qfRl1O2 FhIFRWqGjuBWSIno+nQ2s1T1PjDBTHveuWppR8ZD1GgoYtretcS98v6zs77SZjH8msy5 n6mZe95b2/AQzh3b5aPwx7QeqzmPfddELKnEQOaGXTzcRXDkR3NH6EVP1AbwlxRpudkH GhpzjvWjw24EQlsM7/a/K7NIxucthr3oq1BClAwMkqwcF8XsV45Qh1ew5aQjipyNIxl/ TRDcIGENbJKE8JAq9VcwPxio41TQbTQN3WfDuQja/5U8QZCk7hgAzYt1Kk3RZEfV4VYZ VMng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=UKaxdKP/+FnSDmvjJ5l3d3NL98XhRHTGBmMx5GuPr9Y=; b=aucQBiQNFoOSyenwPtSRZu1mIBfW8FKB0o8DgqEkQiK+o7NjU9TDkFhal+Ddtprav1 i3A4xDHGHE1d7Uhq2hyyfusapoGZupLWDPtWnmXfKD+aXBcDI/8d0bv0goFUgRoI6w7Q FKkbIfmFX4nSP/P3R7StxYnO4/r2UW+Mgu9TUzWd1dZLSbd9vrDwSINXG1wm+PjAiIfJ 4k4Iqiojkq2Wx+RDHpWjMXn7SL2TkHH3wG2h9rBj+689PpRvDqY9hV+mgEJU3sQ6RoqI bdnTkjt1oReE7uZ9zd80QznQRD1tI8LfHApRARIPNB/p8SsNCsBcPjH7GGnoPCLgOxAB cwPA== X-Gm-Message-State: APjAAAUypqUctyxgoSpZEoffN0xwmh14lbkUCXYZFkDcr1pKNCqgNITz XxlBa+lfIZPFImR1K7PZI97HIA== X-Google-Smtp-Source: APXvYqyvate59S7XfetqJx6IUO/rtiYpjARssS2mOdqM252U4fxm3yIsSQgJxftKCmTTrLw3s257VA== X-Received: by 2002:a0c:984a:: with SMTP id e10mr62801652qvd.57.1561467422342; Tue, 25 Jun 2019 05:57:02 -0700 (PDT) Received: from nimloth.alvh.no-ip.org ([177.154.145.99]) by smtp.gmail.com with ESMTPSA id j6sm6988219qkf.119.2019.06.25.05.57.01 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 25 Jun 2019 05:57:01 -0700 (PDT) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id E7D8C1207D8; Tue, 25 Jun 2019 08:56:57 -0400 (-04) Date: Tue, 25 Jun 2019 08:56:57 -0400 From: Alvaro Herrera To: Amit Langote Cc: Pavan Deolasee , stepya@ukr.net, PostgreSQL mailing lists Subject: Re: BUG #15724: Can't create foreign table as partition Message-ID: <20190625125657.GA27674@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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