Error: Interrupted. Compiling: - removing redundant xs:boolean cast. - atomic evaluation of (position() < $seq_4) - inlining Q{http://www.functx.com}is-node-in-sequence#2 - inlining $seq_7 as node()* - atomic evaluation of (position() < $seq_4) - rewriting ($nodes_3)[$seq_4][not(let $node_6 as node()? := . return some(for $nodeInSeq_8 in ((: node()*, true :) ($nodes_3)[(position() < $seq_4)]) return deep-equal($nodeInSeq_8, $node_6)))] - pre-evaluating ((: node()*, true :) for $seq_4 in (1 to count($nodes_3)) return ((: node()*, true :) (basex:item-at($nodes_3, $seq_4))[not(let $node_6 as node()? := . return some(for $nodeInSeq_8 in ((: node()*, true :) ($nodes_3)[(position() < $seq_4)]) return deep-equal($nodeInSeq_8, $node_6)))])) - inlining Q{http://www.functx.com}distinct-nodes#1 - removing redundant $nodes_9 as node()* cast. - inlining $nodes_9 - atomic evaluation of (position() < $seq_10) - simplifying flwor expression - inlining $diff_starts_5 - simplifying flwor expression Query: declare namespace functx = "http://www.functx.com"; declare namespace p="a:b:c"; declare function functx:is-node-in-sequence( $node as node()? , $seq as node()* ) as xs:boolean {some $nodeInSeq in $seq satisfies deep-equal($nodeInSeq,$node)}; declare function functx:distinct-nodes( $nodes as node()* ) as node()* {for $seq in (1 to count($nodes))return $nodes[$seq][not(functx:is-node-in-sequence(.,$nodes[position() < $seq]))]} ; let $diff_starts := functx:distinct-nodes(/products/p:category/start)return $diff_starts Optimized Query: for $seq_13 in (1 to count(db:open-pre("Large_Demo_File",0)/products/p:category/start)) return ((: node()*, true :) (basex:item-at(db:open-pre("Large_Demo_File",0)/products/p:category/start, $seq_13))[not(let $node_14 as node()? := . return some(for $nodeInSeq_15 in ((: node()*, true :) (db:open-pre("Large_Demo_File",0)/products/p:category/start)[(position() < $seq_13)]) return deep-equal($nodeInSeq_15, $node_14)))]) Query plan: