Return-Path: Delivered-To: apmail-db-derby-user-archive@www.apache.org Received: (qmail 62224 invoked from network); 22 Mar 2010 00:30:55 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 22 Mar 2010 00:30:55 -0000 Received: (qmail 6114 invoked by uid 500); 22 Mar 2010 00:30:55 -0000 Delivered-To: apmail-db-derby-user-archive@db.apache.org Received: (qmail 6092 invoked by uid 500); 22 Mar 2010 00:30:55 -0000 Mailing-List: contact derby-user-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Reply-To: "Derby Discussion" Delivered-To: mailing list derby-user@db.apache.org Received: (qmail 6085 invoked by uid 99); 22 Mar 2010 00:30:55 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 22 Mar 2010 00:30:55 +0000 X-ASF-Spam-Status: No, hits=-0.8 required=10.0 tests=AWL,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of pljosh.mail@gmail.com designates 209.85.218.225 as permitted sender) Received: from [209.85.218.225] (HELO mail-bw0-f225.google.com) (209.85.218.225) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 22 Mar 2010 00:30:49 +0000 Received: by bwz25 with SMTP id 25so3369703bwz.8 for ; Sun, 21 Mar 2010 17:30:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type; bh=1NeQsVdXk/b3ptCAdcOthKljR++lEplJFHg7Mu6BzTI=; b=gHg5gZ3S6f+kS0JkdAeTYSgXQianMPLTv7lj/iVhxU+3B7URrjCFGTZTsdNp0mW6cB ZioP7E766/oU58tL+zGdOT7R3BlLl4fAheGqPz3p1tz65zgGW+Wgs6XDeSH745urzLqL TRenK9jvUzlI3MoOdyExWmvwn69u2XPZ35Jlw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=v/UE7szwoxxIlUvOOA+TL0LRt04WmwH1qgGbPYEz/f1wKFF135jSgaxIEHYPldlQ44 e0dmRPItQcVvRt+F/OlnVSf2S8dsTmpa3qZGa3zCE+Mc3vu9QUCNr9xnPImQmhy5/NSn vNpGf4FcbHsYkbqClevJFwZWYr7g3NX8BmZlw= MIME-Version: 1.0 Received: by 10.204.135.154 with SMTP id n26mr7799253bkt.18.1269217825259; Sun, 21 Mar 2010 17:30:25 -0700 (PDT) In-Reply-To: References: <4BA3826D.2060203@gmail.com> <4BA4F4DD.6060702@gmail.com> Date: Mon, 22 Mar 2010 01:30:25 +0100 Message-ID: Subject: Re: Query execution never ends From: Witold Szczerba To: Derby Discussion Content-Type: text/plain; charset=UTF-8 2010/3/21 Witold Szczerba : > 2010/3/20 Bryan Pendleton : >> Witold Szczerba wrote: >>> >>> 2010/3/19 Bryan Pendleton : >>>>> >>>>> SELECT count(*) >>>>> FROM contract co >>>>> LEFT JOIN ContractSubject insured ON insured.contract_id=co.id AND >>>>> insured.id=co.insured_id >>>> >>>> In this query, how does the result (the returned count) change when you >>>> change LEFT JOIN to JOIN? >>> >>> The numbers are almost always the same, it is possible for some >>> contracts not to have insured subjects temporally. >>> Right now the results are: 17667 (left join) and 17666 (inner join). >> >> Then it doesn't sound like the performance problem is due to a different >> amount of data in the outer join case. >> >> Perhaps it is that the presence of the outer join is preventing some >> optimization and thus Derby is choosing an inferior query plan. >> >> Have you compared the query plans of the two queries in the empty table >> case? >> >> Also, have you experimented with updating the statistics or compressing >> the tables in your full-size database? If the statistics are out of date, >> Derby has been known to choose a bad query execution plan. >> >> thanks, >> >> bryan >> >> > > Finally, I have both query plans, one for: > SELECT count(*) > FROM contract co > JOIN user_contract uc ON co.id=uc.contract_id > JOIN ContractSubject insured ON insured.contract_id=co.id AND > insured.id=co.insured_id > (Executed successfully in 0.959 s.) > http://witoldsz.strefa.pl/queryplan-1.txt > > and second: > SELECT count(*) > FROM contract co > JOIN user_contract uc ON co.id=uc.contract_id > LEFT JOIN ContractSubject insured ON insured.contract_id=co.id AND > insured.id=co.insured_id > (Executed successfully in 2,098.677 s.) > http://witoldsz.strefa.pl/queryplan-2.txt > > The problem is that I look at those plans - it is like black magic to > me, maybe you can see something? > > I issued SYSCS_COMPRESS_TABLE for all tables involved, but have not > tried SYSCS_UPDATE_STATISTICS as this procedure does not exist in > Derby 10.4. I will upgrade to 10.5 and try that. > > Thanks, > Witold Szczerba > OK, I have downloaded Derby 10.5.3.0, upgraded the database, compressed tables and updated theirs statistics, invoked both queries and it did not help. Here are the query plans: http://witoldsz.strefa.pl/queryplan-1b.txt http://witoldsz.strefa.pl/queryplan-2b.txt By the way: is there any tool for those query plans to be better readable? They are extremely verbose - 360 lines for one simple query - those query plans are overwhelming. Maybe some grep/sed/awk scripts at least? Regards, Witold Szczerba