Return-Path: X-Original-To: apmail-db-derby-commits-archive@www.apache.org Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0FD20102B9 for ; Mon, 5 Aug 2013 02:49:33 +0000 (UTC) Received: (qmail 77792 invoked by uid 500); 5 Aug 2013 02:49:33 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 77736 invoked by uid 500); 5 Aug 2013 02:49:32 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 77729 invoked by uid 99); 5 Aug 2013 02:49:32 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 05 Aug 2013 02:49:32 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 05 Aug 2013 02:49:30 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 12CD423889BF; Mon, 5 Aug 2013 02:49:10 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1510366 - in /db/derby/code/branches/10.9: ./ java/engine/org/apache/derby/iapi/types/ Date: Mon, 05 Aug 2013 02:49:09 -0000 To: derby-commits@db.apache.org From: mamta@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20130805024910.12CD423889BF@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: mamta Date: Mon Aug 5 02:49:09 2013 New Revision: 1510366 URL: http://svn.apache.org/r1510366 Log: DERBY-2699(performance of like in territory based collation databases may be improved by changing way collation elements are calculated.) Backporting to 10.9. Fix contributed by Knut Anders Hatlen Modified: db/derby/code/branches/10.9/ (props changed) db/derby/code/branches/10.9/java/engine/org/apache/derby/iapi/types/CollationElementsInterface.java db/derby/code/branches/10.9/java/engine/org/apache/derby/iapi/types/CollatorSQLChar.java db/derby/code/branches/10.9/java/engine/org/apache/derby/iapi/types/CollatorSQLClob.java db/derby/code/branches/10.9/java/engine/org/apache/derby/iapi/types/CollatorSQLLongvarchar.java db/derby/code/branches/10.9/java/engine/org/apache/derby/iapi/types/CollatorSQLVarchar.java db/derby/code/branches/10.9/java/engine/org/apache/derby/iapi/types/WorkHorseForCollatorDatatypes.java Propchange: db/derby/code/branches/10.9/ ------------------------------------------------------------------------------ Merged /db/derby/code/trunk:r1428305 Modified: db/derby/code/branches/10.9/java/engine/org/apache/derby/iapi/types/CollationElementsInterface.java URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.9/java/engine/org/apache/derby/iapi/types/CollationElementsInterface.java?rev=1510366&r1=1510365&r2=1510366&view=diff ============================================================================== --- db/derby/code/branches/10.9/java/engine/org/apache/derby/iapi/types/CollationElementsInterface.java (original) +++ db/derby/code/branches/10.9/java/engine/org/apache/derby/iapi/types/CollationElementsInterface.java Mon Aug 5 02:49:09 2013 @@ -31,22 +31,13 @@ import org.apache.derby.iapi.error.Stand */ interface CollationElementsInterface { - /** - * This method translates the string into a series of collation elements. - * These elements will get used in the like method. - * - * @return an array of collation elements for the string - * @throws StandardException - */ - public int[] getCollationElementsForString() throws StandardException; - - /** - * This method returns the count of collation elements for this instance of - * CollationElementsInterface. This method will return the correct value only if - * method getCollationElementsForString has been called previously on this - * instance of CollationElementsInterface. - * - * @return count of collation elements for this instance of CollatorSQLChar - */ - public int getCountOfCollationElements(); + /** + * Check if this instance represents a value that has a single + * collation element. + * + * @return {@code true} if the value has exactly one collation element, + * or {@code false} otherwise + * @throws StandardException if an error occurs when accessing the value + */ + boolean hasSingleCollationElement() throws StandardException; } Modified: db/derby/code/branches/10.9/java/engine/org/apache/derby/iapi/types/CollatorSQLChar.java URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.9/java/engine/org/apache/derby/iapi/types/CollatorSQLChar.java?rev=1510366&r1=1510365&r2=1510366&view=diff ============================================================================== --- db/derby/code/branches/10.9/java/engine/org/apache/derby/iapi/types/CollatorSQLChar.java (original) +++ db/derby/code/branches/10.9/java/engine/org/apache/derby/iapi/types/CollatorSQLChar.java Mon Aug 5 02:49:09 2013 @@ -86,18 +86,12 @@ class CollatorSQLChar extends SQLChar im { return holderForCollationSensitiveInfo.getCollatorForCollation(); } - - /** @see CollationElementsInterface#getCollationElementsForString */ - public int[] getCollationElementsForString() throws StandardException - { - return holderForCollationSensitiveInfo.getCollationElementsForString(); - } - /** @see CollationElementsInterface#getCountOfCollationElements */ - public int getCountOfCollationElements() - { - return holderForCollationSensitiveInfo.getCountOfCollationElements(); - } + // Implementation of CollationElementsInterface interface + + public boolean hasSingleCollationElement() throws StandardException { + return holderForCollationSensitiveInfo.hasSingleCollationElement(); + } /* * DataValueDescriptor interface Modified: db/derby/code/branches/10.9/java/engine/org/apache/derby/iapi/types/CollatorSQLClob.java URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.9/java/engine/org/apache/derby/iapi/types/CollatorSQLClob.java?rev=1510366&r1=1510365&r2=1510366&view=diff ============================================================================== --- db/derby/code/branches/10.9/java/engine/org/apache/derby/iapi/types/CollatorSQLClob.java (original) +++ db/derby/code/branches/10.9/java/engine/org/apache/derby/iapi/types/CollatorSQLClob.java Mon Aug 5 02:49:09 2013 @@ -100,17 +100,11 @@ class CollatorSQLClob extends SQLClob im return holderForCollationSensitiveInfo.getCollatorForCollation(); } - /** @see CollationElementsInterface#getCollationElementsForString */ - public int[] getCollationElementsForString() throws StandardException - { - return holderForCollationSensitiveInfo.getCollationElementsForString(); - } + // Implementation of CollationElementsInterface interface - /** @see CollationElementsInterface#getCountOfCollationElements */ - public int getCountOfCollationElements() - { - return holderForCollationSensitiveInfo.getCountOfCollationElements(); - } + public boolean hasSingleCollationElement() throws StandardException { + return holderForCollationSensitiveInfo.hasSingleCollationElement(); + } /* * DataValueDescriptor interface Modified: db/derby/code/branches/10.9/java/engine/org/apache/derby/iapi/types/CollatorSQLLongvarchar.java URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.9/java/engine/org/apache/derby/iapi/types/CollatorSQLLongvarchar.java?rev=1510366&r1=1510365&r2=1510366&view=diff ============================================================================== --- db/derby/code/branches/10.9/java/engine/org/apache/derby/iapi/types/CollatorSQLLongvarchar.java (original) +++ db/derby/code/branches/10.9/java/engine/org/apache/derby/iapi/types/CollatorSQLLongvarchar.java Mon Aug 5 02:49:09 2013 @@ -89,17 +89,11 @@ class CollatorSQLLongvarchar extends SQL return holderForCollationSensitiveInfo.getCollatorForCollation(); } - /** @see CollationElementsInterface#getCollationElementsForString */ - public int[] getCollationElementsForString() throws StandardException - { - return holderForCollationSensitiveInfo.getCollationElementsForString(); - } + // Implementation of CollationElementsInterface interface - /** @see CollationElementsInterface#getCountOfCollationElements */ - public int getCountOfCollationElements() - { - return holderForCollationSensitiveInfo.getCountOfCollationElements(); - } + public boolean hasSingleCollationElement() throws StandardException { + return holderForCollationSensitiveInfo.hasSingleCollationElement(); + } /* * DataValueDescriptor interface Modified: db/derby/code/branches/10.9/java/engine/org/apache/derby/iapi/types/CollatorSQLVarchar.java URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.9/java/engine/org/apache/derby/iapi/types/CollatorSQLVarchar.java?rev=1510366&r1=1510365&r2=1510366&view=diff ============================================================================== --- db/derby/code/branches/10.9/java/engine/org/apache/derby/iapi/types/CollatorSQLVarchar.java (original) +++ db/derby/code/branches/10.9/java/engine/org/apache/derby/iapi/types/CollatorSQLVarchar.java Mon Aug 5 02:49:09 2013 @@ -88,17 +88,11 @@ class CollatorSQLVarchar extends SQLVarc return holderForCollationSensitiveInfo.getCollatorForCollation(); } - /** @see CollationElementsInterface#getCollationElementsForString */ - public int[] getCollationElementsForString() throws StandardException - { - return holderForCollationSensitiveInfo.getCollationElementsForString(); - } + // Implementation of CollationElementsInterface interface - /** @see CollationElementsInterface#getCountOfCollationElements */ - public int getCountOfCollationElements() - { - return holderForCollationSensitiveInfo.getCountOfCollationElements(); - } + public boolean hasSingleCollationElement() throws StandardException { + return holderForCollationSensitiveInfo.hasSingleCollationElement(); + } /* * DataValueDescriptor interface Modified: db/derby/code/branches/10.9/java/engine/org/apache/derby/iapi/types/WorkHorseForCollatorDatatypes.java URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.9/java/engine/org/apache/derby/iapi/types/WorkHorseForCollatorDatatypes.java?rev=1510366&r1=1510365&r2=1510366&view=diff ============================================================================== --- db/derby/code/branches/10.9/java/engine/org/apache/derby/iapi/types/WorkHorseForCollatorDatatypes.java (original) +++ db/derby/code/branches/10.9/java/engine/org/apache/derby/iapi/types/WorkHorseForCollatorDatatypes.java Mon Aug 5 02:49:09 2013 @@ -21,9 +21,6 @@ package org.apache.derby.iapi.types; -import org.apache.derby.iapi.types.DataValueDescriptor; -import org.apache.derby.iapi.types.BooleanDataValue; - import org.apache.derby.iapi.reference.SQLState; import org.apache.derby.iapi.error.StandardException; @@ -57,21 +54,6 @@ final class WorkHorseForCollatorDatatype * This SQLChar object is passed as a parameter to the constructor. */ private SQLChar stringData; - /** - * Following is the array holding a series of collation elements for the - * string. It will be used in the like method. This gets initialized when - * the like method is first invoked. - */ - private int[] collationElementsForString; - /** - * Number of valid collation elements in the array above. Note that this - * might be smaller than the actual size of the array above. Gets - * initialized when the like method is first invoked. - */ - private int countOfCollationElements; - - // For null strings, cKey = null. - private CollationKey cKey; WorkHorseForCollatorDatatypes( RuleBasedCollator collatorForCharacterDatatypes, @@ -171,8 +153,7 @@ final class WorkHorseForCollatorDatatype CollationElementsInterface escapeCharacter = (CollationElementsInterface) escape; - if (escapeCharacter.getCollationElementsForString() != null && - (escapeCharacter.getCountOfCollationElements() != 1)) + if (!escapeCharacter.hasSingleCollationElement()) { throw StandardException.newException(SQLState.LANG_INVALID_ESCAPE_CHARACTER, escapeCharacter.toString()); @@ -199,87 +180,23 @@ final class WorkHorseForCollatorDatatype return(collatorForCharacterDatatypes); } - /** - * This method returns the count of collation elements for SQLChar object. - * It method will return the correct value only if method - * getCollationElementsForString has been called previously on the SQLChar - * object. - * - * @return count of collation elements for this instance of CollatorSQLChar - */ - int getCountOfCollationElements() - { - return countOfCollationElements; - } - - /** - * This method translates the string into a series of collation elements. - * These elements will get used in the like method. - * - * @return an array of collation elements for the string - * @throws StandardException - */ - int[] getCollationElementsForString() - throws StandardException - { - if (stringData.isNull()) - { - return (int[]) null; - } - - - - // Caching of collationElementsForString is not working properly, in - // order to cache it needs to get invalidated everytime the container - // type's value is changed - through any interface, eg: readExternal, - // setValue, ... To get proper behavior, disabling caching, and will - // file a performance enhancement to implement correct caching. - collationElementsForString = null; - countOfCollationElements = 0; - + /** + * Check if the string consists of a single collation element. + * @return {@code true} iff it's a single collation element + * @see CollationElementsInterface#hasSingleCollationElement() + */ + boolean hasSingleCollationElement() throws StandardException { + if (stringData.isNull()) { + return false; + } - if (collationElementsForString != null) - { - return collationElementsForString; - } - - // countOfCollationElements should always be 0 when - // collationElementsForString is null - if (SanityManager.DEBUG) - { - if (countOfCollationElements != 0) - { - SanityManager.THROWASSERT( - "countOfCollationElements expected to be 0, not " + - countOfCollationElements); - } - } - - - collationElementsForString = new int[stringData.getLength()]; - - CollationElementIterator cei = + CollationElementIterator cei = collatorForCharacterDatatypes.getCollationElementIterator( stringData.getString()); - int nextInt; - while ((nextInt = cei.next()) != CollationElementIterator.NULLORDER) - { - /* Believe it or not, a String might have more - * collation elements than characters. - * So, we handle that case by increasing the int array - * by 5 and copying array elements. - */ - if (countOfCollationElements == collationElementsForString.length) - { - int[] expandedArray = new int[countOfCollationElements + 5]; - System.arraycopy(collationElementsForString, 0, expandedArray, - 0, collationElementsForString.length); - collationElementsForString = expandedArray; - } - collationElementsForString[countOfCollationElements++] = nextInt; - } - - return collationElementsForString; - } + // First call next() to see that there is at least one element, and + // then call next() to see that there is no more than one element. + return cei.next() != CollationElementIterator.NULLORDER && + cei.next() == CollationElementIterator.NULLORDER; + } }