Re: optimizer choosing the wrong index

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Merlin Moncure <mmoncure@gmail.com>
Cc: Martin Below <machtin.below@googlemail.com>, pgsql-general@postgresql.org
Date: 2010-07-08T18:53:15Z
Lists: pgsql-general
Merlin Moncure <mmoncure@gmail.com> writes:
> I think so too, but suppose we wanted to force the other plan anyways:
> select * from ps where (client_id, expires_on) >=
> ('123', '24.11.2010'::timestamp) and (client_id, expires_on) < ('123',
> null) order by client_id, expires_on;

A simpler way to force use of the other index is

	begin;
	drop index wrong_index;
	explain analyze my_query;
	rollback;

> I'd be curious to see explain analyze (not explain) comparisons for
> the 'wrong' index vs above.  I suspect the plan is 'correct' for
> *most* of the data, or you cherry picked (or unluckily drew) a bad
> value to get your 22 times speed difference.

Yeah, it would be interesting to see explain analyze output for both
cases, and for a few different values of the expires_on date if this
one is unlike the typical value.

			regards, tom lane