Package org.nuxeo.ecm.core.storage
Class QueryOptimizer
java.lang.Object
org.nuxeo.ecm.core.storage.QueryOptimizer
- Direct Known Subclasses:
DBSQueryOptimizer
Generic optimizer for a NXQL query.
- Since:
- 5.9.4
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Info about a prefix: the prefix, and how many times it was encountered.protected static class
Renames references if they are in the projection part.protected static class
class
Analyzes references to compute common prefix info in order to later factor them in a parent expression. -
Field Summary
Modifier and TypeFieldDescriptionprotected static final int
protected int
protected FacetFilter
protected boolean
Do we match only relations?protected final SchemaManager
static final String
static final String
static final String
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
addFacetFilters
(List<Predicate> clauses, FacetFilter facetFilter) protected SQLQuery
addIsNotNullClauses
(SQLQuery query, Collection<String> names) protected void
addTypes
(List<Predicate> 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
protected void
addWhere
(List<Predicate> clauses, WhereClause where) Adds a flattened version of all toplevel ANDed WHERE clauses.protected SQLQuery
If we have a query likeSELECT dc:subjects/* FROM ...
then we must make sure we don't match documents that don't have adc:subjects
at all, as this would make the evaluator return onenull
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
Gets the prefix to use for this reference name (NXQL) if it contains a correlated wildcard.getDocumentTypeNamesExtending
(String typeName) protected static int
getExpressionCount
(Expression expr) protected static String
getPredicatePrefix
(Predicate predicate) getStringLiterals
(LiteralList list) protected boolean
isTypeRelation
(String typeName) static Predicate
makeSingleAndPredicate
(String prefix, List<Predicate> predicates) Makes a single AND predicate from several expressions known to have a common prefix.Optimizes a query to provide a WHERE clause containing facet filters, primary and mixin types.static void
reorganizeGroupedExpressions
(Map<String, Predicate> 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<Predicate> clauses) Simplify ecm:primaryType positive references, and non-per-instance mixin types.withFacetFilter
(FacetFilter facetFilter)
-
Field Details
-
TYPE_ROOT
- See Also:
-
TYPE_DOCUMENT
- See Also:
-
TYPE_RELATION
- See Also:
-
CORR_BASE
protected static final int CORR_BASE- See Also:
-
facetFilter
-
schemaManager
-
neverPerInstanceMixins
-
correlationCounter
protected int correlationCounter -
onlyRelations
protected boolean onlyRelationsDo we match only relations? -
GROUPING_BY_EXPR_PREFIX
-
-
Constructor Details
-
QueryOptimizer
public QueryOptimizer()
-
-
Method Details
-
withFacetFilter
-
optimize
Optimizes a query to provide a WHERE clause containing facet filters, primary and mixin types. In addition, the top-level AND clauses are analyzed to provide prefix info. -
makeSingleAndPredicate
Makes a single AND predicate from several expressions known to have a common prefix. -
getPredicatePrefix
-
getExpressionCount
-
reorganizeGroupedExpressions
Reorganizes the grouped expressions in order to have 2-level nesting in case a group is a prefix of another.- Since:
- 9.3
-
findPrefix
Finds a non-empty prefix in the strings.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 inputstring
.strings
andwithPrefix
must both be ArrayLists as they will be mutated and queried by index.- Parameters:
strings
- the input stringswithPrefix
- (return value) the strings that have the found prefix as a prefix- Returns:
- the prefix if found, or null if not
- Since:
- 9.3
-
addFacetFilters
-
getDocumentTypeNamesForFacet
-
getDocumentTypeNamesExtending
-
isTypeRelation
-
addTypes
Finds all the types to take into account (all concrete types being a subtype of the passed types) based on the FROM list.Adds them as a ecm:primaryType match in the toplevel operands.
-
addWhere
Adds a flattened version of all toplevel ANDed WHERE clauses. -
addWhere
-
simplifyTypes
Simplify ecm:primaryType positive references, and non-per-instance mixin types. -
getStringLiterals
-
addWildcardNotNullClauses
If we have a query likeSELECT dc:subjects/* FROM ...
then we must make sure we don't match documents that don't have adc:subjects
at all, as this would make the evaluator return onenull
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.
-
addIsNotNullClauses
-