SPARQL serialization XQUERY

I use sparql from XQuery with MarkLogic 9. I serialize the results from sem:sparql function with sem:query-results-serialize, but the serialization costs a lot of time.

Is there a way to avoid it, or speed it up? By using map or something else?

my code :

let $_ := prof:enable(xdmp:request())
let $sparql:=concat("
SELECT ?encoche ?uriDoc1 ?uriDoc2
WHERE {
  {
      ?encoche <http://www.lefebvre-sarrut.eu/ns/hubeditorial/est-encoche-dans> ?uriDoc1 .
      ?encoche <http://www.lefebvre-sarrut.eu/ns/hubeditorial/est-defini-dans> ?uriDoc2 
  }
}
")
let $p1 := prof:report(xdmp:request())//prof:overall-elapsed
let $res:=sem:sparql($sparql, (), (), ()) 
let $p2 := prof:report(xdmp:request())//prof:overall-elapsed
let $resXML := sem:query-results-serialize($res, "xml")
let $p3 := prof:report(xdmp:request())//prof:overall-elapsed
return ($p1,$p2,$p3)

the return :

PT0.0000221S
PT0.011936S
PT0.2549374S

any idea?

1 answer

  • answered 2022-04-30 20:17 Mads Hansen

    If you look at the sem:query-results-serialize() method in the /Modules/MarkLogic/semantic.xqy module, it invokes query-results-serialize(), which invokes the semi:sparql-results-xml() function from the /Modules/MarkLogic/semantics/sem-impl.xqy module.

    If you look at the semi:sparql-results-xml() method implementation, it is working with a map and generating the XML.

    You could try importing that module and invoking that method directly, or copy the logic and profile to see if there is any area to optimize. However, at first glance I don't see any obvious areas to streamline or improve.

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum