Class BooleanNormalizer
- java.lang.Object
-
- com.apple.foundationdb.record.query.plan.planning.BooleanNormalizer
-
@API(INTERNAL) public class BooleanNormalizer extends Object
A normalizer of a tree ofQueryComponent
predicates into disjunctive normal form.The full normal form has a single
Or
at the root, all of whose children areAnd
, none of whose children have other Boolean operators. This is abbreviated to exclude parent Boolean nodes with only one child. The intermediate form for the normalizer is a list of lists.The size of a Boolean expression in disjunctive normal form (DNF) is the number of terms in the outermost
Or
[O'Donnell 2014]. TheBooleanNormalizer
will not normalize aQueryComponent
if the normalized form would have a size that exceeds the size limit. This limit is useful to avoid wastefully normalizing expressions with a very large DNF. In some cases, such as a large expression in conjunctive normal form (CNF), attempting to normalize such an expression will cause out-of-memory errors.
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_SIZE_LIMIT
The default limit on the size of the DNF that will be produced by the normalizer.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static BooleanNormalizer
getDefaultInstance()
Obtain a normalizer with the default size limitDEFAULT_SIZE_LIMIT
.QueryComponent
normalize(QueryComponent predicate)
Convert the given predicate to disjunctive normal form, if necessary.QueryComponent
normalizeIfPossible(QueryComponent predicate)
Convert the given predicate to disjunctive normal form, if necessary.static BooleanNormalizer
withLimit(int sizeLimit)
Obtain a normalizer with the given size limit.
-
-
-
Field Detail
-
DEFAULT_SIZE_LIMIT
public static final int DEFAULT_SIZE_LIMIT
The default limit on the size of the DNF that will be produced by the normalizer.- See Also:
- Constant Field Values
-
-
Method Detail
-
getDefaultInstance
@Nonnull public static BooleanNormalizer getDefaultInstance()
Obtain a normalizer with the default size limitDEFAULT_SIZE_LIMIT
.- Returns:
- a normalizer with the default size limit
-
withLimit
@Nonnull public static BooleanNormalizer withLimit(int sizeLimit)
Obtain a normalizer with the given size limit.- Parameters:
sizeLimit
- a limit on the size of DNF that this normalizer will produce- Returns:
- a normalizer with the given size limit
-
normalizeIfPossible
@Nullable public QueryComponent normalizeIfPossible(@Nullable QueryComponent predicate)
Convert the given predicate to disjunctive normal form, if necessary. If the size of the DNF would exceed the size limit, return the un-normalized predicate.- Parameters:
predicate
- the query predicate to be normalized- Returns:
- the predicate in disjunctive normal form if it does not exceed the size limit or the predicate otherwise
-
normalize
@Nullable public QueryComponent normalize(@Nullable QueryComponent predicate)
Convert the given predicate to disjunctive normal form, if necessary. If the size of the DNF would exceed the size limit, throw aBooleanNormalizer.DNFTooLargeException
.- Parameters:
predicate
- the query predicate to be normalized- Returns:
- the predicate in disjunctive normal form
- Throws:
com.apple.foundationdb.record.query.plan.planning.BooleanNormalizer.DNFTooLargeException
- if the DNF would exceed the size limit
-
-