Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id EBEF02E30CC for ; Sat, 8 Mar 2008 03:11:42 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 85110-07 for ; Sat, 8 Mar 2008 03:11:38 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from rv-out-0910.google.com (rv-out-0910.google.com [209.85.198.190]) by postgresql.org (Postfix) with ESMTP id 2C3BC2E30BD for ; Sat, 8 Mar 2008 03:11:39 -0400 (AST) Received: by rv-out-0910.google.com with SMTP id g13so568387rvb.43 for ; Fri, 07 Mar 2008 23:11:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding; bh=LoAYEpFLsqO/wHp36pTMX86zft0wM07jImpS3X5tb1E=; b=L6OoOD9zNuLsS4rD+QZhc5NQl/hMJ1OXEMnlKa3M9jI9Cu6cCkxSoboqnl8stJPyMIWmU2Vr/+VkB9NhkThNz6YLyFxMRH2LGcm4X37ENBT/1Y4f0Ej/GadJlbQZtS8bmzQtcDQyEpm41g7WU3SwtjETMditeS8k77hVQh3m6Ms= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding; b=haUREcqJsoen5eVnP+mdNm/qf31JeyCV6LVeIdqCh0KqEW/aDid4vb5iDsJA/V0gzRUM7H0rLzfsfVCIRTbjyY5CeDg78k1XaKU93QEPVoyrXbS5tflYByiwQQUzXPOXS95MHeCdoTVHjqHisK+wneFjPpDgSr+Ye78YSqdMyeY= Received: by 10.141.1.2 with SMTP id d2mr1507192rvi.129.1204960298602; Fri, 07 Mar 2008 23:11:38 -0800 (PST) Received: from ?192.168.1.101? ( [24.7.64.54]) by mx.google.com with ESMTPS id n32sm2969438wag.13.2008.03.07.23.11.36 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 07 Mar 2008 23:11:37 -0800 (PST) Message-ID: <47D23C17.7010207@gmail.com> Date: Fri, 07 Mar 2008 23:11:19 -0800 From: paul rivers User-Agent: Thunderbird 2.0.0.9 (Windows/20071031) MIME-Version: 1.0 To: Mark Mielke CC: josh@agliodbs.com, pgsql-performance@postgresql.org, Tom Lane , Craig James Subject: Re: count * performance issue References: <47D00DB2.7040007@emolecules.com> <18451.1204824562@sss.pgh.pa.us> <200803071727.36146.josh@agliodbs.com> <47D224BE.1060001@mark.mielke.cc> In-Reply-To: <47D224BE.1060001@mark.mielke.cc> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200803/179 X-Sequence-Number: 29133 Mark Mielke wrote: > Josh Berkus wrote: >>>> Count() on Oracle and MySQL is almost instantaneous, even for very >>>> large tables. So why can't Postgres do what they do? >>>> >>> AFAIK the above claim is false for Oracle. They have the same >>> transactional issues we do. >>> >> >> Nope. Oracle's MVCC is implemented through rollback segments, rather than >> non-overwriting the way ours is. So Oracle can just do a count(*) on the >> index, then check the rollback segment for any concurrent >> update/delete/insert activity and adjust the count. This sucks if there's >> a *lot* of concurrent activity, but in the usual case it's pretty fast > > I read the "almost instantaneous" against "the above claim is false" and > "Nope.", and I am not sure from the above whether you are saying that > Oracle keeps an up-to-date count for the index (which might make it > instantaneous?), or whether you are saying it still has to scan the > index - which can take time if the index is large (therefore not > instantaneous). > > Cheers, > mark > > -- > Mark Mielke > Oracle scans the index pages, if the b-tree index is on non-nullable columns, or if the bitmap index is on low-ish cardinality data. Otherwise, it table scans. MyISAM in MySQL would be an example where a counter is kept.