Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 481A4B5E105 for ; Tue, 7 Jun 2011 17:01:56 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 11686-07 for ; Tue, 7 Jun 2011 20:01:48 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-bw0-f46.google.com (mail-bw0-f46.google.com [209.85.214.46]) by mail.postgresql.org (Postfix) with ESMTP id 9A4E0B5E0AD for ; Tue, 7 Jun 2011 17:01:48 -0300 (ADT) Received: by bwz15 with SMTP id 15so64669bwz.19 for ; Tue, 07 Jun 2011 13:01:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type:content-transfer-encoding; bh=ifG63Qh0B/JvRwGmTUy8xcqYpBlUrKS2dGzstsMj78g=; b=p6wqjzBfBQkA4jFK2zHg3WMxlHniP8z0m7MdMkJh8f75Uuyn/MVrXfMJE83Rm5powm BG14W1RwPGTKSIkfvvT/ul2JAtev6O9KbMbCA+IwEylBH04K8Uv5M8OGekvffoRE/xX8 usJAPZBHaZzPf9LK4rsDG6tMbZirvd0Gzive4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; b=FORwcJ4MKYpdhn94lk3JkLuhMavh3mOozVQ4fG6kKEjuwAwYQu9KG+yndUCUIyBLRK We0RbskptmvQGwdi28yxLmjz6r7AEH9ilpqq89WU0m2YfrKtMeYvz0neuWdgA410KUDb io9wwsLwYX6hUtvByUweZ7HgYsZRHLgnA9Rd0= Received: by 10.204.31.76 with SMTP id x12mr8244bkc.213.1307476907116; Tue, 07 Jun 2011 13:01:47 -0700 (PDT) MIME-Version: 1.0 Received: by 10.204.42.140 with HTTP; Tue, 7 Jun 2011 13:01:07 -0700 (PDT) In-Reply-To: <12928.1307457185@sss.pgh.pa.us> References: <201106031238.p53CcA8P075374@wwwmaster.postgresql.org> <27042.1307113140@sss.pgh.pa.us> <12928.1307457185@sss.pgh.pa.us> From: Greg Stark Date: Tue, 7 Jun 2011 21:01:07 +0100 Message-ID: Subject: Re: Re: BUG #6050: Dump and restore of view after a schema change: can't restore the view To: Tom Lane Cc: pgsql-bugs@postgresql.org, Daniel Cristian Cruz Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.898 tagged_above=-5 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, RFC_ABUSE_POST=0.001 X-Spam-Level: X-Archive-Number: 201106/82 X-Sequence-Number: 30461 On Tue, Jun 7, 2011 at 3:33 PM, Tom Lane wrote: > Greg Stark writes: >> On Jun 3, 2011 4:20 PM, "Tom Lane" wrote: >>> I'm inclined to write this off as "so don't do that". =A0There's nothin= g >>> that pg_dump can do to make this work: it has to use the USING syntax >>> for the join, and that doesn't offer any way to qualify the column name >>> on just one side. > >> There's nothing stopping us from adding a nonstandard syntax to cover >> precisely the information needed to resolve this case when dumping. > >> For example we could support USING (a.a=3Db.a) or ON (a.a=3Db.a as a) > > 1. "Nonstandard syntax" is widely seen as "vendor lock-in". =A0I don't > think that people would appreciate such a fix, especially for an issue > so obscure that we've never seen it before. Well our dumps are already not going to be loadable on other SQL implementations. But yes, it's non-ideal which is why I was tempted to do it only when needed. > 2. I don't believe your proposal covers all cases. =A0For instance, there > are cases where there is no valid qualified name for a column, ie, it's > a merged column from an alias-less JOIN. =A0(The existence of such cases > is another reason why USING sucks, but I digress.) Hm, will have to think about that. >> We could use it only in this case where there's ambiguity too so it woul= dn't >> clutter people's dumps. > > No, because the problem case is where ambiguity gets added after the > fact. I think this is an interesting point. It seems there are two cases, one of which I think is much worse than the other. It sounds like you're concerned about someone dumping the view definition, then doing an alter table on one of the underlying tables, then trying to reload their old view definition. As you pointed out later there are lots of ways the alter table could cause the view to no longer work. Many of them involve USING which justifies your complaint that it's fragile but of course it could be as simple as the alter table dropping a needed column... The other case seems worse to me: someone creates the view, does the alter table, then dumps the database. They don't make any further database modifications, the dump is unloadable as it was dumped. That is, pg_dump produced an unloadable dump right off the bat. A lot of work has gone into making pg_dump/pg_restore guarantee that they'll always produce a copy of the database, even if you've done odd things like change the lower bounds of your arrays. A lot of this was from before the days of PITR when pg_dump/pg_restore was the *only* backup option and it was considered absolutely essential that they always work. But even today I think it's still a goal that pg_dump always dump a loadable database. Of course it won't always load in a different context but if you restore it in the right context or restore the whole database it ought to work. I had in mind for pg_dump to decide to use the non-standard syntax iff it was necessary at dump time. That doesn't protect against someone changing the table referenced after the dump but that's fine by me. At least when it was dumped the sql would have loaded to produce the same view as was dumped. --=20 greg