From: Wolfgang M. <wol...@ex...> - 2009-12-15 22:00:18
|
> A great topic! I'd certainly welcome optimizations like this. I > wonder: If a FLWOR expression has an 'order by' clause, is it even > possible to optimize the expression's positional predicate (or > subsequence)? Or does 'order by' make optimizations impossible? The "order by" has to be processed to determine the position of each item in the result sequence. It would be an option to use the range index as Mike suggested to speed up the sorting. >> Note that using subsequence instead of the predicate can be a lot >> faster sometimes. > > I didn't realize that. Can you generalize about when subsequence > would be faster? And would you say it's always at least as fast as > the predicate? Mike used position() within the predicate: [position() = (1 to 10)]. This will indeed be slower than a corresponding subsequence($input, 1, 10). Reason: the predicate has to be evaluated once for every item in the context sequence. This doesn't make a big difference if you have a simple expression like $a[position() = (1 to 10)], but it could result in a substantial performance loss for more complex expressions involving a path expression like a//*/b[position() = (1 to 10)]. To be on the safe side, I would recommend subsequence() if you need to select *more than one* item. Wolfgang |