Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 8E8916336A1 for ; Mon, 6 Apr 2009 11:29:45 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 35551-03 for ; Mon, 6 Apr 2009 11:29:43 -0300 (ADT) X-Greylist: delayed 12:07:29.967735 by SQLgrey-1.7.6 Received: from tinlc.com (unknown [72.18.206.65]) by mail.postgresql.org (Postfix) with ESMTP id C1C286336B3 for ; Mon, 6 Apr 2009 11:29:43 -0300 (ADT) Received: from biglumber.com ([72.18.206.64] helo=localhost) by tinlc.com with smtp (Exim 4.60) (envelope-from ) id 1LqppJ-0000UD-3C; Mon, 06 Apr 2009 09:29:29 -0500 From: "Greg Sabino Mullane" To: tonyceb@andrew.cmu.edu Cc: pgsql-sql@postgresql.org CC: pgsql-sql@postgresql.org Subject: Re: Performance problem with row count trigger X-PGP-Key: 2529 DF6A B8F7 9407 E944 45B4 BC9B 9067 1496 4AC8 X-Request-PGP: http://www.biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8 In-Reply-To: <49D653E8.7040008@andrew.cmu.edu> Date: Mon, 6 Apr 2009 14:29:28 -0000 X-Mailer: JoyMail 2.01 Message-ID: <948fef7e99f6ecc30c0abd802f530fe4@biglumber.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.1 tagged_above=0 required=5 tests=RDNS_NONE=0.1 X-Spam-Level: X-Archive-Number: 200904/40 X-Sequence-Number: 32386 -----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 > A separate table just for that one column? Would that really help, > given that I'd have to add the foreign key dataset_id to the related > table? How does splitting activity across dataset and, say, > dataset_counts help things? Well, it reduce the size (and bloat) of the main table and let's you offload the indexes as well. (especially important for pre-HOT systems). It's also a win if there are many queries against the main table that *don't* hit the summary count column. The cost of another table join for queries that *do* hit it is probably offset by keeping the main table small and only updated when it really needs to be. Still, it depends a lot on your particular circumstances; the thread was started because of the pain of updating this one column, but only you can make the final call about whether a separate table is a Good Idea or a Silly Microoptimization. >> 2) Do you really need bigint for the counts? > Probably not. Still, changing to INTEGER hasn't changed the performance > in any measurable way. I was simply thinking about the amount of space used here, not speed. Of course, if there is any conceivable way that the amounts in question would *ever* exceed two billion, you should keep it BIGINT, as changing it later would be painful. > I'm not sure I understand the danger you're talking about here. Doesn't > putting the whole start_bulkload_assoc_count(), bulk insert, and > end_bulkload_assoc_count() process in a transaction save me from any of > these problems? Or is there some more subtle problem I'm not seeing? No, that would work perfectly fine. The danger I was referring to was someone calling the first function and then committing before they remembered to call the second one. It pays to be paranoid around databases :), but if you have control of the environment, and that scenario seems unlikely, it should be fine the way it is. Oh, and I just remembered that the end_.. function should be clearing the temporary hash we build up - I think the version I emailed neglected to do that. Wouldn't want those numbers to stick around in the session. - -- Greg Sabino Mullane greg@turnstep.com End Point Corporation PGP Key: 0x14964AC8 200904061028 http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8 -----BEGIN PGP SIGNATURE----- iEYEAREDAAYFAknaEdIACgkQvJuQZxSWSsgeeACfQRXopdyHdYoj5SLTiwedIYAc bDUAoNvouyYtixHeXLowWqYr9Oc/jS/t =sJ+s -----END PGP SIGNATURE-----