Skip site navigation (1) Skip section navigation (2)

Re: sum(int4)/sum(int2) improvement

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Atsushi Ogawa <a_ogawa(at)hi-ho(dot)ne(dot)jp>
Cc: pgsql-patches(at)postgresql(dot)org
Subject: Re: sum(int4)/sum(int2) improvement
Date: 2005-09-01 16:49:32
Message-ID: 29185.1125593372@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-patches
Atsushi Ogawa <a_ogawa(at)hi-ho(dot)ne(dot)jp> writes:
> Tom Lane wrote:
>> Why is this better than the fix already in place?

> Because per-tuple context is reset many times. If per-tuple context is 
> never used, the following codes of AllocSetReset become effective.

>     /* Nothing to do if context has never contained any data */
>     if (block == NULL)
>         return;

Hm.  It's still pretty ugly though, since fixing only those two places
isn't very exciting.

I went back and looked at your AllocSetReset patch from last May, and
liked it better on second consideration.  The point I had missed before
is that even though we're adding an instruction to palloc, it's only
needed in the "slow" paths.  The cases that we have to be worried about,
IMHO, are:

1. Loop containing palloc(s) and pfree(s).

2. Loop containing palloc(s) and MemoryContextReset.

3. Loop containing only MemoryContextReset.

(We need not worry about cases doing only palloc since that is obviously
not sustainable over any long period.)  Case 1 is the one that was
bothering me, but in practice, once the loop is rolling the pallocs
should mostly be reusing previously-pfreed chunks.  That is the "fast"
path through AllocSetAlloc, and it doesn't need any extra overhead
because it doesn't need to clear the alloc-set-is-empty flag --- the
set is clearly already nonempty if it has free chunks.  There's enough
instructions in the other paths that one more isn't going to hurt.

In case 2 we're adding instructions to both palloc and
MemoryContextReset, for no gain :-( ... but again, these are in code
paths that aren't the fastest possible.  I don't think it'll hurt
noticeably.

I notice also that MemoryContextIsEmpty could return a better answer
if we maintained a flag like this.  This is not real important in the
current scheme of things, but might be more interesting someday.

I'll fix up the old patch and apply it.  I think that's a better answer
than kluging up the aggregate functions themselves.

			regards, tom lane

In response to

Responses

pgsql-patches by date

Next:From: Darcy BuskermolenDate: 2005-09-01 17:34:03
Subject: Re: Version number in psql banner
Previous:From: Alvaro HerreraDate: 2005-09-01 16:46:16
Subject: Re: prevent encoding conversion recursive error

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group