Re: Invalidating dependent views and functions

From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Scott Bailey <artacus(at)comcast(dot)net>, hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Invalidating dependent views and functions
Date: 2010-04-30 15:21:15
Message-ID: v2gb42b73151004300821z6d4c144bw4f375fc16abf7d2d@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Apr 30, 2010 at 8:08 AM, Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
> On Fri, Apr 30, 2010 at 3:33 AM, Scott Bailey <artacus(at)comcast(dot)net> wrote:
>> Proposal: Add an invalid flag to pg_class. Invalid objects would be ignored
>> when doing dependency checks for DDL statements. And an exception would be
>> thrown when an invalid object is called.
>>
>> This is similar to what Oracle does. And most Oracle tools have find and
>> compile invalid objects with a statement like:
>> ALTER VIEW foo RECOMPILE;
>> ALTER PACKAGE bar RECOMPILE BODY;
>
> Keep in mind that our implementation is apparently quite different
> from Oracle's.  Of course I have no idea what they do under the hood,
> but we don't even store the original text of the view.  Instead, we
> store a parsed version of the view text that refers to the target
> objects logically rather than by name.  That has some advantages; for
> example, you can rename a column in some other table that the view
> uses, and nothing breaks.  You can rename a whole table that is used
> by the view, and nothing breaks.  Even if we added storage for the
> text of the view, recompiling it might result in some fairly
> astonishing behavior - you might suddenly be referring to tables or
> columns that were quite different from the ones you originally
> targeted, if the old ones were renamed out of the way and new,
> eponymous ones were added.
>
> I'm familiar with the view-dependency-hell problem you mention, having
> fought with it (succesfully, I'm pleased to say, using a big Perl
> script to manage things - and also - obligatory dig here - to work
> around our lack of support for CREATE IF NOT EXISTS) on many
> occasions, but I don't have any brilliant ideas about how to solve it.
>  I would like to eventually support ALTER VIEW ... DROP COLUMN; note
> that we do now support ADDING columns to a view using CREATE OR
> REPLACE as long as all the new ones are at the end.  But neither of
> those things is going to help with a case like yours, when you want to
> change the type of the column.  I'm not really sure what to do about
> that case.

We discussed keeping view sources for invalidation purposes in depth
earlier. The main takeaway was that recompiling view sources simply
doesn't work: if your view definition is: 'select * from table', the
recompile would add fields to the view which SQL (unfortunately)
expressly forbids. This is maybe solvable, but complicated.

aside: I've been lobbying for (somefoo).* to NOT do this, that is,
that is allow it to pick up extra fields on somefoo as they appear,
with not so great results so far.

I happen to think that the way functions are invalidated right now
based on table changes actually work pretty well. Plans are
invalidated appropriately and functions are dropped if you suffer
major argument changes. Before thinking about improving this, you
have to grapple with (for starters) the mess of interactions with
search_path and function definitions. IOW, functions not getting
planned until they are used is a nice property.

merlin

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2010-04-30 16:22:41 Re: pg_start_backup and pg_stop_backup Re: Re: [COMMITTERS] pgsql: Make CheckRequiredParameterValues() depend upon correct
Previous Message Kevin Grittner 2010-04-30 15:18:34 Re: missing file in git repo