tkobayas commented on issue #6493:
URL: 
https://github.com/apache/incubator-kie-drools/issues/6493#issuecomment-3450014132

   If a rule has combination of nested `OR`s, it will be transformed to a 
parent `OR` of all possible combinations of those branches. In the reproducer 
`rule2`, the sequence of `OR` blocks contains 8, 8, 6, 8, 3, 5, 5, 2 
alternatives, then, it results in 460800 combinations, which are huge and lead 
to OOM.
   
   In other words, such many `OR` blocks are not good fit for drools.
   
   To avoid the issue, there may be some approaches. One idea is to split some 
parts as "preprocess rules".
   
   e.g.
   
   ```
   rule "preprocess1"
        salience -500
        when
                ( ( $f: /facts [ name == "TOP1", valueStr != null, 
valueStr.contains("R21") ])
                 or ( $f: /facts [ name == "TOP2", valueStr != null, 
valueStr.contains("R22") ])
                 or ( $f: /facts [ name == "TOP3", valueStr != null, 
valueStr.contains("R23") ])
                 or ( $f: /facts [ name == "TOP4", valueStr != null, 
valueStr.contains("R24") ])
                 or ( $f: /facts [ name == "TOP1", valueStr != null, 
valueStr.contains("R31") ])
                 or ( $f: /facts [ name == "TOP2", valueStr != null, 
valueStr.contains("R32") ])
                 or ( $f: /facts [ name == "TOP3", valueStr != null, 
valueStr.contains("R33") ])
                 or ( $f: /facts [ name == "TOP4", valueStr != null, 
valueStr.contains("R34") ]) )
       then
           $f.setPreprocess1(true); // add this flag to `DroolsFact.java`
           facts.update($f);
   end
   
   rule "preprocess2"
   ...
   // similar preprocess rules for the 4 `OR` blocks of `rule 2`
   ...
   
   rule "rule2"
        salience -200
        when
                result: /results[ this != null ]
           /eventTypes[ event == "EXTERNAL1",  customEvent == "EXTERNAL2", 
customEvent == "EXTERNAL3", customEvent == "EXTERNAL4", customEvent == 
"EXTERNAL5", customEvent == "EXTERNAL5", customEvent == null ]
           /channels[ channel == "WEB" ]
                ( ( /facts [ name == "SCORING", value  >= 200 && value <= 300 
]) )
   
                ( ( /facts [ preprocess1 == true, preprocess2 == true, 
preprocess3 == true, preprocess4 == true ]) )
   
                ( ( /facts [ name == "ID1", val61: value, tp61: type ]
                 and eval( listManager.validValue(val61, tp61, "e11cfe001f") ))
                 or ( /facts [ name == "ID1", value == "3" ])
                 or ( /facts [ name == "DECLINES", value >= 3 ]) )
                ( ( /facts [ name == "DECLINES", value > 2 ]) )
                ( ( /facts [ name == "SCORING", value == 1 ])
                 or ( /facts [ name == "TOP1", value != "2" ])
                 or ( /facts [ name == "TOP2", val83: value, tp83: type ]
                 and eval( listManager.validValue(val83, tp83, "c8cdea680002") 
))
                 or ( /facts [ name == "TOP3", val84: value, tp84: type ]
                 and eval( listManager.inValidValue(val84, tp84, "aaa29006a") ))
                 or ( /facts [ name == "TOP4", val85: value, tp85: type ]
                 and eval(! listManager.validValue(val85, tp85, "1cfe001f") )) )
                ( ( /facts [ name == "ID1", valueStr != null, 
valueStr.contains("abc") ])
                 or /facts [ name == "SCORING" , v192 : value ]
                 and /facts [ name == "DECLINES2" , v192 >= value ]
                 or ( /facts [ name == "TOP1", valueStr != null, 
!valueStr.contains("abc") ])
                 or ( not /facts [ name == "TOP2" ] )
                 or /facts [ name == "TOP3" , v195 : value ]
                 and /facts [ name == "ID1" , v195 == value ] )
                ( ( /facts [ name == "DECLINES3", value == "ACTION" ])
                 or /facts [ name == "TOP4", factval102: valueStr, factval102 
!= null ]
                 and /facts [ name == "ID1", otherfactval102: valueStr, 
otherfactval102 != null, otherfactval102.contains(factval102) ] )
       then
           ...
   ```
   I guess it will significantly reduce the transformed combinations.
   
   The example is my quick idea. It might need some adjustment depending on 
your use case.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to