Looking at:
1:: You have a cross product (graph patterns without connections between
them).
{ { SELECT ...
WHERE
{ ?inst rdf:type dbyago:PhysicalEntity100001930
{ SELECT (count(?inst1) AS ?countc) ?c ?countec
then ?inst is used in the triple pattern and is not connected to
SELECT/count.
You'll get A x B result where A is number of ?inst rdf:type
dbyago:PhysicalEntity100001930 and B number from the SELECT (number of
groups).
if
?inst rdf:type dbyago:PhysicalEntity100001930
is large, that's a lot of work
That maybe more an indication of mistaken query structure because ?inst
isn't used anywhere else - it's a different variable to the inner ?inst.
?inst is only used in count(?inst), which is renamed to ?countec then.
In your query, the name ?inst is also used at the start leading to 2e6
extra result rows.
SELECT (sum(?subTotal) AS ?sum)
WHERE
{ { SELECT ...
WHERE
{ ?inst rdf:type dbyago:PhysicalEntity100001930 <<****
{ SELECT (count(?inst1) AS ?countc) ?c ?countec
Andy