Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YM4PH-0001Jx-BY for pgsql-bugs@arkaria.postgresql.org; Fri, 13 Feb 2015 00:46:55 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YM4PG-0003o5-NE for pgsql-bugs@arkaria.postgresql.org; Fri, 13 Feb 2015 00:46:54 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YM4PF-0003mK-Iw for pgsql-bugs@postgresql.org; Fri, 13 Feb 2015 00:46:53 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YM4PB-0006Gz-Ti for pgsql-bugs@postgresql.org; Fri, 13 Feb 2015 00:46:52 +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 t1D0kkkq017890; Thu, 12 Feb 2015 19:46:46 -0500 From: Tom Lane To: felix.buenemann@gmail.com cc: pgsql-bugs@postgresql.org, Kevin Grittner Subject: Re: BUG #12766: Dump/Load of Materialized View with inlined SQL function fails In-reply-to: <20150213000055.2584.16773@wrigleys.postgresql.org> References: <20150213000055.2584.16773@wrigleys.postgresql.org> Comments: In-reply-to felix.buenemann@gmail.com message dated "Fri, 13 Feb 2015 00:00:55 +0000" Date: Thu, 12 Feb 2015 19:46:46 -0500 Message-ID: <17889.1423788406@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org felix.buenemann@gmail.com writes: > pg_dump dumps materialized views in the wrong order, if the view is > alphabetically sorted before a table that it references indirectly through a > stored procedure in sql language. > The reason seems to be that pg_dump does not know about the indirect > dependency of the matview, so it doesn't reorder the tables/matviews > properly. It's mathematically impossible to guarantee that pg_dump could handle such things --- maybe it could do simple cases, given enormously more knowledge about PL functions than it actually possesses, but a full solution would be equivalent to solving the halting problem. So we're not going to try to fix this in pg_dump. Having said that, I wonder why CREATE MATERIALIZED VIEW seems to insist on running the planner and even executing the query when told WITH NO DATA. If it were satisfied to store the view definition and quit, we'd not be seeing a failure here. > Problematic dump from error above: > https://gist.github.com/056f157a200e334dc5b0 > Minimal testcase (thanks to RhodiumToad on IRC): > http://pgsql.privatepaste.com/cc80393e25 BTW, links to pages that will probably not be there next month are entirely inadequate documentation for bug reports. For the sake of the archives, here's the test case: create table t1 (a integer); create function f1() returns integer language sql stable as $f$ select a from t1 limit 1; $f$; create table t2 (b integer); create materialized view m1 as select f1(), b from t2; Dumping and restoring this causes the reported failure, since m1 is restored before t1. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs