X-Original-To: pgsql-performance@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 26FD1476355 for ; Sun, 20 Apr 2003 11:21:29 -0400 (EDT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id 4C9A3476369 for ; Sun, 20 Apr 2003 11:21:28 -0400 (EDT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h3KFLXU6026962; Sun, 20 Apr 2003 11:21:33 -0400 (EDT) To: Kevin Brown Cc: pgsql-performance@postgresql.org Subject: Re: [SQL] Yet Another (Simple) Case of Index not used In-reply-to: <20030420062852.GK1847@filer> References: <200304090918.45275.josh@agliodbs.com> <20030419130146.GI1847@filer> <21955.1050767928@sss.pgh.pa.us> <20030420011336.GJ1847@filer> <24735.1050809664@sss.pgh.pa.us> <20030420062852.GK1847@filer> Comments: In-reply-to Kevin Brown message dated "Sat, 19 Apr 2003 23:28:52 -0700" Date: Sun, 20 Apr 2003 11:21:32 -0400 Message-ID: <26961.1050852092@sss.pgh.pa.us> From: Tom Lane X-Spam-Status: No, hits=-32.5 required=5.0 tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, REFERENCES,REPLY_WITH_QUOTES autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200304/178 X-Sequence-Number: 1684 Kevin Brown writes: > This is why I suspect the best way to manage this would be to manage > the counter itself using the MVCC mechanism (that is, you treat the > shared counter as a row in a table just like any other and, in fact, > it might be most beneficial for it to actually be exactly that), which > handles the visibility problem automatically. But I don't know how > much contention there would be as a result. Hm. Contention probably wouldn't be the killer, since if transactions don't try to update the count until they are about to commit, they won't be holding the row lock for long. (You'd have to beware of deadlocks between transactions that need to update multiple counters, but that seems soluble.) What *would* be a problem is that such counter tables would accumulate huge numbers of dead rows very quickly, making it inefficient to find the live row. Josh already mentioned this as a problem with user-trigger-based counting. You could stanch the bleeding with sufficiently frequent vacuums, perhaps, but it just doesn't look very appealing. Ultimately what this comes down to is "how much overhead are we willing to load onto all other operations in order to make SELECT-COUNT(*)-with- no-WHERE-clause fast"? Postgres has made a set of design choices that favor the other operations. If you've designed an application that lives or dies by fast COUNT(*), perhaps you should choose another database. regards, tom lane