Return-Path: Delivered-To: apmail-db-derby-dev-archive@www.apache.org Received: (qmail 63292 invoked from network); 20 Jun 2008 18:16:47 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 20 Jun 2008 18:16:47 -0000 Received: (qmail 77759 invoked by uid 500); 20 Jun 2008 18:16:42 -0000 Delivered-To: apmail-db-derby-dev-archive@db.apache.org Received: (qmail 77731 invoked by uid 500); 20 Jun 2008 18:16:41 -0000 Mailing-List: contact derby-dev-help@db.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: Delivered-To: mailing list derby-dev@db.apache.org Received: (qmail 77543 invoked by uid 99); 20 Jun 2008 18:16:39 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 20 Jun 2008 11:16:39 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.140] (HELO brutus.apache.org) (140.211.11.140) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 20 Jun 2008 18:15:56 +0000 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 25280234C146 for ; Fri, 20 Jun 2008 11:15:45 -0700 (PDT) Message-ID: <654022969.1213985745150.JavaMail.jira@brutus> Date: Fri, 20 Jun 2008 11:15:45 -0700 (PDT) From: "Kathey Marsden (JIRA)" To: derby-dev@db.apache.org Subject: [jira] Updated: (DERBY-3732) SQL Length function materializes lob into memory In-Reply-To: <953379663.1213917585016.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/DERBY-3732?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Kathey Marsden updated DERBY-3732: ---------------------------------- Attachment: LengthThruBlob.java One possible workaround is just to select the BLOB and call Blob.length(). worst case this call will go through the entire stream without materializing. When inserting the Blob, it is better to use the setBinaryStream call that takes length so that the length is stored in the stream and the call to Blob.length() willl be a lot faster. See attached program LengthThruBlob. It needs Astream.java from the original repro zip file. > SQL Length function materializes lob into memory > ------------------------------------------------ > > Key: DERBY-3732 > URL: https://issues.apache.org/jira/browse/DERBY-3732 > Project: Derby > Issue Type: Improvement > Components: SQL > Affects Versions: 10.3.3.0, 10.4.1.3, 10.5.0.0 > Reporter: Kathey Marsden > Priority: Minor > Attachments: LengthLargeLob.zip, LengthThruBlob.java > > > Currently the SQL length function materializes the entire lob into memory. In SQLBinary.getLength() we have > public final int getLength() throws StandardException > { > if (stream != null) { > if (streamValueLength != -1) > return streamValueLength; > } > return (getBytes() == null) ? 0 : getBytes().length; > } > Which actually is doubly bad because we call getBytes twice and materialize it twice. > It would be good to read the length from the stream if available and otherwise stream the value to get the length, rather than materializing it into memory. > To reproduce, run the attached repro. > java -Xmx16M LengthLargeLob > It gives an out of memory exception > Caused by: java.lang.OutOfMemoryError: Java heap space > at org.apache.derby.iapi.types.SQLBinary.readFromStream(SQLBinary.java:415) > at org.apache.derby.iapi.types.SQLBinary.readExternal(SQLBinary.java:318) > at org.apache.derby.iapi.types.SQLBinary.getValue(SQLBinary.java:220) > at org.apache.derby.iapi.types.SQLBinary.getBytes(SQLBinary.java:210) > at org.apache.derby.iapi.types.SQLBinary.getLength(SQLBinary.java:250) > at org.apache.derby.impl.sql.execute.BaseActivation.getDB2Length(BaseActivation.java:1684) > at org.apache.derby.exe.acf81e0010x011axa317x5db8x0000003d9dc81.e1(Unknown Source) > at org.apache.derby.impl.services.reflect.DirectCall.invoke(ReflectGeneratedClass.java:141) > at org.apache.derby.impl.sql.execute.ProjectRestrictResultSet.doProjection(ProjectRestrictResultSet.java:497) > at org.apache.derby.impl.sql.execute.ProjectRestrictResultSet.getNextRowCore(ProjectRestrictResultSet.java:291) > at org.apache.derby.impl.sql.execute.BasicNoPutResultSetImpl.getNextRow(BasicNoPutResultSetImpl.java:460) > at org.apache.derby.impl.jdbc.EmbedResultSet.movePosition(EmbedResultSet.java:423) > ... 2 more > [ > -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.