pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Gaetano Mendola <mendola@bigfoot.com>
To: pgsql-performance@postgresql.org <pgsql-performance@postgresql.org>
Cc: Michael Fuhr <mike@fuhr.org>
Subject: Re: Wrong plan sequential scan instead of an index one
Date: Fri, 30 Mar 2007 13:32:34 +0200
Message-ID: <460CF552.5000903@bigfoot.com> (raw)
In-Reply-To: <20070330104611.GA1540@winnie.fuhr.org>
References: <460CD941.6080303@bigfoot.com>
	<b41c75520703300251oe916648r75c16c1bf70cd10@mail.gmail.com>
	<460CE19A.3060909@bigfoot.com>
	<20070330104611.GA1540@winnie.fuhr.org>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Michael Fuhr wrote:
> On Fri, Mar 30, 2007 at 12:08:26PM +0200, Gaetano Mendola wrote:
>> Claus Guttesen wrote:
>>> Try changing random_page_cost from the default 4 to 2 in postgresql.conf:
>>>
>>> random_page_cost = 2
>> I have tuned that number already at 2.5, lowering it to 2 doesn't change
>> the plan.
> 
> The following 19-fold overestimate is influencing the rest of the
> plan:
> 
>   ->  Seq Scan on l_pvcp  (cost=0.00..2.17 rows=19 width=4) (actual time=0.066..0.081 rows=1 loops=1)
>         Filter: (value ~~* '%pi%'::text)
> 
> Have you tried increasing the statistics target on l_pvcp.value?
> I ran your queries against canned data in 8.2.3 and better statistics
> resulted in more accurate row count estimates for this and other
> parts of the plan.  I don't recall if estimates for non-leading-character
> matches in earlier versions can benefit from better statistics.
> 


test=# alter table l_pvcp alter column value set statistics 1000;
ALTER TABLE
test=# analyze l_pvcp;
ANALYZE
test=# explain analyze SELECT COUNT(id) FROM t_oa_2_00_card WHERE pvcp in (select id from l_pvcp where value ilike '%pi%');
                                                              QUERY PLAN
- ---------------------------------------------------------------------------------------------------------------------------------------
 Aggregate  (cost=154321.83..154321.84 rows=1 width=8) (actual time=4948.627..4948.628 rows=1 loops=1)
   ->  Hash IN Join  (cost=2.22..153877.08 rows=177898 width=8) (actual time=2.262..4940.395 rows=7801 loops=1)
         Hash Cond: ("outer".pvcp = "inner".id)
         ->  Seq Scan on t_oa_2_00_card  (cost=0.00..147695.25 rows=880125 width=12) (actual time=0.040..3850.074 rows=877682 loops=1)
         ->  Hash  (cost=2.17..2.17 rows=19 width=4) (actual time=0.073..0.073 rows=1 loops=1)
               ->  Seq Scan on l_pvcp  (cost=0.00..2.17 rows=19 width=4) (actual time=0.052..0.067 rows=1 loops=1)
                     Filter: (value ~~* '%pi%'::text)
 Total runtime: 4948.717 ms
(8 rows)


and nothing changed.


Regards
Gaetano Mendola

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGDPVS7UpzwH2SGd4RAp+DAJ9Z5HdDcKx9rOQDbm+uAdb8uEc8OgCgjGmM
Z351j5icCHT4yMOLEu3ZcJY=
=CY1c
-----END PGP SIGNATURE-----



view thread (15+ messages)  latest in thread

Message-ID: <460CF552.5000903@bigfoot.com>
Permalink:  ../460CF552.5000903@bigfoot.com/
Also on:    postgresql.org/message-id/460CF552.5000903@bigfoot.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: mendola@bigfoot.com, mike@fuhr.org
  Subject: Re: Wrong plan sequential scan instead of an index one
  In-Reply-To: <460CF552.5000903@bigfoot.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox