Dear BaseX community I am currently working with BaseX to write a rather long XQuery statement with quite large intermediate structures (XML documents / fragments) bound to variables (in FLWOR expressions), which I query by XPath using attributes etc. further down. Having nested loops, this is becoming very slow. Are those intermediate structures automatically indexed? Or how can I achieve indexing on them? Or do I need to write them into a database for this indexing? (Can I specify a datbase as "in-memory"?) Then I guess I need a "BaseX script" rather than a single XQuery? Of course, I am looking for the most elegant/idiomatic way. Or is it best to build index-like intermediate structures myself, probably using maps rather than XML documents? Furthermore, are there profiling tools inside BaseX, or would I need to fire up a Java IDE to see where most time is being spent? Thanks in advance for any suggestions! Sebastian