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

Issue 269: GROUP BY queries with a column or having clause that contains…

Issue 269: GROUP BY queries with a column or having clause that contains IN(SELECT ...) could return the wrong values. Example: SELECT X IN(SELECT Y) FROM Z GROUP BY X.
上级 10d41cd7
......@@ -106,10 +106,8 @@ public class ConditionInSelect extends Condition {
}
public void updateAggregate(Session session) {
// TODO exists: is it allowed that the subquery contains aggregates?
// probably not
// select id from test group by id having 1 in (select * from test2
// where id=count(test.id))
left.updateAggregate(session);
query.updateAggregate(session);
}
public boolean isEverything(ExpressionVisitor visitor) {
......
......@@ -150,9 +150,6 @@ public class ExpressionColumn extends Expression {
}
public Value getValue(Session session) {
// TODO refactor: simplify check if really part of an aggregated value /
// detection of
// usage of non-grouped by columns without aggregate function
Select select = columnResolver.getSelect();
if (select != null) {
HashMap<Expression, Object> values = select.getCurrentGroup();
......
--- special grammar and test cases ---------------------------------------------------------------------------------------------
create table test(id int);
> ok
insert into test values(1), (2), (4);
> update count: 3
select a.id, a.id in(select 4) x from test a, test b where a.id in (b.id, b.id - 1);
> ID X
> -- -----
> 1 FALSE
> 1 FALSE
> 2 FALSE
> 4 TRUE
> rows: 4
select a.id, a.id in(select 4) x from test a, test b where a.id in (b.id, b.id - 1) group by a.id;
> ID X
> -- -----
> 1 FALSE
> 2 FALSE
> 4 TRUE
> rows: 3
select a.id, 4 in(select a.id) x from test a, test b where a.id in (b.id, b.id - 1) group by a.id;
> ID X
> -- -----
> 1 FALSE
> 2 FALSE
> 4 TRUE
> rows: 3
drop table test;
> ok
create domain x as int not null;
> ok
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论