提交 b2a70c1c authored 作者: Thomas Mueller Graf's avatar Thomas Mueller Graf

The condition in(select...) did not work correctly in some cases if the subquery was ordered

上级 804c05b1
......@@ -21,9 +21,11 @@ Change Log
<h2>Next Version (unreleased)</h2>
<ul>
<li>The condition "in(select...)" did not work correctly in some cases if the subquery had an "order by".
</li>
<li>Issue #184: The Platform-independent zip had Windows line endings in Linux scripts.
</li>
<li>The "script" command did not include sequences of temporary tables.
<li>Issue #186: The "script" command did not include sequences of temporary tables.
</li>
</ul>
......
......@@ -130,6 +130,13 @@ public abstract class Query extends Prepared {
*/
public abstract void setOrder(ArrayList<SelectOrderBy> order);
/**
* Whether the query has an order.
*
* @return true if it has
*/
public abstract boolean hasOrder();
/**
* Set the 'for update' flag.
*
......
......@@ -143,6 +143,11 @@ public class Select extends Query {
orderList = order;
}
@Override
public boolean hasOrder() {
return orderList != null || sort != null;
}
/**
* Add a condition to the list of conditions.
*
......
......@@ -102,6 +102,11 @@ public class SelectUnion extends Query {
orderList = order;
}
@Override
public boolean hasOrder() {
return orderList != null || sort != null;
}
private Value[] convert(Value[] values, int columnCount) {
Value[] newValues;
if (columnCount == values.length) {
......
......@@ -43,7 +43,9 @@ public class ConditionInSelect extends Condition {
@Override
public Value getValue(Session session) {
query.setSession(session);
query.setDistinct(true);
if (!query.hasOrder()) {
query.setDistinct(true);
}
LocalResult rows = query.query(0);
try {
Value l = left.getValue(session);
......
......@@ -206,13 +206,8 @@ public class LocalResult implements ResultInterface, ResultTarget {
if (distinctRows == null) {
distinctRows = ValueHashMap.newInstance();
for (Value[] row : rows) {
if (row.length > visibleColumnCount) {
Value[] r2 = new Value[visibleColumnCount];
System.arraycopy(row, 0, r2, 0, visibleColumnCount);
row = r2;
}
ValueArray array = ValueArray.get(row);
distinctRows.put(array, row);
ValueArray array = getArrayOfVisible(row);
distinctRows.put(array, array.getList());
}
}
ValueArray array = ValueArray.get(values);
......@@ -271,6 +266,15 @@ public class LocalResult implements ResultInterface, ResultTarget {
}
}
private ValueArray getArrayOfVisible(Value[] values) {
if (values.length > visibleColumnCount) {
Value[] v2 = new Value[visibleColumnCount];
System.arraycopy(values, 0, v2, 0, visibleColumnCount);
values = v2;
}
return ValueArray.get(values);
}
/**
* Add a row to this object.
*
......@@ -281,7 +285,7 @@ public class LocalResult implements ResultInterface, ResultTarget {
cloneLobs(values);
if (distinct) {
if (distinctRows != null) {
ValueArray array = ValueArray.get(values);
ValueArray array = getArrayOfVisible(values);
distinctRows.put(array, values);
rowCount = distinctRows.size();
if (rowCount > maxMemoryRows) {
......
......@@ -3,6 +3,18 @@
-- Initial Developer: H2 Group
--
--- special grammar and test cases ---------------------------------------------------------------------------------------------
create table test(id int) as select 1;
> ok
select * from test where id in (select id from test order by 'x');
> ID
> --
> 1
> rows (ordered): 1
drop table test;
> ok
select abs(cast(0.0 as double)) x;
> X
> ---
......@@ -62,7 +74,7 @@ LIMIT 2 )
AND studentID = 2;
> SUM(POINTS)
> -----------
> null
> 30
> rows (ordered): 1
SELECT eventID X FROM RESULTS
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论