Author: thomasm
Date: Fri Nov 20 14:15:14 2015
New Revision: 1715367
URL: http://svn.apache.org/viewvc?rev=1715367&view=rev
Log:
OAK-2539 SQL2 query not working with filter (s.[stringa] = 'a' OR
CONTAINS(s.[stringb], 'b'))
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngineImpl.java
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngineImpl.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngineImpl.java?rev=1715367&r1=1715366&r2=1715367&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngineImpl.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngineImpl.java
Fri Nov 20 14:15:14 2015
@@ -257,29 +257,15 @@ public abstract class QueryEngineImpl im
boolean mdc = false;
try {
- MdcAndPrepared map = prepareAndGetCheapest(queries);
- mdc = map.mdc;
- Query q = map.query;
- return q.executeQuery();
+ Query query = prepareAndGetCheapest(queries);
+ mdc = setupMDC(query);
+ return query.executeQuery();
} finally {
if (mdc) {
clearMDC();
}
}
}
-
- /**
- * POJO class used to return the cheapest prepared query from the set and
related MDC status
- */
- private static class MdcAndPrepared {
- private final boolean mdc;
- private final Query query;
-
- public MdcAndPrepared(final boolean mdc, @Nonnull final Query q) {
- this.mdc = mdc;
- this.query = checkNotNull(q);
- }
- }
/**
* will prepare all the available queries and by based on the {@link
ForceOptimised} flag return
@@ -289,17 +275,14 @@ public abstract class QueryEngineImpl im
* @return
*/
@Nonnull
- private MdcAndPrepared prepareAndGetCheapest(@Nonnull final Set<Query>
queries) {
- MdcAndPrepared map = null;
- Query cheapest = null;
-
+ private Query prepareAndGetCheapest(@Nonnull final Set<Query> queries) {
+ Query result = null;
if (checkNotNull(queries).size() == 1) {
// we only have the original query so we prepare and return it.
- cheapest = queries.iterator().next();
- cheapest.prepare();
- LOG.debug("No optimisations found. Cheapest is the original query:
{}", cheapest);
- map = new MdcAndPrepared(setupMDC(cheapest), cheapest);
+ result = queries.iterator().next();
+ result.prepare();
+ LOG.debug("No optimisations found. Query: {}", result);
} else {
double bestCost = Double.POSITIVE_INFINITY;
double originalCost = Double.POSITIVE_INFINITY;
@@ -316,8 +299,8 @@ public abstract class QueryEngineImpl im
LOG.debug("contains an unfiltered fulltext condition");
cost = Double.POSITIVE_INFINITY;
}
- if (cheapest == null || cost < bestCost) {
- cheapest = q;
+ if (result == null || cost < bestCost) {
+ result = q;
bestCost = cost;
}
if (!q.isOptimised()) {
@@ -326,11 +309,11 @@ public abstract class QueryEngineImpl im
}
}
- if (original != null && bestCost == originalCost && cheapest !=
original) {
+ if (original != null && bestCost == originalCost && result !=
original) {
// if the optimised cost is the same as the original SQL2
query we prefer the original. As
// we deal with references the `cheapest!=original` should
work.
LOG.trace("Same cost for original and optimised. Using
original");
- cheapest = original;
+ result = original;
}
switch (forceOptimised) {
@@ -338,7 +321,7 @@ public abstract class QueryEngineImpl im
LOG.debug("Forcing the original SQL2 query to be executed by
flag");
for (Query q : checkNotNull(queries)) {
if (!q.isOptimised()) {
- map = new MdcAndPrepared(setupMDC(q), q);
+ result = q;
}
}
break;
@@ -347,7 +330,7 @@ public abstract class QueryEngineImpl im
LOG.debug("Forcing the optimised SQL2 query to be executed by
flag");
for (Query q : checkNotNull(queries)) {
if (q.isOptimised()) {
- map = new MdcAndPrepared(setupMDC(q), q);
+ result = q;
}
}
break;
@@ -355,34 +338,19 @@ public abstract class QueryEngineImpl im
// CHEAPEST is the default behaviour
case CHEAPEST:
default:
- if (cheapest == null) {
+ if (result == null) {
// this should not really happen. Defensive coding.
LOG.debug("Cheapest is null. Returning the original SQL2
query.");
for (Query q : checkNotNull(queries)) {
if (!q.isOptimised()) {
- map = new MdcAndPrepared(setupMDC(q), q);
+ result = q;
}
}
- } else {
- LOG.debug("Cheapest cost: {} - query: {}", bestCost,
cheapest);
- map = new MdcAndPrepared(setupMDC(cheapest), cheapest);
- }
- }
- }
-
-
- if (map == null) {
- // we should only get here in case of testing forcing weird
conditions
- LOG.trace("`MdcAndPrepared` is null. Falling back to the original
query");
- for (Query q : checkNotNull(queries)) {
- if (!q.isOptimised()) {
- map = new MdcAndPrepared(setupMDC(q), q);
- break;
}
}
}
- return map;
+ return result;
}
protected void setTraversalEnabled(boolean traversalEnabled) {