Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZmuY3-000765-W0 for pgsql-hackers@arkaria.postgresql.org; Fri, 16 Oct 2015 02:15:12 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZmuY3-0003kh-IL for pgsql-hackers@arkaria.postgresql.org; Fri, 16 Oct 2015 02:15:11 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZmuWm-0002G4-5a for pgsql-hackers@postgresql.org; Fri, 16 Oct 2015 02:13:52 +0000 Received: from out.smtp-auth.no-ip.com ([8.23.224.60]) by magus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1ZmuWg-0006Sj-T1 for pgsql-hackers@postgresql.org; Fri, 16 Oct 2015 02:13:51 +0000 X-No-IP: alvh.no-ip.org@noip-smtp X-Report-Spam-To: abuse@no-ip.com Received: from alvin.alvh.no-ip.org (unknown [186.37.78.200]) (Authenticated sender: alvh.no-ip.org@noip-smtp) by smtp-auth.no-ip.com (Postfix) with ESMTPA id 07E3A400E57; Thu, 15 Oct 2015 19:13:40 -0700 (PDT) Received: by alvin.alvh.no-ip.org (Postfix, from userid 1000) id 1DC4E1EE9; Thu, 15 Oct 2015 23:13:35 -0300 (CLT) Date: Thu, 15 Oct 2015 23:13:35 -0300 From: Alvaro Herrera To: zhangjinyu Cc: pgsql-hackers@postgresql.org Subject: Re: Patch: Optimize memory allocation in function 'bringetbitmap' Message-ID: <20151016021334.GA3391@alvherre.pgsql> References: <495deb78.4186.1500dacaa63.Coremail.beijing_pg@163.com> <20150927175608.GM295765@alvherre.pgsql> <1443451254826-5867647.post@n5.nabble.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1443451254826-5867647.post@n5.nabble.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org zhangjinyu wrote: > >>>>However I wonder if it would be simpler to have the dtup structure have > >>>>the pointers, so that you can pass it as NULL in the first call and then > >>>>followup calls reuse the one allocated in the first call. > Jinyu: the memory is allocated from perRangeCxt and perRangeCxt will be > reset in loop, > so this way don't work. You're right. I think we can do better: have brin_deform_tuple accept another argument of type BrinMemTuple *, which can be NULL. If NULL, the function calls brin_new_memtuple to allocate a new one (just like current code); if not NULL, that one is used. Have brin_new_memtuple also allocate the values/allnulls/hasnulls arrays, which are now part of the BrinMemTuple struct. Then, bringetbitmap calls brin_new_memtuple once before changing to perRangeCxt, then reuse the returned inside the loop (we probably need brin_memtuple_initialize to clear out the struct at the end of each loop iteration). Other callers of brin_deform_tuple just pass NULL to get the current behavior. -- Álvaro Herrera http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers