db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1574565 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/ engine/org/apache/derby/impl/sql/execute/ testing/org/apache/derbyTesting/functionTests/tests/lang/
Date Wed, 05 Mar 2014 16:31:08 GMT
Author: mamta
Date: Wed Mar  5 16:31:07 2014
New Revision: 1574565

URL: http://svn.apache.org/r1574565
Log:
DERBY-6025(Wrong results with IN lists and indexes in territory based collation)

Basically, when all the elements in the inlist are not all constants, then we can not figure
out at compile time the minimum and maximum values in the list. Mimimum and maximum values
in the in list are required to be passed as start and stop keys if compiler decides to use
an index for the inlist predicate. Since these can not be determined at compile time for non
constant elements, InListOperatorNoce.generateStartStopKey ends up generating code which will
run at execution time of the query and at that time, we will compare the values of the individual
elements in the in list to determine the minimum and maximum values. The porblem is that currently,
Derby does not pass the collation information of the left operand of the inlist to execution
time and because of that, we end up doing English comparison of the values rather than terriroty
based comparison in case of territory based database. The fix is to have InListOperatorNoce.generateStartStopKey
generate code to pass collation inf
 ormation also. This way, we will do collation based comparison of in list elements in case
of territory based database. I have run the reproducible case from jira against my changes
and the query now returns correct row. I have run derbyall against the changes and it finished
with no errors. The junit suite is running into following 3 failures but I have verified that
those 3 failures happen without my changes too. So I will assume that these failures are not
caused by my changes. The failures are copied below.
There were 3 failures:
1) testStartNetworkServerLogMessageOnDualStart(org.apache.derbyTesting.functionTests.tests.derbynet.DerbyNetAutoStartTest)junit.framework.AssertionFailedError:
did not find the expected string: An exception was thrown during network server startup within
the maximum wait time 240000
at org.apache.derbyTesting.functionTests.tests.derbynet.DerbyNetAutoStartTest.testStartNetworkServerLogMessageOnDualStart(DerbyNetAutoStartTest.java:272)
2) test_5391(org.apache.derbyTesting.functionTests.tests.lang.SysDiagVTIMappingTest)junit.framework.AssertionFailedError
at org.apache.derbyTesting.functionTests.tests.lang.SysDiagVTIMappingTest.vetTimestamp(SysDiagVTIMappingTest.java:933)
3) test_5391(org.apache.derbyTesting.functionTests.tests.lang.SysDiagVTIMappingTest)junit.framework.AssertionFailedError
at org.apache.derbyTesting.functionTests.tests.lang.SysDiagVTIMappingTest.vetTimestamp(SysDiagVTIMappingTest.java:933)



Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/InListOperatorNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/BaseExpressionActivation.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/InListOperatorNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/InListOperatorNode.java?rev=1574565&r1=1574564&r2=1574565&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/InListOperatorNode.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/InListOperatorNode.java
Wed Mar  5 16:31:07 2014
@@ -677,8 +677,20 @@ public final class InListOperatorNode ex
 		/* left side of the "in" operator is our "judge" when we try to get
 		 * the min/max value of the operands on the right side.  Judge's type
 		 * is important for us, and is input parameter to min/maxValue.
+		 * We found in DERBY-6025(Wrong results with IN lists and indexes in 
+		 * territory based collation) that we need to make sure that we also
+		 * left operand's collation information with Judge object. The reason
+		 * we are sending precision/scale etc along with type id and collation
+		 * information is that DataTypeDescriptor constructor requires all
+		 * those properties too along with the collation information.
 		 */
 		int leftTypeFormatId = leftOperand.getTypeId().getTypeFormatId();
+		int leftPrecision = leftOperand.getTypeServices().getPrecision();
+		int leftScale = leftOperand.getTypeServices().getScale();
+		boolean leftIsNullable = leftOperand.getTypeServices().isNullable();
+		int leftMaximumWidth = leftOperand.getTypeServices().getMaximumWidth();
+		int leftCollationType = leftOperand.getTypeServices().getCollationType();
+		int leftCollationDerivation = leftOperand.getTypeServices().getCollationDerivation();
 		int leftJDBCTypeId = leftOperand.getTypeId().isUserDefinedTypeId() ?
 								leftOperand.getTypeId().getJDBCTypeId() : -1;
 
@@ -728,6 +740,12 @@ public final class InListOperatorNode ex
 			 */
 			mb.push(leftTypeFormatId);
 			mb.push(leftJDBCTypeId);
+			mb.push(leftPrecision);
+			mb.push(leftScale);
+			mb.push(leftIsNullable);
+			mb.push(leftMaximumWidth);
+			mb.push(leftCollationType);
+			mb.push(leftCollationDerivation);
 
 			/* decide to get min or max value
 			 */
@@ -742,7 +760,7 @@ public final class InListOperatorNode ex
                 ClassName.BaseExpressionActivation,
                 methodNam,
                 ClassName.DataValueDescriptor,
-                6);
+                12);
 		}
 	}
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/BaseExpressionActivation.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/BaseExpressionActivation.java?rev=1574565&r1=1574564&r2=1574565&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/BaseExpressionActivation.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/BaseExpressionActivation.java
Wed Mar  5 16:31:07 2014
@@ -23,6 +23,7 @@ package org.apache.derby.impl.sql.execut
 
 import org.apache.derby.catalog.types.UserDefinedTypeIdImpl;
 import org.apache.derby.iapi.error.StandardException;
