pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andreas Joseph Krogh <andreak@officenet.no>
Cc: pgsql-sql@postgresql.org
Subject: Re: PG won't use index on ORDER BY <expression>
Date: Thu, 09 Aug 2007 19:35:08 -0400
Message-ID: <3878.1186702508@sss.pgh.pa.us> (raw)
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>

Andreas Joseph Krogh <andreak@officenet.no> 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



view thread (9+ messages)  latest in thread

Message-ID: <3878.1186702508@sss.pgh.pa.us>
Permalink:  ../3878.1186702508@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/3878.1186702508@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, andreak@officenet.no
  Subject: Re: PG won't use index on ORDER BY <expression>
  In-Reply-To: <3878.1186702508@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox