db:token($analyticsmgmt:analyticsDatabase, $docPath, 'topicpath')
Next, how much results do you get for a single request? Is it always a single result, or can it be a vast number? How are the values distributued (index:tokens may help to assess this)?
You can attach "=> prof:time()" to an expression to do some isolated performance measurements.
In principle, it makes no difference if the data is stored in one huge document or in millions of documents.