When a comparison field is multi-valued with respect to a query’s perspective table, it is possible that all, some, or none of its values related to a given perspective object will match the target value or range. By default, sets are implicitly compared using “any” quantification. However, the explicit quantifiers ANY, ALL, and NONE can be used. Here is how these quantifiers work:
• Every clause can be thought of as having the general form <field path> = {target}, which means the values produced by the <field path> must match the values in the {target} set. The {target} set is defined by the comparison operator and values specified in the clause (e.g., Size > 10, Size = [1000 TO 10000]). How the link path matches the {target} set depends on how the <field path> is quantified.
• When a field path has no explicit quantification, such as A.B.C, then the path is implicitly quantified with “any”. This means that at least one value in the set {A.B.C} must match the target value set. Logically, the set is constructed by gathering all C’s for all B’s for all A’s into a single set; if the intersection between this set and the {target} set is not empty, the quantified expression is true.
• The explicitly quantified link path ANY(A.B.C) is identical to the implicitly quantified link path A.B.C.
• If a set implicitly or explicitly quantified with ANY is empty, it does not match the {target} set. Hence, if there are no A values, or no A’s have a B value, or no B’s have a C value, the set is empty and the clause cannot match the {target} set.
• The explicit quantifier ALL requires that the <field path> is not an empty set and that every member is contained in the {target} set. For ALL(A.B.C), some A’s might not have a B value and some B’s might not have a C value, but that’s OK – as long as the set {A.B.C} is not be empty and every C value in the set matches the {target} set, the clause is true.
• The explicit quantifier NONE requires that no member of the <field path> is contained in the {target} set. Unlike ANY and ALL, this means NONE matches the {target} set if the <field path> set is empty. Otherwise, no member of the set {A.B.C} must match a {target} set value for the clause to be true. Semantically, NONE is the same as NOT ANY.
• A <field path> can use multiple quantifiers, up to one per field. For example ALL(A).ANY(B).NONE(C) can be interpreted as “No C’s for any B for every A can match a target value”. Put another way, for the quantified <field path> to be true for a perspective object P, all of P’s A values must have at least one B value for which none of its C values match the {target} set. The same existence criteria applies as described above: if a given B has no C values, NONE(C) is true for that B; if a given A has no B values, ANY(B) is false for that A; if a given object P has no A values, ALL(A) is false for that P.
• Implicit “any” quantification is used for any link “sub-path” this is not explicitly quantified. For example, ALL(A).B.C is the same as ALL(A).ANY(B.C). Similarly, A.B.NONE(C) is the same as ANY(A.B).NONE(C).
• Note that ALL(A.B) is not the same as ALL(A).ALL(B). This is because in the first case, we collect the set of all B’s for all A’s and test the set – if a given A has no B’s, that’s OK as long as the set {A.B} is not empty and every value matches the {target} set. However, in ALL(A).ALL(B), if a given A has no B values, ALL(A) fails for that A, therefore the clause is false for the corresponding perspective object.
• However, ANY(A.B) is effectively the same as ANY(A).ANY(B) because in both cases we only need one A to have one B that matches the {target} set. Similarly, NONE(A.B) is effectively the same as NONE(A).NONE(B) because NONE(X) is the same as NOT ANY(X).
• Nested quantifiers are not allowed (e.g., ANY(A.ALL(B))).