You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by "Bill Chen (JIRA)" <de...@db.apache.org> on 2005/12/13 17:28:46 UTC

[jira] Created: (DERBY-756) OutOfMemory Error on continous execution of select statement using COUNT() and DISTINCT on same connection

OutOfMemory Error on continous execution of select statement using COUNT() and DISTINCT on same connection
----------------------------------------------------------------------------------------------------------

         Key: DERBY-756
         URL: http://issues.apache.org/jira/browse/DERBY-756
     Project: Derby
        Type: Bug
  Components: Demos/Scripts, JDBC, Network Client, Network Server, SQL  
    Versions: 10.0.2.1, 10.1.2.1    
 Environment: Windows XP, Java 1.5.0_05, Derby network server 10.0.2.1, 10.1.2.1, Derby heapsize 128m, IBM Universal JDBC driver
    Reporter: Bill Chen
    Priority: Critical


The OutOfMemory is thrown when I continously execute a sql statement on an openned JDBC connection. A PreparedStatement and ResultSet is created on the connection everytime and close after each execution. I suspect that the bug is related to function COUNT() with keyword DISTINCT. For example, "select count(distinct ID) from TEST where FLAG <> 2". It will be fine if DISTINCT is not used, or select count(*) is used.

The exception like "Exception in thread "DRDAConnThread_2" java.lang.OutOfMemoryError: Java heap space" could be thrown on Derby side, or sometimes on client side.

Please find the test code and schema I used for testing:
create table:
CREATE TABLE Test
(
    ID BIGINT NOT NULL,
    NAME VARCHAR(512) NOT NULL,
    FLAG int,
      CONSTRAINT PK_ID PRIMARY KEY (ID)
);

insert data:
insert into TEST values (0, 'name0', 0);
insert into TEST values (1, 'name1', 1);
insert into TEST values (2, 'name2', 2);


Java client:

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.DriverManager;
import java.sql.SQLException;


public class DerbyTest
{
    static public void main(String args[]) throws Exception
    {
        Class.forName("com.ibm.db2.jcc.DB2Driver");
        Connection conn = null;
        try
        {
            conn = DriverManager.getConnection("jdbc:derby:net://localhost:1527/testDB", "admin", "admin");
            for (int i = 0; i < 10000000; i++)
            {
                System.out.println("Query "+i);

                String sql = "select count(distinct ID) from TEST where FLAG <> 2";
                PreparedStatement pStmt = null;
                ResultSet rs = null;

                try
                {

                    pStmt = conn.prepareStatement(sql);
                    rs = pStmt.executeQuery();
                    if (rs.next())
                    {
                        rs.getInt(1);
                    }
                }
                catch (SQLException e)
                {
                    e.printStackTrace();
                }
                finally
                {
                    if (rs != null)
                        rs.close();

                    if (pStmt != null)
                        pStmt.close();

                }
            }
        }
        finally
        {
            if (conn != null)
                conn.close();
        }
    }

}


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Updated: (DERBY-756) OutOfMemory Error on continous execution of select statement using COUNT() and DISTINCT on same connection

