(Complex) Nested vs. (Simple) Separated Selectors

Consider the following selectors, with the result of the first two used as parameters in the third:

Facility[] fs1 = Facility:equals(active,”yes”);
Immrecord[] im2 = Immrecord:lessThan(lastvisitdate, Mez:today());
Children[] cs1 = and(
	relationshipIn(facility, fs1),
	relationshipIn(immrecord, im2)
);

We distinguish between complex and simple selectors as complex selectors consisting of multiple nested selectors. The following, therefor, is the complex selector version of the above snippet.

Children[] cs1 = and(
	relationshipIn(facility, Facility:equals(Active,”yes”)),
	relationshipIn(immrecord, Immrecord:lessThan(lastvisitdate, Mez:today()))
);

This complex selector is more performant, potentially far more so. The reason is given in Lesson 10 of the Beginner's Tutorial, section "A Note on Complex Selectors":

Whenever possible, a single complex selector should always be preferred above multiple simple selectors. This is due to the fact that Helium will automatically optimise the backing data base queries for selectors. Using complex selectors instead of multiple simple intermediate selectors might therefore provide a significant performance advantage.

Another example can be seen at the above link.