]
Mario Fusco commented on DROOLS-1685:
-------------------------------------
The rulesets you pasted are not totally equivalent. In the first one you have
{code}
entity.entityTypeId in ( 291262 )
{code}
while in second
{code}
entity.entityTypeId == 291262
{code}
I think this could make a huge difference performance wise because only the second
constraint can be indexed. If your problem persists after having fixed this difference
please send a complete reproducer so I could further investigate this problem.
Improve performance of rules using "or" in LHS
----------------------------------------------
Key: DROOLS-1685
URL:
https://issues.jboss.org/browse/DROOLS-1685
Project: Drools
Issue Type: Enhancement
Components: core engine, kie server
Affects Versions: 6.5.0.Final
Reporter: Russell Morrisey
Assignee: Mario Fusco
The following two rulesets produce the same output, but their performance differs
dramatically.
My understanding is that the two rulesets should be equivalent to one another. It seems
like the 'or' operation must be handled inefficiently by the engine. Is there
anything that can be improved the engine's performance in this case?
Ruleset #1 takes ~3 seconds to execute on my local machine (for a dataset with 3
entities, 1 service ordered each). Ruleset #2 runs in ~200 ms.
*Ruleset 1*
{code:java}
rule "Rule183"
dialect "mvel"
when
$entity : Entity( )
( $service : ServiceOrdered( serviceId == "FORM" , entity == $entity ,
entity.entityTypeId in ( 291262, 291275, 291277 ) ) or $service : ServiceOrdered(
serviceId == "DISSO" , entity == $entity , entity.entityTypeId in ( 291262 ) ,
stateId == 290864 ) )
$r1 : QuestionDefinition( id == 590 )
then
Question fact0 = new Question();
fact0.setQuestionDefinition( $r1 );
fact0.setEntity( $entity );
insert( fact0 );
end
{code}
*Ruleset 2*
{code:java}
rule "Rule183"
dialect "mvel"
when
$entity : Entity( )
$service : ServiceOrdered( serviceId == "FORM" , entity == $entity ,
entity.entityTypeId in ( 291262, 291275, 291277 ) )
$r1 : QuestionDefinition( id == 590 )
then
Question fact0 = new Question();
fact0.setQuestionDefinition( $r1 );
fact0.setEntity( $entity );
insert( fact0 );
end
{code}
{code}
rule "Rule183-2"
dialect "mvel"
when
$entity : Entity( )
$service : ServiceOrdered( serviceId == "DISSO" , entity == $entity ,
entity.entityTypeId == 291262 , stateId == 290864 )
$r1 : QuestionDefinition( id == 590 )
then
Question fact0 = new Question();
fact0.setQuestionDefinition( $r1 );
fact0.setEntity( $entity );
insert( fact0 );
end
{code}