You are welcome. Tuning a query can be painful. 馃檪
A "dumb" approach is to filter by fileid's first character (I don't know if it's a string or numeric) or by using some other characteristic. Then, the subquery approach would be more doable.
Victor Mariano Leite The problem is that your query has to first get all the results and then order them. So, that could easily cause an OOM. One thing to do is to somehow trim your query. Can you add other constraints (as triples in the query or using FILTER)? Also, this StackOverflow might be useful, https://stackoverflow.com/questions/29103024/sparql-randomly-select-one-connection-for-each-node
Ellie Y. Renat S. Already started looking at both OpenTapioca and the DBPedia link. My use cases are very much targeted at orgs and people.