by
Krull >> Thu, 11 Jan 2001 3:39:32 GMT
I seem to remember that the where clause is quite highly optimised for only one condition as long as it doesn't call a method (ie it is only accessing a property on the object).
Hi David,
The compile time 'where clause' optimisation you are thinking of is actually more specific than that. It only applies when iterating a single-key dictionary when the where clause consists of a simple relative key expression e.g. obj.memberkey1 > value1. Multi-keyed dictionary iterations and more complicated expressions including ranges e.g. key1 > lowerValue1 AND key1 < upperValue1 are not currently optimised. Consider, for example a foreach statement of the form:
foreach o in dict where o.key <rel op> searchkey do // <rel op> is > or >=,
. . .
endforeach;
or in a reverse iteration:
foreach o in dict reversed where o.key <rel op> searchkey do // <rel op> is < or <=
. . .
endforeach;
These cases are optimised by the compiler to use the Iterator::startKey<rel op> methods to start the iteration at the first entry in the dictionary satisfying the search condition. Remember that the JADE foreach statement is simply 'syntactical sugar' for an iterator loop so any further optimisations the compiler or a separate backend query optimiser could do for you can be coded manually using Dictionary/Iterator relative key methods and suitable termination conditions.