Re: [HACKERS] Postgres Speed or lack thereof

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Massimo Dal Zotto <dz(at)cs(dot)unitn(dot)it>
Cc: hackers(at)postgreSQL(dot)org (PostgreSQL Hackers)
Subject: Re: [HACKERS] Postgres Speed or lack thereof
Date: 1999-01-28 19:39:15
Message-ID: 23893.917552355@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Massimo Dal Zotto <dz(at)cs(dot)unitn(dot)it> writes:
> We could use 4 methods for dynamic allocation:

This sounds pretty close to what I was thinking, too. We already have
the notion of "memory contexts" which can have different alloc/free
implementations, so there's already a structure to put these different
alloc methods into.

However, we probably don't really want to touch each individual palloc()
call in the system to change it to a MemoryContextAlloc(some-context, size)
call. Not only would that be horribly tedious, but an awful lot of
these calls are made for the purpose of creating an object that the
requesting routine intends to pass back to its caller. In that
situation, the requesting routine doesn't really *know* what the
lifetime of the storage needs to be --- it's the caller that determines
what's going to happen.

I think what we want is to define palloc() as allocating
not-individually-freeable storage from the current context, which is set
by the most closely nested main control routine (parser, planner,
executor, etc). That should handle the majority of the existing code
and thus minimize the number of places that have to be touched.
pfree() goes away, eventually, and can be made a no-op meanwhile.

This assumes that the number of places that really *want* to free
storage earlier than end of context is much smaller than the number
of places that don't want to be bothered --- therefore, it makes more
sense to redefine palloc() as the not-separately-freeable kind and
change the places that do want to control their storage lifetime,
instead of changing all the other places.

> 4) fast_talloc - we could introduce a `tuple' context handled like
> fast_palloc for storage used only while processing one tuple.

Right, that could be the most closely nested context for operations that
iterate over tuples. A further idea I had is to define allocations
from that context as being only good for one tuple, but to not bother to
physically clear the context after every single tuple --- do it every
ten or hundred or so tuples, instead. The amount of storage wasted
won't be very large, and it cuts the per-tuple time cost even more.
(Of course, if resetting a context to empty only takes a few
instructions, you might as well just do it every time. I'm not sure
offhand if that will be true or not.)

regards, tom lane

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jackson, DeJuan 1999-01-28 19:44:41 RE: [HACKERS] Problem with multiple SUMs
Previous Message Tom Lane 1999-01-28 18:57:32 Re: [HACKERS] new heap manager mmalloc