Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 556159FB2E9 for ; Thu, 9 Aug 2007 20:52:50 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 07202-01-7 for ; Thu, 9 Aug 2007 20:52:36 -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 F3BAC9FC627 for ; Thu, 9 Aug 2007 20:51:59 -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 l79NZ9Ag003879; Thu, 9 Aug 2007 19:35:09 -0400 (EDT) To: Andreas Joseph Krogh cc: pgsql-sql@postgresql.org Subject: Re: PG won't use index on ORDER BY In-reply-to: <200708100015.34117.andreak@officenet.no> References: <200708092018.44111.andreak@officenet.no> <87fy2s1nrd.fsf@oxford.xeocode.com> <200708092238.46284.andreak@officenet.no> <200708100015.34117.andreak@officenet.no> Comments: In-reply-to Andreas Joseph Krogh message dated "Fri, 10 Aug 2007 00:15:33 +0200" Date: Thu, 09 Aug 2007 19:35:08 -0400 Message-ID: <3878.1186702508@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200708/61 X-Sequence-Number: 28999 Andreas Joseph Krogh writes: >> Another question then: Why doesn't "varchar_pattern_ops" handle ordering? It does handle ordering, just not the ordering you're asking for here. If you substituted USING ~<~ for ASC you'd find that the pattern_ops index could be used for that. >> This means I need 2 indexes on the columns I want to match with LIKE and >> ORDER BY. Just doesn't seem right to need 2 "similar" indexes... If you want to use the same index for both, you have to run the database in C locale. Non-C locales generally define a sort ordering that is not compatible with LIKE searches. (The point of the pattern_ops opclass is really to force C-locale ordering of the index when the ordinary text comparison operators yield a different ordering.) > -- This doesn't > EXPLAIN ANALYZE select firstname, lastname from person order by > concat_lower(firstname, lastname) ASC, created DESC limit 10; This ORDER BY is asking for an ordering that is almost completely unrelated to the index's ordering. regards, tom lane