Re: Help on query plan.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "William N(dot) Zanatta" <william(at)veritel(dot)com(dot)br>
Cc: pgsql-general(at)postgresql(dot)org, sszabo(at)megazone23(dot)bigpanda(dot)com
Subject: Re: Help on query plan.
Date: 2003-01-21 16:47:44
Message-ID: 3410.1043167664@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"William N. Zanatta" <william(at)veritel(dot)com(dot)br> writes:
> And now, the same query with enable_seqscan set to OFF.

> explain analyze select * from tbl_access where((ip >='12'::character
> varying) AND (ip < '13'::character varying));
> QUERY PLAN

> ----------------------------------------------------------------------------------------------------------------------------------
> Index Scan using teste1 on tbl_access (cost=0.00..63182.79 rows=16968
> width=133) (actual time=0.91..1813.32 rows=20318 loops=1)
> Index Cond: ((ip >= '12'::character varying) AND (ip <
> '13'::character varying))
> Total runtime: 1863.33 msec

Okay, so the rows estimate isn't too far off (17k vs 20k) --- you could
doubtless make it more accurate by increasing the statistics target, but
that won't help here (the cost estimate would actually go up).

So the index is selecting about 1.7% of the table in this case. For
randomly-scattered rows, that's usually near the threshold of where an
indexscan stops making sense. Given the very low actual runtime of the
indexscan, I have to guess that the data is not randomly scattered but
is actually pretty well clustered --- and that the planner is failing
to account for that effect adequately.

What does pg_stats show as the correlation value for the ip column?
If you increase the statistics target and re-ANALYZE, does the
correlation value change?

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Peter Childs 2003-01-21 16:56:08 Logging of queryies
Previous Message William N. Zanatta 2003-01-21 16:33:49 Re: Help on query plan.