Re: WIP patch: Improve relation size functions such as pg_relation_size() to avoid producing an error when called against a no longer visible relation

From: Phil Sorber <phil(at)omniti(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Cc: OmniTI DBA <dba(at)omniti(dot)com>
Subject: Re: WIP patch: Improve relation size functions such as pg_relation_size() to avoid producing an error when called against a no longer visible relation
Date: 2011-12-20 02:31:10
Message-ID: CADAkt-g4cujTGmiz0wzS7DNJi1UasDNcD0ZFoz9xHyfbR34pMQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Dec 19, 2011 at 1:27 PM, Phil Sorber <phil(at)omniti(dot)com> wrote:
> On Sat, Dec 17, 2011 at 3:52 PM, Phil Sorber <phil(at)omniti(dot)com> wrote:
>> Attached is a patch that addresses the todo item "Improve relation
>> size functions such as pg_relation_size() to avoid producing an error
>> when called against a no longer visible relation."
>>
>> http://archives.postgresql.org/pgsql-general/2010-10/msg00332.php
>>
>> Instead of returning an error, they now return NULL if the OID is
>> found in pg_class when using SnapshotAny. I only applied it to 4
>> functions: select pg_relation_size, pg_total_relation_size,
>> pg_table_size and pg_indexes_size. These are the ones that were using
>> relation_open(). I changed them to using try_relation_open(). For
>> three of them I had to move the try_relation_open() call up one level
>> in the call stack and change the parameter types for some support
>> functions from Oid to Relation. They now also call a new function
>> relation_recently_dead() which is what checks for relation in
>> SnapshotAny. All regression tests passed.
>>
>> Is SnapshotAny the snapshot I should be using? It seems to get the
>> correct results. I can drop a table and I get NULL. Then after a
>> vacuumdb it returns an error.
>
> Something I'd like to point out myself is that I need to be using
> ObjectIdAttributeNumber instead of Anum_pg_class_relfilenode. Probably
> just luck that I got the intended results before. This will also
> change the logic in a few other places.
>
> Still not clear on the semantics of Snapshot{Any|Self|Now|Dirty}.

I've attached the updated version of my patch with the changes
mentioned in the previous email.

Attachment Content-Type Size
improve_relation_size_functions_v2.patch text/x-patch 6.9 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Noah Misch 2011-12-20 03:10:02 Re: ALTER TABLE lock strength reduction patch is unsafe
Previous Message Alvaro Herrera 2011-12-20 02:21:19 Re: Review: Non-inheritable check constraints