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.92) (envelope-from ) id 1jH9OT-0002P9-Ks for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Mar 2020 17:00:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jH9OS-0000be-Dk for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Mar 2020 17:00:40 +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 1jH9OS-0000bW-1O for pgsql-hackers@lists.postgresql.org; Wed, 25 Mar 2020 17:00:40 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jH9OP-0000tF-KF for pgsql-hackers@lists.postgresql.org; Wed, 25 Mar 2020 17:00:38 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id 02PH0aGX004732; Wed, 25 Mar 2020 13:00:36 -0400 From: Tom Lane To: Guancheng Luo cc: pgsql-hackers@lists.postgresql.org Subject: Re: [PATCH] Check operator when creating unique index on partition table In-reply-to: References: Comments: In-reply-to Guancheng Luo message dated "Wed, 25 Mar 2020 18:43:43 +0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <4730.1585155636.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 25 Mar 2020 13:00:36 -0400 Message-ID: <4731.1585155636@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Guancheng Luo writes: > I found that things could go wrong in some cases, when the unique index = and the partition key use different opclass. I agree that this is an oversight, but it seems like your solution is overcomplicated and probably still too forgiving. Should we not just insist that the index opfamily match the partition key opfamily? It looks to me like that would reduce the code change to about like this: - if (key->partattrs[i] =3D=3D indexInfo->ii_IndexAttrNumber= s[j]) + if (key->partattrs[i] =3D=3D indexInfo->ii_IndexAttrNumber= s[j] && + key->partopfamily[i] =3D=3D get_opclass_family(classOb= jectId[j])) which is a lot more straightforward and provides a lot more certainty that the index will act as the partition constraint demands. This would reject, for example, a hash index associated with a btree-based partition constraint, but I'm not sure we're losing anything much thereby. (I do not think your patch is correct for the case where the opfamilies belong to different AMs, anyway.) I'm not really on board with adding a whole new test script for this, either. regards, tom lane