Posted by "Manish Khettry (JIRA)" <de...@db.apache.org>.
     [ http://issues.apache.org/jira/browse/DERBY-756?page=all ]

Manish Khettry updated DERBY-756:
---------------------------------

    Attachment: mem_leak.diff

Ran derbylang. Fix is simple enough I think-- I also removed some unused imports.

> OutOfMemory Error on continous execution of select statement using COUNT() and DISTINCT on same connection
> ----------------------------------------------------------------------------------------------------------
>
>          Key: DERBY-756
>          URL: http://issues.apache.org/jira/browse/DERBY-756
>      Project: Derby
>         Type: Bug
>   Components: Demos/Scripts, JDBC, Network Client, Network Server, SQL
>     Versions: 10.0.2.1, 10.1.2.1
>  Environment: Windows XP, Java 1.5.0_05, Derby network server 10.0.2.1, 10.1.2.1, Derby heapsize 128m, IBM Universal JDBC driver
>     Reporter: Bill Chen
>     Assignee: Manish Khettry
>     Priority: Critical
>  Attachments: mem_leak.diff
>
> The OutOfMemory is thrown when I continously execute a sql statement on an openned JDBC connection. A PreparedStatement and ResultSet is created on the connection everytime and close after each execution. I suspect that the bug is related to function COUNT() with keyword DISTINCT. For example, "select count(distinct ID) from TEST where FLAG <> 2". It will be fine if DISTINCT is not used, or select count(*) is used.
> The exception like "Exception in thread "DRDAConnThread_2" java.lang.OutOfMemoryError: Java heap space" could be thrown on Derby side, or sometimes on client side.
> Please find the test code and schema I used for testing:
> create table:
> CREATE TABLE Test
> (
>     ID BIGINT NOT NULL,
>     NAME VARCHAR(512) NOT NULL,
>     FLAG int,
>       CONSTRAINT PK_ID PRIMARY KEY (ID)
> );
> insert data:
> insert into TEST values (0, 'name0', 0);
> insert into TEST values (1, 'name1', 1);
> insert into TEST values (2, 'name2', 2);
> Java client:
> import java.sql.Connection;
> import java.sql.PreparedStatement;
> import java.sql.ResultSet;
> import java.sql.DriverManager;
> import java.sql.SQLException;
> public class DerbyTest
> {
>     static public void main(String args[]) throws Exception
>     {
>         Class.forName("com.ibm.db2.jcc.DB2Driver");
>         Connection conn = null;
>         try
>         {
>             conn = DriverManager.getConnection("jdbc:derby:net://localhost:1527/testDB", "admin", "admin");
>             for (int i = 0; i < 10000000; i++)
>             {
>                 System.out.println("Query "+i);
>                 String sql = "select count(distinct ID) from TEST where FLAG <> 2";
>                 PreparedStatement pStmt = null;
>                 ResultSet rs = null;
>                 try
>                 {
>                     pStmt = conn.prepareStatement(sql);
>                     rs = pStmt.executeQuery();
>                     if (rs.next())
>                     {
>                         rs.getInt(1);
>                     }
>                 }
>                 catch (SQLException e)
>                 {
>                     e.printStackTrace();
>                 }
>                 finally
>                 {
>                     if (rs != null)
>                         rs.close();
>                     if (pStmt != null)
>                         pStmt.close();
>                 }
>             }
>         }
>         finally
>         {
>             if (conn != null)
>                 conn.close();
>         }
>     }
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Assigned: (DERBY-756) OutOfMemory Error on continous execution of select statement using COUNT() and DISTINCT on same connection

Posted by "Manish Khettry (JIRA)" <de...@db.apache.org>.
     [ http://issues.apache.org/jira/browse/DERBY-756?page=all ]

Manish Khettry reassigned DERBY-756:
------------------------------------

    Assign To: Manish Khettry

> OutOfMemory Error on continous execution of select statement using COUNT() and DISTINCT on same connection
> ----------------------------------------------------------------------------------------------------------
>
>          Key: DERBY-756
>          URL: http://issues.apache.org/jira/browse/DERBY-756
>      Project: Derby
>         Type: Bug
>   Components: Demos/Scripts, JDBC, Network Client, Network Server, SQL
>     Versions: 10.0.2.1, 10.1.2.1
>  Environment: Windows XP, Java 1.5.0_05, Derby network server 10.0.2.1, 10.1.2.1, Derby heapsize 128m, IBM Universal JDBC driver
>     Reporter: Bill Chen
>     Assignee: Manish Khettry
>     Priority: Critical

>
> The OutOfMemory is thrown when I continously execute a sql statement on an openned JDBC connection. A PreparedStatement and ResultSet is created on the connection everytime and close after each execution. I suspect that the bug is related to function COUNT() with keyword DISTINCT. For example, "select count(distinct ID) from TEST where FLAG <> 2". It will be fine if DISTINCT is not used, or select count(*) is used.
> The exception like "Exception in thread "DRDAConnThread_2" java.lang.OutOfMemoryError: Java heap space" could be thrown on Derby side, or sometimes on client side.
> Please find the test code and schema I used for testing:
> create table:
> CREATE TABLE Test
> (
>     ID BIGINT NOT NULL,
>     NAME VARCHAR(512) NOT NULL,
>     FLAG int,
>       CONSTRAINT PK_ID PRIMARY KEY (ID)
> );
> insert data:
> insert into TEST values (0, 'name0', 0);
> insert into TEST values (1, 'name1', 1);
> insert into TEST values (2, 'name2', 2);
> Java client:
> import java.sql.Connection;
> import java.sql.PreparedStatement;
> import java.sql.ResultSet;
> import java.sql.DriverManager;
> import java.sql.SQLException;
> public class DerbyTest
> {
>     static public void main(String args[]) throws Exception
>     {
>         Class.forName("com.ibm.db2.jcc.DB2Driver");
>         Connection conn = null;
>         try
>         {
>             conn = DriverManager.getConnection("jdbc:derby:net://localhost:1527/testDB", "admin", "admin");
>             for (int i = 0; i < 10000000; i++)
>             {
>                 System.out.println("Query "+i);
>                 String sql = "select count(distinct ID) from TEST where FLAG <> 2";
>                 PreparedStatement pStmt = null;
>                 ResultSet rs = null;
>                 try
>                 {
>                     pStmt = conn.prepareStatement(sql);
>                     rs = pStmt.executeQuery();
>                     if (rs.next())
>                     {
>                         rs.getInt(1);
>                     }
>                 }
>                 catch (SQLException e)
>                 {
>                     e.printStackTrace();
>                 }
>                 finally
>                 {
>                     if (rs != null)
>                         rs.close();
>                     if (pStmt != null)
>                         pStmt.close();
>                 }
>             }
>         }
>         finally
>         {
>             if (conn != null)
>                 conn.close();
>         }
>     }
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


Re: Activation re-using language ResultSets & performance gain

Posted by Manish Khettry <ma...@gmail.com>.
It may be worth it to have one person (or a few) inspect all ResultSet
implementations to make sure that the open/close/reopen/finish methods do
the right thing.

On 1/16/06, Satheesh Bandaram <sa...@sourcery.org> wrote:
>
> This does looks like a great optimization. It would be good to have an
> Improvement item filed with your Activation change. People can investigate
> individual failures and post their fixes to ResultSet implementations. I
> would like to help address some of the resultset changes.
>
> Satheesh
>
> Daniel John Debrunner wrote:
>
> Manish Khettry (JIRA) wrote:
>
>        [ http://issues.apache.org/jira/browse/DERBY-756?page=comments#action_12362606 ]
>
> Manish Khettry commented on DERBY-756:
> --------------------------------------
>
>     Shouldn't DistinctScalarAggregateRS implement a close or a finish method
> (not sure what the difference is) and close the scan controller there.
>
>  The close() and finish() methods are actually explained in their javadoc
> in the language org.apache.derby.iapi.sql.ResultSet class.
> [note this is not a JDBC java.sql.ResultSet object]
>
> close() -  Tells the system that there will be no more calls to
> getNextRow() (until the next open() call)
>
> finish() - Tells the system that there will be no more access to any
> database information via this result set
>
> So close means the ResultSet may be opened again for more access, while
> finish means it will not be used again.
>
> However, their use in the code always doesn't match that, and that does
> cause confusion, at least to me.
>
> Language ResultSets (not JDBC ones) can be and are opened multiple
> times, for example when scanning a table multiple times within a join.
>
> An Activation, which represents the internal state of
> java.sql.PreparedStatement object & has the lifetime of the
> java.sql.PreparedStatement, contains a top-level language ResultSet.
> This top-level language ResultSet provides the execution of the SQL
> statement, DML, DDL or a query. The top-level ResultSet may contain
> other ResultSets and could be seen as a tree structure. For the simple
> case of a primary key lookup query like:
>
>    select name from customer where id = ?
>
> The activation would contain this:
>
> top result set
> ProjectRestrictRS << IndexRowToBaseRowRS << TableScanRS
>
> Now for some reason, even though the api of ResultSet say they can be
> re-used, and in some cases they are, this result set tree is thrown away
> after each execution. That is, the top result set has its finish()
> method called and then the activation removes its reference to it. Then
> on the next execution a new (identical) tree is set up.
>
> There is potential for a huge performance gain if this top level result
> set and its tree are re-used and have the same lifetime as the
> Activation. The saving comes in two forms, not having to create many
> objects on each execution, and not creating short-lived objects for the
> garbage collector to handle.
>
> I made a simple fix, it's a couple of lines of code, just calling close
> & finish at the correct times, and for the above simple primary key
> lookup query, the performance went from 17,300 to 24,000 selects per
> second (cached data, single user). I'll post a patch shortly as an
> indication of the direction, once I can separate it from other changes
> in my client.
>
> However, I'm running the Derby tests and there are some (maybe 25-30)
> failures, I think because not all the language ResultSet implementations
> are correctly written to be re-opened. Interestingly, the first failure
> I saw was in an aggregrate test, which goes back to the issue Manish saw.
>
> Even if derbyall passed I would be nervous about submitting this patch
> for real, because I don't think there's a lot of testing using repeat
> executions of PreparedStatements in the tests. The ij tests mainly use
> Statement, this is a single use of an activation so this change would
> not affect them. Thus such a patch could regress Derby by making it more
> likely existing bugs would be exposed.
>
> Given the performance gains, I think we need to start re-using
> ResultSets from Activation, and devise a way to ensure the testing
> covers the re-use. The main issue is there is a large number of
> ResultSet implementations to cover.
> Dan.
>
>
>
>

Activation re-using language ResultSets & performance gain

Posted by Daniel John Debrunner <dj...@apache.org>.
Manish Khettry (JIRA) wrote:

>     [ http://issues.apache.org/jira/browse/DERBY-756?page=comments#action_12362606 ] 
> 
> Manish Khettry commented on DERBY-756:
> --------------------------------------

> Shouldn't DistinctScalarAggregateRS implement a close or a finish method
>(not sure what the difference is) and close the scan controller there.

The close() and finish() methods are actually explained in their javadoc
in the language org.apache.derby.iapi.sql.ResultSet class.
[note this is not a JDBC java.sql.ResultSet object]

close() -  Tells the system that there will be no more calls to
getNextRow() (until the next open() call)

finish() - Tells the system that there will be no more access to any
database information via this result set

So close means the ResultSet may be opened again for more access, while
finish means it will not be used again.

However, their use in the code always doesn't match that, and that does
cause confusion, at least to me.

Language ResultSets (not JDBC ones) can be and are opened multiple
times, for example when scanning a table multiple times within a join.

An Activation, which represents the internal state of
java.sql.PreparedStatement object & has the lifetime of the
java.sql.PreparedStatement, contains a top-level language ResultSet.
This top-level language ResultSet provides the execution of the SQL
statement, DML, DDL or a query. The top-level ResultSet may contain
other ResultSets and could be seen as a tree structure. For the simple
case of a primary key lookup query like:

   select name from customer where id = ?

The activation would contain this:

top result set
ProjectRestrictRS << IndexRowToBaseRowRS << TableScanRS

Now for some reason, even though the api of ResultSet say they can be
re-used, and in some cases they are, this result set tree is thrown away
after each execution. That is, the top result set has its finish()
method called and then the activation removes its reference to it. Then
on the next execution a new (identical) tree is set up.

There is potential for a huge performance gain if this top level result
set and its tree are re-used and have the same lifetime as the
Activation. The saving comes in two forms, not having to create many
objects on each execution, and not creating short-lived objects for the
garbage collector to handle.

I made a simple fix, it's a couple of lines of code, just calling close
& finish at the correct times, and for the above simple primary key
lookup query, the performance went from 17,300 to 24,000 selects per
second (cached data, single user). I'll post a patch shortly as an
indication of the direction, once I can separate it from other changes
in my client.

However, I'm running the Derby tests and there are some (maybe 25-30)
failures, I think because not all the language ResultSet implementations
are correctly written to be re-opened. Interestingly, the first failure
I saw was in an aggregrate test, which goes back to the issue Manish saw.

Even if derbyall passed I would be nervous about submitting this patch
for real, because I don't think there's a lot of testing using repeat
executions of PreparedStatements in the tests. The ij tests mainly use
Statement, this is a single use of an activation so this change would
not affect them. Thus such a patch could regress Derby by making it more
likely existing bugs would be exposed.

Given the performance gains, I think we need to start re-using
ResultSets from Activation, and devise a way to ensure the testing
covers the re-use. The main issue is there is a large number of
ResultSet implementations to cover.
Dan.


Re: [jira] Commented: (DERBY-756) OutOfMemory Error on continous execution of select statement using COUNT() and DISTINCT on same connection

Posted by Mike Matrigali <mi...@sbcglobal.net>.
sounds right, mostly access won't close scans unless directed to.  And 
as you point out a list of open scans is maintained.  This is even more
important now that many result sets are "open across commit" by default
now, so access can't even close them at commit.

Manish Khettry (JIRA) wrote:
>     [ http://issues.apache.org/jira/browse/DERBY-756?page=comments#action_12362606 ] 
> 
> Manish Khettry commented on DERBY-756:
> --------------------------------------
> 
> It looks like the scan controller created in DistinctScalarAggregateResultSet is never closed. This causes the scanController instance variable in RAMTransaction to continue to grow with each open/close. 
> 
> Shouldn't DistinctScalarAggregateRS implement a close or a finish method (not sure what the difference is) and close the scan controller there.
> 
> 
> 
>>OutOfMemory Error on continous execution of select statement using COUNT() and DISTINCT on same connection
>>----------------------------------------------------------------------------------------------------------
>>
>>         Key: DERBY-756
>>         URL: http://issues.apache.org/jira/browse/DERBY-756
>>     Project: Derby
>>        Type: Bug
>>  Components: Demos/Scripts, JDBC, Network Client, Network Server, SQL
>>    Versions: 10.0.2.1, 10.1.2.1
>> Environment: Windows XP, Java 1.5.0_05, Derby network server 10.0.2.1, 10.1.2.1, Derby heapsize 128m, IBM Universal JDBC driver
>>    Reporter: Bill Chen
>>    Assignee: Manish Khettry
>>    Priority: Critical
> 
> 
>>The OutOfMemory is thrown when I continously execute a sql statement on an openned JDBC connection. A PreparedStatement and ResultSet is created on the connection everytime and close after each execution. I suspect that the bug is related to function COUNT() with keyword DISTINCT. For example, "select count(distinct ID) from TEST where FLAG <> 2". It will be fine if DISTINCT is not used, or select count(*) is used.
>>The exception like "Exception in thread "DRDAConnThread_2" java.lang.OutOfMemoryError: Java heap space" could be thrown on Derby side, or sometimes on client side.
>>Please find the test code and schema I used for testing:
>>create table:
>>CREATE TABLE Test
>>(
>>    ID BIGINT NOT NULL,
>>    NAME VARCHAR(512) NOT NULL,
>>    FLAG int,
>>      CONSTRAINT PK_ID PRIMARY KEY (ID)
>>);
>>insert data:
>>insert into TEST values (0, 'name0', 0);
>>insert into TEST values (1, 'name1', 1);
>>insert into TEST values (2, 'name2', 2);
>>Java client:
>>import java.sql.Connection;
>>import java.sql.PreparedStatement;
>>import java.sql.ResultSet;
>>import java.sql.DriverManager;
>>import java.sql.SQLException;
>>public class DerbyTest
>>{
>>    static public void main(String args[]) throws Exception
>>    {
>>        Class.forName("com.ibm.db2.jcc.DB2Driver");
>>        Connection conn = null;
>>        try
>>        {
>>            conn = DriverManager.getConnection("jdbc:derby:net://localhost:1527/testDB", "admin", "admin");
>>            for (int i = 0; i < 10000000; i++)
>>            {
>>                System.out.println("Query "+i);
>>                String sql = "select count(distinct ID) from TEST where FLAG <> 2";
>>                PreparedStatement pStmt = null;
>>                ResultSet rs = null;
>>                try
>>                {
>>                    pStmt = conn.prepareStatement(sql);
>>                    rs = pStmt.executeQuery();
>>                    if (rs.next())
>>                    {
>>                        rs.getInt(1);
>>                    }
>>                }
>>                catch (SQLException e)
>>                {
>>                    e.printStackTrace();
>>                }
>>                finally
>>                {
>>                    if (rs != null)
>>                        rs.close();
>>                    if (pStmt != null)
>>                        pStmt.close();
>>                }
>>            }
>>        }
>>        finally
>>        {
>>            if (conn != null)
>>                conn.close();
>>        }
>>    }
>>}
> 
> 


[jira] Commented: (DERBY-756) OutOfMemory Error on continous execution of select statement using COUNT() and DISTINCT on same connection

Posted by "Manish Khettry (JIRA)" <de...@db.apache.org>.
    [ http://issues.apache.org/jira/browse/DERBY-756?page=comments#action_12362606 ] 

Manish Khettry commented on DERBY-756:
--------------------------------------

It looks like the scan controller created in DistinctScalarAggregateResultSet is never closed. This causes the scanController instance variable in RAMTransaction to continue to grow with each open/close. 

Shouldn't DistinctScalarAggregateRS implement a close or a finish method (not sure what the difference is) and close the scan controller there.


> OutOfMemory Error on continous execution of select statement using COUNT() and DISTINCT on same connection
> ----------------------------------------------------------------------------------------------------------
>
>          Key: DERBY-756
>          URL: http://issues.apache.org/jira/browse/DERBY-756
>      Project: Derby
>         Type: Bug
>   Components: Demos/Scripts, JDBC, Network Client, Network Server, SQL
>     Versions: 10.0.2.1, 10.1.2.1
>  Environment: Windows XP, Java 1.5.0_05, Derby network server 10.0.2.1, 10.1.2.1, Derby heapsize 128m, IBM Universal JDBC driver
>     Reporter: Bill Chen
>     Assignee: Manish Khettry
>     Priority: Critical

>
> The OutOfMemory is thrown when I continously execute a sql statement on an openned JDBC connection. A PreparedStatement and ResultSet is created on the connection everytime and close after each execution. I suspect that the bug is related to function COUNT() with keyword DISTINCT. For example, "select count(distinct ID) from TEST where FLAG <> 2". It will be fine if DISTINCT is not used, or select count(*) is used.
> The exception like "Exception in thread "DRDAConnThread_2" java.lang.OutOfMemoryError: Java heap space" could be thrown on Derby side, or sometimes on client side.
> Please find the test code and schema I used for testing:
> create table:
> CREATE TABLE Test
> (
>     ID BIGINT NOT NULL,
>     NAME VARCHAR(512) NOT NULL,
>     FLAG int,
>       CONSTRAINT PK_ID PRIMARY KEY (ID)
> );
> insert data:
> insert into TEST values (0, 'name0', 0);
> insert into TEST values (1, 'name1', 1);
> insert into TEST values (2, 'name2', 2);
> Java client:
> import java.sql.Connection;
> import java.sql.PreparedStatement;
> import java.sql.ResultSet;
> import java.sql.DriverManager;
> import java.sql.SQLException;
> public class DerbyTest
> {
>     static public void main(String args[]) throws Exception
>     {
>         Class.forName("com.ibm.db2.jcc.DB2Driver");
>         Connection conn = null;
>         try
>         {
>             conn = DriverManager.getConnection("jdbc:derby:net://localhost:1527/testDB", "admin", "admin");
>             for (int i = 0; i < 10000000; i++)
>             {
>                 System.out.println("Query "+i);
>                 String sql = "select count(distinct ID) from TEST where FLAG <> 2";
>                 PreparedStatement pStmt = null;
>                 ResultSet rs = null;
>                 try
>                 {
>                     pStmt = conn.prepareStatement(sql);
>                     rs = pStmt.executeQuery();
>                     if (rs.next())
>                     {
>                         rs.getInt(1);
>                     }
>                 }
>                 catch (SQLException e)
>                 {
>                     e.printStackTrace();
>                 }
>                 finally
>                 {
>                     if (rs != null)
>                         rs.close();
>                     if (pStmt != null)
>                         pStmt.close();
>                 }
>             }
>         }
>         finally
>         {
>             if (conn != null)
>                 conn.close();
>         }
>     }
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Commented: (DERBY-756) OutOfMemory Error on continous execution of select statement using COUNT() and DISTINCT on same connection

Posted by "Manish Khettry (JIRA)" <de...@db.apache.org>.
    [ http://issues.apache.org/jira/browse/DERBY-756?page=comments#action_12363917 ] 

Manish Khettry commented on DERBY-756:
--------------------------------------

I ran the test case in the bug with a maximum heap size of 1 MB; atleast I specified -Xmx1m-- its possible that the JVM can't run with 1 MB and upped it to something more reasonable.

Before the fix, we would run out of memory at about the 4000'th iteration. The good news is that we get to about 81,000 iterations. The bad news is that we still run out of memory. I changed the query from a count(distinct id) to a simple count(*) and the OutOfMemory error was thrown after about 81-82K executes. I think there is another memory leak (or two) in our system that we need to identify and fix. Is it safe to mark this bug closed and file another bug to track that issue or should I use this bug to track the memory leak that remains.

If I don't hear from anyone, I'll mark this bug closed and file another one.

> OutOfMemory Error on continous execution of select statement using COUNT() and DISTINCT on same connection
> ----------------------------------------------------------------------------------------------------------
>
>          Key: DERBY-756
>          URL: http://issues.apache.org/jira/browse/DERBY-756
>      Project: Derby
>         Type: Bug
>   Components: Demos/Scripts, JDBC, Network Client, Network Server, SQL
>     Versions: 10.0.2.1, 10.1.2.1
>  Environment: Windows XP, Java 1.5.0_05, Derby network server 10.0.2.1, 10.1.2.1, Derby heapsize 128m, IBM Universal JDBC driver
>     Reporter: Bill Chen
>     Assignee: Manish Khettry
>     Priority: Critical
>  Attachments: mem_leak.diff
>
> The OutOfMemory is thrown when I continously execute a sql statement on an openned JDBC connection. A PreparedStatement and ResultSet is created on the connection everytime and close after each execution. I suspect that the bug is related to function COUNT() with keyword DISTINCT. For example, "select count(distinct ID) from TEST where FLAG <> 2". It will be fine if DISTINCT is not used, or select count(*) is used.
> The exception like "Exception in thread "DRDAConnThread_2" java.lang.OutOfMemoryError: Java heap space" could be thrown on Derby side, or sometimes on client side.
> Please find the test code and schema I used for testing:
> create table:
> CREATE TABLE Test
> (
>     ID BIGINT NOT NULL,
>     NAME VARCHAR(512) NOT NULL,
>     FLAG int,
>       CONSTRAINT PK_ID PRIMARY KEY (ID)
> );
> insert data:
> insert into TEST values (0, 'name0', 0);
> insert into TEST values (1, 'name1', 1);
> insert into TEST values (2, 'name2', 2);
> Java client:
> import java.sql.Connection;
> import java.sql.PreparedStatement;
> import java.sql.ResultSet;
> import java.sql.DriverManager;
> import java.sql.SQLException;
> public class DerbyTest
> {
>     static public void main(String args[]) throws Exception
>     {
>         Class.forName("com.ibm.db2.jcc.DB2Driver");
>         Connection conn = null;
>         try
>         {
>             conn = DriverManager.getConnection("jdbc:derby:net://localhost:1527/testDB", "admin", "admin");
>             for (int i = 0; i < 10000000; i++)
>             {
>                 System.out.println("Query "+i);
>                 String sql = "select count(distinct ID) from TEST where FLAG <> 2";
>                 PreparedStatement pStmt = null;
>                 ResultSet rs = null;
>                 try
>                 {
>                     pStmt = conn.prepareStatement(sql);
>                     rs = pStmt.executeQuery();
>                     if (rs.next())
>                     {
>                         rs.getInt(1);
>                     }
>                 }
>                 catch (SQLException e)
>                 {
>                     e.printStackTrace();
>                 }
>                 finally
>                 {
>                     if (rs != null)
>                         rs.close();
>                     if (pStmt != null)
>                         pStmt.close();
>                 }
>             }
>         }
>         finally
>         {
>             if (conn != null)
>                 conn.close();
>         }
>     }
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Closed: (DERBY-756) OutOfMemory Error on continous execution of select statement using COUNT() and DISTINCT on same connection

Posted by "Manish Khettry (JIRA)" <de...@db.apache.org>.
     [ http://issues.apache.org/jira/browse/DERBY-756?page=all ]
     
Manish Khettry closed DERBY-756:
--------------------------------


Per Satheesh, closing this issue but the subtask should still be open.

> OutOfMemory Error on continous execution of select statement using COUNT() and DISTINCT on same connection
> ----------------------------------------------------------------------------------------------------------
>
>          Key: DERBY-756
>          URL: http://issues.apache.org/jira/browse/DERBY-756
>      Project: Derby
>         Type: Bug
>   Components: Demos/Scripts, JDBC, Network Client, Network Server, SQL
>     Versions: 10.0.2.1, 10.1.2.1
>  Environment: Windows XP, Java 1.5.0_05, Derby network server 10.0.2.1, 10.1.2.1, Derby heapsize 128m, IBM Universal JDBC driver
>     Reporter: Bill Chen
>     Assignee: Manish Khettry
>     Priority: Critical
>  Attachments: mem_leak.diff
>
> The OutOfMemory is thrown when I continously execute a sql statement on an openned JDBC connection. A PreparedStatement and ResultSet is created on the connection everytime and close after each execution. I suspect that the bug is related to function COUNT() with keyword DISTINCT. For example, "select count(distinct ID) from TEST where FLAG <> 2". It will be fine if DISTINCT is not used, or select count(*) is used.
> The exception like "Exception in thread "DRDAConnThread_2" java.lang.OutOfMemoryError: Java heap space" could be thrown on Derby side, or sometimes on client side.
> Please find the test code and schema I used for testing:
> create table:
> CREATE TABLE Test
> (
>     ID BIGINT NOT NULL,
>     NAME VARCHAR(512) NOT NULL,
>     FLAG int,
>       CONSTRAINT PK_ID PRIMARY KEY (ID)
> );
> insert data:
> insert into TEST values (0, 'name0', 0);
> insert into TEST values (1, 'name1', 1);
> insert into TEST values (2, 'name2', 2);
> Java client:
> import java.sql.Connection;
> import java.sql.PreparedStatement;
> import java.sql.ResultSet;
> import java.sql.DriverManager;
> import java.sql.SQLException;
> public class DerbyTest
> {
>     static public void main(String args[]) throws Exception
>     {
>         Class.forName("com.ibm.db2.jcc.DB2Driver");
>         Connection conn = null;
>         try
>         {
>             conn = DriverManager.getConnection("jdbc:derby:net://localhost:1527/testDB", "admin", "admin");
>             for (int i = 0; i < 10000000; i++)
>             {
>                 System.out.println("Query "+i);
>                 String sql = "select count(distinct ID) from TEST where FLAG <> 2";
>                 PreparedStatement pStmt = null;
>                 ResultSet rs = null;
>                 try
>                 {
>                     pStmt = conn.prepareStatement(sql);
>                     rs = pStmt.executeQuery();
>                     if (rs.next())
>                     {
>                         rs.getInt(1);
>                     }
>                 }
>                 catch (SQLException e)
>                 {
>                     e.printStackTrace();
>                 }
>                 finally
>                 {
>                     if (rs != null)
>                         rs.close();
>                     if (pStmt != null)
>                         pStmt.close();
>                 }
>             }
>         }
>         finally
>         {
>             if (conn != null)
>                 conn.close();
>         }
>     }
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Updated: (DERBY-756) OutOfMemory Error on continous execution of select statement using COUNT() and DISTINCT on same connection

Posted by "Kathey Marsden (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-756?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Kathey Marsden updated DERBY-756:
---------------------------------

    Fix Version/s: 10.1.3.2

> OutOfMemory Error on continous execution of select statement using COUNT() and DISTINCT on same connection
> ----------------------------------------------------------------------------------------------------------
>
>                 Key: DERBY-756
>                 URL: https://issues.apache.org/jira/browse/DERBY-756
>             Project: Derby
>          Issue Type: Bug
>          Components: Demos/Scripts, JDBC, Network Client, Network Server, SQL
>    Affects Versions: 10.0.2.1, 10.1.2.1
>         Environment: Windows XP, Java 1.5.0_05, Derby network server 10.0.2.1, 10.1.2.1, Derby heapsize 128m, IBM Universal JDBC driver
>            Reporter: Bill Chen
>            Assignee: Manish Khettry
>            Priority: Critical
>             Fix For: 10.1.3.2, 10.2.1.6
>
>         Attachments: mem_leak.diff
>
>
> The OutOfMemory is thrown when I continously execute a sql statement on an openned JDBC connection. A PreparedStatement and ResultSet is created on the connection everytime and close after each execution. I suspect that the bug is related to function COUNT() with keyword DISTINCT. For example, "select count(distinct ID) from TEST where FLAG <> 2". It will be fine if DISTINCT is not used, or select count(*) is used.
> The exception like "Exception in thread "DRDAConnThread_2" java.lang.OutOfMemoryError: Java heap space" could be thrown on Derby side, or sometimes on client side.
> Please find the test code and schema I used for testing:
> create table:
> CREATE TABLE Test
> (
>     ID BIGINT NOT NULL,
>     NAME VARCHAR(512) NOT NULL,
>     FLAG int,
>       CONSTRAINT PK_ID PRIMARY KEY (ID)
> );
> insert data:
> insert into TEST values (0, 'name0', 0);
> insert into TEST values (1, 'name1', 1);
> insert into TEST values (2, 'name2', 2);
> Java client:
> import java.sql.Connection;
> import java.sql.PreparedStatement;
> import java.sql.ResultSet;
> import java.sql.DriverManager;
> import java.sql.SQLException;
> public class DerbyTest
> {
>     static public void main(String args[]) throws Exception
>     {
>         Class.forName("com.ibm.db2.jcc.DB2Driver");
>         Connection conn = null;
>         try
>         {
>             conn = DriverManager.getConnection("jdbc:derby:net://localhost:1527/testDB", "admin", "admin");
>             for (int i = 0; i < 10000000; i++)
>             {
>                 System.out.println("Query "+i);
>                 String sql = "select count(distinct ID) from TEST where FLAG <> 2";
>                 PreparedStatement pStmt = null;
>                 ResultSet rs = null;
>                 try
>                 {
>                     pStmt = conn.prepareStatement(sql);
>                     rs = pStmt.executeQuery();
>                     if (rs.next())
>                     {
>                         rs.getInt(1);
>                     }
>                 }
>                 catch (SQLException e)
>                 {
>                     e.printStackTrace();
>                 }
>                 finally
>                 {
>                     if (rs != null)
>                         rs.close();
>                     if (pStmt != null)
>                         pStmt.close();
>                 }
>             }
>         }
>         finally
>         {
>             if (conn != null)
>                 conn.close();
>         }
>     }
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Reopened: (DERBY-756) OutOfMemory Error on continous execution of select statement using COUNT() and DISTINCT on same connection

Posted by "Satheesh Bandaram (JIRA)" <de...@db.apache.org>.
     [ http://issues.apache.org/jira/browse/DERBY-756?page=all ]
     
Satheesh Bandaram reopened DERBY-756:
-------------------------------------


Reopening to set fixin.

> OutOfMemory Error on continous execution of select statement using COUNT() and DISTINCT on same connection
> ----------------------------------------------------------------------------------------------------------
>
>          Key: DERBY-756
>          URL: http://issues.apache.org/jira/browse/DERBY-756
>      Project: Derby
>         Type: Bug
>   Components: Demos/Scripts, JDBC, Network Client, Network Server, SQL
>     Versions: 10.0.2.1, 10.1.2.1
>  Environment: Windows XP, Java 1.5.0_05, Derby network server 10.0.2.1, 10.1.2.1, Derby heapsize 128m, IBM Universal JDBC driver
>     Reporter: Bill Chen
>     Assignee: Manish Khettry
>     Priority: Critical
>      Fix For: 10.2.0.0
>  Attachments: mem_leak.diff
>
> The OutOfMemory is thrown when I continously execute a sql statement on an openned JDBC connection. A PreparedStatement and ResultSet is created on the connection everytime and close after each execution. I suspect that the bug is related to function COUNT() with keyword DISTINCT. For example, "select count(distinct ID) from TEST where FLAG <> 2". It will be fine if DISTINCT is not used, or select count(*) is used.
> The exception like "Exception in thread "DRDAConnThread_2" java.lang.OutOfMemoryError: Java heap space" could be thrown on Derby side, or sometimes on client side.
> Please find the test code and schema I used for testing:
> create table:
> CREATE TABLE Test
> (
>     ID BIGINT NOT NULL,
>     NAME VARCHAR(512) NOT NULL,
>     FLAG int,
>       CONSTRAINT PK_ID PRIMARY KEY (ID)
> );
> insert data:
> insert into TEST values (0, 'name0', 0);
> insert into TEST values (1, 'name1', 1);
> insert into TEST values (2, 'name2', 2);
> Java client:
> import java.sql.Connection;
> import java.sql.PreparedStatement;
> import java.sql.ResultSet;
> import java.sql.DriverManager;
> import java.sql.SQLException;
> public class DerbyTest
> {
>     static public void main(String args[]) throws Exception
>     {
>         Class.forName("com.ibm.db2.jcc.DB2Driver");
>         Connection conn = null;
>         try
>         {
>             conn = DriverManager.getConnection("jdbc:derby:net://localhost:1527/testDB", "admin", "admin");
>             for (int i = 0; i < 10000000; i++)
>             {
>                 System.out.println("Query "+i);
>                 String sql = "select count(distinct ID) from TEST where FLAG <> 2";
>                 PreparedStatement pStmt = null;
>                 ResultSet rs = null;
>                 try
>                 {
>                     pStmt = conn.prepareStatement(sql);
>                     rs = pStmt.executeQuery();
>                     if (rs.next())
>                     {
>                         rs.getInt(1);
>                     }
>                 }
>                 catch (SQLException e)
>                 {
>                     e.printStackTrace();
>                 }
>                 finally
>                 {
>                     if (rs != null)
>                         rs.close();
>                     if (pStmt != null)
>                         pStmt.close();
>                 }
>             }
>         }
>         finally
>         {
>             if (conn != null)
>                 conn.close();
>         }
>     }
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Resolved: (DERBY-756) OutOfMemory Error on continous execution of select statement using COUNT() and DISTINCT on same connection

Posted by "Manish Khettry (JIRA)" <de...@db.apache.org>.
     [ http://issues.apache.org/jira/browse/DERBY-756?page=all ]
     
Manish Khettry resolved DERBY-756:
----------------------------------

    Resolution: Fixed

Modified DistinctScalarAggregateResultSet:close to free resources initialized during open.


> OutOfMemory Error on continous execution of select statement using COUNT() and DISTINCT on same connection
> ----------------------------------------------------------------------------------------------------------
>
>          Key: DERBY-756
>          URL: http://issues.apache.org/jira/browse/DERBY-756
>      Project: Derby
>         Type: Bug
>   Components: Demos/Scripts, JDBC, Network Client, Network Server, SQL
>     Versions: 10.0.2.1, 10.1.2.1
>  Environment: Windows XP, Java 1.5.0_05, Derby network server 10.0.2.1, 10.1.2.1, Derby heapsize 128m, IBM Universal JDBC driver
>     Reporter: Bill Chen
>     Assignee: Manish Khettry
>     Priority: Critical
>  Attachments: mem_leak.diff
>
> The OutOfMemory is thrown when I continously execute a sql statement on an openned JDBC connection. A PreparedStatement and ResultSet is created on the connection everytime and close after each execution. I suspect that the bug is related to function COUNT() with keyword DISTINCT. For example, "select count(distinct ID) from TEST where FLAG <> 2". It will be fine if DISTINCT is not used, or select count(*) is used.
> The exception like "Exception in thread "DRDAConnThread_2" java.lang.OutOfMemoryError: Java heap space" could be thrown on Derby side, or sometimes on client side.
> Please find the test code and schema I used for testing:
> create table:
> CREATE TABLE Test
> (
>     ID BIGINT NOT NULL,
>     NAME VARCHAR(512) NOT NULL,
>     FLAG int,
>       CONSTRAINT PK_ID PRIMARY KEY (ID)
> );
> insert data:
> insert into TEST values (0, 'name0', 0);
> insert into TEST values (1, 'name1', 1);
> insert into TEST values (2, 'name2', 2);
> Java client:
> import java.sql.Connection;
> import java.sql.PreparedStatement;
> import java.sql.ResultSet;
> import java.sql.DriverManager;
> import java.sql.SQLException;
> public class DerbyTest
> {
>     static public void main(String args[]) throws Exception
>     {
>         Class.forName("com.ibm.db2.jcc.DB2Driver");
>         Connection conn = null;
>         try
>         {
>             conn = DriverManager.getConnection("jdbc:derby:net://localhost:1527/testDB", "admin", "admin");
>             for (int i = 0; i < 10000000; i++)
>             {
>                 System.out.println("Query "+i);
>                 String sql = "select count(distinct ID) from TEST where FLAG <> 2";
>                 PreparedStatement pStmt = null;
>                 ResultSet rs = null;
>                 try
>                 {
>                     pStmt = conn.prepareStatement(sql);
>                     rs = pStmt.executeQuery();
>                     if (rs.next())
>                     {
>                         rs.getInt(1);
>                     }
>                 }
>                 catch (SQLException e)
>                 {
>                     e.printStackTrace();
>                 }
>                 finally
>                 {
>                     if (rs != null)
>                         rs.close();
>                     if (pStmt != null)
>                         pStmt.close();
>                 }
>             }
>         }
>         finally
>         {
>             if (conn != null)
>                 conn.close();
>         }
>     }
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Commented: (DERBY-756) OutOfMemory Error on continous execution of select statement using COUNT() and DISTINCT on same connection

Posted by "Satheesh Bandaram (JIRA)" <de...@db.apache.org>.
    [ http://issues.apache.org/jira/browse/DERBY-756?page=comments#action_12363928 ] 

Satheesh Bandaram commented on DERBY-756:
-----------------------------------------

My suggestion is to create a sub-task of this bug, to cover any other memory leak, if present. Current bug covers issue that is specific to Distinct and that seems to be fixed with Manish's patch. Once a sub-task is created, this can be closed.

> OutOfMemory Error on continous execution of select statement using COUNT() and DISTINCT on same connection
> ----------------------------------------------------------------------------------------------------------
>
>          Key: DERBY-756
>          URL: http://issues.apache.org/jira/browse/DERBY-756
>      Project: Derby
>         Type: Bug
>   Components: Demos/Scripts, JDBC, Network Client, Network Server, SQL
>     Versions: 10.0.2.1, 10.1.2.1
>  Environment: Windows XP, Java 1.5.0_05, Derby network server 10.0.2.1, 10.1.2.1, Derby heapsize 128m, IBM Universal JDBC driver
>     Reporter: Bill Chen
>     Assignee: Manish Khettry
>     Priority: Critical
>  Attachments: mem_leak.diff
>
> The OutOfMemory is thrown when I continously execute a sql statement on an openned JDBC connection. A PreparedStatement and ResultSet is created on the connection everytime and close after each execution. I suspect that the bug is related to function COUNT() with keyword DISTINCT. For example, "select count(distinct ID) from TEST where FLAG <> 2". It will be fine if DISTINCT is not used, or select count(*) is used.
> The exception like "Exception in thread "DRDAConnThread_2" java.lang.OutOfMemoryError: Java heap space" could be thrown on Derby side, or sometimes on client side.
> Please find the test code and schema I used for testing:
> create table:
> CREATE TABLE Test
> (
>     ID BIGINT NOT NULL,
>     NAME VARCHAR(512) NOT NULL,
>     FLAG int,
>       CONSTRAINT PK_ID PRIMARY KEY (ID)
> );
> insert data:
> insert into TEST values (0, 'name0', 0);
> insert into TEST values (1, 'name1', 1);
> insert into TEST values (2, 'name2', 2);
> Java client:
> import java.sql.Connection;
> import java.sql.PreparedStatement;
> import java.sql.ResultSet;
> import java.sql.DriverManager;
> import java.sql.SQLException;
> public class DerbyTest
> {
>     static public void main(String args[]) throws Exception
>     {
>         Class.forName("com.ibm.db2.jcc.DB2Driver");
>         Connection conn = null;
>         try
>         {
>             conn = DriverManager.getConnection("jdbc:derby:net://localhost:1527/testDB", "admin", "admin");
>             for (int i = 0; i < 10000000; i++)
>             {
>                 System.out.println("Query "+i);
>                 String sql = "select count(distinct ID) from TEST where FLAG <> 2";
>                 PreparedStatement pStmt = null;
>                 ResultSet rs = null;
>                 try
>                 {
>                     pStmt = conn.prepareStatement(sql);
>                     rs = pStmt.executeQuery();
>                     if (rs.next())
>                     {
>                         rs.getInt(1);
>                     }
>                 }
>                 catch (SQLException e)
>                 {
>                     e.printStackTrace();
>                 }
>                 finally
>                 {
>                     if (rs != null)
>                         rs.close();
>                     if (pStmt != null)
>                         pStmt.close();
>                 }
>             }
>         }
>         finally
>         {
>             if (conn != null)
>                 conn.close();
>         }
>     }
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Commented: (DERBY-756) OutOfMemory Error on continous execution of select statement using COUNT() and DISTINCT on same connection

Posted by "Satheesh Bandaram (JIRA)" <de...@db.apache.org>.
    [ http://issues.apache.org/jira/browse/DERBY-756?page=comments#action_12363503 ] 

Satheesh Bandaram commented on DERBY-756:
-----------------------------------------

Thanks for your patch, Manish... I have submitted your patch. Please RESOLVE this bug and after confirming CLOSE the fix, CLOSE it. Let me know if you need any help testing or closing the issue.

Sending        java\engine\org\apache\derby\impl\sql\execute\DistinctScalarAggregateResultSet.java
Transmitting file data .
Committed revision 370978.


> OutOfMemory Error on continous execution of select statement using COUNT() and DISTINCT on same connection
> ----------------------------------------------------------------------------------------------------------
>
>          Key: DERBY-756
>          URL: http://issues.apache.org/jira/browse/DERBY-756
>      Project: Derby
>         Type: Bug
>   Components: Demos/Scripts, JDBC, Network Client, Network Server, SQL
>     Versions: 10.0.2.1, 10.1.2.1
>  Environment: Windows XP, Java 1.5.0_05, Derby network server 10.0.2.1, 10.1.2.1, Derby heapsize 128m, IBM Universal JDBC driver
>     Reporter: Bill Chen
>     Assignee: Manish Khettry
>     Priority: Critical
>  Attachments: mem_leak.diff
>
> The OutOfMemory is thrown when I continously execute a sql statement on an openned JDBC connection. A PreparedStatement and ResultSet is created on the connection everytime and close after each execution. I suspect that the bug is related to function COUNT() with keyword DISTINCT. For example, "select count(distinct ID) from TEST where FLAG <> 2". It will be fine if DISTINCT is not used, or select count(*) is used.
> The exception like "Exception in thread "DRDAConnThread_2" java.lang.OutOfMemoryError: Java heap space" could be thrown on Derby side, or sometimes on client side.
> Please find the test code and schema I used for testing:
> create table:
> CREATE TABLE Test
> (
>     ID BIGINT NOT NULL,
>     NAME VARCHAR(512) NOT NULL,
>     FLAG int,
>       CONSTRAINT PK_ID PRIMARY KEY (ID)
> );
> insert data:
> insert into TEST values (0, 'name0', 0);
> insert into TEST values (1, 'name1', 1);
> insert into TEST values (2, 'name2', 2);
> Java client:
> import java.sql.Connection;
> import java.sql.PreparedStatement;
> import java.sql.ResultSet;
> import java.sql.DriverManager;
> import java.sql.SQLException;
> public class DerbyTest
> {
>     static public void main(String args[]) throws Exception
>     {
>         Class.forName("com.ibm.db2.jcc.DB2Driver");
>         Connection conn = null;
>         try
>         {
>             conn = DriverManager.getConnection("jdbc:derby:net://localhost:1527/testDB", "admin", "admin");
>             for (int i = 0; i < 10000000; i++)
>             {
>                 System.out.println("Query "+i);
>                 String sql = "select count(distinct ID) from TEST where FLAG <> 2";
>                 PreparedStatement pStmt = null;
>                 ResultSet rs = null;
>                 try
>                 {
>                     pStmt = conn.prepareStatement(sql);
>                     rs = pStmt.executeQuery();
>                     if (rs.next())
>                     {
>                         rs.getInt(1);
>                     }
>                 }
>                 catch (SQLException e)
>                 {
>                     e.printStackTrace();
>                 }
>                 finally
>                 {
>                     if (rs != null)
>                         rs.close();
>                     if (pStmt != null)
>                         pStmt.close();
>                 }
>             }
>         }
>         finally
>         {
>             if (conn != null)
>                 conn.close();
>         }
>     }
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Resolved: (DERBY-756) OutOfMemory Error on continous execution of select statement using COUNT() and DISTINCT on same connection

Posted by "Satheesh Bandaram (JIRA)" <de...@db.apache.org>.
     [ http://issues.apache.org/jira/browse/DERBY-756?page=all ]
     
Satheesh Bandaram resolved DERBY-756:
-------------------------------------

    Fix Version: 10.2.0.0
     Resolution: Fixed

Fixed in 10.2.

> OutOfMemory Error on continous execution of select statement using COUNT() and DISTINCT on same connection
> ----------------------------------------------------------------------------------------------------------
>
>          Key: DERBY-756
>          URL: http://issues.apache.org/jira/browse/DERBY-756
>      Project: Derby
>         Type: Bug
>   Components: Demos/Scripts, JDBC, Network Client, Network Server, SQL
>     Versions: 10.0.2.1, 10.1.2.1
>  Environment: Windows XP, Java 1.5.0_05, Derby network server 10.0.2.1, 10.1.2.1, Derby heapsize 128m, IBM Universal JDBC driver
>     Reporter: Bill Chen
>     Assignee: Manish Khettry
>     Priority: Critical
>      Fix For: 10.2.0.0
>  Attachments: mem_leak.diff
>
> The OutOfMemory is thrown when I continously execute a sql statement on an openned JDBC connection. A PreparedStatement and ResultSet is created on the connection everytime and close after each execution. I suspect that the bug is related to function COUNT() with keyword DISTINCT. For example, "select count(distinct ID) from TEST where FLAG <> 2". It will be fine if DISTINCT is not used, or select count(*) is used.
> The exception like "Exception in thread "DRDAConnThread_2" java.lang.OutOfMemoryError: Java heap space" could be thrown on Derby side, or sometimes on client side.
> Please find the test code and schema I used for testing:
> create table:
> CREATE TABLE Test
> (
>     ID BIGINT NOT NULL,
>     NAME VARCHAR(512) NOT NULL,
>     FLAG int,
>       CONSTRAINT PK_ID PRIMARY KEY (ID)
> );
> insert data:
> insert into TEST values (0, 'name0', 0);
> insert into TEST values (1, 'name1', 1);
> insert into TEST values (2, 'name2', 2);
> Java client:
> import java.sql.Connection;
> import java.sql.PreparedStatement;
> import java.sql.ResultSet;
> import java.sql.DriverManager;
> import java.sql.SQLException;
> public class DerbyTest
> {
>     static public void main(String args[]) throws Exception
>     {
>         Class.forName("com.ibm.db2.jcc.DB2Driver");
>         Connection conn = null;
>         try
>         {
>             conn = DriverManager.getConnection("jdbc:derby:net://localhost:1527/testDB", "admin", "admin");
>             for (int i = 0; i < 10000000; i++)
>             {
>                 System.out.println("Query "+i);
>                 String sql = "select count(distinct ID) from TEST where FLAG <> 2";
>                 PreparedStatement pStmt = null;
>                 ResultSet rs = null;
>                 try
>                 {
>                     pStmt = conn.prepareStatement(sql);
>                     rs = pStmt.executeQuery();
>                     if (rs.next())
>                     {
>                         rs.getInt(1);
>                     }
>                 }
>                 catch (SQLException e)
>                 {
>                     e.printStackTrace();
>                 }
>                 finally
>                 {
>                     if (rs != null)
>                         rs.close();
>                     if (pStmt != null)
>                         pStmt.close();
>                 }
>             }
>         }
>         finally
>         {
>             if (conn != null)
>                 conn.close();
>         }
>     }
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Commented: (DERBY-756) OutOfMemory Error on continous execution of select statement using COUNT() and DISTINCT on same connection

Posted by "Rajesh Kartha (JIRA)" <de...@db.apache.org>.
    [ http://issues.apache.org/jira/browse/DERBY-756?page=comments#action_12360355 ] 

Rajesh Kartha commented on DERBY-756:
-------------------------------------

I observed the OutofMemoryError running in embedded mode (v10.1.2).  On my box, I noticed 100% CPU utilization all though and ran into the error pretty early(~ 82000 attempt of the loop).



> OutOfMemory Error on continous execution of select statement using COUNT() and DISTINCT on same connection
> ----------------------------------------------------------------------------------------------------------
>
>          Key: DERBY-756
>          URL: http://issues.apache.org/jira/browse/DERBY-756
>      Project: Derby
>         Type: Bug
>   Components: Demos/Scripts, JDBC, Network Client, Network Server, SQL
>     Versions: 10.0.2.1, 10.1.2.1
>  Environment: Windows XP, Java 1.5.0_05, Derby network server 10.0.2.1, 10.1.2.1, Derby heapsize 128m, IBM Universal JDBC driver
>     Reporter: Bill Chen
>     Priority: Critical

>
> The OutOfMemory is thrown when I continously execute a sql statement on an openned JDBC connection. A PreparedStatement and ResultSet is created on the connection everytime and close after each execution. I suspect that the bug is related to function COUNT() with keyword DISTINCT. For example, "select count(distinct ID) from TEST where FLAG <> 2". It will be fine if DISTINCT is not used, or select count(*) is used.
> The exception like "Exception in thread "DRDAConnThread_2" java.lang.OutOfMemoryError: Java heap space" could be thrown on Derby side, or sometimes on client side.
> Please find the test code and schema I used for testing:
> create table:
> CREATE TABLE Test
> (
>     ID BIGINT NOT NULL,
>     NAME VARCHAR(512) NOT NULL,
>     FLAG int,
>       CONSTRAINT PK_ID PRIMARY KEY (ID)
> );
> insert data:
> insert into TEST values (0, 'name0', 0);
> insert into TEST values (1, 'name1', 1);
> insert into TEST values (2, 'name2', 2);
> Java client:
> import java.sql.Connection;
> import java.sql.PreparedStatement;
> import java.sql.ResultSet;
> import java.sql.DriverManager;
> import java.sql.SQLException;
> public class DerbyTest
> {
>     static public void main(String args[]) throws Exception
>     {
>         Class.forName("com.ibm.db2.jcc.DB2Driver");
>         Connection conn = null;
>         try
>         {
>             conn = DriverManager.getConnection("jdbc:derby:net://localhost:1527/testDB", "admin", "admin");
>             for (int i = 0; i < 10000000; i++)
>             {
>                 System.out.println("Query "+i);
>                 String sql = "select count(distinct ID) from TEST where FLAG <> 2";
>                 PreparedStatement pStmt = null;
>                 ResultSet rs = null;
>                 try
>                 {
>                     pStmt = conn.prepareStatement(sql);
>                     rs = pStmt.executeQuery();
>                     if (rs.next())
>                     {
>                         rs.getInt(1);
>                     }
>                 }
>                 catch (SQLException e)
>                 {
>                     e.printStackTrace();
>                 }
>                 finally
>                 {
>                     if (rs != null)
>                         rs.close();
>                     if (pStmt != null)
>                         pStmt.close();
>                 }
>             }
>         }
>         finally
>         {
>             if (conn != null)
>                 conn.close();
>         }
>     }
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Closed: (DERBY-756) OutOfMemory Error on continous execution of select statement using COUNT() and DISTINCT on same connection

Posted by "Satheesh Bandaram (JIRA)" <de...@db.apache.org>.
     [ http://issues.apache.org/jira/browse/DERBY-756?page=all ]
     
Satheesh Bandaram closed DERBY-756:
-----------------------------------


> OutOfMemory Error on continous execution of select statement using COUNT() and DISTINCT on same connection
> ----------------------------------------------------------------------------------------------------------
>
>          Key: DERBY-756
>          URL: http://issues.apache.org/jira/browse/DERBY-756
>      Project: Derby
>         Type: Bug
>   Components: Demos/Scripts, JDBC, Network Client, Network Server, SQL
>     Versions: 10.0.2.1, 10.1.2.1
>  Environment: Windows XP, Java 1.5.0_05, Derby network server 10.0.2.1, 10.1.2.1, Derby heapsize 128m, IBM Universal JDBC driver
>     Reporter: Bill Chen
>     Assignee: Manish Khettry
>     Priority: Critical
>      Fix For: 10.2.0.0
>  Attachments: mem_leak.diff
>
> The OutOfMemory is thrown when I continously execute a sql statement on an openned JDBC connection. A PreparedStatement and ResultSet is created on the connection everytime and close after each execution. I suspect that the bug is related to function COUNT() with keyword DISTINCT. For example, "select count(distinct ID) from TEST where FLAG <> 2". It will be fine if DISTINCT is not used, or select count(*) is used.
> The exception like "Exception in thread "DRDAConnThread_2" java.lang.OutOfMemoryError: Java heap space" could be thrown on Derby side, or sometimes on client side.
> Please find the test code and schema I used for testing:
> create table:
> CREATE TABLE Test
> (
>     ID BIGINT NOT NULL,
>     NAME VARCHAR(512) NOT NULL,
>     FLAG int,
>       CONSTRAINT PK_ID PRIMARY KEY (ID)
> );
> insert data:
> insert into TEST values (0, 'name0', 0);
> insert into TEST values (1, 'name1', 1);
> insert into TEST values (2, 'name2', 2);
> Java client:
> import java.sql.Connection;
> import java.sql.PreparedStatement;
> import java.sql.ResultSet;
> import java.sql.DriverManager;
> import java.sql.SQLException;
> public class DerbyTest
> {
>     static public void main(String args[]) throws Exception
>     {
>         Class.forName("com.ibm.db2.jcc.DB2Driver");
>         Connection conn = null;
>         try
>         {
>             conn = DriverManager.getConnection("jdbc:derby:net://localhost:1527/testDB", "admin", "admin");
>             for (int i = 0; i < 10000000; i++)
>             {
>                 System.out.println("Query "+i);
>                 String sql = "select count(distinct ID) from TEST where FLAG <> 2";
>                 PreparedStatement pStmt = null;
>                 ResultSet rs = null;
>                 try
>                 {
>                     pStmt = conn.prepareStatement(sql);
>                     rs = pStmt.executeQuery();
>                     if (rs.next())
>                     {
>                         rs.getInt(1);
>                     }
>                 }
>                 catch (SQLException e)
>                 {
>                     e.printStackTrace();
>                 }
>                 finally
>                 {
>                     if (rs != null)
>                         rs.close();
>                     if (pStmt != null)
>                         pStmt.close();
>                 }
>             }
>         }
>         finally
>         {
>             if (conn != null)
>                 conn.close();
>         }
>     }
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira