Re: GiST memory allocation

From: Neil Conway <neilc(at)samurai(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: GiST memory allocation
Date: 2004-11-02 04:49:39
Message-ID: 1099370979.17405.178.camel@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, 2004-11-02 at 02:20, Tom Lane wrote:
> Neil Conway <neilc(at)samurai(dot)com> writes:
> > (the observation here is that 99% of the allocations done by
> > gist.c are for internal use only -- we rarely allocate anything that
> > needs to live longer than the current GiST API call).
>
> You sure about that? In btree quite a lot of the allocs need to survive
> across the current scan.

I'm specifically talking about gist.c, which just handles index
creation, tuple insertion and tuple deletion -- AFAICS we only rarely
need to allocate anything that lives beyond the current API call. Scans
are handled by gistscan.c. It might be nice to make better use of memory
contexts in both, but it's gist.c that is particularly in need at the
moment, I think.

> I think this is not acceptable. It certainly wouldn't be acceptable for
> btree --- you couldn't even use a PL-language function as an index
> operator, because the PL itself would need to do system catalog accesses
> that could result in re-entrant btree scans. If you got away with it
> for GiST it would only be because GiST is a stepchild that the system
> doesn't depend on. That doesn't sound like the direction to go in.

One alternative is to create memory contexts for each insertion /
creation / deletion operation, but that is pretty ugly, and probably
inefficient for insertion/deletion.

I can't really think of a better solution than a static memory context.
I don't think the reentrency will be a problem right now, but if it
becomes a problem in the future we can solve it via some book-keeping
(e.g. on entry to GiST bump a counter, when the counter == 0 and we're
exiting a GiST API then reset the memory context).

-Neil

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Greg Stark 2004-11-02 06:01:19 Re: tablespaces for temporary files
Previous Message Bruce Momjian 2004-11-02 03:36:06 Re: gettext calls in pgport