Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TjB0I-0007xY-Nf for pgsql-performance@arkaria.postgresql.org; Thu, 13 Dec 2012 15:47:18 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1TjB0I-0006PV-5Z for pgsql-performance@arkaria.postgresql.org; Thu, 13 Dec 2012 15:47:18 +0000 Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TjB0G-0006OG-JD for pgsql-performance@postgresql.org; Thu, 13 Dec 2012 15:47:16 +0000 Received: from mailout-us.gmx.com ([74.208.5.67]) by makus.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1TjB0F-0002Dt-Kt for pgsql-performance@postgresql.org; Thu, 13 Dec 2012 15:47:16 +0000 Received: (qmail 27952 invoked by uid 0); 13 Dec 2012 15:47:14 -0000 Received: from 76.255.19.161 by rms-us020 with HTTP Cc: "pgsql-performance" Content-Type: text/plain; charset="utf-8" Date: Thu, 13 Dec 2012 10:47:14 -0500 From: "Kevin Grittner" Message-ID: <20121213154714.80050@gmx.com> MIME-Version: 1.0 Subject: Re: Limit & offset effect on query plans To: "Pavan Deolasee" ,"Amitabh Kant" X-Authenticated: #138763884 X-Flags: 0001 X-Mailer: GMX.com Web Mailer x-registered: 0 Content-Transfer-Encoding: 8bit X-GMX-UID: 1Z27cCF+3zOlOQ09LnwhccZ+IGRvbwAM 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 Pavan Deolasee wrote: > Amitabh Kant wrote: >> Our scripts automatically add "LIMIT ALL" & "OFFSET 0" to every >> select query if no values are passed on for these parameters. I >> remember reading through the mailing list that it's better not >> to pass them if they are not needed as they add a cost to the >> query plan. Is this the case, or am i looking at a very minor >> optimization. >> > > I would tend to think that is the latter. While undoubtedly > limit/offset clause will add another node during query planning > and execution, AFAICS the OFFSET 0 and LIMIT ALL cases are > optimized to a good extent. So the overhead of having them will > not be significant. I ran some quick tests on my i7 under Linux. Plan time was increased by about 40 microseconds (based on EXPLAIN runtime) and added a limit node to the plan. Execution time on a SELECT * FROM tenk1 in the regression database went up by 1.35 ms on fully cached runs. -Kevin -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance