You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by Pavel Bortnovskiy <PB...@Jefferies.com> on 2011/01/20 19:28:56 UTC

Can it be that Derby (in-memory) is deadlocking on this query?

Hello:

while running my application, I noticed that when the following query 
(which uses a subquery with tables joining on themselves) is executed, the 
application processes 185 records and then sits indefinitely in 
ResultSet.next() method:

SELECT 
    P1.ID ,
    R1.description
    P1.BOOK
    P1.NOMINAL
    P1.NOMINAL * R1.Factor
FROM
    P_TABLE P1,
    R_TABLE R1,
    (
      select 
        R2.IN_ID
      from 
        P_TABLE P2,
        R_TABLE R2
      where 
        P2.IN_ID = R2.IN_ID AND
        P2.NOMINAL <> 0  AND
        R2.IType='X'
      GROUP BY R2.IN_ID 
      HAVING COUNT(*) >1
    ) as MULTI
WHERE
    P1.IN_ID = R1.IN_ID  AND
    MULTI.IN_ID = R1.IN_ID


Then I tried running AquaDataStudio with this query and it's been over 16 
minutes without any results back:



However, when I run the subquery itself, it executes practically 
instanteneously:



And if I replace the subquery with where R1.IN in ('P32764', 'P32765', ... 
[all results from subquery]), it executes in a few ms:



I have a suspicion that Derby (which is running in in-memory only mode) is 
deadlocking.
What can I do on my end (without exposing our data) to help you diagnose 
this.

Please respond as soon as you can, since this is quite important and 
urgent.

Thank you,
Pavel.




Jefferies archives and monitors outgoing and incoming e-mail. The contents of this email, including any attachments, are confidential to the ordinary user of the email address to which it was addressed. If you are not the addressee of this email you may not copy, forward, disclose or otherwise use it or any part of it in any form whatsoever. This email may be produced at the request of regulators or in connection with civil litigation. Jefferies accepts no liability for any errors or omissions arising as a result of transmission. Use by other than intended recipients is prohibited.  In the United Kingdom, Jefferies operates as Jefferies International Limited; registered in England: no. 1978621; registered office: Vintners Place, 68 Upper Thames Street, London EC4V 3BJ.  Jefferies International Limited is authorised and regulated by the Financial Services Authority.

Re: Can it be that Derby (in-memory) is deadlocking on this query?

Posted by Knut Anders Hatlen <kn...@oracle.com>.
Pavel Bortnovskiy <PB...@Jefferies.com> writes:

> Hello:
>
> while running my application, I noticed that when the following query
> (which uses a subquery with tables joining on themselves) is
> executed, the application processes 185 records and then sits
> indefinitely in ResultSet.next() method:

Which version of Derby are you running? Derby 10.6.1.0 fixed two bugs
that caused infinite loops (DERBY-4376 and DERBY-4387).

> What can I do on my end (without exposing our data) to help you
> diagnose this.

A thread dump taken while the execution is stuck (can for example be
obtained by using the jstack tool that comes with the JDK) could give a
clue as to where to look for the bug.

Thanks,

-- 
Knut Anders