I notice that queries using values like
SELECT ?item ?item2 ?inv WHERE { VALUES ?collection {wd:Q28045665 wd:Q28045660 wd:Q28045674 wd:Q2066737 wd:Q18600731 } . # The different collections ?item p:P217 ?inv1statement . ?inv1statement ps:P217 ?inv . ?inv1statement pq:P195 ?collection . ?item2 p:P217 ?inv2statement . ?inv2statement ps:P217 ?inv . ?inv2statement pq:P195 ?collection . FILTER(?item!=?item2) } LIMIT 500
often time out.
if you unpack it in a bunch of unions it completes in less than a second:
SELECT ?item ?item2 ?inv WHERE { { ?inv1statement pq:P195 wd:Q28045665 . } union { ?inv1statement pq:P195 wd:Q28045660 . } union { ?inv1statement pq:P195 wd:Q28045674 . } union { ?inv1statement pq:P195 wd:Q2066737 . } union { ?inv1statement pq:P195 wd:Q18600731 . } ?item p:P217 ?inv1statement . ?inv1statement ps:P217 ?inv . { ?inv2statement pq:P195 wd:Q28045665 . } union { ?inv2tatement pq:P195 wd:Q28045660 . } union { ?inv2statement pq:P195 wd:Q28045674 . } union { ?inv2statement pq:P195 wd:Q2066737 . } union { ?inv2statement pq:P195 wd:Q18600731 . } ?item2 p:P217 ?inv2statement . ?inv2statement ps:P217 ?inv . FILTER(?item!=?item2) } LIMIT 500