X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 50570D1B566 for ; Mon, 27 Oct 2003 18:53:22 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 06577-08 for ; Mon, 27 Oct 2003 14:52:52 -0400 (AST) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id 8D37DD1B910 for ; Mon, 27 Oct 2003 14:52:12 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.10/8.12.10) with ESMTP id h9RIqDit001736; Mon, 27 Oct 2003 13:52:13 -0500 (EST) To: Neil Conway Cc: Greg Stark , Dror Matalon , PostgreSQL Performance Subject: Re: Various performance questions In-reply-to: <1067280005.463.48.camel@tokyo> References: <20031026194449.GD2979@rlx11.zapatec.com> <87u15vxrue.fsf@stark.dyndns.tv> <1067269309.459.33.camel@tokyo> <877k2qy36r.fsf@stark.dyndns.tv> <1067280005.463.48.camel@tokyo> Comments: In-reply-to Neil Conway message dated "Mon, 27 Oct 2003 13:40:06 -0500" Date: Mon, 27 Oct 2003 13:52:12 -0500 Message-ID: <1735.1067280732@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200310/688 X-Sequence-Number: 4436 Neil Conway writes: > On Mon, 2003-10-27 at 12:56, Greg Stark wrote: >> Neil Conway writes: >>> Uh, what? Why would an int8 need to be "dynamically allocated >>> repeatedly"? >> >> Perhaps I'm wrong, I'm extrapolating from a comment Tom Lane made that >> profiling showed that the bulk of the cost in count() went to allocating >> int8s. He commented that this could be optimized by having count() and sum() >> bypass the regular api. I don't have the original message handy. > I'm still confused: int64 should be stack-allocated, AFAICS. Tom, do you > recall what the issue here is? Greg is correct. int8 is a pass-by-reference datatype and so every aggregate state-transition function cycle requires at least one palloc (to return the function result). I think in the current state of the code it requires two pallocs :-(, because we can't trust the transition function to palloc its result in the right context without palloc'ing leaked junk in that context, so an extra palloc is needed to copy the result Datum into a longer-lived context than we call the function in. There was some speculation a few weeks ago about devising a way to let performance-critical transition functions avoid the excess palloc's by working with a specialized API instead of the standard function call API, but I think it'll have to wait for 7.5. regards, tom lane