Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 937F21288B2D for ; Wed, 1 Feb 2012 12:14:14 -0400 (AST) Received: from mahout.postgresql.org ([98.129.198.123]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Rscp3-00077K-Hx for pgsql-bugs@postgresql.org; Wed, 01 Feb 2012 16:14:14 +0000 Received: from [204.145.124.246] (helo=wrigleys.postgresql.org) by mahout.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Rscoq-0006YS-W9 for pgsql-bugs@postgresql.org; Wed, 01 Feb 2012 16:14:01 +0000 Received: from www-data by wrigleys.postgresql.org with local (Exim 4.72) (envelope-from ) id 1Rscoq-0002pv-Ep for pgsql-bugs@postgresql.org; Wed, 01 Feb 2012 16:14:00 +0000 Date: Wed, 01 Feb 2012 16:14:00 +0000 Message-Id: Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #6426: Complex query runs 10 times longer with "LIMIT 20" To: pgsql-bugs@postgresql.org From: aschetinin@gmail.com X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201202/11 X-Sequence-Number: 32354 The following bug has been logged on the website: Bug reference: 6426 Logged by: Andrew Schetinin Email address: aschetinin@gmail.com PostgreSQL version: 9.1.2 Operating system: Debian Linux Description: = I have a complex query that, when unlimited, runs in 2.5 seconds and returns 400+ records. The same query, with added "LIMIT 20 OFFSET 0" at the end, runs 25 seconds! (and returns correct 20 records) I think there is a bug in the query optimizer. Other variations of this query (with slightly different constraints and joins) work fast with and without LIMIT. = The same query works fast in PostgreSQL 8.4 (tested on another machine with Ubuntu and not exactly the same but very-very similar database). I can provide the query execution plans of the two cases (as long as they are not published on the Web); but not the database because there is customer's data in it. Please let me know if anybody is interested in researching the problem. Regards, Andrew Schetinin