Mark,
If this is with the latest version (if not, which?), could you try:
SELECT DISTINCT ?O ?T ?E
WHERE{
{ SELECT ?O ?T
WHERE {
?O :oE ?x; ## <<< correction
:oT ?T .
} ORDER BY DESC(?T)
LIMIT 3
}
?E a x:E. ## <<< Moved
}
It might be the optimizer is not generating a particular sensible plan.
There look to be 2337 answers (3*779) because it is an unconstranded
cross product.
Ask for the results in an efficient format like
application/sparql-results+json.
It's hard to say anything really concrete without a complete, runnable
example though.
I would note that your queries have a number of unconnected parts.
Unconnected parts simply lead to a cross product and often fairly
useless answers for the application compared to asking the parts separately.
Here
?E a x:E.
shares no variables with
SELECT ?O ?T
and in the larger query and the results are every combination of ?E with
(?O ?T). (779 * 3)
?E a prov:E.
SELECT ?O ?T ... OPTIONAL {?O :op ?P.}
SELECT ?SH ... ?SH :shS ?S.
are three separate groups of patterns which leads to a 3-way cross
product which can get very large.
Andy
On 04/06/14 04:53, Mark Feblowitz wrote:
This is a fragment of an even larger query that might never complete in our
lifetimes:
SELECT DISTINCT ?O ?T ?E
WHERE{
?E a x:E.
{ SELECT ?O ?T
WHERE {
?O :oE ?;
:oT ?T .
} ORDER BY DESC(?T)
LIMIT 3
}
}
Here’s what I want:
For every E, the top 3 O’s as sorted by T.
My TDB store contains 779 O’s, 7273 E’s, and a T for every O.
The full query is this:
SELECT DISTINCT ?O ?T ?S ?E ?P
WHERE{
?E a prov:E.
{ SELECT ?O ?T
WHERE {
?O :otE ?E;
:oT ?T .
} ORDER BY DESC(?T)
LIMIT 3
}{ SELECT ?SH
WHERE {
?EHS :ehsO ?O.
?EH :ehEHSf ?EHS.
?SHS :shsEHS ?EHS;
:shsSH ?SH .
?SH :rank ?SHRank.
} ORDER BY ASC(?SHRank)
LIMIT 1
}
?SH :shS ?S.
OPTIONAL {?O :op ?P.}
}
A pretty complex query, and one that *certainly* won’t complete if the simpler
one won’t.
Thanks,
Mark