group explicitly for performance improvements
Wednesday, 15 June 2016 · 1 message
GS
Graydon Saunders15 Jun 2016 22:30 #
I'm wading about in several tens of megabytes of health care data, trying to figure out what connects to which, as it were. There are a few thousand relationship elements that define some of the connections, and often more than one such element per @type, so it's not enough to just group them by _this_ relationship elements type, I need all the relationship elements which have a particular type value.
let $relationships as element(relationship)+ := //relationship[@type]
let $relTypes as xs:string+ :=
distinct-values($relationships/@type/string())
let $relByType := map:merge(for $x in $relTypes return
map:entry($x,$relationships[@type eq $x]))
return $relByType82895.5 ms
let $relationships as element(relationship)+ := //relationship[@type]
let $relByType := map:merge(for $x in $relationships
let $key := $x/@type
group by $key
return map:entry($key,$x))
return $relByType170.79ms
Holy Wow.
Offered just in case anyone else is wondering why their query is so slow.
-- Graydon
Written for BaseX 8.4. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery