From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Fabrício dos Anjos Silva <fabricio(dot)silva(at)linkcom(dot)com(dot)br> |
Cc: | pgsql-performance(at)postgresql(dot)org |
Subject: | Re: Wrong index choice |
Date: | 2010-10-03 21:39:54 |
Message-ID: | 6006.1286141994@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-performance |
=?ISO-8859-1?Q?Fabr=EDcio_dos_Anjos_Silva?= <fabricio(dot)silva(at)linkcom(dot)com(dot)br> writes:
> explain analyze select max(cnpj) from empresa where dtcriacao >=
> current_date-5;
> QUERY
> PLAN
> -----------------------------------------------------------------------------------------
> Result (cost=32.24..32.24 rows=1 width=0) (actual time=5223.937..5223.938
> rows=1 loops=1)
> InitPlan 1 (returns $0)
> -> Limit (cost=0.00..32.24 rows=1 width=15) (actual
> time=5223.921..5223.922 rows=1 loops=1)
> -> Index Scan Backward using idx_cnpj on empresa
> (cost=0.00..65925.02 rows=2045 width=15) (actual time=5223.913..5223.913
> rows=1 loops=1)
> Index Cond: ((cnpj)::text IS NOT NULL)
> Filter: (dtcriacao >= (('now'::text)::date - 5))
> Total runtime: 5224.037 ms
> (7 rows)
BTW, a large part of the reason that it's switching to this plan type
too soon is that you've got random_page_cost set really small:
> seq_page_cost = 0.01
> random_page_cost = 0.01
I think you need to back those off by an order of magnitude or so.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Greg Smith | 2010-10-04 03:07:27 | Re: How does PG know if data is in memory? |
Previous Message | Craig Ringer | 2010-10-03 02:42:45 | Re: How does PG know if data is in memory? |