Issue Details (XML | Word | Printable)

Key: DERBY-106
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: Gerald Khin
Votes: 0
Watchers: 0
Operations

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

HashJoinStrategy leads to java.lang.OutOfMemoryError

Created: 17/Dec/04 04:08 PM   Updated: 12/Jul/06 12:05 AM
Return to search
Component/s: SQL
Affects Version/s: None
Fix Version/s: 10.1.1.0

Time Tracking:
Not Specified

Resolution Date: 23/Mar/05 06:58 AM


 Description  « Hide
My application is running out of memory: I encounterd a java.lang.OutOfMemoryError. I used -Xmx256M. Unfortunatley, I cannot spend an arbitrary amount of JVM memory.

Then, I commented out the line in class OptimizerFactoryImpl which was adding the HashJoinStrategy to the set of Join strategies:

if (joinStrategySet == null)
{
// JoinStrategy[] jss = new JoinStrategy[2];
JoinStrategy[] jss = new JoinStrategy[1];
jss[0] = new NestedLoopJoinStrategy();
// jss[1] = new HashJoinStrategy();
joinStrategySet = jss;
}

And with these changes the OutOfMemoryError has gone away! And it works even with -Xmx128M!!!

So I guess that there is a major memory issue with this HashJoin strategy implementation.

If it turns out to be too complicated to make the memory consumption more predicatble or even bounded to some configurable limit, then I need at least as a workaround a way to turn off the HashJoin strategy completely: I did it by patching and building my own derby.jar, but if there would be an official solution with some kind of switch like a system property, it would be great!



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Jack Klebanoff added a comment - 17/Dec/04 05:12 PM
Do you know whether the memory overflow occurred during compilation or execution? Do you have a stack trace from the OutOfMemoryError? Do you know the sizes of the tables being joined?

Gerald Khin added a comment - 20/Dec/04 07:56 AM
The system property derby.language.maxMemoryPerTable is the system property I asked for. Setting it to 0 works like a charm and turns the hash join strategy off. So I'm happy and the bug can be closed. Perhaps this system property should be mentioned somewhere in the derby tuning manual.

For completenesss, if someone is still interested on details:

The SQL query of interest is this one:

SELECT c.* FROM AttrOcc c WHERE EXISTS (SELECT 'X' FROM Occ p WHERE c.OccID=p.ID AND p.DISCRIMINATOR=1)

As you can see, there are two tables involved: A table Occ and a table Attrocc whereas the latter has a foreign key
constraint on column OccID that refers to the primary key column ID of table Occ:

CREATE TABLE Occ (
  ID CHAR(15) PRIMARY KEY,
  DISCRIMINATOR NUMERIC(10),
  ...
)

CREATE TABLE AttrOcc (
  ID CHAR(15) PRIMARY KEY,
  OCCID CHAR(15) NOT NULL REFERENCES OCC ON DELETE CASCADE,
  ...
)

There is no index on column Occ.DISCRIMINATOR.

Table Occ has 267661 rows and table AttrOcc has 153084 rows.

My testprogram runs with -Xmx128m.

If I use default derby.language.maxMemoryPerTable (i.e.) 1024K, then the SQL statement above leads to that OutOfMemoryError.
And the query take 192s for execution.

If I create a compound index on Occ(ID,DISCRIMINATOR) and use default derby.language.maxMemoryPerTable (i.e.) 1024K, then
it needs a bit less memory, so that it runs with -Xmx128. And it takes 140s to execute. So this is slighly better.

If I set derby.language.maxMemoryPerTable to 0 (and without index on Occ(ID,DISCRIMINATOR)), then memory consumption is
minimal: -Xmx48 is sufficient. And it takes only 19s to execute (This is an order of magnitude better than the
derby.language.maxMemoryPerTable=1024 variant).



Repository Revision Date User Message
ASF #157861 Thu Mar 17 02:35:44 UTC 2005 mikem committing change by Jack Klebanoff (klebanoff-derby@sbcglobal.net).

Fix for DERBY-106

This change fixes the BackingStoreHashTable class to actually spill
over to disk when necessary. Prior to this fix it was possible for
hash joins to fail with out of memory errors, when they should instead
have spilled to disk.
Files Changed
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/BackingStoreHashTableFromScan.java
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/OptimizerImpl.java
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/HashTableResultSet.java
ADD /incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/TestDiskHashtable.java
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/compile/Optimizable.java
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromBaseTable.java
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/ScrollInsensitiveResultSet.java
ADD /incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/TestDiskHashtable.out
MODIFY /incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/build.xml
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/NestedLoopJoinStrategy.java
ADD /incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/store/access/DiskHashtable.java
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/Level2OptimizerImpl.java
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/compile/Optimizer.java
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromTable.java
ADD /incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/SpillHash.out
MODIFY /incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbylang.runall
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/store/access/BackingStoreHashtable.java
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/HashScanResultSet.java
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/compile/JoinStrategy.java
MODIFY /incubator/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/HashJoinStrategy.java
MODIFY /incubator/derby/code/trunk/build.xml
ADD /incubator/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SpillHash.java

Jack Klebanoff added a comment - 23/Mar/05 06:58 AM
Subversion revision 157861

Jack Klebanoff made changes - 23/Mar/05 06:58 AM
Field Original Value New Value
Resolution Fixed [ 1 ]
Fix Version/s 10.1.0.0 [ 10993 ]
Status Open [ 1 ] Closed [ 6 ]
Rick Hillegas added a comment - 12/Jul/06 12:05 AM
Assigning to SQL component.

Rick Hillegas made changes - 12/Jul/06 12:05 AM
Component/s SQL [ 11408 ]