Uploaded image for project: 'Drools'
  1. Drools
  2. DROOLS-4632

Optimize single pattern forall statement

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Done
    • Icon: Major Major
    • None
    • None
    • None
    • None
    • 2019 Week 41-43 (from Okt 7)
    • NEW
    • NEW

      At the moment a single pattern forall statement like

      forall( Type( constraints ) )
      

      it is automatically rewritten as

      forall( $t : Type() Type( this == $t, constraints ) )
      

      and then implemented with 2 not nodes and join.

      [EntryPointNode(1) EntryPoint::DEFAULT ] on Partition(MAIN)
          [ObjectTypeNode(4)::EntryPoint::DEFAULT objectType=[ClassObjectType class=org.drools.testcoverage.common.model.Person] expiration=-1ms ] on Partition(MAIN)
              [JoinNode(5) - [ClassObjectType class=org.drools.testcoverage.common.model.Person]] on Partition(1) Ld -1 Li -1 Rd 0 Ri 0
                  [NotNode(7) - [ClassObjectType class=org.drools.testcoverage.common.model.Person]] on Partition(1) Ld -1 Li -1 Rd 9223372036854775807 Ri 9223372036854775807
                      RightInputAdapterNode(8)[ tupleMemoryEnabled=true, tupleSource=[NotNode(7) - [ClassObjectType class=org.drools.testcoverage.common.model.Person]], source=null, associations={[Rule name=R1, agendaGroup=MAIN, salience=0, no-loop=false]=1}, partitionId=Partition(1)] on Partition(1)
                          [NotNode(9) - <source from a subnetwork>] on Partition(1) Ld 0 Li 0 Rd -1 Ri -1
                              [RuleTerminalNode(10): rule=R1] on Partition(1) d -1 i -1
              [AlphaNode(6) constraint=!(age >= 18) || !(name.startsWith("M"))] on Partition(1) d 2056 i 9223372036854775807
                  [NotNode(7) - [ClassObjectType class=org.drools.testcoverage.common.model.Person]] on Partition(1) Ld -1 Li -1 Rd 9223372036854775807 Ri 9223372036854775807
          [ObjectTypeNode(2)::EntryPoint::DEFAULT objectType=[ClassObjectType class=org.drools.core.reteoo.InitialFactImpl] expiration=-1ms ] on Partition(MAIN)
              [LeftInputAdapterNode(3)] on Partition(1) Ld 0 Li 0
                  [JoinNode(5) - [ClassObjectType class=org.drools.testcoverage.common.model.Person]] on Partition(1) Ld -1 Li -1 Rd 0 Ri 0
                  [NotNode(9) - <source from a subnetwork>] on Partition(1) Ld 0 Li 0 Rd -1 Ri -1
      

      It would be much faster to rewrite it as

      not( Type( !constraints ) )
      

      and then evaluate it with one single not node.

      [EntryPointNode(1) EntryPoint::DEFAULT ] on Partition(MAIN)
          [ObjectTypeNode(4)::EntryPoint::DEFAULT objectType=[ClassObjectType class=org.drools.testcoverage.common.model.Person] expiration=-1ms ] on Partition(MAIN)
              [AlphaNode(5) constraint=!(age >= 18) || !(name.startsWith("M"))] on Partition(1) d 2056 i 2056
                  [NotNode(6) - [ClassObjectType class=org.drools.testcoverage.common.model.Person]] on Partition(1) Ld -1 Li -1 Rd 0 Ri 2056
                      [RuleTerminalNode(7): rule=R1] on Partition(1) d -1 i -1
          [ObjectTypeNode(2)::EntryPoint::DEFAULT objectType=[ClassObjectType class=org.drools.core.reteoo.InitialFactImpl] expiration=-1ms ] on Partition(MAIN)
              [LeftInputAdapterNode(3)] on Partition(1) Ld 0 Li 0
                  [NotNode(6) - [ClassObjectType class=org.drools.testcoverage.common.model.Person]] on Partition(1) Ld -1 Li -1 Rd 0 Ri 2056
      

              mfusco@redhat.com Mario Fusco
              mfusco@redhat.com Mario Fusco
              Tibor Zimányi Tibor Zimányi
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: