Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YkYMB-00040m-Jg for pgsql-bugs@arkaria.postgresql.org; Tue, 21 Apr 2015 13:36:55 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YkYMB-0005fo-2V for pgsql-bugs@arkaria.postgresql.org; Tue, 21 Apr 2015 13:36:55 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YkSQe-0001FD-AU for pgsql-bugs@postgresql.org; Tue, 21 Apr 2015 07:17:08 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YkSQZ-0002RM-Bm for pgsql-bugs@postgresql.org; Tue, 21 Apr 2015 07:17:06 +0000 MIME-Version: 1.0 Subject: BUG #13112: Catastrophic performance degradation without DISTINCT ON statement To: pgsql-bugs@postgresql.org From: oyvind.harboe@zylin.com Date: Tue, 21 Apr 2015 07:16:22 +0000 Message-ID: <20150421071622.5211.13275@wrigleys.postgresql.org> X-Pg-Spam-Score: -1.9 (-) Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org The following bug has been logged on the website: Bug reference: 13112 Logged by: Øyvind Harboe Email address: oyvind.harboe@zylin.com PostgreSQL version: 9.1.0 Operating system: Ubuntu Description: I've been testing out PostgreSQL vs. Derby/MS SQL for our application when I ran into a problem where the performance of PostgreSQL went from great to abysmal for no apparent reason. After a bit of digging, I've found that the problem is with the SQL statement that Apache Cayenne generates. Apache Cayenne generates statements of the following form which yields bad performance on PostgreSQL with complicated WHERE statements and numerous columns: 1) SELECT DISTINCT a,b,c,d,e,f ... WHERE somecomplicatedstatement If I rewrite this statement to the form below using the 'DISTINCT ON()' syntax(which is PostgreSQL specific dialect), then I get great performance again: 2) SELECT DISTINCT ON(a) a,b,c,d,e,f ... WHERE somecomplicatedstatement Numbers on my machine: 1) 44000ms 2) 4300ms Here's where I read up on the DISTINCT ON syntax: http://www.postgresql.org/docs/9.4/static/sql-select.html -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs