Uploaded image for project: 'Blazegraph (by SYSTAP)'
  1. Blazegraph (by SYSTAP)
  2. BLZG-1541

UNION + BIND defeats the query optimizer



    • Type: Bug
    • Status: Open
    • Priority: Medium
    • Resolution: Unresolved
    • Affects Version/s: BLAZEGRAPH_2_1_4
    • Fix Version/s: None
    • Component/s: Wikidata Query Service
    • Labels:


      The query optimizer fails to re-order the following query (from Wikidata), which contains a UNION including the BINDing of a constant. The query runs fine if the order of the clauses is changed over – and the optimizer can do this re-ordering, but only if the BIND statements are not present.

      PREFIX wikibase: <http://wikiba.se/ontology#>
      PREFIX wd: <http://www.wikidata.org/entity/> 
      PREFIX wdt: <http://www.wikidata.org/prop/direct/>
      PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
      SELECT ?entity ?entityS ?image ?event (year(?date) as ?year) WHERE {  # afficher label puis lien wikidata
            ?entityS wdt:P569 ?date .                           # date de naissance
            BIND ('naissance' AS ?event) .
         } UNION {                                              # OR
            ?entityS wdt:P570 ?date .                           # date de décès
            BIND ('décès' AS ?event) .
         } .
            ?entityS wdt:P119 wd:Q311  .                        # cimetière du Père-Lachaise   
         } UNION {                                              # OR (claim[119:311,119:3006253])
            ?entityS wdt:P119 wd:Q3006253                       # columbarium du Père-Lachaise
         OPTIONAL { ?entityS wdt:P1442 ?image } .            # affiche l'image de la tombe si elle existe            
         SERVICE wikibase:label {
            bd:serviceParam wikibase:language "fr,en" .       # afficher label français sinon label anglais
            ?entityS rdfs:label ?entity
         FILTER (datatype(?date) = xsd:dateTime)      
         FILTER (month(?date) = month(now()))
         FILTER (day(?date) = day(now()))           
      ORDER BY ?date                                          # tri par date
      LIMIT 100

      Here is alink to the explain report

      The key thing to successfully optimize this query is to start with the assertions for the cemetery (cardinality 3711 and 280), rather than for the dates of birth or death (cardinality 1,986,189 and 1,013,169).

      The optimizer can successfully do this reordering, if the clauses {{ BIND ('naissance' AS ?event)}} and BIND ('décès' AS ?event) are commented out.

      The query also runs fine if these clauses are left in, but the two UNION blocks are swapped, so that the cemetery assertions appear first.

      However, with the BIND clauses left in, the optimizer cannot reorder the query if the date assertions appear first.




            michaelschmidt michaelschmidt
            Jheald James Heald
            0 Vote for this issue
            2 Start watching this issue