skip to main content
Corticon Studio: Rule Modeling Guide : Writing Rules to access external data : Enabling Database Access for Rules using root-level Entities : Optimizing Aggregations that Extend to Database

Try Corticon Now
Optimizing Aggregations that Extend to Database
Our rulesheet used a condition statement that did a calculation and a difference, calling a statement when it evaluated as true, as shown:
As written, load.weight ->sum > plane.maxCargoWeight, the condition will copy all the relevant cargo records into Corticon's memory to perform its sum, and then evaluate whether total weight is greater that the plane's capacity. As we are extended to database, the number of values could be large. Corticon lets you optimize such calculations for non-conditional (column 0) actions.
You can recast the conditions by creating an attribute in the FlightPlan entity to store a calculation. Here, we created the load attribute, and then set its properties so that the Data Type, Integer is the same as the weight data it will aggregate, and setting the Mode to Transient as this is data that will be just used locally:
You could rewrite the conditions and actions to create a non-conditional rule followed by a conditional test of the computed result, as follows:
This optimizes the performance by calculating load on the database-side, and then evaluating the load against maxCargoWeight in memory.
Note: This feature applies to all Collection operators that are aggregation operators: sum, avg, size, min, and max. See Aggregations that optimize database access for more information about these Collection operators.