I have an idea for a possible optimisation for queries of the following general form:
This pattern crops up surprisingly often in real SPARQL workloads since it is often used to either limit a variable to exclude certain possibilities or to avoid self referential links in the data.
In some cases it seems like this could be safely rewritten as follows:
Or perhaps in a more generalised form like so:
Which would nicely deal with the case of stating that a variable is not equal to multiple constant values.
As I pointed out earlier this would not apply in every case, specifically I think at least the following must be true:
- The variable must be guaranteed to be bound (similar to existing filter equality and implicit join optimisations)
There is also the potential to spot cases where the variable will always be unbound and thus the expression is always an error and replace the entire sub-tree with table empty as we already do for equality and implicit join filters.
I plan on taking a look at implementing this in the new year, if anyone has any thoughts on this (especially wrt to restrictions that should apply to when the optimisation is considered safe) then please comment.