Re: sql query not using indexes

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Sergio de Almeida Lenzi <lenzi(at)k1(dot)com(dot)br>, pgsql-sql <pgsql-sql(at)postgresql(dot)org>
Subject: Re: sql query not using indexes
Date: 2000-09-22 17:12:02
Message-ID: Pine.BSF.4.10.10009221005340.66920-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Fri, 22 Sep 2000, Tom Lane wrote:

> indexscans; the current code may have overcorrected a shade, but I think
> it's closer to reality than 6.5 was.
>
> As Hiroshi already commented, the difference in results suggests that
> the desired data is very nonuniformly scattered in the table. 7.0
> computes cost estimates on the assumption that the target data is
> uniformly scattered. For a sufficiently nonselective WHERE condition
> (ie, one that the planner thinks will match a large fraction of the
> table's rows) it looks better to do a seqscan and pick up the matching
> rows than to follow the index pointers. Adding a LIMIT doesn't change
> this equation.
>
> I like Hiroshi's recommendation: add an ORDER BY to help favor the
> indexscan.

Yeah, I didn't notice the lack of the order by when I responded. I
forget that order by isn't required to use limit since it's fairly
ugly to not use one ("What, you wanted to get a implementation defined
effectively random 10 rows?")

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Jie Liang 2000-09-22 21:41:25 Re: how to store a query, that results in a table
Previous Message Tom Lane 2000-09-22 16:51:32 Re: sql query not using indexes