Issue Details (XML | Word | Printable)

Key: DERBY-756
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Critical Critical
Assignee: Manish Khettry
Reporter: Bill Chen
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Derby

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

Created: 14/Dec/05 01:27 AM   Updated: 19/Oct/07 04:12 PM
Return to search
Component/s: Demos/Scripts, JDBC, Network Client, Network Server, SQL
Affects Version/s: 10.0.2.1, 10.1.2.1
Fix Version/s: 10.1.3.2, 10.2.1.6

Time Tracking:
Issue & Sub-Tasks
Issue Only
Not Specified

File Attachments:
  Size
File Licensed for inclusion in ASF works mem_leak.diff 2006-01-19 03:19 PM Manish Khettry 2 kB
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

Resolution Date: 15/Feb/06 02:55 PM

Sub-Tasks  All   Open   
No sub-tasks match this view.

 Description  « Hide
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();
        }
    }

}


 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Manish Khettry made changes - 13/Jan/06 04:04 PM
Field Original Value New Value
Assignee Manish Khettry [ mkhettry ]
Manish Khettry made changes - 13/Jan/06 04:06 PM
Status Open [ 1 ] In Progress [ 3 ]
Manish Khettry made changes - 19/Jan/06 03:19 PM
Attachment mem_leak.diff [ 12322105 ]
Manish Khettry made changes - 25/Jan/06 12:09 PM
Resolution Fixed [ 1 ]
Status In Progress [ 3 ] Resolved [ 5 ]
Manish Khettry made changes - 03/Feb/06 04:02 AM
Status Resolved [ 5 ] Closed [ 6 ]
Satheesh Bandaram made changes - 15/Feb/06 02:55 PM
Resolution Fixed [ 1 ]
Status Closed [ 6 ] Reopened [ 4 ]
Satheesh Bandaram made changes - 15/Feb/06 02:55 PM
Status Reopened [ 4 ] Resolved [ 5 ]
Fix Version/s 10.2.0.0 [ 11187 ]
Resolution Fixed [ 1 ]
Satheesh Bandaram made changes - 15/Feb/06 02:55 PM
Status Resolved [ 5 ] Closed [ 6 ]
Kathey Marsden made changes - 19/Oct/07 04:12 PM
Fix Version/s 10.1.3.2 [ 12311972 ]