Skip site navigation (1) Skip section navigation (2)

Re: Wrong index used when ORDER BY LIMIT 1

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Szűcs Gábor <surrano(at)gmail(dot)com>
Cc: "pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Wrong index used when ORDER BY LIMIT 1
Date: 2005-12-21 19:34:19
Message-ID: 15421.1135193659@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-performance
=?ISO-8859-2?Q?Sz=FBcs_G=E1bor?= <surrano(at)gmail(dot)com> writes:
> Query is:
> SELECT idopont WHERE muvelet = x ORDER BY idopont LIMIT 1.

Much the best solution for this would be to have an index on
	(muvelet, idopont)
--- perhaps you can reorder the columns of "muvelet_vonalkod_muvelet"
instead of making a whole new index --- and then say

	SELECT idopont WHERE muvelet = x ORDER BY muvelet, idopont LIMIT 1

PG 8.1 can apply such an index to your original query, but older
versions will need the help of the modified ORDER BY to recognize
that the index is usable.

			regards, tom lane

In response to

Responses

pgsql-performance by date

Next:From: Tom LaneDate: 2005-12-21 19:39:35
Subject: Re: ORDER BY costs
Previous:From: Michael FuhrDate: 2005-12-21 18:51:02
Subject: Re: Wrong index used when ORDER BY LIMIT 1

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group