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 1icBV6-0005Gg-BA for pgsql-bugs@arkaria.postgresql.org; Tue, 03 Dec 2019 16:58:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1icBV3-0002up-SU for pgsql-bugs@arkaria.postgresql.org; Tue, 03 Dec 2019 16:58:09 +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 1icBV3-0002ui-GK for pgsql-bugs@lists.postgresql.org; Tue, 03 Dec 2019 16:58:09 +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 1icBUw-0007M3-VL for pgsql-bugs@postgresql.org; Tue, 03 Dec 2019 16:58:08 +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 xB3Gvwsp013714; Tue, 3 Dec 2019 11:57:58 -0500 From: Tom Lane To: Alexey Bashtanov cc: pgsql-bugs@postgresql.org Subject: Re: pg_dump losing index column collations for unique and primary keys In-reply-to: References: Comments: In-reply-to Alexey Bashtanov message dated "Tue, 03 Dec 2019 16:35:20 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <13712.1575392277.1@sss.pgh.pa.us> Date: Tue, 03 Dec 2019 11:57:57 -0500 Message-ID: <13713.1575392277@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Alexey Bashtanov writes: > I found that pg_dump fails to note down the collations used primary and > unique keys supporting indexes. > To reproduce: > create table f(a text); > create unique index f_pkey on f(a collate "C.UTF-8"); > alter table f add primary key using index f_pkey; Hm. I kinda think that we should reject the above. The point of ADD PRIMARY KEY USING INDEX ought to be to allow you to build the index concurrently; it should not be something you can use to create a DDL state that is impossible to arrive at with plain ADD PRIMARY KEY. As an example of the sort of problem that I'm worried about, consider a situation where the index's collation has a different notion of equality than the column's default collation has. (Which is entirely possible now that we have nondeterministic collations.) That's going to lead to weird restrictions on whether the index really satisfies query WHERE conditions, and I'd bet considerable money that we'd have bugs due to failing to account for that. In short, I'd say the bug here is not pg_dump's fault at all, but failure to insist on collation match in ADD PRIMARY KEY USING INDEX. regards, tom lane