Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fGaWN-00055v-Bn for pgsql-hackers@arkaria.postgresql.org; Thu, 10 May 2018 01:37:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fGaWI-0003KQ-H7 for pgsql-hackers@arkaria.postgresql.org; Thu, 10 May 2018 01:37:22 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fGaWI-0003KH-3k for pgsql-hackers@lists.postgresql.org; Thu, 10 May 2018 01:37:22 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fGaWF-00087l-6D for pgsql-hackers@lists.postgresql.org; Thu, 10 May 2018 01:37:20 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id DB52821D06; Wed, 9 May 2018 21:37:17 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Wed, 09 May 2018 21:37:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:content-type:date:from:in-reply-to:message-id:mime-version :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=G4JQmZ3+0547LcQ+QvHSASrOlJo+NYw35p+9E9HXLxE=; b=hHVe5gLM miVLaqujx2bJDaJ/8MdVo0tEpvvsy3TSMbHam1S91AfII9NqcLIKYrypCX/UFy0r S8t+ZTeWc4+696l/wbx04PZLzLox+bnDOB2AqyRHdxMVLUpIMVnLoDVyRGJW/37c xsS7RuMXO729TfLgF2MaVRIstce1PiG9TRcm+O+9+Yzl1huL86dyHmGlOrBLWjVx dIzGnj7yyGiBUyGt2nmh/x275pFTtMyDMhS5+7QQASX6iDtSe72eWTfyRMUwmWmS qCz80rS2jZS/Mfbv4Cu2FwRTPwJ12dr2Zx0QW0+v6jIE+rDFiykGV/Xp0Z6cpsrw 9XaCR0P0xmgaQg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; bh=G4JQmZ3+0547LcQ+QvHSASrOlJo+N Yw35p+9E9HXLxE=; b=cg2dCyXxde6lXBF50CPuSFhqCSl7MjCXYN/505AO3XhTa OmHAazlinV9GZ7l3MxnBgtcRtB9I5tMx90jbwH5pL03oO5VF4tyyrff57n1fyA64 fB1ADUibHJFKc7tm4ijKknPXCjbEegMc+qp/UnacRuwTepVhXn+n0r71EWTFj2rO F+nt7FsQE7MYaG0pKZJsfSO8F67NCmG20SxHMsdfMt0XUc4PJzWu5T4dR8govtdl FOGLn2VnNV0cwHFRl/G/YoqVBFmPjdCElFgepp4qO3DZSiiSlcVAgI/ELEw4L/A7 Uc9WFrE2H898JhK48/UdNCVTXrfladDHghSjgqIOw== X-ME-Sender: Received: from paquier.xyz (c137162.net61215.cablenet.ne.jp [61.215.137.162]) by mail.messagingengine.com (Postfix) with ESMTPA id 7595B1025D; Wed, 9 May 2018 21:37:15 -0400 (EDT) Date: Thu, 10 May 2018 10:37:11 +0900 From: Michael Paquier To: Amit Langote Cc: Robert Haas , Simon Riggs , Arseny Sher , "pgsql-hackers@lists.postgresql.org" Subject: Re: Indexes on partitioned tables and foreign partitions Message-ID: <20180510013711.GD26879@paquier.xyz> References: <87sh71cakz.fsf@ars-thinkpad> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="/unnNtmY43mpUSKx" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --/unnNtmY43mpUSKx Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, May 10, 2018 at 10:15:05AM +0900, Amit Langote wrote: > While I agree with this, let me point out that we do allow inherited check > constraints on foreign tables that are not actually enforced locally. >=20 > create table p (a int) partition by range (a); > create table p1 partition of p for values from (minvalue) to (1); > create table p2base (a int); > create foreign table p2 partition of p for values from (1) to (maxvalue) > server loopback options (table_name 'p2base'); >=20 > alter table p add check (a between -1000 and 1000); >=20 > -- routed to foreign partition, which doesn't enforce check constraints > insert into p values (1001); > INSERT 0 1 That's not actually a surprise, right? Since foreign tables can be part of inheritance trees in 9.5, CHECK constraints on foreign tables are not enforced locally, but used as planner hints to guess how a query would work remotely. So getting partition children to work the same way is consistent. > We have to do the following to prevent that. >=20 > alter table p2base add check (a between -1000 and 1000); > insert into p values (1001); > ERROR: new row for relation "p2base" violates check constraint > "p2base_a_check" > DETAIL: Failing row contains (1001). > CONTEXT: remote SQL command: INSERT INTO public.p2base(a) VALUES ($1) This bit looks natural to me as well. -- Michael --/unnNtmY43mpUSKx Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAlrzokcACgkQnvQgOdby QH3AhxAAjx+8sQWiELhCJ+wNuJTZQhNMsY+TBTzlFg5Bvf5fpKTuqbabqZUfeYHx P/fZWT3OWlal1Hrkz+usPEa4/zDayoJPGXkvOK3C2hD5HvLzfMOWr5wIB6QUj8yd ys6bbCAnyVmVMhDiXJeBpczNPOy6rakiJCmwZR7GoKSwZyuwzD65Bgu8mJ5kIAjl AG5/sQyxPk2sYLsRGN98XYz7RV4zCxN2u/Eed6bjnIDU5BvbJvErbhKQwQFRclte sxAZw90x95c6uMlp794V36Nt+Vr3CZKmQkux+rsorMd228ElOlxcKfpba5w+Coo5 hfZyt9yUXkm6Be4+nC+Hz5dJvTjARao6BYVGe8Hnseo2ngiEeJXXgWQWuTN3kqR7 wxZtzIJlJlgj/PUnUYL3rEQFlV46LHbXRJ68PTspEvA0zA/lvhcrndjtFbotLm4m wvoaoLosw+OUlpPGkc4eHoCtS0139jwvZXUkrYzJtQYZugq5sOUy9PR+sCME1FL1 rSUsIj3ifblxAtIr4yPVxwtIe3gXTlG3Bk7umnlVAE+5AGNWbVyqhqg8mGETaLNK kPgkwSay2ox0t3QDsLh7EPhbjgcuVJ+Mr+RPN2K423H02j4N2QFSYSMbR6c+jYFC XJQ8tn7XJlGhD1A/k/bFFCtAR2MLs2GjoDSOBukP8w4YflAZUVY= =yPBT -----END PGP SIGNATURE----- --/unnNtmY43mpUSKx--