#541 Saxon-SA key optimization

v8.7.3
closed
Michael Kay
5
2012-10-08
2006-06-15
Michael Kay
No

The Saxon-SA optimizer may replace an expression of the
form

//X[./Y=Z]

with an index lookup. Two problems have been found in
this code. Firstly, the rewrite should not take place
if the "use" expression (./Y in this specimen) has
dependencies on local variables. Secondly, the rewrite
doesn't link up the expression tree correctly, which
has the effect that subsequent optimization phases may
make further rewrites to the tree that are incorrect.
This can happen if the above expression is part of a
more complex expression that is also amenable to
similar optimizations.

Source fixes (for Saxonica reference only, since this
problem is specific to Saxon-SA):

(a) in net.sf.saxon.functions.KeyFn.java, method
internalKeyCall at line 50, add the following two lines:

    k.adoptChildExpression(value);
    k.adoptChildExpression(doc);

(b) in OptimizerSA at line 170 add

   if ((use.getDependencies() &

~StaticProperty.DEPENDS_ON_CONTEXT_ITEM) != 0) {
return null;
}

Discussion