public abstract class QueryOptimizer extends Object
Modifier and Type | Class and Description |
---|---|
static class |
QueryOptimizer.PrefixInfo
Info about a prefix: the prefix, and how many times it was encountered.
|
protected static class |
QueryOptimizer.ProjectionReferenceRenamer
Renames references if they are in the projection part.
|
protected static class |
QueryOptimizer.ProjectionWildcardsFinder |
class |
QueryOptimizer.ReferencePrefixAnalyzer
Analyzes references to compute common prefix info in order to later factor them in a parent expression.
|
Modifier and Type | Field and Description |
---|---|
protected static int |
CORR_BASE |
protected int |
correlationCounter |
protected FacetFilter |
facetFilter |
protected static Collector<Expression,?,Map<String,List<Expression>>> |
GROUPING_BY_EXPR_PREFIX |
protected Set<String> |
neverPerInstanceMixins |
protected boolean |
onlyRelations
Do we match only relations?
|
protected SchemaManager |
schemaManager |
static String |
TYPE_DOCUMENT |
static String |
TYPE_RELATION |
static String |
TYPE_ROOT |
Constructor and Description |
---|
QueryOptimizer() |
Modifier and Type | Method and Description |
---|---|
protected void |
addFacetFilters(List<Expression> clauses,
FacetFilter facetFilter) |
protected SQLQuery |
addIsNotNullClauses(SQLQuery query,
Collection<String> names) |
protected void |
addTypes(List<Expression> clauses,
FromClause node)
Finds all the types to take into account (all concrete types being a subtype of the passed types) based on the
FROM list.
|
protected void |
addWhere(List<Expression> clauses,
Expression expr) |
protected void |
addWhere(List<Expression> clauses,
WhereClause where)
Adds a flattened version of all toplevel ANDed WHERE clauses.
|
protected SQLQuery |
addWildcardNotNullClauses(SQLQuery query)
If we have a query like
SELECT dc:subjects/* FROM ... then we must make sure we don't match documents
that don't have a dc:subjects at all, as this would make the evaluator return one null value for
each due to its semantics of doing the equivalent of LEFT JOINs. |
static String |
findPrefix(List<String> strings,
List<String> withPrefix)
Finds a non-empty prefix in the strings.
|
abstract String |
getCorrelatedWildcardPrefix(String name)
Gets the prefix to use for this reference name (NXQL) if it contains a correlated wildcard.
|
protected Set<String> |
getDocumentTypeNamesExtending(String typeName) |
protected Set<String> |
getDocumentTypeNamesForFacet(String mixin) |
protected static int |
getExpressionCount(Expression expr) |
protected static String |
getExpressionPrefix(Expression expr) |
protected static Set<String> |
getStringLiterals(LiteralList list) |
protected boolean |
isTypeRelation(String typeName) |
static Expression |
makeSingleAndExpression(String prefix,
List<Expression> exprs)
Makes a single AND expression from several expressions known to have a common prefix.
|
SQLQuery |
optimize(SQLQuery query)
Optimizes a query to provide a WHERE clause containing facet filters, primary and mixin types.
|
static void |
reorganizeGroupedExpressions(Map<String,Expression> groupedExpressions)
Reorganizes the grouped expressions in order to have 2-level nesting in case a group is a prefix of another.
|
protected void |
simplifyTypes(List<Expression> clauses)
Simplify ecm:primaryType positive references, and non-per-instance mixin types.
|
QueryOptimizer |
withFacetFilter(FacetFilter facetFilter) |
public static final String TYPE_ROOT
public static final String TYPE_DOCUMENT
public static final String TYPE_RELATION
protected static final int CORR_BASE
protected FacetFilter facetFilter
protected final SchemaManager schemaManager
protected final Set<String> neverPerInstanceMixins
protected int correlationCounter
protected boolean onlyRelations
protected static Collector<Expression,?,Map<String,List<Expression>>> GROUPING_BY_EXPR_PREFIX
public QueryOptimizer()
public QueryOptimizer withFacetFilter(FacetFilter facetFilter)
public SQLQuery optimize(SQLQuery query)
public static Expression makeSingleAndExpression(String prefix, List<Expression> exprs)
protected static String getExpressionPrefix(Expression expr)
protected static int getExpressionCount(Expression expr)
public static void reorganizeGroupedExpressions(Map<String,Expression> groupedExpressions)
public static String findPrefix(List<String> strings, List<String> withPrefix)
If a prefix is found, the other strings having it as a prefix are collected in withPrefix
, and the prefix
and the found strings are moved from the input string
.
strings
and withPrefix
must both be ArrayLists as they will be mutated and queried by index.
strings
- the input stringswithPrefix
- (return value) the strings that have the found prefix as a prefixprotected void addFacetFilters(List<Expression> clauses, FacetFilter facetFilter)
protected Set<String> getDocumentTypeNamesForFacet(String mixin)
protected Set<String> getDocumentTypeNamesExtending(String typeName)
protected boolean isTypeRelation(String typeName)
protected void addTypes(List<Expression> clauses, FromClause node)
Adds them as a ecm:primaryType match in the toplevel operands.
protected void addWhere(List<Expression> clauses, WhereClause where)
protected void addWhere(List<Expression> clauses, Expression expr)
protected void simplifyTypes(List<Expression> clauses)
protected static Set<String> getStringLiterals(LiteralList list)
protected SQLQuery addWildcardNotNullClauses(SQLQuery query)
SELECT dc:subjects/* FROM ...
then we must make sure we don't match documents
that don't have a dc:subjects
at all, as this would make the evaluator return one null
value for
each due to its semantics of doing the equivalent of LEFT JOINs.
To prevent this, we add a clause ... AND dc:subjects/* IS NOT NULL
.
For correlated wildcards this is enough, but for uncorrelated wildcards we must avoid adding extra JOINs, so we must artificially correlated them. This requires rewriting the query with correlated wildcards instead of uncorrelated ones.
protected SQLQuery addIsNotNullClauses(SQLQuery query, Collection<String> names)
public abstract String getCorrelatedWildcardPrefix(String name)
The prefix is used to group together sets of expression that all use references with the same prefix.
name
- the reference name (NXQL)Copyright © 2018 Nuxeo. All rights reserved.