Hi Giuseppe,
The following query may be faster:
for $u in db:open("db1")/text/s/t
group by $k := $u/f || "#" || $u/@o
where db:open("db2")/text/line[text() = $k]
let $n := count($u)
order by $n descending
return $k || " " || $n
Cheers,
Christian
On Tue, Sep 19, 2017 at 3:35 PM, Giuseppe Celano
<[email protected]> wrote:
> I am using BaseX 8.6.4 and I am trying to do a group-by/order-by operation,
> and I see that two logically equivalent queries perform very differently: one
> cannot see the end, while the other can (and fast). I can provide further
> details if necessary, but these are the queries (look at the last line of
> both, where the difference is):
>
> (This does not work:)
>
> declare variable $p := db:open("db2")/text/line/text(); (: returns a list of
> values like ΠΕΡΙ#n-s---mv- :)
>
> for $u in db:open("db1")/text/s/t
> let $a := $u/f/text()
> (: returns one value like ΠΕΡΙ :)
> let $b := $u/@o/data(.) (:
> returns one value like n-s---mv- :)
> group by $k := $a || "#" || $b (:
> builds a value like ΠΕΡΙ#n-s---mv- :)
> let $n := count($u)
> order by $n descending
> return
> if ($p = $k) then $k || " " || $n else ()
>
> (This works:)
>
> for $u in db:open("db1")/text/s/t
> let $a := $u/f/text()
> (: returns one value like ΠΕΡΙ :)
> let $b := $u/@o/data(.) (:
> returns one value like n-s---mv- :)
> group by $k := $a || "#" || $b (:
> builds a value like ΠΕΡΙ#n-s---mv- :)
> let $n := count($u)
> order by $n descending
> return
> if (db:text("db2", $k)) then $k || " " || $n else ()
>
> The problem is with directly accessing the database with db:text() or
> indirectly using XPATH. I would tend to use XPATH and expect to get an
> underlying translation into db:text(), but this seems not to happen: why?
>
> Best,
> Giuseppe