db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r586505 - in /db/derby/code/branches/10.1/java/engine/org/apache/derby/impl: sql/GenericParameter.java sql/execute/DistinctScalarAggregateResultSet.java store/access/RAMTransaction.java
Date Fri, 19 Oct 2007 15:42:05 GMT
Author: kmarsden
Date: Fri Oct 19 08:42:04 2007
New Revision: 586505

URL: http://svn.apache.org/viewvc?rev=586505&view=rev
Log:
DERBY-756  OutOfMemory Error on continous execution of select statement using COUNT() and
DISTINCT on same connection

merge from trunk


Modified:
    db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/GenericParameter.java
    db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/execute/DistinctScalarAggregateResultSet.java
    db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/store/access/RAMTransaction.java

Modified: db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/GenericParameter.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/GenericParameter.java?rev=586505&r1=586504&r2=586505&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/GenericParameter.java
(original)
+++ db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/GenericParameter.java
Fri Oct 19 08:42:04 2007
@@ -352,11 +352,11 @@
 		{
 			try
 			{
-				return value.getString();
+				return value.getTraceString();
 			}
 			catch (StandardException se)
 			{
-				return "unexpected exception from getString() - " + se;
+				return "unexpected exception from getTraceString() - " + se;
 			}
 		}
 	}

Modified: db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/execute/DistinctScalarAggregateResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/execute/DistinctScalarAggregateResultSet.java?rev=586505&r1=586504&r2=586505&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/execute/DistinctScalarAggregateResultSet.java
(original)
+++ db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/execute/DistinctScalarAggregateResultSet.java
Fri Oct 19 08:42:04 2007
@@ -20,17 +20,8 @@
 
 package org.apache.derby.impl.sql.execute;
 
-import org.apache.derby.iapi.services.monitor.Monitor;
-
 import org.apache.derby.iapi.services.sanity.SanityManager;
 
-import org.apache.derby.iapi.services.stream.HeaderPrintWriter;
-import org.apache.derby.iapi.services.stream.InfoStreams;
-
-import org.apache.derby.iapi.services.io.Formatable;
-
-import org.apache.derby.iapi.sql.execute.CursorResultSet;
-import org.apache.derby.iapi.sql.ResultSet;
 import org.apache.derby.iapi.sql.execute.ExecRow;
 import org.apache.derby.iapi.sql.execute.ExecIndexRow;
 import org.apache.derby.iapi.sql.execute.NoPutResultSet;
@@ -45,19 +36,13 @@
 
 import org.apache.derby.iapi.services.loader.GeneratedMethod;
 
-import org.apache.derby.iapi.sql.execute.ExecutionFactory;
-import org.apache.derby.iapi.sql.execute.ExecutionContext;
-import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
-
-import org.apache.derby.iapi.types.RowLocation;
 
 import org.apache.derby.iapi.error.StandardException;
 
 import org.apache.derby.iapi.services.io.FormatableArrayHolder;
 
 import java.util.Properties;
-import java.util.Vector;
-import java.util.Enumeration;
+
 
 /**
  * This ResultSet evaluates scalar aggregates where
@@ -272,6 +257,14 @@
 		openTime += getElapsedMillis(beginTime);
 	}
 
+        /**
+         * @inheritDoc
+         */
+        public void close() throws StandardException
+        {
+            super.close();
+            closeSource();
+        }
 	///////////////////////////////////////////////////////////////////////////////
 	//
 	// SCAN ABSTRACTION UTILITIES

Modified: db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/store/access/RAMTransaction.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/store/access/RAMTransaction.java?rev=586505&r1=586504&r2=586505&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/store/access/RAMTransaction.java
(original)
+++ db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/store/access/RAMTransaction.java
Fri Oct 19 08:42:04 2007
@@ -20,12 +20,14 @@
 
 package org.apache.derby.impl.store.access;
 
+import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.Hashtable;
 import java.util.Properties;
 import java.util.Vector;
 
 import org.apache.derby.iapi.reference.SQLState;
+import org.apache.derby.iapi.util.ReuseFactory;
 
 import org.apache.derby.iapi.services.context.ContextManager;
 
@@ -119,6 +121,11 @@
 	private Vector sorts;
 	private Vector sortControllers;
 
+    /** List of sort identifiers (represented as <code>Integer</code> objects)
+     * which can be reused. Since sort identifiers are used as array indexes,
+     * we need to reuse them to avoid leaking memory (DERBY-912). */
+    private ArrayList freeSortIds;
+
 	/**
 	Where to look for temporary conglomerates.
 	**/
@@ -162,6 +169,7 @@
 		conglomerateControllers = new Vector();
 
 		sorts                   = null; // allocated on demand.
+		freeSortIds             = null; // allocated on demand.
 		sortControllers         = null; // allocated on demand
 
         if (parent_tran != null)
@@ -313,6 +321,7 @@
                         sort.drop(this);
                 }
                 sorts.removeAllElements();
+                freeSortIds.clear();
             }
 		}
 	}
@@ -1716,10 +1725,22 @@
                         estimatedRowSize);
 
 		// Add the sort to the sorts vector
-		if (sorts == null)
+		if (sorts == null) {
 			sorts = new Vector();
-		long sortid = sorts.size();
-		sorts.addElement(sort);
+            freeSortIds = new ArrayList();
+        }
+
+        int sortid;
+        if (freeSortIds.isEmpty()) {
+            // no free identifiers, add sort at the end
+            sortid = sorts.size();
+            sorts.addElement(sort);
+        } else {
+            // reuse a sort identifier
+            sortid = ((Integer) freeSortIds.remove(freeSortIds.size() - 1))
+                .intValue();
+            sorts.setElementAt(sort, sortid);
+        }
 
 		return sortid;
 	}
@@ -1747,6 +1768,7 @@
         {
             sort.drop(this);
             sorts.setElementAt(null, (int) sortid);
+            freeSortIds.add(ReuseFactory.getInteger((int) sortid));
         }
     }
 



Mime
View raw message