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 BC4999FA435 for ; Tue, 12 Sep 2006 10:33:13 -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 41434-08 for ; Tue, 12 Sep 2006 10:33:02 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from lists.commandprompt.com (host-130.commandprompt.net [207.173.203.130]) by postgresql.org (Postfix) with ESMTP id 13E859FA1E2 for ; Tue, 12 Sep 2006 10:33:02 -0300 (ADT) Received: from alvh.no-ip.org (201-221-203-193.bk11-dsl.surnet.cl [201.221.203.193]) (authenticated bits=0) by lists.commandprompt.com (8.13.7/8.13.6) with ESMTP id k8CDWva2003536; Tue, 12 Sep 2006 06:32:57 -0700 Received: by alvh.no-ip.org (Postfix, from userid 1000) id 2184FC3716E; Tue, 12 Sep 2006 09:32:55 -0400 (CLT) Date: Tue, 12 Sep 2006 09:32:55 -0400 From: Alvaro Herrera To: Heikki Linnakangas Cc: Guillaume Cottenceau , pgsql-performance@postgresql.org Subject: Re: Poor performance on seq scan Message-ID: <20060912133254.GC11324@alvh.no-ip.org> Mail-Followup-To: Heikki Linnakangas , Guillaume Cottenceau , pgsql-performance@postgresql.org References: <450684EC.4090304@designaproduct.biz> <4506902C.7090407@enterprisedb.com> <4506A9E7.2060303@designaproduct.biz> <87y7spw8v9.fsf@meuh.mnc.lan> <4506B508.80806@enterprisedb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4506B508.80806@enterprisedb.com> User-Agent: Mutt/1.5.13 (2006-08-11) X-Virus-Scanned: ClamAV version 0.88.3, clamav-milter version 0.88.3 on projects.commandprompt.com X-Virus-Status: Clean X-Greylist: Sender succeded SMTP AUTH authentication, not delayed by milter-greylist-1.6 (lists.commandprompt.com [192.168.2.159]); Tue, 12 Sep 2006 06:32:58 -0700 (PDT) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=1.273 tagged_above=0 required=5 tests=AWL, BIZ_TLD, FORGED_RCVD_HELO X-Spam-Level: * X-Archive-Number: 200609/81 X-Sequence-Number: 20767 Heikki Linnakangas wrote: > Guillaume Cottenceau wrote: > >Laszlo Nagy writes: > > > >>>Probably, but PostgreSQL doesn't know how to do that. Even if it > >>>did, it depends on how many matches there is. If you scan the index > >>>and then fetch the matching rows from the heap, you're doing random > >>>I/O to the heap. That becomes slower than scanning the heap > >>>sequentially if you're going to get more than a few hits. > >>> > >>I have 700 000 rows in the table, and usually there are less than 500 > >>hits. So probably using a "seq index scan" would be faster. :-) Now I > >> > > > >You can confirm this idea by temporarily disabling sequential > >scans. Have a look at this chapter: > > I don't think it will anyway do a "seq index scan" as Laszlo envisions. > PostgreSQL cannot do "fetch index tuple and apply %Mug% to it. If it > matches, fetch heap tuple". Even if you disable sequential scans, it's > still going to fetch every heap tuple to see if it matches "%Mug%". It's > just going to do it in index order, which is slower than a seq scan. Are you saying that an indexscan "Filter" only acts after getting the heap tuple? If that's the case, then there's room for optimization here, namely if the affected column is part of the index key, then we could do the filtering before fetching the heap tuple. -- Alvaro Herrera http://www.CommandPrompt.com/ PostgreSQL Replication, Consulting, Custom Development, 24x7 support