2 Replies Latest reply on Jan 23, 2013 12:00 PM by Ben Rogers

    How rules are executed?

      How the rule engine decides which rules to execute in a very complex rulebase? what is the pattern?
        • 1. Re: How rules are executed?
          Snehal Sunilkumar
          OPA does not follow any pattern for executing the rule base. You can't predict what rule may be executed when.

          • 2. Re: How rules are executed?
            Ben Rogers
            When OPA builds the rulebase, it takes all of the compiled rules and sorts them into an optimised order.

            It does this so that all of the rules can be executed in a highly efficient linear left-to-right sweep. This is all explained in the following Oracle Whitepaper - "Linear Inferencing - High Performance Processing". Page 2 is the most relevant:


            Have a look at this diagram.

            When the value of an attribute is changed, it triggers an inferencing cycle. OPA knows the structure of the rulebase, so it knows that by changing attribute X then it also affects rule Y and Z.

            So for example:

            A is true if
            ...B is true and
            ...C is true

            D is true if
            ...B is true

            B is used in the rule A and D.
            By setting B, the inferencing cycle will see if A is now known, and D is now known.

            You can do this yourself by doing visual browsers of B.

            Here are some useful help articles about this:

            Inferencing Cycle:


            Rule structure and dependencies:


            So... you could predict which attributes will be set next when base attribute(s) have been changed. You can do this by looking at the structure of the rulebase and seeing which inferred attributes (via rules) are set when the base attribute is changed.
            Do a visual browser on a base attribute and "generate influenced rules"... effectively by doing this you are forward-chaining and that is what the Engine will do once a base attribute is changed.

            Try this out in the debugger. Set a base attribute to a different value, and you will see the forward chaining impact ... all of the changed attributes from this cycle will be highlighted in a green background in the debugger...You could check this matches your "prediction" from the visual browser file...

            Hope this helps... let me know if this is not clear.