提交 0d27db6c authored 作者: Thomas Mueller's avatar Thomas Mueller

Queries "group by" that contain a subquery with an aggregate function returned…

Queries "group by" that contain a subquery with an aggregate function returned the wrong result in some cases.
上级 7a163bbc
......@@ -21,6 +21,8 @@ Change Log
<ul><li>Improved spatial index and data type.
</li><li>Issue 467: OSGi Class Loader (ability to create reference to class
in other ClassLoader, for example in another OSGi bundle).
</li><li>Queries "group by" that contain a subquery with an aggregate function
returned the wrong result in some cases.
</li><li>Fix bug in unique and non-unique hash indexes which manifested as incorrect results
when the search key was a different cardinal type from the table index key.
e.g. where the one was INT and the other was LONG
......
......@@ -160,7 +160,8 @@ public class Select extends Query {
private void queryGroupSorted(int columnCount, ResultTarget result) {
int rowNumber = 0;
setCurrentRowNumber(0);
Value[] previousKeyValues = null;
currentGroup = null;
Value[] previousKeyValues = null;
while (topTableFilter.next()) {
setCurrentRowNumber(rowNumber + 1);
if (condition == null || Boolean.TRUE.equals(condition.getBooleanValue(session))) {
......@@ -312,6 +313,7 @@ public class Select extends Query {
ValueHashMap<HashMap<Expression, Object>> groups = ValueHashMap.newInstance();
int rowNumber = 0;
setCurrentRowNumber(0);
currentGroup = null;
ValueArray defaultGroup = ValueArray.get(new Value[0]);
while (topTableFilter.next()) {
setCurrentRowNumber(rowNumber + 1);
......@@ -604,8 +606,6 @@ public class Select extends Query {
throw DbException.getUnsupportedException("FOR UPDATE && AGGREGATE");
} else if (topTableFilter.getJoin() != null) {
throw DbException.getUnsupportedException("FOR UPDATE && JOIN");
} else if (topTableFilter.getJoin() != null) {
throw DbException.getUnsupportedException("FOR UPDATE && JOIN");
}
}
topTableFilter.lock(session, exclusive, exclusive);
......
......@@ -40,6 +40,7 @@ public class TestOptimizations extends TestBase {
@Override
public void test() throws Exception {
deleteDb("optimizations");
testGroupSubquery();
testAnalyzeLob();
testLike();
testExistsSubquery();
......@@ -73,6 +74,28 @@ public class TestOptimizations extends TestBase {
testConvertOrToIn();
deleteDb("optimizations");
}
private void testGroupSubquery() throws Exception {
Connection conn = getConnection("optimizations");
Statement stat = conn.createStatement();
stat.execute("create table t1(id int)");
stat.execute("create table t2(id int)");
stat.execute("insert into t1 values(2), (2), (3)");
stat.execute("insert into t2 values(2), (3)");
stat.execute("create index t1id_index on t1(id)");
ResultSet rs;
rs = stat.executeQuery("select id, (select count(*) from t2 " +
"where t2.id = t1.id) cc from t1 group by id order by id");
rs.next();
assertEquals(2, rs.getInt(1));
assertEquals(1, rs.getInt(2));
rs.next();
assertEquals(3, rs.getInt(1));
assertEquals(1, rs.getInt(2));
rs.next();
stat.execute("drop table t1, t2");
conn.close();
}
private void testAnalyzeLob() throws Exception {
Connection conn = getConnection("optimizations");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论