You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by ab...@apache.org on 2007/08/16 20:01:30 UTC
svn commit: r566789 - in /db/derby/code/branches/10.3/java:
engine/org/apache/derby/impl/sql/compile/ConditionalNode.java
testing/org/apache/derbyTesting/functionTests/tests/lang/CaseExpressionTest.java
Author: abrown
Date: Thu Aug 16 11:01:28 2007
New Revision: 566789
URL: http://svn.apache.org/viewvc?view=rev&rev=566789
Log:
DERBY-2986: Port to 10.3:
svn merge -r 566216:566217 https://svn.apache.org/repos/asf/db/derby/code/trunk
svn merge -r 566234:566235 https://svn.apache.org/repos/asf/db/derby/code/trunk
Modified:
db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/ConditionalNode.java
db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CaseExpressionTest.java
Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/ConditionalNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/ConditionalNode.java?view=diff&rev=566789&r1=566788&r2=566789
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/ConditionalNode.java (original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/sql/compile/ConditionalNode.java Thu Aug 16 11:01:28 2007
@@ -206,7 +206,8 @@
* @exception StandardException Thrown on error.
*/
private DataTypeDescriptor findType(ValueNodeList thenElseList,
- FromList fromList) throws StandardException
+ FromList fromList, SubqueryList subqueryList, Vector aggregateVector)
+ throws StandardException
{
/* We need to "prebind" because we want the Types. Provide
* dummy SubqueryList and AggreateList (we don't care)
@@ -214,11 +215,11 @@
ValueNode thenNode =
((ValueNode)thenElseList.elementAt(0)).bindExpression(
- fromList, new SubqueryList(), new Vector());
+ fromList, subqueryList, aggregateVector);
ValueNode elseNode =
((ValueNode)thenElseList.elementAt(1)).bindExpression(
- fromList, new SubqueryList(), new Vector());
+ fromList, subqueryList, aggregateVector);
DataTypeDescriptor thenType = thenNode.getTypeServices();
DataTypeDescriptor elseType = elseNode.getTypeServices();
@@ -257,7 +258,8 @@
if (isConditionalNode(thenNode))
{
theType =
- findType(((ConditionalNode)thenNode).thenElseList, fromList);
+ findType(((ConditionalNode)thenNode).thenElseList, fromList,
+ subqueryList, aggregateVector);
}
if (theType != null) return theType;
@@ -266,7 +268,8 @@
if (isConditionalNode(elseNode))
{
theType =
- findType(((ConditionalNode)elseNode).thenElseList, fromList);
+ findType(((ConditionalNode)elseNode).thenElseList, fromList,
+ subqueryList, aggregateVector);
}
if (theType != null) return theType;
@@ -386,14 +389,21 @@
thenElseList.elementAt(0),
bcon.getLeftOperand().getTypeServices().getNullabilityType(true),
getContextManager());
+
thenElseList.setElementAt(cast,0);
+ thenElseList.bindExpression(fromList,
+ subqueryList,
+ aggregateVector);
+
} else {
- recastNullNodes(thenElseList, findType(thenElseList, fromList));
+ /* Following call to "findType()" will indirectly bind the
+ * expressions in the thenElseList, so no need to call
+ * "thenElseList.bindExpression(...)" after we do this.
+ * DERBY-2986.
+ */
+ recastNullNodes(thenElseList,
+ findType(thenElseList, fromList, subqueryList, aggregateVector));
}
-
- thenElseList.bindExpression(fromList,
- subqueryList,
- aggregateVector);
// Can't get the then and else expressions until after they've been bound
ValueNode thenExpression = (ValueNode) thenElseList.elementAt(0);
Modified: db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CaseExpressionTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CaseExpressionTest.java?view=diff&rev=566789&r1=566788&r2=566789
==============================================================================
--- db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CaseExpressionTest.java (original)
+++ db/derby/code/branches/10.3/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CaseExpressionTest.java Thu Aug 16 11:01:28 2007
@@ -31,6 +31,7 @@
import org.apache.derbyTesting.junit.BaseJDBCTestCase;
import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
+import org.apache.derbyTesting.junit.JDBC;
import org.apache.derbyTesting.junit.SQLUtilities;
import org.apache.derbyTesting.junit.TestConfiguration;
@@ -183,6 +184,43 @@
"SELECT CASE WHEN 1 = 1 THEN NULL " +
"ELSE (CASE WHEN 1 = 1 THEN NULL ELSE ",
" END) END from AllDataTypesTable");
+
+ s.close();
+ }
+
+ /**
+ * Test a query that has many WHEN conditions in it. This is mostly
+ * checking for the performance regression filed as DERBY-2986. That
+ * regression may not be noticeable in the scope of the full regression
+ * suite, but if this test is run standalone then this fixture could
+ * still be useful.
+ */
+ public void testMultipleWhens() throws SQLException
+ {
+ Statement s = createStatement();
+ JDBC.assertFullResultSet(
+ s.executeQuery(
+ "values CASE WHEN 10 = 1 THEN 'a' " +
+ "WHEN 10 = 2 THEN 'b' " +
+ "WHEN 10 = 3 THEN 'c' " +
+ "WHEN 10 = 4 THEN 'd' " +
+ "WHEN 10 = 5 THEN 'e' " +
+ "WHEN 10 = 6 THEN 'f' " +
+ "WHEN 10 = 7 THEN 'g' " +
+ "WHEN 10 = 8 THEN 'h' " +
+ "WHEN 10 = 11 THEN 'i' " +
+ "WHEN 10 = 12 THEN 'j' " +
+ "WHEN 10 = 15 THEN 'k' " +
+ "WHEN 10 = 16 THEN 'l' " +
+ "WHEN 10 = 23 THEN 'm' " +
+ "WHEN 10 = 24 THEN 'n' " +
+ "WHEN 10 = 27 THEN 'o' " +
+ "WHEN 10 = 31 THEN 'p' " +
+ "WHEN 10 = 41 THEN 'q' " +
+ "WHEN 10 = 42 THEN 'r' " +
+ "WHEN 10 = 50 THEN 's' " +
+ "ELSE '*' END"),
+ new String[][] {{"*"}});
s.close();
}