BIND clause slows down some queries
- Dominant language
- Java
- Stars
- 1.4k
- Forks
- 712
- Avg merge
- 15h 41m
- Merged PRs (30d)
- 53
Description
### 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
```{sparql}
PREFIX rdfs:
PREFIX reconx:
PREFIX mnx:
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:
```{sparql}
...
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
Contributor guide
Research direction
Start by reproducing the inline, BIND, and VALUES query variants from the issue against Fuseki 5.3.0 and compare their execution behavior. No source file or test is named; trace the query-optimization path involved in constant bindings, and consider the work complete when equivalent variants perform comparably with a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- databases, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100