Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id DB9AA9FA35D for ; Sat, 27 Oct 2007 01:26:27 -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 77686-07 for ; Sat, 27 Oct 2007 01:26:23 -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.180]) by postgresql.org (Postfix) with ESMTP id 810029FA358 for ; Sat, 27 Oct 2007 01:26:23 -0300 (ADT) Received: by wa-out-1112.google.com with SMTP id m38so1476862waf for ; Fri, 26 Oct 2007 21:26:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; 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; bh=4LgkHR1DqsWFBhU0l+OBDWLEdwc97aqna17FbIumuGU=; b=JgZha6XZxfU9UuDEU+C+Av6M3gDlhpoqhNTyvLD41IDM+AwuTeME6XU89y+7cuoBkK39MhGIrBCGalQSUh10VUg/6xOzQUOib8V3FijZ3AwRGfgYLpPrpgp6iwx8N1hJ8FJFP18HnRw0s7+4qR1kJOQ7mlWEIZP2eWY6CFPPeTA= 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=JeIMOp/bMOP5KDhXkTffwTnNaFW/C25CCG9x3dLwiOoOglcWRbB5+Upz5+qmpCZHsq93Ww0fUewpVrI9BuLY/F1uIjowXDl1483v3KToSI7IKy/HwI67OJ49cmsMbU5lJb/J2Lu7ikIwWzpg+e0EjMqYgCw16XmUTAbEwwkKNbE= Received: by 10.114.148.1 with SMTP id v1mr4276174wad.1193459181415; Fri, 26 Oct 2007 21:26:21 -0700 (PDT) Received: by 10.115.60.17 with HTTP; Fri, 26 Oct 2007 21:26:21 -0700 (PDT) Message-ID: <8cac8dd0710262126t147f8974rb58a1e7c615e0725@mail.gmail.com> Date: Sat, 27 Oct 2007 10:26:21 +0600 From: Anton To: pgsql-performance@postgresql.org Subject: Re: partitioned table and ORDER BY indexed_field DESC LIMIT 1 In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <46CEB522.9030907@enterprisedb.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200710/316 X-Sequence-Number: 27338 I want ask about problem with partioned tables (it was discussed some time ago, see below). Is it fixed somehow in 8.2.5 ? 2007/8/24, Luke Lonergan : > Below is a patch against 8.2.4 (more or less), Heikki can you take a look at > it? > > This enables the use of index scan of a child table by recognizing sort > order of the append node. Kurt Harriman did the work. ... > > On 8/24/07 3:38 AM, "Heikki Linnakangas" wrote: > > > Anton wrote: > >>>> =# 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? > > > > The planner isn't smart enough to push the "ORDER BY ... LIMIT ..." > > below the append node. Therefore it needs to fetch all rows from all the > > tables, and the fastest way to do that is a seq scan. -- engineer