提交 489f7c63 authored 作者: Thomas Mueller's avatar Thomas Mueller

Comparison with "x = all(select ...)" or similar returned the wrong result for some cases.

上级 8f803a37
......@@ -18,7 +18,9 @@ Change Log
<h1>Change Log</h1>
<h2>Next Version (unreleased)</h2>
<ul><li>Issue 335: Could not run DROP ALL OBJECTS DELETE FILES on older databases with CLOB or BLOB data.
<ul><li>Comparison with "x = all(select ...)" or similar returned the wrong result for some cases
(for example if the subquery returned no rows, or multiple rows with the same value, or null, or if x was null).
</li><li>Issue 335: Could not run DROP ALL OBJECTS DELETE FILES on older databases with CLOB or BLOB data.
The problem was that the metadata table was not locked in some cases, so that
a rollback could result in a corrupt database in a database if the lob storage was upgraded.
</li><li>Source code switching using //## has been simplified.
......
......@@ -45,21 +45,17 @@ public class ConditionInSelect extends Condition {
LocalResult rows = query.query(0);
session.addTemporaryResult(rows);
Value l = left.getValue(session);
if (rows.getRowCount() == 0) {
return ValueBoolean.get(all);
} else if (l == ValueNull.INSTANCE) {
return l;
}
if (!session.getDatabase().getSettings().optimizeInSelect) {
return getValueSlow(rows, l);
}
if (compareType != Comparison.EQUAL && compareType != Comparison.EQUAL_NULL_SAFE) {
if (all || (compareType != Comparison.EQUAL && compareType != Comparison.EQUAL_NULL_SAFE)) {
return getValueSlow(rows, l);
}
if (rows.getRowCount() == 0) {
return ValueBoolean.get(false);
}
if (l == ValueNull.INSTANCE) {
return l;
}
if (all && rows.getRowCount() > 1) {
return ValueBoolean.get(false);
}
int dataType = rows.getColumnType(0);
if (dataType == Value.NULL) {
return ValueBoolean.get(false);
......@@ -75,16 +71,11 @@ public class ConditionInSelect extends Condition {
}
private Value getValueSlow(LocalResult rows, Value l) {
// this only returns the correct result if the result has at least one
// row, and if l is not null
boolean hasNull = false;
boolean result = all;
boolean hasRow = false;
while (rows.next()) {
if (!hasRow) {
if (l == ValueNull.INSTANCE) {
return l;
}
hasRow = true;
}
boolean value;
Value r = rows.currentRow()[0];
if (r == ValueNull.INSTANCE) {
......@@ -101,9 +92,6 @@ public class ConditionInSelect extends Condition {
break;
}
}
if (!hasRow) {
return ValueBoolean.get(false);
}
if (!result && hasNull) {
return ValueNull.INSTANCE;
}
......
--- special grammar and test cases ---------------------------------------------------------------------------------------------
create table test(id int) as select 1;
> ok
select * from test where id >= all(select id from test where 1=0);
> ID
> --
> 1
> rows: 1
select * from test where id = all(select id from test where 1=0);
> ID
> --
> 1
> rows: 1
select * from test where id = all(select id from test union all select id from test);
> ID
> --
> 1
> rows: 1
select * from test where null >= all(select id from test where 1=0);
> ID
> --
> 1
> rows: 1
select * from test where null = all(select id from test where 1=0);
> ID
> --
> 1
> rows: 1
select * from test where null = all(select id from test union all select id from test);
> ID
> --
> rows: 0
select * from test where id >= all(select cast(null as int) from test);
> ID
> --
> rows: 0
select * from test where id = all(select null from test union all select id from test);
> ID
> --
> rows: 0
select * from test where null >= all(select cast(null as int) from test);
> ID
> --
> rows: 0
select * from test where null = all(select null from test union all select id from test);
> ID
> --
> rows: 0
drop table test;
> ok
select x from dual order by y.x;
> exception
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论