+import org.apache.derby.iapi.types.DataTypeDescriptor;
 import org.apache.derby.iapi.types.DataValueDescriptor;
 import org.apache.derby.iapi.types.TypeId;
 
@@ -67,21 +68,37 @@ public abstract class BaseExpressionActi
 	 * @param judgeTypeFormatId		type format id of the judge
 	 * @param judgeUserJDBCTypeId	JDBC type id if judge is user type;
 	 *								-1 if not user type
+	 * @param judgePrecision		precision of the judge
+	 * @param judgeScale		    scale of the judge
+	 * @param judgeIsNullable		nullability of the judge
+	 * @param judgeMaximumWidth		maximum width of the judge
+	 * @param judgeCollationType	collation type of the judge
+	 * @param judgeCollationDerivation		collation derivation of the judge
 	 *
-	 * @return	The minimum value of the 4.
+	 * @return	The minimum value of the 4. 
 	 */
 	public static DataValueDescriptor minValue(DataValueDescriptor v1,
 											  DataValueDescriptor v2,
 											  DataValueDescriptor v3,
 											  DataValueDescriptor v4,
 											  int judgeTypeFormatId,
-											  int judgeUserJDBCTypeId)
+											  int judgeUserJDBCTypeId,
+											  int judgePrecision,
+											  int judgeScale,
+											  boolean judgeIsNullable,
+											  int judgeMaximumWidth,
+											  int judgeCollationType,
+											  int judgeCollationDerivation)
 										throws StandardException
 	{
 		DataValueDescriptor judge;
 
         if (judgeUserJDBCTypeId == -1) {
-            judge = new TypeId(judgeTypeFormatId, null).getNull();
+        	judge = new DataTypeDescriptor(
+        			new TypeId(judgeTypeFormatId, null),
+        			judgePrecision,judgeScale,judgeIsNullable,
+        			judgeMaximumWidth,judgeCollationType,
+        			judgeCollationDerivation).getNull();
         } else {
             judge = new TypeId(judgeTypeFormatId,
                                new UserDefinedTypeIdImpl()).getNull();
@@ -131,13 +148,23 @@ public abstract class BaseExpressionActi
 											  DataValueDescriptor v3,
 											  DataValueDescriptor v4,
 											  int judgeTypeFormatId,
-											  int judgeUserJDBCTypeId)
+											  int judgeUserJDBCTypeId,
+											  int judgePrecision,
+											  int judgeScale,
+											  boolean judgeIsNullable,
+											  int judgeMaximumWidth,
+											  int judgeCollationType,
+											  int judgeCollationDerivation)
 										throws StandardException
 	{
 		DataValueDescriptor judge;
-		if (judgeUserJDBCTypeId == -1)
-			judge =  new TypeId(judgeTypeFormatId, null).getNull();
-		else
+		if (judgeUserJDBCTypeId == -1) {
+        	judge = new DataTypeDescriptor(
+        			new TypeId(judgeTypeFormatId, null),
+        			judgePrecision,judgeScale,judgeIsNullable,
+        			judgeMaximumWidth,judgeCollationType,
+        			judgeCollationDerivation).getNull();
+		} else
 			judge =  new TypeId(judgeTypeFormatId, new UserDefinedTypeIdImpl()).getNull();
 
 		DataValueDescriptor maxVal = v1;

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java?rev=1574565&r1=1574564&r2=1574565&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java
Wed Mar  5 16:31:07 2014
@@ -81,6 +81,7 @@ public class CollationTest extends BaseJ
     /** Test cases to run with Norwegian case-sensitive collation. */
     private final static String[] NORWEGIAN_CASE_SENSITIVE = {
         "testNorwayCollation",
+        "testInListNorwayCollation",
         "testLikeEscapeClauseLengthRestriction",
     };
 
@@ -438,6 +439,31 @@ public void testPolishCollation() throws
     
       }    
   
+/**
+ * Test in list with constant and non constant elements & Norwegian collation
+ * DERBY-6025(Wrong results with IN lists and indexes in territory based 
+ *   collation)
+ */
+public void testInListNorwayCollation() throws SQLException {
+    Statement s = createStatement();
+    s.execute("CREATE TABLE derby6025_T1( c1 varchar(40) )");
+    s.executeUpdate("INSERT INTO derby6025_T1 VALUES" +
+    		"'Stranda Idrottslag', 'Aalesunds Fotballklubb'");
+    ResultSet rs = s.executeQuery("select * from derby6025_T1 where C1 in "+
+    		"('Aalesunds Fotballklubb', cast('xyz' as char(3)))");
+    JDBC.assertFullResultSet(rs,
+      		new String[][] {{"Aalesunds Fotballklubb"}});
+    
+    s.executeUpdate("create index i1 on derby6025_T1(c1)");
+    //After an index is created on column c1, following query returned 
+    // 0 rows without the fix for DERBY-6025. After DERBY-6025 is fixed, 
+    // it correctly returns 1 row.
+    rs = s.executeQuery("select * from derby6025_T1 where C1 in "+
+    		"('Aalesunds Fotballklubb', cast('xyz' as char(3)))");
+    JDBC.assertFullResultSet(rs,
+      		new String[][] {{"Aalesunds Fotballklubb"}});
+    s.execute("DROP TABLE derby6025_T1");	
+    }
 
   /**
    * Test order by with Norwegian collation



Mime
View raw message