Hi list! Recently I started to wonder why functions in my XQuery modules make no use of indexes unless I force them to by using the respective function like db:text(). Now I just did some I think minimal changes to the example for text index at: http://docs.basex.org/wiki/Indexes#Text_Index. If I just change it like below I loose almost all index optimization. The only optimizations left are: * Using db:open or collection with a string but not one in a variable of a for FLOWR expression or the simple map operator. * Using xquery:eval and passing a context with db:open or collection Is there any chance that this will change any time soon? Is this a fundamental restriction? Best regards Omar xquery version "3.1"; declare namespace _ = "urn:local:namespace:_"; import module namespace functx = "http://www.functx.com"; declare function _:_1st_example($ctx as document-node()) { $ctx//*[text() = 'Germany'] }; declare function _:_2nd_example($file as xs:string) { doc($file)//name[. = 'Germany'] }; declare function _:_3rd_example($dbname as xs:string+) { ( for $c in ($dbname!collection(.))//country where $c//city/name = 'Hanoi' return $c/name, $dbname!xquery:eval("//*[text() = 'Vietnam']", map {'': db:open(.)})) }; ( (: 1st example :) _:_1st_example(.), (: 2nd example :) _:_2nd_example('factbook.xml'), (: 3rd example :) _:_3rd_example(('factbook', 'factbook')), xs:string(_:_1st_example) ) Optimized Query: (let $ctx_314 := . return $ctx_314/descendant::*[(text() = "Germany")], db:open-pre("factbook",0)/descendant::name[(. = "Germany")], (for $c_317 in (("factbook", "factbook") ! collection(.))/descendant::country[(descendant::city/name = "Hanoi")] return $c_317/name, (("factbook", "factbook") ! xquery:eval("//*[text() = 'Vietnam']", map { "":db:open(.) }))), _:_1st_example cast as xs:string?) Compiling: [...] - RUNTIME: pre-evaluate root() to document-node() - RUNTIME: rewrite descendant-or-self step(s) - RUNTIME: apply text index for "Vietnam" - RUNTIME: pre-evaluate root() to document-node() - RUNTIME: rewrite descendant-or-self step(s) - RUNTIME: apply text index for "Vietnam"