Page MenuHomePhabricator

Can't use BIND and wikibase:statements in the same query
Open, Needs TriagePublicBUG REPORT

Description

Steps to Reproduce:

I try to execute the following query on https://query.wikidata.org/ :

SELECT distinct ?id ?lang ?n
WHERE {
    {
        ?id rdfs:label|skos:altLabel "Paris"@en .
        BIND("EN" AS ?lang)
    }
    UNION
    {
        ?id rdfs:label|skos:altLabel "Paris"@eu .
        BIND("EU" AS ?lang)
    }
    ?id wikibase:statements ?n .
}

Actual Results:

Query timeout

Expected Results:

No timeout

Additional information:

In the following similar cases the query executes successfuly:

Removing the UNION (with the second condition):

SELECT distinct ?id ?lang ?n
WHERE {
    {
        ?id rdfs:label|skos:altLabel "Paris"@en .
        BIND("EN" AS ?lang)
    }
    ?id wikibase:statements ?n .
}

Removing the BIND statements:

SELECT distinct ?id ?n
WHERE {
    {
        ?id rdfs:label|skos:altLabel "Paris"@en .
    }
    UNION
    {
        ?id rdfs:label|skos:altLabel "Paris"@eu .
    }
    ?id wikibase:statements ?n .
}

Removing the "wikibase:statements" statement:

SELECT distinct ?id ?lang ?n
WHERE {
    {
        ?id rdfs:label|skos:altLabel "Paris"@en .
        BIND("EN" AS ?lang)
    }
    UNION
    {
        ?id rdfs:label|skos:altLabel "Paris"@eu .
        BIND("EU" AS ?lang)
    }
}

Event Timeline

Disabling the optimizer works as a workaround:

SELECT distinct ?id ?lang ?n
WHERE {
    hint:Query hint:optimizer "None".
    {
        ?id rdfs:label|skos:altLabel "Paris"@en .
        BIND("EN" AS ?lang)
    }
    UNION
    {
        ?id rdfs:label|skos:altLabel "Paris"@eu .
        BIND("EU" AS ?lang)
    }
    ?id wikibase:statements ?n .
}

Presumably it’s deciding to find all wikibase:statements triples first and join them against the label/altLabel triples later, which is unwise.