Page MenuHomePhabricator

timeout on geospatial query; resolved by OPTIONAL?
Closed, DeclinedPublic

Description

This query times out because of the clause marked ###

SELECT ?place ?placeLabel ?page ?location ?dist WHERE
{
  wd:Q84 wdt:P625 ?loc .
  SERVICE wikibase:around {
      ?place wdt:P625 ?location .
      bd:serviceParam wikibase:center ?loc .
      bd:serviceParam wikibase:radius "1" .
  }
  ?page schema:about ?place; schema:isPartOf <https://en.wikipedia.org/> ###
  BIND(geof:distance(?loc, ?location) as ?dist)
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en" .
  }
} order by ?dist

If you put the clause in optional {...} it runs ok: https://w.wiki/yrX

The former query should return a subset of the latter query (about half of 1600 results), so why does it time out?

Event Timeline

The following equivalent query works fine:

SELECT ?place ?placeLabel ?page ?location ?dist WHERE
{
  wd:Q84 wdt:P625 ?loc .
  SERVICE wikibase:around {
      ?place wdt:P625 ?location .
      bd:serviceParam wikibase:center ?loc .
      bd:serviceParam wikibase:radius "1" .
  }
  optional {?page schema:about ?place; schema:isPartOf <https://en.wikipedia.org/>} ###
  filter(bound(?page))  ###
  BIND(geof:distance(?loc, ?location) as ?dist)
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en" .
  }
} order by ?dist

So the original query does some stupid reordering: probably tries ?page schema:about ?place before binding ?place

dcausse added a subscriber: dcausse.

Definitely a blazegraph opitimization issue.
Disabling the optimizer seems to also help:

SELECT ?place ?placeLabel ?page ?location ?dist WHERE
{
  hint:Query hint:optimizer "None".
  wd:Q84 wdt:P625 ?loc .
  SERVICE wikibase:around {
      ?place wdt:P625 ?location .
      bd:serviceParam wikibase:center ?loc .
      bd:serviceParam wikibase:radius "1" .
  }
  ?page schema:about ?place;
        schema:isPartOf <https://en.wikipedia.org/> ###
  BIND(geof:distance(?loc, ?location) as ?dist)
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en" .
  }
} order by ?dist

I'm closing since I think this is unlikely we have the expertise/bandwidth to address such complex issue related to blazegraph internals.