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 1hsr8K-0004n5-JB for pgsql-bugs@arkaria.postgresql.org; Wed, 31 Jul 2019 16:07:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hsr8I-0000IN-3Y for pgsql-bugs@arkaria.postgresql.org; Wed, 31 Jul 2019 16:07:18 +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 1hsr8H-00008L-NK for pgsql-bugs@lists.postgresql.org; Wed, 31 Jul 2019 16:07:17 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1hsr8F-0003Jh-Bf for pgsql-bugs@lists.postgresql.org; Wed, 31 Jul 2019 16:07:16 +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 x6VG7B70005346; Wed, 31 Jul 2019 12:07:11 -0400 From: Tom Lane To: tom@intevation.de cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15934: pg_dump output in wrong order if custom operator class is used as subtype_opclass in a range type In-reply-to: <15934-58b8c8ab7a09ea15@postgresql.org> References: <15934-58b8c8ab7a09ea15@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Wed, 31 Jul 2019 10:12:25 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <5344.1564589231.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 31 Jul 2019 12:07:11 -0400 Message-ID: <5345.1564589231@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk PG Bug reporting form writes: > consider the following to reproduce (to keep the example short, the oper= ator > class is reduced to the minimum needed to reproduce the problem): > ... > Dropping and recreating the database as above and looking at the output = of > `pg_dump -OcC test' shows that the DDL for creating the operator used = in > the operator class comes at the end (after the DDL for the operator > class): Huh. I'm surprised nobody has tripped over this before, because it's been broken since range types were introduced. The core of the problem is that pg_dump doesn't treat opclass members (pg_amop rows) as independent objects, which is problematic because pg_depend does think they're independent objects. So the dependency entries involving this opclass are operator 3 (integer, integer) of operator family testclass for access met= hod btree: ~~(integer,integer) | operator ~~(integer,integer) = | n operator 3 (integer, integer) of operator family testclass for access met= hod btree: ~~(integer,integer) | operator class testclass for access metho= d btree | i operator class testclass for access method btree = | operator family testclass for access meth= od btree | a type testrange = | operator class testclass for access metho= d btree | n pg_dump ignores the first two of these, meaning it has no knowledge that operator ~~ needs to be dumped before opclass testclass. Now it does have a general rule that all else being equal, operators should be dumped before opclasses, and that saves it most of the time. But in this example, all else is not equal, because the last-mentioned dependency forces the opclass to be moved up, to before type testrange. And the same general sort rules say that types come before operators, so without a dependency to force the operator to be moved up too, we get the wrong result. Clearly, we gotta upgrade pg_dump's intelligence about handling this dependency structure. The most straightforward fix would involve promoting pg_amop (and pg_amproc) entries to be full DumpableObjects, but I'm apprehensive about the overhead that would add ... I'll try to work on a fix later this week, with hopes of getting it into next month's releases. Thanks for the report! regards, tom lane