From: Tom Lane <tgl@sss.pgh.pa.us>
To: FabrÃcio dos Anjos Silva <fabricio.silva@linkcom.com.br>
Cc: pgsql-performance@postgresql.org
Subject: Re: Wrong index choice
Date: Sun, 03 Oct 2010 17:39:54 -0400
Message-ID: <6006.1286141994@sss.pgh.pa.us> (raw)
In-Reply-To: <AANLkTimKtC1PLdyK6ToRHG-5GA_qmULtMvYQeFYpgtL+@mail.gmail.com>
References: <AANLkTikvrMuHC=+AqBEBd0gW-ahiLQ2c-U2gdW9KuWse@mail.gmail.com>
<AANLkTimKtC1PLdyK6ToRHG-5GA_qmULtMvYQeFYpgtL+@mail.gmail.com>
=?ISO-8859-1?Q?Fabr=EDcio_dos_Anjos_Silva?= <fabricio.silva@linkcom.com.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
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: tgl@sss.pgh.pa.us, fabricio.silva@linkcom.com.br
Subject: Re: Wrong index choice
In-Reply-To: <6006.1286141994@sss.pgh.pa.us>
* 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