提交 33df92bf authored 作者: isuruperera's avatar isuruperera

Bug fix in previous commit

Added test case
上级 22ed33c4
......@@ -320,7 +320,7 @@ public class ConditionAndOr extends Condition {
return null;
}
Expression commonExpressionLeft = left.getSubexpression(0);
Expression commonExpressionRight = right.getSubexpression(0);
Expression commonExpressionRight = left.getSubexpression(1);
Expression combinedExpression;
if (left.getSubexpression(0).getSQL().equals(right.getSubexpression(0).getSQL())) {
combinedExpression = new ConditionAndOr(OR, left.getSubexpression(1), right.getSubexpression(1));
......
......@@ -84,6 +84,7 @@ public class TestOptimizations extends TestDb {
testOrderedIndexes();
testIndexUseDespiteNullsFirst();
testConvertOrToIn();
testConditionAndOrDistributiveLaw();
deleteDb("optimizations");
}
......@@ -1177,4 +1178,30 @@ public class TestOptimizations extends TestDb {
assertContains(rs.getString(1), "/* PUBLIC.TABLE_B_IDX");
conn.close();
}
private void testConditionAndOrDistributiveLaw() throws SQLException {
deleteDb("optimizations");
Connection conn = getConnection("optimizations");
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE IF NOT EXISTS TABLE_A (" +
"id int(10) NOT NULL AUTO_INCREMENT, " +
"name VARCHAR(30) NOT NULL," +
"occupation VARCHAR(20)," +
"age int(10)," +
"salary int(10)," +
"PRIMARY KEY(id))");
stat.execute("INSERT INTO TABLE_A (name,occupation,age,salary) VALUES" +
"('mark', 'doctor',25,5000)," +
"('kevin', 'artist',20,4000)," +
"('isuru', 'engineer',25,5000)," +
"('josaph', 'businessman',30,7000)," +
"('sajeewa', 'analyst',24,5000)," +
"('randil', 'engineer',25,5000)," +
"('ashan', 'developer',24,5000)");
ResultSet rs = stat.executeQuery("SELECT * FROM TABLE_A WHERE (salary = 5000 AND name = 'isuru') OR" +
"(age = 25 AND name = 'isuru') ");
rs.next();
assertTrue("engineer".equals(rs.getString("occupation")));
conn.close();
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论