&lt;quote&gt;<br>It is rather common for people to
            write something like &quot;<tt>(not (exists (A)))</tt>,&quot; but this is just a
            very inefficient way to write <tt>(not (A))</tt>.<br>&lt;/quote&gt; <br><br>Kudos to Ernest Friedman-Hill to put this sentence into the Jess documentation.<br><br>Maybe I should quote hiom in the Drools Expert doc ;-)<br>
<br>-W<br><br><br><div class="gmail_quote">On Fri, Aug 21, 2009 at 11:11 PM, Shah, Malay <span dir="ltr">&lt;<a href="mailto:Malay.Shah@morganstanley.com">Malay.Shah@morganstanley.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
May be I have not put the question right. We have a drool rule that is running extremely slow for large sets of data. The rule is something like:<br>
<br>
For every object A, perform action if there does not exist an object B such that A.id = B.id.<br>
And the corresponding drool rule is as follows:<br>
<br>
when<br>
    A()<br>
    not(exists B(A.id = id))<br>
then<br>
    action......<br>
<br>
The performance is bad because of not exists clause here. We have got OOM exceptions with relatively large amounts of data for this rule. To improve performance, we basically hacked the rule/code into something like this:<br>

<br>
Create a global variable x that is a HashSet of all ids of object A, and the drool rule now is:<br>
<br>
 global java.util.HashSet x;<br>
when<br>
        B()<br>
        eval<br>
        (<br>
                ! (x.contains(<a href="http://b.id" target="_blank">b.id</a>) )<br>
        )<br>
then<br>
        action.....<br>
<br>
This obviously is performing much better with hashes involved. But, I don&#39;t like the fact that we have to write the logic of this rule at two places. I would rather create this variable x (don&#39;t care whether it is global or temporarily bound) in the rule itself and use it in the condition to help performance and have all logic for the rule at one place.<br>

<br>
Is there a way to generate this hashset x in the condition part of the rule itself? Yes, I understand that I am trying to mix up the procedural part of code with drool code. But, I was just wondering if this is possible to keep the java code clean and have the intelligence of information that the rule needs to be evaluated in the rule itself.<br>

<br>
Hope this clears some doubts.<br>
<br>
Thanks<br>
<font color="#888888"><br>
Malay Shah<br>
</font><div><div></div><div class="h5"><br>
-----Original Message-----<br>
From: <a href="mailto:rules-users-bounces@lists.jboss.org">rules-users-bounces@lists.jboss.org</a> [mailto:<a href="mailto:rules-users-bounces@lists.jboss.org">rules-users-bounces@lists.jboss.org</a>] On Behalf Of Greg Barton<br>

Sent: Friday, August 21, 2009 4:44 PM<br>
To: Rules Users List<br>
Subject: Re: [rules-users] populating global variable in Condition Section?<br>
<br>
This is a galactically bad idea.  Using a global in this way is inherently unsafe as there&#39;s no guarantee that ebtween the time you set the var and when it&#39;s used later in the condition that the value is the same.  What is your reason for wanting to use a global in this way?  You should use a temporary bound variable instead.<br>

<br>
--- On Fri, 8/21/09, Shah, Malay &lt;<a href="mailto:Malay.Shah@morganstanley.com">Malay.Shah@morganstanley.com</a>&gt; wrote:<br>
<br>
&gt; From: Shah, Malay &lt;<a href="mailto:Malay.Shah@morganstanley.com">Malay.Shah@morganstanley.com</a>&gt;<br>
&gt; Subject: [rules-users] populating global variable in Condition Section?<br>
&gt; To: <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt; Date: Friday, August 21, 2009, 3:19 PM<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; Hi,<br>
&gt;<br>
&gt; Is it possible<br>
&gt; to populate a global variable in<br>
&gt; the condition section of the<br>
&gt; drool rule, and use it later in the condition itself?<br>
&gt; I currently have a<br>
&gt; global HashSet variable that I construct before firing the rule, but I<br>
&gt; would like this code of constructing this global variable to be with<br>
&gt; the drool rule itself. Any help on this would be much appreciated.<br>
&gt;<br>
&gt; Thanks<br>
&gt;<br>
&gt; Malay<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; NOTICE: If received in error, please<br>
&gt; destroy, and notify sender. Sender does not intend to waive<br>
&gt; confidentiality or privilege. Use of this email is<br>
&gt; prohibited when received in error. We may monitor and store emails to the extent<br>
&gt; permitted by applicable law.<br>
&gt;<br>
&gt;<br>
&gt; -----Inline Attachment Follows-----<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; rules-users mailing list<br>
&gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br>
</div></div>--------------------------------------------------------------------------<br>
<div class="im">NOTICE: If received in error, please destroy, and notify sender. Sender does not intend to waive confidentiality or privilege. Use of this email is prohibited when received in error. We may monitor and store emails to the extent permitted by applicable law.<br>

<br>
</div><div><div></div><div class="h5">_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</div></div></blockquote></div><br>