Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 1F9909F9A27 for ; Fri, 24 Aug 2007 07:32:48 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 40695-10 for ; Fri, 24 Aug 2007 07:32:45 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from wa-out-1112.google.com (wa-out-1112.google.com [209.85.146.182]) by postgresql.org (Postfix) with ESMTP id 0E8F69F9A1B for ; Fri, 24 Aug 2007 07:32:44 -0300 (ADT) Received: by wa-out-1112.google.com with SMTP id v27so935530wah for ; Fri, 24 Aug 2007 03:32:43 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=FDAFLpFLafii54g8ELmJV9HcM473wgZvFLOlvgtLEKSW6KZsA4IrNWzB1slSlC44d0FdrTDNHc2gtQa5+Mzx3F0v8JHnE5ivcKvcNhJ/AAcQNtZfb8NzYZvms7H/yjL1kkRix+q2lhgAJ+Q1zRtxBynwyWBPdeUhvRY+DBvZaIY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=kJw3TI6H6YJg8RNLIlfeFGYF8YkIR+w4wtL3gzL5nTbgHxZgUJZGbEb5AKGnG3fYIY+f5OQ6cKu8iBoLGALvo1jay80FB/tEvFPEkri8l3drZqS6XhpMeKA+DqJbdjItaEIjqdXOe7Abh0KBNBhT/w0rN+5Wh46XCJUUaOd3JFk= Received: by 10.114.176.1 with SMTP id y1mr868996wae.1187951563115; Fri, 24 Aug 2007 03:32:43 -0700 (PDT) Received: by 10.114.240.13 with HTTP; Fri, 24 Aug 2007 03:32:43 -0700 (PDT) Message-ID: <8cac8dd0708240332p5f213616ldf71290e725f4593@mail.gmail.com> Date: Fri, 24 Aug 2007 16:32:43 +0600 From: Anton To: pgsql-performance@postgresql.org Subject: Re: partitioned table and ORDER BY indexed_field DESC LIMIT 1 In-Reply-To: <2ca799770708240324w155857e8m5911cbd5c6ff2307@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <8cac8dd0708240153p4f3ef2d9xae912259926d860@mail.gmail.com> <2ca799770708240324w155857e8m5911cbd5c6ff2307@mail.gmail.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200708/283 X-Sequence-Number: 26413 > > =# explain SELECT * FROM n_traf ORDER BY date_time DESC LIMIT 1; > > QUERY PLAN > --------------------------------------------------------------------------------------------------------- > > Limit (cost=824637.69..824637.69 rows=1 width=32) > > -> Sort (cost=824637.69..838746.44 rows=5643499 width=32) > > Sort Key: public.n_traf.date_time > > -> Result (cost=0.00..100877.99 rows=5643499 width=32) > > -> Append (cost= 0.00..100877.99 rows=5643499 width=32) > > -> Seq Scan on n_traf (cost=0.00..22.30 > > rows=1230 width=32) > > -> Seq Scan on n_traf_y2007m01 n_traf > > (cost=0.00..22.30 rows=1230 width=32) ... > > -> Seq Scan on n_traf_y2007m12 n_traf > > (cost=0.00..22.30 rows=1230 width=32) > > (18 rows) > > > > Why it no uses indexes at all? > > ------------------------------------------- > I'm no expert but I'd guess that the the planner doesn't know which > partition holds the latest time so it has to read them all. Agree. But why it not uses indexes when it reading them? -- engineer