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
Nested ClassesModifier and TypeClassDescriptionstatic classInfo about a prefix: the prefix, and how many times it was encountered.protected static classRenames references if they are in the projection part.protected static classclassAnalyzes references to compute common prefix info in order to later factor them in a parent expression. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final intprotected intprotected FacetFilterprotected booleanDo we match only relations?protected final SchemaManagerstatic final Stringstatic final Stringstatic final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddFacetFilters(List<Predicate> clauses, FacetFilter facetFilter) protected SQLQueryaddIsNotNullClauses(SQLQuery query, Collection<String> names) protected voidaddTypes(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 voidprotected voidaddWhere(List<Predicate> clauses, WhereClause where) Adds a flattened version of all toplevel ANDed WHERE clauses.protected SQLQueryIf we have a query likeSELECT dc:subjects/* FROM ...then we must make sure we don't match documents that don't have adc:subjectsat all, as this would make the evaluator return onenullvalue for each due to its semantics of doing the equivalent of LEFT JOINs.static StringfindPrefix(List<String> strings, List<String> withPrefix) Finds a non-empty prefix in the strings.abstract StringGets the prefix to use for this reference name (NXQL) if it contains a correlated wildcard.getDocumentTypeNamesExtending(String typeName) protected static intgetExpressionCount(Expression expr) protected static StringgetPredicatePrefix(Predicate predicate) getStringLiterals(LiteralList list) protected booleanisTypeRelation(String typeName) static PredicatemakeSingleAndPredicate(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 voidreorganizeGroupedExpressions(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 voidsimplifyTypes(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.stringsandwithPrefixmust 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:subjectsat all, as this would make the evaluator return onenullvalue 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
-