Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id EBBA02E010A for ; Sun, 16 Mar 2008 23:21:53 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 39584-02 for ; Sun, 16 Mar 2008 23:21:29 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from momjian.us (momjian.us [70.90.9.53]) by postgresql.org (Postfix) with ESMTP id E8C172E156A for ; Sun, 16 Mar 2008 23:21:36 -0300 (ADT) Received: (from bruce@localhost) by momjian.us (8.11.6/8.11.6) id m2H2LOp12205; Sun, 16 Mar 2008 22:21:24 -0400 (EDT) From: Bruce Momjian Message-Id: <200803170221.m2H2LOp12205@momjian.us> Subject: Re: [PERFORM] Very slow (2 tuples/second) sequential scan after bulk insert; speed returns to ~500 tuples/second after commit In-Reply-To: <47D7DE12.80700@enterprisedb.com> To: Heikki Linnakangas Date: Sun, 16 Mar 2008 22:21:24 -0400 (EDT) CC: Tom Lane , Craig Ringer , pgsql-patches X-Mailer: ELM [version 2.4ME+ PL124 (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="US-ASCII" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200803/213 X-Sequence-Number: 5276 This has been applied by Tom. --------------------------------------------------------------------------- Heikki Linnakangas wrote: > Tom Lane wrote: > > "Heikki Linnakangas" writes: > >> Elsewhere in our codebase where we use arrays that are enlarged as > >> needed, we keep track of the "allocated" size and the "used" size of the > >> array separately, and only call repalloc when the array fills up, and > >> repalloc a larger than necessary array when it does. I chose to just > >> call repalloc every time instead, as repalloc is smart enough to fall > >> out quickly if the chunk the allocation was made in is already larger > >> than the new size. There might be some gain avoiding the repeated > >> repalloc calls, but I doubt it's worth the code complexity, and calling > >> repalloc with a larger than necessary size can actually force it to > >> unnecessarily allocate a new, larger chunk instead of reusing the old > >> one. Thoughts on that? > > > > Seems like a pretty bad idea to me, as the behavior you're counting on > > only applies to chunks up to 8K or thereabouts. > > Oh, you're right. Though I'm sure libc realloc has all kinds of smarts > as well, it does seem better to not rely too much on that. > > > In a situation where > > you are subcommitting lots of XIDs one at a time, this is likely to have > > quite awful behavior (or at least, you're at the mercy of the local > > malloc library as to how bad it is). I'd go with the same > > double-it-each-time-needed approach we use elsewhere. > > Yep, patch attached. I also changed xactGetCommittedChildren to return > the original array instead of copying it, as Alvaro suggested. > > -- > Heikki Linnakangas > EnterpriseDB http://www.enterprisedb.com > > -- > Sent via pgsql-patches mailing list (pgsql-patches@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-patches -- Bruce Momjian http://momjian.us EnterpriseDB http://postgres.enterprisedb.com + If your life is a hard drive, Christ can be your backup. +