Return-Path: X-Original-To: apmail-cayenne-dev-archive@www.apache.org Delivered-To: apmail-cayenne-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E2CEE17E71 for ; Tue, 21 Apr 2015 10:18:54 +0000 (UTC) Received: (qmail 1245 invoked by uid 500); 21 Apr 2015 10:18:54 -0000 Delivered-To: apmail-cayenne-dev-archive@cayenne.apache.org Received: (qmail 1218 invoked by uid 500); 21 Apr 2015 10:18:54 -0000 Mailing-List: contact dev-help@cayenne.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cayenne.apache.org Delivered-To: mailing list dev@cayenne.apache.org Received: (qmail 1203 invoked by uid 99); 21 Apr 2015 10:18:54 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 21 Apr 2015 10:18:54 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: message received from 54.191.145.13 which is an MX secondary for dev@cayenne.apache.org) Received: from [54.191.145.13] (HELO mx1-us-west.apache.org) (54.191.145.13) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 21 Apr 2015 10:18:50 +0000 Received: from mail-wi0-f182.google.com (mail-wi0-f182.google.com [209.85.212.182]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with ESMTPS id D266421005 for ; Tue, 21 Apr 2015 10:18:29 +0000 (UTC) Received: by wiun10 with SMTP id n10so15761539wiu.1 for ; Tue, 21 Apr 2015 03:18:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:content-type:content-transfer-encoding; bh=Ma5ONuglWvtvr6Oujc93qXRQ6ke/P5V3gPAR85JT9i4=; b=x/HMO4eK5NRk2QBtxvE0bLQDA3oWKFupu59THs7uyeAdY4D5eWITsfY9nYqsQM+uQi qtflGIm8QMqPVd9znXkgiasVOyuEJPMwJ3CxZspr8kthniVwmMPGIoXgezS4sCZAG572 u2bHj2jEsNFzQu6QJ84VR6Gm4EZpoL1+qDATo/LhjBaePrdQwXshOwdJebxrkjkF4oNO brmwA2T7xNRXlLE0mDlNMPv8JfndBOErpYx4Z/67UvRHEihZz54rI/lePX/44sDvEKGE m++OiZ5TNkb5YKQYsh8KHH8vw2DLdLn9YLTJHv61WUxCPxiUAwq78GzqvFnLCEKMRp9a QXPg== MIME-Version: 1.0 X-Received: by 10.194.88.71 with SMTP id be7mr39427334wjb.139.1429611508596; Tue, 21 Apr 2015 03:18:28 -0700 (PDT) Sender: oyvindharboe@gmail.com Received: by 10.27.178.29 with HTTP; Tue, 21 Apr 2015 03:18:28 -0700 (PDT) In-Reply-To: References: <37CE457F-0457-499D-BB3B-9468D19E6A77@objectstyle.org> <347BA30A-1236-48AB-B9E7-D51F91D41C32@objectstyle.org> Date: Tue, 21 Apr 2015 12:18:28 +0200 X-Google-Sender-Auth: B3sDEut715HZLMyerqviOE7r5xI Message-ID: Subject: Re: Problem with catastrophic performance degradation under PostgreSQL From: =?UTF-8?Q?=C3=98yvind_Harboe?= To: dev@cayenne.apache.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org Nice. Thanks! Our app is stuck on Cayenne 3 until we can pay off some technical debt. On Tue, Apr 21, 2015 at 11:55 AM, Andrus Adamchik wrote: > Done. The fix is 4.0-only [1] I optimized the ON(..) loop from O(N2) to O= (N). > > Andrus > > [1] https://github.com/apache/cayenne/commit/27a99fab4fb06725cba3e71d2a05= d9fad129b260 > > >> On Apr 21, 2015, at 9:16 AM, Andrus Adamchik wr= ote: >> >> Looks pretty good to me. I'll run a quick test and commit. >> >> Thanks, >> Andrus >> >>> On Apr 20, 2015, at 8:39 PM, =C3=98yvind Harboe wrote: >>> >>> Hi Andrus, >>> >>> here's my stab at it. I'm sure it's all sorts of wrong :-) but the >>> pathological performance drop on PostgreSQL is gone. >>> >>> I actually tested this on Cayenne 3 and then copied it over to a patch >>> on origin/master. >>> >>> >>> ---------- Forwarded message ---------- >>> From: Andrus Adamchik >>> Date: Mon, Apr 20, 2015 at 6:07 PM >>> Subject: Re: Problem with catastrophic performance degradation under Po= stgreSQL >>> To: dev@cayenne.apache.org >>> >>> >>> Hi, >>> >>> So, Cayenne adds DISTINCT whenever a qualifier includes a to-many >>> relationship (for obvious reasons). Since we are dealing with an >>> object query, I guess we always know the ID columns and can rewrite >>> DISTINCT for PostgreSQL as "DISTINCT ON(id1, id2, ...)" to achieve the >>> desired effect. >>> >>> You want to take a shot at providing a fix for that? >>> >>> Thanks, >>> Andrus >>> >>> >>>> On Apr 20, 2015, at 6:09 PM, =C3=98yvind Harboe wrote: >>>> >>>> Q: Would it be a good idea to modify the PostgreSQL Cayenne adapter to= use >>>> the 'DISTINCT ON()' syntax? >>>> >>>> I've been testing out PostgreSQL vs. Derby 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 Cayenne generates. >>>> >>>> Cayenne generates statements of the following form which yields bad >>>> performance on PostgreSQL with complicated WHERE statements and numero= us >>>> 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 perform= ance >>>> again: >>>> >>>> 2) SELECT DISTINCT ON(a) a,b,c,d,e,f ... WHERE somecomplicatedstatemen= t >>>> >>>> >>>> >>>> >>>> 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 >>>> >>>> >>>> >>>> -- >>>> =C3=98yvind Harboe - Can Zylin Consulting help on your project? >>>> http://www.zylin.com/ >>> >>> >>> >>> >>> -- >>> =C3=98yvind Harboe - Can Zylin Consulting help on your project? >>> http://www.zylin.com/ >>> <0001-postgresql-improves-performance-by-taking-advantage-.patch> >> >> > --=20 =C3=98yvind Harboe - Can Zylin Consulting help on your project? http://www.zylin.com/