Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V59vr-0005kS-40 for pgsql-performance@arkaria.postgresql.org; Fri, 02 Aug 2013 07:37:51 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1V59vq-0006uY-Ja for pgsql-performance@arkaria.postgresql.org; Fri, 02 Aug 2013 07:37:50 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V59vp-0006uR-NL for pgsql-performance@postgresql.org; Fri, 02 Aug 2013 07:37:49 +0000 Received: from mimolette.dalibo.net ([212.85.154.222]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V59vm-0004bC-Ux for pgsql-performance@postgresql.org; Fri, 02 Aug 2013 07:37:49 +0000 Received: from [192.168.0.38] (ip-68.net-81-220-133.standre.rev.numericable.fr [81.220.133.68]) by mimolette.dalibo.net (Postfix) with ESMTPSA id B6C384501D2B; Fri, 2 Aug 2013 09:37:45 +0200 (CEST) Message-ID: <51FB61C8.4090206@dalibo.com> Date: Fri, 02 Aug 2013 09:37:44 +0200 From: Vik Fearing User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130623 Thunderbird/17.0.7 MIME-Version: 1.0 To: Scott Marlowe CC: Tom Lane , "pgsql-performance@postgresql.org" Subject: Re: subselect requires offset 0 for good performance. References: <4522.1375400642@sss.pgh.pa.us> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org On 08/02/2013 03:22 AM, Scott Marlowe wrote: > On Thu, Aug 1, 2013 at 5:44 PM, Tom Lane wrote: >> Scott Marlowe writes: >>> I am running 8.4.15 and can try 8.4.17 if some patch has been applied >>> to it to address this issue. I just want to know should I >>> A: upgrade to 8.4.17 >>> or >>> B: create a self contained test case. >> A quick look at the release notes shows no planner fixes in 8.4.16 or >> 8.4.17, so it would be rather surprising if (A) helps. > OK. I was doing some initial testing and if I select out the 4 columns > into a test table the query runs fast. If I select all the columns > into a test table it runs slow, so it appears table width affects > this. Will have more to report tomorrow on it. I don't know what your query is, but here's one I was working on yesterday that shows the problem. It may not be the smallest test case possible, but it works. EXPLAIN ANALYZE WITH RECURSIVE x (start_time) AS ( SELECT generate_series(1, 1000000) ), t (time, timeround) AS ( SELECT time, time - time % 900000 AS timeround FROM (SELECT min(start_time) AS time FROM x) AS tmp UNION ALL SELECT time, time - time % 900000 FROM (SELECT (SELECT min(start_time) AS time FROM x WHERE start_time >= t.timeround + 900000) FROM t WHERE t.time IS NOT NULL OFFSET 0 ) tmp ) SELECT count(*) FROM t WHERE time IS NOT NULL; If you remove the OFFSET 0, you'll see two more subplans (because "time" is referenced three times). The difference is much more noticeable if you make the x CTE its own table. Vik PS: This query is emulating a LooseIndexScan. http://wiki.postgresql.org/wiki/Loose_indexscan -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance