X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 777B4D1BACD for ; Wed, 21 Apr 2004 05:34:53 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 45089-08 for ; Wed, 21 Apr 2004 05:34:52 -0300 (ADT) Received: from FE-mail04.sfg.albacom.net (FE-mail04.albacom.net [213.217.149.84]) by svr1.postgresql.org (Postfix) with ESMTP id ADF96D1BABD for ; Wed, 21 Apr 2004 05:34:50 -0300 (ADT) Received: from axa.it (217.221.80.72) by FE-mail04.sfg.albacom.net (7.0.009) id 40757DA1000F0A8A; Wed, 21 Apr 2004 10:34:48 +0200 Message-ID: <40863228.907@axa.it> Date: Wed, 21 Apr 2004 10:34:48 +0200 From: Edoardo Ceccarelli User-Agent: Mozilla Thunderbird 0.5 (Windows/20040207) X-Accept-Language: it, en, en-us MIME-Version: 1.0 To: Nick Barr Cc: pgsql-performance@postgresql.org Subject: Re: slow seqscan References: <40862003.2090201@axa.it> <4086272E.2080102@chuckie.co.uk> In-Reply-To: <4086272E.2080102@chuckie.co.uk> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200404/336 X-Sequence-Number: 6636 > > In general we are going to need more information, like what kind of > search filters you are using on the text field and an EXPLAIN ANALYZE. > But can you try and run the following, bearing in mind it will take a > while to complete. > > REINDEX TABLE > > From what I remember there were issues with index space not being > reclaimed in a vacuum. I believe this was fixed in 7.4. By not > reclaiming the space the indexes grow larger and larger over time, > causing PG to prefer a sequential scan over an index scan (I think). > > The query is this: SELECT *, oid FROM annuncio400 WHERE rubric = 'DD' AND LOWER(testo) Like LOWER('cbr%') OFFSET 0 LIMIT 11 dba400=# explain analyze SELECT *, oid FROM annuncio400 WHERE rubric = 'DD' AND LOWER(testo) Like LOWER('cbr%') OFFSET 0 LIMIT 11; QUERY PLAN -------------------------------------------------------------------------------------------------------------------- Limit (cost=0.00..3116.00 rows=11 width=546) (actual time=51.47..56.42 rows=11 loops=1) -> Seq Scan on annuncio400 (cost=0.00..35490.60 rows=125 width=546) (actual time=51.47..56.40 rows=12 loops=1) Filter: ((rubric = 'DD'::bpchar) AND (lower((testo)::text) ~~ 'cbr%'::text)) Total runtime: 56.53 msec (4 rows) But the strangest thing ever is that if I change the filter with another one that represent a smaller amount of data it uses the index scan!!! check this (same table, same query, different rubric=MA index): dba400=# explain analyze SELECT *, oid FROM annuncio400 WHERE rubric = 'MA' AND LOWER(testo) Like LOWER('cbr%') OFFSET 0 LIMIT 11; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------- Limit (cost=0.00..6630.72 rows=9 width=546) (actual time=42.74..42.74 rows=0 loops=1) -> Index Scan using rubric on annuncio400 (cost=0.00..6968.48 rows=9 width=546) (actual time=42.73..42.73 rows=0 loops=1) Index Cond: (rubric = 'MA'::bpchar) Filter: (lower((testo)::text) ~~ 'cbr%'::text) Total runtime: 42.81 msec (5 rows) Thanks for your help Edoardo > >