Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TNoin-0000Bj-7p for pgsql-performance@postgresql.org; Mon, 15 Oct 2012 17:44:57 +0000 Received: from llsa731-a03.servidoresdns.net ([82.223.190.25]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TNoig-0003X9-H9 for pgsql-performance@postgresql.org; Mon, 15 Oct 2012 17:44:56 +0000 Received: from [150.214.57.156] (jmcortes.ctima.uma.es [150.214.57.156]) by llsa731-a03.servidoresdns.net (Postfix) with ESMTPA id 6E7BA5404C7 for ; Mon, 15 Oct 2012 19:44:47 +0200 (CEST) Message-ID: <507C4B8E.3010806@ismsolar.com> Date: Mon, 15 Oct 2012 19:44:46 +0200 From: =?ISO-8859-1?Q?Pedro_Jim=E9nez?= User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20121005 Thunderbird/16.0 MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: limit order by performance issue Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201210/213 X-Sequence-Number: 48172 Hello, I'm trying to do a simple SQL query over Postgresl 9.0 running on Ubuntu. I have a large table (over 100 million records) with three fields, id_signal (bigint), time_stamp (timestamp) and var_value (float). My query looks like this: select var_value from ism_floatvalues where id_signal = 29660 order by time_stamp desc limit 1; So I want to select the last value from a determinated ID (is_signal). This query runs FOREVER, while if I delete "limit 1" it runs instantly.... Any help? Regards.