The rule searches for assign operator with an aggregate function expression immediately following an aggregate operator with a sequence expression. XQuery aggregate functions are implemented in both scalar (one XDM Instance input as a sequence) and iterative (a stream of XDM Instances each one is single object).
Before plan__parent ASSIGN( $v2 : sf1( $v1 ) ) SUBPLAN{ AGGREGATE( $v1 : sequence( $v0 ) ) plan__nested NESTEDTUPLESOURCE } plan__child Where sf1 is a XQuery aggregate function expression (count, max, min, average, sum) with any supporting functions like treat, promote or data. Also plan__parent does not use $v1 After plan__parent SUBPLAN{ AGGREGATE( $v2 : af1( $v0 ) ) plan__nested NESTEDTUPLESOURCE } plan__child Where af1 is a XQuery aggregate function expression (count, max, min, average, sum) that has been implemented in an iterative approach and works on individual tuples instead of one value in given as a sequence.
@author prestoncarman