Re: Is this expected? (Index scanning)

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Mitch Vincent <mitch(at)venux(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Is this expected? (Index scanning)
Date: 2001-05-07 03:10:02
Message-ID: Pine.BSF.4.21.0105062003200.74573-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sun, 6 May 2001, Mitch Vincent wrote:

> Indexes on both void and lower(cust_name) here..
>
> I get ->
>
> EXPLAIN select * from invoice_master WHERE lower(cust_name) like 'mitch' AND
> void = 'f' order by created LIMIT 100;
> NOTICE: QUERY PLAN:
>
> Limit (cost=2241.98..2241.98 rows=100 width=319)
> -> Sort (cost=2241.98..2241.98 rows=604 width=319)
> -> Index Scan using invoice_cust_name on invoice_master
> (cost=0.00..2214.09 rows=604 width=319)
>
> The above query matches zero rows.
>
> EXPLAIN SELECT * FROM invoice_master WHERE lower(cust_name) like '%mitch'
> AND void = 'f' ORDER BY created LIMIT 100;
> NOTICE: QUERY PLAN:
>
> Limit (cost=4310.65..4310.65 rows=1 width=319)
> -> Sort (cost=4310.65..4310.65 rows=1 width=319)
> -> Seq Scan on invoice_master (cost=0.00..4310.64 rows=1
> width=319)
>
> The above query matches zero rows.
>
> EXPLAIN SELECT * FROM invoice_master WHERE lower(cust_name) like 'mitch%'
> AND void = 'f' ORDER BY created LIMIT 100;
> NOTICE: QUERY PLAN:
>
> Limit (cost=2241.98..2241.98 rows=100 width=319)
> -> Sort (cost=2241.98..2241.98 rows=604 width=319)
> -> Index Scan using invoice_cust_name on invoice_master
> (cost=0.00..2214.09 rows=604 width=319)
>
> The above query matches 53 rows..

In the first and last case the like is anchored at the beginning so it
uses the name index. The middle case can't use that index, and how
well distributed are the values of void (is it a boolean?)? It's likely
that the index isn't very selective, if most of the rows are void='f'
then that index is probably more expensive to scan than the sequence scan
would be.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andrey Mikuloff 2001-05-07 03:42:00 bugs or no in PostgreSQL 7.1 ?
Previous Message Mitch Vincent 2001-05-07 02:19:05 Is this expected? (Index scanning)