Re: Rethinking sinval callback hook API

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Rethinking sinval callback hook API
Date: 2011-08-21 21:53:45
Message-ID: CA+TgmoYzOTtwNSZQuVTfwBznjcVPEeT0kP=7w1rehv=E+LMDUA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Aug 19, 2011 at 2:13 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Currently, we have two types of callbacks that can be registered to get
> control when an invalidation message is received: syscache callbacks and
> relcache callbacks.  It strikes me that we might be better advised to
> unify these into a single type of callback that gets a
> SharedInvalidationMessage struct pointer (we could pass NULL to signify
> a cache reset event).  That would avoid having to add another
> registration list every time we decide that there's a reason for
> callbacks to see another type of inval message.  There are a couple of
> reasonably near-term reasons why we might want to do this:
>
> 1. Robert was speculating the other day about wanting to be able to
> snoop the inval traffic.  Right now, callbacks can only snoop a fairly
> small subset of it.

Is that true? It appears to me that the events that aren't exposed at
all are smgr and relmap invalidations, which don't seem terribly
important, and presumably not a majority of the traffic.

> 2. In conjunction with what I'm doing with plancache, it struck me that
> it might be nice to subdivide relcache inval messages into two types,
> one indicating a schema (DDL) change and one that just indicates that
> statistics changed; this would allow us to avoid redoing parse analysis
> and rewrite for a cached query as a consequence of autovacuum stats
> updates.  With the current scheme, plancache.c would need to register
> two different kinds of callbacks to handle that, or we'd need some other
> API change for relcache callbacks so they could distinguish.

Would this be enough for us to find a noticeable performance improvement?

> A small disadvantage of this is that callbacks would have to know about
> struct SharedInvalidationMessage, which right now isn't tremendously
> widely known, but that doesn't seem like a fatal objection to me.
> In practice that struct definition has been pretty stable.

I'm not opposed to trying to create a better/more universal API, but I
find that a bit grotty. We've already resorted to some ugly
bit-space-preserving hacks in that structure, and I'm not sure we
won't have more in the future. In particular, exposing the
backend_lo/backend_hi thing seems like a recipe for distributed
confusion. Would it be too expensive to expose an opaque struct with
accessor functions? Or pass the extracted values as separate
arguments?

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2011-08-21 22:24:50 Re: Rethinking sinval callback hook API
Previous Message Robert Haas 2011-08-21 21:38:52 Re: the big picture for index-only scans