X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 436659DCBDF for ; Wed, 21 Dec 2005 15:34:24 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 04276-05 for ; Wed, 21 Dec 2005 15:34:23 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 4BBD99DCBF5 for ; Wed, 21 Dec 2005 15:34:21 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id jBLJYJhR015422; Wed, 21 Dec 2005 14:34:20 -0500 (EST) To: =?ISO-8859-2?Q?Sz=FBcs_G=E1bor?= cc: "pgsql-performance@postgresql.org" Subject: Re: Wrong index used when ORDER BY LIMIT 1 In-reply-to: <43A998D4.4070300@gmail.com> References: <43A998D4.4070300@gmail.com> Comments: In-reply-to =?ISO-8859-2?Q?Sz=FBcs_G=E1bor?= message dated "Wed, 21 Dec 2005 19:03:00 +0100" Date: Wed, 21 Dec 2005 14:34:19 -0500 Message-ID: <15421.1135193659@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.029 required=5 tests=[AWL=0.029] X-Spam-Score: 0.029 X-Spam-Level: X-Archive-Number: 200512/541 X-Sequence-Number: 16362 =?ISO-8859-2?Q?Sz=FBcs_G=E1bor?= 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