提交 8c989d7f authored 作者: Thomas Mueller's avatar Thomas Mueller

Issue 387: WHERE condition getting pushed into sub-query with LIMIT.

上级 33f44932
...@@ -18,7 +18,7 @@ Change Log ...@@ -18,7 +18,7 @@ Change Log
<h1>Change Log</h1> <h1>Change Log</h1>
<h2>Next Version (unreleased)</h2> <h2>Next Version (unreleased)</h2>
<ul><li>- <ul><li>Issue 387: WHERE condition getting pushed into sub-query with LIMIT.
</li></ul> </li></ul>
<h2>Version 1.3.165 (2012-03-18)</h2> <h2>Version 1.3.165 (2012-03-18)</h2>
......
...@@ -171,6 +171,15 @@ public abstract class Query extends Prepared { ...@@ -171,6 +171,15 @@ public abstract class Query extends Prepared {
*/ */
public abstract void addGlobalCondition(Parameter param, int columnId, int comparisonType); public abstract void addGlobalCondition(Parameter param, int columnId, int comparisonType);
/**
* Check whether adding condition to the query is allowed. This is not
* allowed for views that have an order by and a limit, as it would affect
* the returned results.
*
* @return true if adding global conditions is allowed
*/
public abstract boolean allowGlobalConditions();
/** /**
* Check if this expression and all sub-expressions can fulfill a criteria. * Check if this expression and all sub-expressions can fulfill a criteria.
* If any part returns false, the result is false. * If any part returns false, the result is false.
......
...@@ -1258,4 +1258,11 @@ public class Select extends Query { ...@@ -1258,4 +1258,11 @@ public class Select extends Query {
return CommandInterface.SELECT; return CommandInterface.SELECT;
} }
public boolean allowGlobalConditions() {
if (offsetExpr == null && (limitExpr == null || sort == null)) {
return true;
}
return false;
}
} }
...@@ -413,4 +413,8 @@ public class SelectUnion extends Query { ...@@ -413,4 +413,8 @@ public class SelectUnion extends Query {
return CommandInterface.SELECT; return CommandInterface.SELECT;
} }
public boolean allowGlobalConditions() {
return left.allowGlobalConditions() && right.allowGlobalConditions();
}
} }
...@@ -260,6 +260,9 @@ public class ViewIndex extends BaseIndex { ...@@ -260,6 +260,9 @@ public class ViewIndex extends BaseIndex {
if (masks == null) { if (masks == null) {
return q; return q;
} }
if (!q.allowGlobalConditions()) {
return q;
}
int firstIndexParam = originalParameters == null ? 0 : originalParameters.size(); int firstIndexParam = originalParameters == null ? 0 : originalParameters.size();
firstIndexParam += view.getParameterOffset(); firstIndexParam += view.getParameterOffset();
IntArray paramIndex = new IntArray(); IntArray paramIndex = new IntArray();
......
--- special grammar and test cases --------------------------------------------------------------------------------------------- --- special grammar and test cases ---------------------------------------------------------------------------------------------
create table test(id int, name varchar);
> ok
insert into test values(5, 'b'), (5, 'b'), (20, 'a');
> update count: 3
select * from (select * from test order by name limit 1) where id < 10;
> ID NAME
> -- ----
> rows (ordered): 0
drop table test;
> ok
create table test (id int not null, pid int); create table test (id int not null, pid int);
> ok > ok
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论