Rudolf, your query looks reasonable to me. Maybe Tamino is doing the self join before evaluating the filter conditions? If you remove the sort clause, how long does it take? Why don’t you try nested for loops like this:
declare namespace xs = “XML Schema”
for $mainflt in input()/Fltshare
where $mainflt/@startdate >= xs:date(“2003-01-01”)
and $mainflt/@enddate <= xs:date(“2004-01-01”)
and $mainflt/@arrdep = “A”
return
for $shareflt in $mainflt/Shared/Flight
where ( ($mainflt/@mainflt = “B” and $shareflt/@sharefltnr >= “K”) or $mainflt/@mainflt > “B”)
return
{ $mainflt/@mainflt }
{ $mainflt/@arrdep }
{ $mainflt/@startdate }
{ $mainflt/@enddate }
{ $mainflt/Opdays }
{ $shareflt }
sort by ($mainflt/@mainflt,$shareflt/@sharefltnr,$mainflt/@startdate,$mainflt/@enddate)
Actually, the sort by clause seems wrong to me. I thought that the sort expression is relative to the output data from the FLWR statement, in which case the variables $mainflt and $shareflt have no meaning. Maybe the sort expression should be
sort by (@mainflt,Shared/Flight/@sharefltnr,@startdate,@enddate)
Alternately, you could loop on the shareflight first, like below, but it seems like it would be slower to me. Tell us your results though.
declare namespace xs = “XML Schema”
for $shareflt in input()/FltShare/Shared/Flight
let $mainflt := $shareflt/…/…/…/FltShare
where ( ($mainflt/@mainflt = “B” and $shareflt/@sharefltnr >= “K”) or $mainflt/@mainflt > “B”)
and $mainflt/@startdate >= xs:date(“2003-01-01”)
and $mainflt/@enddate <= xs:date(“2004-01-01”)
and $mainflt/@arrdep = “A”)
return
{ $mainflt/@mainflt }
{ $mainflt/@arrdep }
{ $mainflt/@startdate }
{ $mainflt/@enddate }
{ $mainflt/Opdays }
{ $shareflt }
sort by ($mainflt/@mainflt,$shareflt/@sharefltnr,$mainflt/@startdate,$mainflt/@enddate)
Bill
#API-Management#Tamino#webMethods