Skip to content

BIND clause slows down some queries #3021

Open
@mpagni12

Description

@mpagni12

Version

5.3.0

Question

Dear fuseki community,

I have observed several times with different queries, that the presence of a simple BIND clause can drastically slows down its execution.

For example, the following query

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX reconx: <https://reconx.vital-it.ch/kg/>
PREFIX mnx: <https://rdf.metanetx.org/schema/>

SELECT 
    ?mnet
    ?chem_1
    ?chem_1_label
    ?chem_2
    ?chem_2_label
WHERE{
    {
        SELECT DISTINCT ?mnet ?mnxm ?chem_1 ?chem_2
        WHERE{
            {
                SELECT DISTINCT ?mnet ?mnxm ?chem_1 ?chem_2
                WHERE{
                    BIND( reconx:vmh_Recon AS ?mnet ) # fix a model here to focus the results 
                    ?mnet reconx:reac/reconx:equaSource/reconx:part/reconx:spec/reconx:chem ?chem_1 .
                    ?mnxm mnx:chemXref ?chem_1, ?chem_2
                    FILTER( STR( ?chem_1 ) < STR( ?chem_2 ))
                }  
            }
            ?mnet reconx:reac/reconx:equaSource/reconx:part/reconx:spec/reconx:chem ?chem_2
        }
    }
    ?chem_1 reconx:label ?chem_1_label .
    ?chem_2 reconx:label ?chem_2_label .
}

takes at least half an hour to execute on my local fuseki instance.

But, if I remove the BIND clause from the most inner WHERE clause, by inlining the subject:

...
WHERE{
       # BIND( reconx:vmh_Recon AS ?mnet ) # fix a model here to focus the results
       reconx:vmh_Recon reconx:reac/reconx:equaSource/reconx:part/reconx:spec/reconx:chem ?chem_1 .
       ?mnxm mnx:chemXref ?chem_1, ?chem_2
       FILTER( STR( ?chem_1 ) < STR( ?chem_2 ))
}
...

the query now executes in a couple of second!

Replacing the BIND clause with a VALUES clause also executes very slowly.

The same query executed on GraphDB populated with the same dataset takes a couple of second to execute, with no significant differences between the three variants (inline, BIND, VALUES)

I tend to prefer to use the syntax with the explicit BIND or VALUES clause, because in a complex query it permits to syntactically highlight the "input parameter". But currently, the price is too high. I wonder it has to do with the query optimiser.

This being reported, thanks a lot for maintaining fuseki which is a great open-source tool.

Marco

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions