Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id E09E29F9D8B for ; Thu, 9 Aug 2007 22:35:31 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 49929-04 for ; Thu, 9 Aug 2007 22:35:25 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 2D7B89F9CB3 for ; Thu, 9 Aug 2007 22:35:26 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.1/8.14.1) with ESMTP id l7A1ZDoI007475; Thu, 9 Aug 2007 21:35:14 -0400 (EDT) To: Andreas Joseph Krogh cc: pgsql-sql@postgresql.org, "Rodrigo De =?utf-8?q?Le=C3=B3n?=" Subject: Re: PG won't use index on ORDER BY In-reply-to: <200708092310.53309.andreak@officenet.no> References: <200708092018.44111.andreak@officenet.no> <200708092238.46284.andreak@officenet.no> <200708092310.53309.andreak@officenet.no> Comments: In-reply-to Andreas Joseph Krogh message dated "Thu, 09 Aug 2007 23:10:52 +0200" Date: Thu, 09 Aug 2007 21:35:13 -0400 Message-ID: <7474.1186709713@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200708/62 X-Sequence-Number: 29000 Andreas Joseph Krogh writes: > I forgot to mention: I use UTF-8. IIRC, it works fine with C-locale without > the "varchar_pattern_ops", which is why it works for you I think. That shouldn't make any difference, and doesn't for me in testing here: regression=# select version(); version ----------------------------------------------------------------------------------------------------------- PostgreSQL 8.2.4 on x86_64-unknown-linux-gnu, compiled by GCC gcc (GCC) 4.1.2 20070626 (Red Hat 4.1.2-13) (1 row) regression=# show lc_collate; lc_collate ------------ en_US.utf8 (1 row) regression=# show server_encoding ; server_encoding ----------------- UTF8 (1 row) regression=# \d person Table "public.person" Column | Type | Modifiers -----------+-------------------+----------------------------------------------------- id | integer | not null default nextval('person_id_seq'::regclass) firstname | character varying | lastname | character varying | Indexes: "person_pkey" PRIMARY KEY, btree (id) "person_lowerfullname_idx" btree ((lower(COALESCE(firstname, ''::character varying)::text) || lower(COALESCE(lastname, ''::character varying)::text))) regression=# explain select id from person order by (lower(COALESCE(firstname, '')) || lower(COALESCE(lastname, ''))) ASC limit 1; QUERY PLAN ------------------------------------------------------------------------------------------------- Limit (cost=0.00..0.08 rows=1 width=68) -> Index Scan using person_lowerfullname_idx on person (cost=0.00..62.25 rows=800 width=68) (2 rows) So there's something going on that you haven't told us about your installation. regards, tom lane