Author: thomasm
Date: Thu Nov 17 09:40:38 2016
New Revision: 1770136
URL: http://svn.apache.org/viewvc?rev=1770136&view=rev
Log:
OAK-5120 Automatically convert *all* "or" queries to "union" for SQL-2, take 2
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/AndImpl.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/SQL2OptimiseQueryTest.java
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/AndImpl.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/AndImpl.java?rev=1770136&r1=1770135&r2=1770136&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/AndImpl.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/AndImpl.java
Thu Nov 17 09:40:38 2016
@@ -254,11 +254,12 @@ public class AndImpl extends ConstraintI
if (getLastConstraint() instanceof OrImpl) {
return this;
}
- for (int i = 0; i < constraints.size() - 1; i++) {
- ConstraintImpl c = constraints.get(i);
+ ArrayList<ConstraintImpl> andList = getAllAndConditions();
+ for (int i = 0; i < andList.size() - 1; i++) {
+ ConstraintImpl c = andList.get(i);
if (c instanceof OrImpl) {
ArrayList<ConstraintImpl> list = new
ArrayList<ConstraintImpl>();
- list.addAll(constraints);
+ list.addAll(andList);
list.remove(i);
list.add(c);
return new AndImpl(list);
@@ -266,6 +267,18 @@ public class AndImpl extends ConstraintI
}
return this;
}
+
+ private ArrayList<ConstraintImpl> getAllAndConditions() {
+ ArrayList<ConstraintImpl> list = new ArrayList<ConstraintImpl>();
+ for(ConstraintImpl c : constraints) {
+ if (c instanceof AndImpl) {
+ list.addAll(((AndImpl) c).getAllAndConditions());
+ } else {
+ list.add(c);
+ }
+ }
+ return list;
+ }
@Override
public Set<ConstraintImpl> convertToUnion() {
Modified:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/SQL2OptimiseQueryTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/SQL2OptimiseQueryTest.java?rev=1770136&r1=1770135&r2=1770136&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/SQL2OptimiseQueryTest.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/SQL2OptimiseQueryTest.java
Thu Nov 17 09:40:38 2016
@@ -236,6 +236,14 @@ public class SQL2OptimiseQueryTest exten
public void optimiseAndOrAnd() throws ParseException {
optimiseAndOrAnd(
"select * from [nt:unstructured] as [c] " +
+ "where isdescendantnode('/tmp') " +
+ "and ([a]=1 or [b]=2) and ([c]=3 or [d]=4)",
+ "(isdescendantnode(c, /tmp)) and (d = 4) and (b = 2), " +
+ "(isdescendantnode(c, /tmp)) and (d = 4) and (a = 1), " +
+ "(isdescendantnode(c, /tmp)) and (c = 3) and (b = 2), " +
+ "(isdescendantnode(c, /tmp)) and (c = 3) and (a = 1)");
+ optimiseAndOrAnd(
+ "select * from [nt:unstructured] as [c] " +
"where ([a]=1 or [b]=2) and ([x]=3 or [y]=4)",
"(y = 4) and (b = 2), " +
"(y = 4) and (a = 1), " +