]> granicus.if.org Git - postgresql/commitdiff
Tom Lane <tgl@sss.pgh.pa.us> writes:
authorBruce Momjian <bruce@momjian.us>
Sat, 4 Jun 2005 20:14:12 +0000 (20:14 +0000)
committerBruce Momjian <bruce@momjian.us>
Sat, 4 Jun 2005 20:14:12 +0000 (20:14 +0000)
> a_ogawa <a_ogawa@hi-ho.ne.jp> writes:
> > It is a reasonable idea. However, the majority part of MemSet was not
> > able to be avoided by this idea. Because the per-tuple contexts are used
> > at the early stage of executor.
>
> Drat.  Well, what about changing that?  We could introduce additional
> contexts or change the startup behavior so that the ones that are
> frequently reset don't have any data in them unless you are working
> with pass-by-ref values inside the inner loop.

That might be possible. However, I think that we should change only
aset.c about this article.
I thought further: We can check whether context was used from the last
reset even when blocks list is not empty. Please see attached patch.

The effect of the patch that I measured is as follows:

o Execution time that executed the SQL ten times.
(1)Linux(CPU: Pentium III, Compiler option: -O2)
 - original: 24.960s
 - patched : 23.114s

(2)Linux(CPU: Pentium 4, Compiler option: -O2)
 - original: 8.730s
 - patched : 7.962s

(3)Solaris(CPU: Ultra SPARC III, Compiler option: -O2)
 - original: 37.0s
 - patched : 33.7s

Atsushi Ogawa (a_ogawa)

src/backend/utils/mmgr/aset.c

index 4f60b186c27bc6c0e60e738218fd09711e409df3..f7550929f1f6c6de14af88bc3f908c5dc405f1cd 100644 (file)
@@ -11,7 +11,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/utils/mmgr/aset.c,v 1.60 2005/05/14 20:29:13 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/utils/mmgr/aset.c,v 1.61 2005/06/04 20:14:12 momjian Exp $
  *
  * NOTE:
  *     This is a new (Feb. 05, 1999) implementation of the allocation set
@@ -399,6 +399,17 @@ AllocSetReset(MemoryContext context)
        if (block == NULL)
                return;
 
+       /*
+        * When blocks list has only "keeper" block and freeptr of the block
+        * is initial value, the context is not used from last reset.
+        */
+       if (block == set->keeper && block->next == NULL)
+       {
+               char       *datastart = ((char *) block) + ALLOC_BLOCKHDRSZ;
+               if (block->freeptr == datastart)
+                       return;
+       }
+
        /* Clear chunk freelists */
        MemSetAligned(set->freelist, 0, sizeof(set->freelist));