X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 6772AD7811 for ; Mon, 7 Nov 2005 05:51:34 -0400 (AST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 72554-08 for ; Mon, 7 Nov 2005 09:51:31 +0000 (GMT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75]) by svr1.postgresql.org (Postfix) with ESMTP id 5AE7AD680C for ; Mon, 7 Nov 2005 05:51:31 -0400 (AST) Received: from mainbox.archonet.com (84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99]) by smtp.metronet.co.uk (MetroNet Mail) with ESMTP id E55A7418423; Mon, 7 Nov 2005 09:51:24 +0000 (GMT) Received: from localhost (localhost.localdomain [127.0.0.1]) by mainbox.archonet.com (Postfix) with ESMTP id 69D5515EDA; Mon, 7 Nov 2005 09:46:44 +0000 (GMT) Received: from mainbox.archonet.com ([127.0.0.1]) by localhost (mainbox [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 22981-03; Mon, 7 Nov 2005 09:46:39 +0000 (GMT) Received: from [192.168.1.17] (client17.office.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 0545415ED9; Mon, 7 Nov 2005 09:46:39 +0000 (GMT) Message-ID: <436F227E.3060805@archonet.com> Date: Mon, 07 Nov 2005 09:46:38 +0000 From: Richard Huxton User-Agent: Mozilla Thunderbird 1.0.7 (X11/20051013) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Jeroen van Iddekinge Cc: pgsql-performance@postgresql.org Subject: Re: Performance problem with pg8.0 References: <436E453F.3060606@lycos.com> In-Reply-To: <436E453F.3060606@lycos.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.033 required=5 tests=[AWL=0.033] X-Spam-Score: 0.033 X-Spam-Level: X-Archive-Number: 200511/117 X-Sequence-Number: 15374 Jeroen van Iddekinge wrote: > Hello, > > I have some strange performance problems with quering a table.It has > 5282864, rows and contains the following columns : id > ,no,id_words,position,senpos and sentence all are integer non null. > > Index on : > * no > * no,id_words > * id_words > * senpos, sentence, "no") > * d=primary key > > "select count(1) from words_in_text" takes 9 seconds to compleet. Because it's reading through the whole table. See mailing list archives for discussion of why it doesn't just use an index. > The query 'select * from words_in_text' takes a verry long time to > return the first record (more that 2 minutes) why? A long time for the first row, hardly any time for the others. That's because it assembles all the rows and returns them at the same time. If you don't want all the rows at once use a cursor. > Also the following query behaves strange. > select * from words_in_text where no <100 order by no; > explain shows that pg is using sequence scan. When i turn of sequence > scan, index scan is used and is faster. I have a 'Explain verbose > analyze' of this query is at the end of the mail. It's just the "explain analyze" that's needed - the "verbose" gives far more detail than you'll want at this stage. > The number of estimated rows is wrong, so I did 'set statistics 1000' on > column no. After this the estimated number of rows was ok, but pg still > was using seq scan. I don't see the correct row estimate - it looks like it's getting it wrong again to me. > Can anyone explain why pg is using sequence and not index scan? There's one of two reasons: 1. It thinks it's going to fetch more rows than it does. 2. It has the relative costs of a seq-scan vs index accesses wrong. Can you try an "EXPLAIN ANALYZE" of select * from words_in_text where no < 100 AND no >= 0 order by no; Substitute whatever lower bound is sensible for "no". Let's see if that gives the system a clue. Then, we'll need to look at your other tuning settings. Have you made any changes to your postgresql.conf settings, in particular those mentioned here: http://www.powerpostgresql.com/PerfList -- Richard Huxton Archonet Ltd