X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 33FE93A43B9 for ; Wed, 24 Nov 2004 17:37:28 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 85200-04 for ; Wed, 24 Nov 2004 17:37:15 +0000 (GMT) Received: from web54301.mail.yahoo.com (web54301.mail.yahoo.com [68.142.225.143]) by svr1.postgresql.org (Postfix) with SMTP id 1B6423A43D7 for ; Wed, 24 Nov 2004 17:37:00 +0000 (GMT) Received: (qmail 2443 invoked by uid 60001); 24 Nov 2004 17:36:59 -0000 Message-ID: <20041124173659.2441.qmail@web54301.mail.yahoo.com> Received: from [158.109.36.173] by web54301.mail.yahoo.com via HTTP; Wed, 24 Nov 2004 18:36:59 CET Date: Wed, 24 Nov 2004 18:36:59 +0100 (CET) From: sdfasdfas sdfasdfs Subject: "Group By " index usage To: pgsql-performance@postgresql.org MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200411/385 X-Sequence-Number: 9339 I have a table with this index: create index ARTISTS_NAME on ARTISTS ( lower(AR_NAME) ); 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 loops=1) 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) ~~ 'a%'::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" operator. ¿Could you help me? I am really lost. ______________________________________________ Renovamos el Correo Yahoo!: ¡100 MB GRATIS! Nuevos servicios, más seguridad http://correo.yahoo.es