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 1hdl4W-0007Vf-KE for pgsql-bugs@arkaria.postgresql.org; Thu, 20 Jun 2019 00:37:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hdl4U-0007wX-Ls for pgsql-bugs@arkaria.postgresql.org; Thu, 20 Jun 2019 00:36:58 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hdl4U-0007mv-31 for pgsql-bugs@lists.postgresql.org; Thu, 20 Jun 2019 00:36:58 +0000 Received: from mail-qk1-x742.google.com ([2607:f8b0:4864:20::742]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hdl4M-0002Zb-8s for pgsql-bugs@lists.postgresql.org; Thu, 20 Jun 2019 00:36:57 +0000 Received: by mail-qk1-x742.google.com with SMTP id x18so756878qkn.13 for ; Wed, 19 Jun 2019 17:36:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=2bFmXR4WROeXDuoDvKcvrycHGOGryRK30zKU3JdMx8w=; b=cg/43ydxouwcsPWnAL73av2d+BMacvNiLS+iGzoHND3L+eTmrvX6bjEXQn5nsGyLIX i15x7CMo17atf0FdbVY0xUVCrXKfW//h+gdSg6cMVmwKS9A+A5/aWJjiVpAqEDQ1leua rP8+xv8uV7GmPIomxKlUDKz0io4ScqZEd9udJmn/VjLF16uXiwgBoHxPh3c1F42q5OGy Mnztylw+KUGKlzt8a7AEWNBvAf6YBaONwyXqOto2PCfqroEZCCP027V6k4ugRagi5boZ PGcvSIq5+lM7LxSbD/aNIQ1oLwW7DbNErYfYLtOYhl5EiKnufbFFuChM33qIQUB8cIL/ 3vJA== 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:subject:message-id:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=2bFmXR4WROeXDuoDvKcvrycHGOGryRK30zKU3JdMx8w=; b=NsmTNXY2qcjOryAgBtcDAwCbTsp0Hq2UH62nxKuOMjbwvu4z70q219gTOW4vxDelOF OFR8aSL6xNrAt4IEXgUCU6z4z7RdBjM6YvszCKumZjbdHGToEJrmIicL4Hhi06uzmu+Y DKfJIw534Nc5Xr38nCq4NxeCOwNjv/tShfESNYGELu5mMcQxdurxsHaxAxs2Mw8vneEv i5wb6IVdMN6GxeHXkbO2Bvri1LNNalzQaHFOUNFaB4QSaEEO+n4yOU0+LTSkKV4MMbt7 qt2t0q8B6F/BmQuLOyFsHV6QTK2viQ3Bfy6Ts3MiYbzkWoqqRn2DlxRs280ja0/Lhj7v BguA== X-Gm-Message-State: APjAAAW3f+0q46LCT8689dN3RUVtqbBisNOVu9BKzEK1MR8NJGtsNdCP vlHQB+F1Rl6iSH9BLHX9vHrcrsjvnigTk2zXS3Dm2MIrbc6ohsBLvwhCtKGHW9xIYY4Xi72RPOw f5s0ty7zQMFsn8oe6R/ajDqZopo3UOWZL4/jjh/WF2eGEu5xfXi6sZcpoDl8IcIknGYkaYnFabR TnfWxFuiliikCR X-Google-Smtp-Source: APXvYqxeGDhIqz38mQNWEDiJnGPMCsxAcFn+pVZvMHfgt3rGZDjfqOUKIz8+84PIjEZIDAZXHuYcGg== X-Received: by 2002:a37:6652:: with SMTP id a79mr14829597qkc.60.1560991007896; Wed, 19 Jun 2019 17:36:47 -0700 (PDT) Received: from nimloth.alvh.no-ip.org ([190.121.34.37]) by smtp.gmail.com with ESMTPSA id o66sm11470267qkb.90.2019.06.19.17.36.46 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 19 Jun 2019 17:36:46 -0700 (PDT) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id 8F7CB120C21; Wed, 19 Jun 2019 20:36:44 -0400 (-04) Date: Wed, 19 Jun 2019 20:36:44 -0400 From: Alvaro Herrera To: stepya@ukr.net, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15724: Can't create foreign table as partition Message-ID: <20190620003644.GA24765@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="y0ulUmNC+osPPQO6" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20190329135519.GA21373@alvherre.pgsql> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --y0ulUmNC+osPPQO6 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit On 2019-Mar-29, Alvaro Herrera wrote: > On 2019-Mar-29, PG Bug reporting form wrote: > > > CREATE FOREIGN TABLE staging.msg_json PARTITION of msg_json > > FOR VALUES FROM (20170101) TO (20180101) > > SERVER postgres_big_data_arch > > OPTIONS (schema_name 'fix_capture', table_name 'msg_json'); > > > > I got error !!!! > > > > SQL Error [42809]: ERROR: cannot create index on foreign table "msg_json" > > ERROR: cannot create index on foreign table "msg_json" > > ERROR: cannot create index on foreign table "msg_json" > > Ah, this is because we try to propagate the index to the partition, > which appears to be less than desirable. Maybe this patch fixes it? I > have not tested it, only verified that it compiles. The previously proposed patch doesn't work; there are a few other places that needed patching. Here's a proposed patch. I'm not sure whether this is a bug fix or a new feature. With this patch, an index creation will no longer fail in the presence of a partition that is a foreign table, as long as the index is not a constraint index (not unique, not primary key). Conversely, creating/attaching a partition that is a foreign table does not fail if the partitioned table only has non-constraint indexes. With the current code, these commands would all fail, and the resulting behavior is pretty unhelpful, as reported in this thread and elsewhere. Any opinions on backpatching this? I'm considering pg11, but also considering not to backpatch at all. (There *is* a much smaller bugfix here, which is that we don't raise an error when unique/pk indexes exist and a foreign table is attached as partition.) -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services --y0ulUmNC+osPPQO6 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-Fix-index-creation-with-foreign-partitions.patch"