Skip site navigation (1) Skip section navigation (2)

Re: "Group By " index usage

From: "Alban Medici (NetCentrex)" <amedici(at)fr(dot)netcentrex(dot)net>
To: <pgsql-performance(at)postgresql(dot)org>
Subject: Re: "Group By " index usage
Date: 2004-11-30 16:04:58
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-performance
 Did you test with ILIKE instead of lower LIKE lower ?

-----Original Message-----
From: pgsql-performance-owner(at)postgresql(dot)org
[mailto:pgsql-performance-owner(at)postgresql(dot)org] On Behalf Of sdfasdfas
Sent: mercredi 24 novembre 2004 18:37
To: pgsql-performance(at)postgresql(dot)org
Subject: [PERFORM] "Group By " index usage

I have a table with this index:

 create index ARTISTS_NAME on ARTISTS (

Te index is over a colum with this definition:

 AR_NAME              VARCHAR(256)         null,

I want to optimize this query:

 select * from artists where lower(ar_name) like
lower('a%') order by lower(ar_name) limit 20;

I think the planner should use the index i have. But the result of the
explain command is:

 explain analyze select * from artists where
lower(ar_name) like lower('a%') order by
lower(ar_name) limit 20;

            QUERY PLAN   
 Limit  (cost=20420.09..20420.14 rows=20 width=360) (actual
time=2094.13..2094.19 rows=20 loops=1)
   ->  Sort  (cost=20420.09..20433.52 rows=5374
width=360) (actual time=2094.13..2094.16 rows=21
         Sort Key: lower((ar_name)::text)
         ->  Index Scan using artists_name on artists
(cost=0.00..19567.09 rows=5374 width=360) (actual
time=0.11..1391.97 rows=59047 loops=1)
               Index Cond: ((lower((ar_name)::text) >=
'a'::text) AND (lower((ar_name)::text) < 'b'::text))
               Filter: (lower((ar_name)::text) ~~
 Total runtime: 2098.62 msec
(7 rows)

The "ORDER BY" clause is not using the index!. I don't know why.

I have the locale configured to C, and the index works well with the "like"

¿Could you help me? I am really lost. 

Renovamos el Correo Yahoo!: ¡100 MB GRATIS!
Nuevos servicios, más seguridad

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

In response to

pgsql-performance by date

Next:From: Josh BerkusDate: 2004-12-01 00:26:42
Subject: Re: Hardware purchase question
Previous:From: Thomas SwanDate: 2004-11-30 15:42:04
Subject: Re: VACUUM ANALYZE downgrades performance

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group