X-Original-To: pgsql-performance-postgresql.org@postgresql.org Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id 128969FA4A7 for ; Tue, 12 Sep 2006 07:47:48 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 07558-06 for ; Tue, 12 Sep 2006 10:47:39 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey- Received: from webmail.enterprisedb.com (edb04.managed.contegix.com [63.246.7.176]) by postgresql.org (Postfix) with ESMTP id 510C39FA45F for ; Tue, 12 Sep 2006 07:47:39 -0300 (ADT) Received: from [192.168.0.20] (unknown [62.232.55.118]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by webmail.enterprisedb.com (Postfix) with ESMTP id 20322A24C5F; Tue, 12 Sep 2006 05:47:36 -0500 (CDT) Message-ID: <4506902C.7090407@enterprisedb.com> Date: Tue, 12 Sep 2006 11:47:08 +0100 From: Heikki Linnakangas User-Agent: Thunderbird 1.5.0.5 (X11/20060812) MIME-Version: 1.0 To: Laszlo Nagy CC: pgsql-performance@postgresql.org Subject: Re: Poor performance on seq scan References: <450684EC.4090304@designaproduct.biz> In-Reply-To: <450684EC.4090304@designaproduct.biz> Content-Type: text/plain; charset=ISO-8859-2; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.135 tagged_above=0 required=5 tests=FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200609/74 X-Sequence-Number: 20760 Laszlo Nagy wrote: > I made another test. I create a file with the identifiers and names of > the products: > > psql#\o products.txt > psql#select id,name from product; > > Then I can search using grep: > > grep "Mug" products.txt | cut -f1 -d\| > > There is a huge difference. This command runs within 0.5 seconds. That > is, at least 76 times faster than the seq scan. It is the same if I > vacuum, backup and restore the database. I thought that the table is > stored in one file, and the seq scan will be actually faster than > grepping the file. Can you please tell me what am I doing wrong? I'm > not sure if I can increase the performance of a seq scan by adjusting > the values in postgresql.conf. I do not like the idea of exporting the > product table periodically into a txt file, and search with grep. :-) Is there any other columns besides id and name in the table? How big is products.txt compared to the heap file? > Another question: I have a btree index on product(name). It contains > all product names and the identifiers of the products. Wouldn't it be > easier to seq scan the index instead of seq scan the table? The index > is only 66MB, the table is 1123MB. 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. -- Heikki Linnakangas EnterpriseDB http://www.enterprisedb.com