X-Original-To: pgsql-performance-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id F18A79FA5BE for ; Thu, 15 Jun 2006 15:33:56 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 34827-04 for ; Thu, 15 Jun 2006 15:33:47 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mir3-fs.mir3.com (mail.mir3.com [65.208.188.100]) by postgresql.org (Postfix) with ESMTP id AB1F59FA13E for ; Thu, 15 Jun 2006 15:33:47 -0300 (ADT) Received: mir3-fs.mir3.com 172.16.1.11 from 172.16.2.68 172.16.2.68 via HTTP with MS-WebStorage 6.0.6249 Received: from archimedes.mirlogic.com by mir3-fs.mir3.com; 15 Jun 2006 11:33:45 -0700 Subject: Re: Optimizer internals From: Mark Lewis To: pgsql-performance@lusis.org Cc: PGSQL Performance In-Reply-To: References: Content-Type: text/plain Content-Transfer-Encoding: 7bit Organization: MIR3, Inc. Date: Thu, 15 Jun 2006 11:33:45 -0700 Message-Id: <1150396425.31200.66.camel@archimedes> Mime-Version: 1.0 X-Mailer: Evolution 2.0.2 (2.0.2-27) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/321 X-Sequence-Number: 19678 On Thu, 2006-06-15 at 14:05 -0400, John Vincent wrote: > Now I've been told by our DBA that we should have been able to wholy > satisfy that query via the indexes. DB2 can satisfy the query using only indexes because DB2 doesn't do MVCC. Although MVCC is generally a win in terms of making the database easier to use and applications less brittle, it also means that the database must inspect the visibility information for each row before it can answer a query. For most types of queries this isn't a big deal, but for count(*) type queries, it slows things down. Since adding the visibility information to indexes would make them significantly more expensive to use and maintain, it isn't done. Therefore, each row has to be fetched from the main table anyway. Since in this particular query you are counting all rows of the database, PG must fetch each row from the main table regardless, so the sequential scan is much faster because it avoids traversing the index and performing random read operations. -- Mark Lewis