[FIX] XQuery: optimization bug fixed, tests added