Order Predicates Efficiently

Ordering Predicates efficiently can reduce the amount of data that is being checked, allowing for faster processing.

If you need to identify features in a Rule or Action using more than one Predicate, then you need to think about how these Predicates should be ordered. This will need to be done anywhere that you specify a class of objects other than in the Rule or Action’s root node (i.e. a For All, Existence, Aggregate, Chaining or Loop Over Objects component within a Rule or Action).

Predicates are applied in the sequence in which they appear. Ordering efficiently will narrow down a selection more quickly than an inefficient order.

Knowledge of the data will help to decide how to achieve this. Often, a selection set is reduced using a spatial intersection or within distance check, but sometimes there is another attribute which can be used to reduce the selection set.

     Note: Ensuring that the first Predicate uses an indexed value is the most important consideration, but it is also useful to consider the ordering of subsequent checks, based on either their complexity or ability to reduce the selection set.

More complex Predicates are better left until after the faster, simpler Predicates that filter out as much data as possible.

Identifying Improvements

In a set of Rule logic which:

  1. Starts by reducing the selection set spatially

  2. Then performs a more detailed geometric comparison

  3. Ends with a simple attribute comparison

It will actually be quickest to perform the attribute comparison second and the detailed geometric comparison third.

This is because the attribute comparison will be very fast, so it is worth doing this before the final complex geometric check in order to be able to easily reduce the number of complex geometric comparisons.

ClosedEfficient ordering Example

In the example shown below, the action sets a road "Centre-line" to be non-drivable if it is at least 90% within "Footpath" polygons.

An action determining if roads intercept footpaths and are drivable
Action determining if roads intercept pavements and are drivable

If we take a closer look at some of the logic we can see how predicates can be ordered to efficiently run on the data. Here we look at the "Classification" string value before doing a more complex spatial comparison.

A subset of predicates ordered sensibly
A subset of the predicates ordered efficiently