Peter is right here. Predicates are slower than simple literal/bound
variable constraints (apples to apples). Although, you can't compare the
overhead of a predicate with the overhead of 2 additional join nodes in
the network (apples to bananas :)).
There may be exceptions, specially if you can restrict a match space
in a join node with a previous join node with lower match space, with a
combined lower cost, but this has nothing to do with using or not
predicates.
The general rule Peter stated is a good rule of thumb.
[]s
Edson
Michael Neale wrote:
surprising, as the normal advice is to avoid predicates. However, in
that case, the predicate is inside the "column", and there is plenty
of filtering done before the predicate test is executed - and the
predicate is self is very very simple and cheap, so its probably not
suprising, a much simpler rule/network means faster in that case.
Just goes to show, make no assumptions !
I think in that case, the predicate version also looks clearer with
its intent (we just need some nicer syntax for it which we will have
soon).
Michael.
On 12/29/06, *Peter Lin* <[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>> wrote:
as a general rule, joins are more expensive than predicate
constraints and simple literal constraints.
think of it this way, it's like doing a sql query on 1 table, vs
doing a join on several tables.
peter
On 12/29/06, *Geoffrey De Smet* < [EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>> wrote:
I have 2 alternatives of writing my rules,
here is a cutout (see below for all the rules *):
A) With predicates
query "matchRepeater"
Match($homeTeam : homeTeam, $awayTeam : awayTeam, $day1 :
day);
Match(homeTeam == $awayTeam, awayTeam == $homeTeam,
$day2 : day -> ($day2.getIndex() == $day1.getIndex()
+ 1));
end
B) With separate facts
query "matchRepeater"
$day1 : Day($index1 : index);
$day2 : Day($index2 : index -> ($index2 == $index1 + 1));
Match($homeTeam : homeTeam, $awayTeam : awayTeam, day ==
$day1);
Match(homeTeam == $awayTeam, awayTeam == $homeTeam, day
== $day2);
end
Now, I was expecting B to be faster, because A uses predicates
which
aren't indexed. Or I was expecting them to be equally fast.
However, using the trunk version of today I 've recorded this
benchmark:
nl10, 100 iterations:
A = 3m 02s
B = 3m 45s
Using a trunk version of a few weeks ago I had this:
nl6, 1500 iterations:
A = 10m 10s
B = 11m 33s
In both cases, A is faster the B, which surprises me.
What could be causing this?
Performance and scalability is the only issue when trying to
break the
traveling tournament problem records, so understanding how to
write
faster rules is important to me :)
--
With kind regards,
Geoffrey De Smet
* All the rules:
A)
query "fourConsecutiveHomeMatches"
Match($homeTeam : homeTeam, $day1 : day);
Match(homeTeam == $homeTeam, $day2 : day ->
($day2.getIndex() ==
$day1.getIndex() + 1));
Match(homeTeam == $homeTeam, $day3 : day ->
($day3.getIndex() ==
$day1.getIndex() + 2));
Match(homeTeam == $homeTeam, $day4 : day ->
($day4.getIndex() ==
$day1.getIndex() + 3));
end
query "fourConsecutiveAwayMatches"
Match($awayTeam : awayTeam, $day1 : day);
Match(awayTeam == $awayTeam, $day2 : day ->
($day2.getIndex() ==
$day1.getIndex() + 1));
Match(awayTeam == $awayTeam, $day3 : day ->
($day3.getIndex() ==
$day1.getIndex() + 2));
Match(awayTeam == $awayTeam, $day4 : day ->
($day4.getIndex() ==
$day1.getIndex() + 3));
end
query "matchRepeater"
Match($homeTeam : homeTeam, $awayTeam : awayTeam, $day1 :
day);
Match(homeTeam == $awayTeam, awayTeam == $homeTeam, $day2
: day ->
($day2.getIndex() == $day1.getIndex() + 1));
end
B)
query "fourConsecutiveHomeMatches"
$day1 : Day($index1 : index);
$day2 : Day($index2 : index -> ($index2 == $index1 + 1));
$day3 : Day($index2 : index -> ($index2 == $index1 + 2));
$day4 : Day($index2 : index -> ($index2 == $index1 + 3));
Match($homeTeam : homeTeam, day == $day1);
Match(homeTeam == $homeTeam, day == $day2);
Match(homeTeam == $homeTeam, day == $day3);
Match(homeTeam == $homeTeam, day == $day4);
end
query "fourConsecutiveAwayMatches"
$day1 : Day($index1 : index);
$day2 : Day($index2 : index -> ($index2 == $index1 + 1));
$day3 : Day($index2 : index -> ($index2 == $index1 + 2));
$day4 : Day($index2 : index -> ($index2 == $index1 + 3));
Match($awayTeam : awayTeam, day == $day1);
Match(awayTeam == $awayTeam, day == $day2);
Match(awayTeam == $awayTeam, day == $day3);
Match(awayTeam == $awayTeam, day == $day4);
end
query "matchRepeater"
$day1 : Day($index1 : index);
$day2 : Day($index2 : index -> ($index2 == $index1 + 1));
Match($homeTeam : homeTeam, $awayTeam : awayTeam, day ==
$day1);
Match(homeTeam == $awayTeam, awayTeam == $homeTeam, day
== $day2);
end
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email
<http://xircles.codehaus.org/manage_email>
--
Edson Tirelli
Software Engineer - JBoss Rules Core Developer
Office: +55 11 3124-6000
Mobile: +55 11 9218-4151
JBoss, a division of Red Hat @ www.jboss.com
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email