BaseX - Out of memory when using enclosing xml in XQuery -


i've been trying query basex db contains more 1500000 items. when run query

for $item in collection('coll')//item     return $item (: returns xml element :) 

it executes in less second.

but when try return result in xml "out of main memory" error.

<xml>{     $item in collection('coll')//item        return $item }</xml> 

this makes me want abandon native xml db approach (same happens other dbs, such existdb), if has info problem, extremely helpful.

thanks

due semantics of xquery, child nodes need copied if wrapped new parent node. demonstrated following query, compares node identity of original , copied node. yield false:

let $node := <node/> let $parent := <parent>{ $node }</parent> return $parent/node $node 

as copying millions of nodes expensive, inevitably leads out-of-memory error.

if write results files, here pragmatic solution around restriction:

(:~   : writes element file, wrapped root node.  : @param  $path      path file  : @param  $elements  elements write  : @param  $name      name of root node  :) declare function local:write-to(   $path      xs:string,   $elements  element()*,   $name      xs:string ) empty-sequence() {   file:write-text($path, '<' || $name || '>'),   file:append($path, $elements),   file:append-text($path, '</' || $name || '>') };  local:write-to('result.xml', <result/>, 'root') 

to anticipate criticism: clear hack. example, approach conflicts various non-default serialization parameters of basex (the result not well-formed if xml declaration needs be output, etc.).


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -