Skip to content

Instantly share code, notes, and snippets.

@klinovp
Created February 10, 2022 09:04
Show Gist options
  • Save klinovp/3dcc00c19d640b2046cbe8302600dd23 to your computer and use it in GitHub Desktop.
Save klinovp/3dcc00c19d640b2046cbe8302600dd23 to your computer and use it in GitHub Desktop.
Variable replacement for query optimisation is tricky

One query example:

select * {
  ?s1 <urn:p> ?o1
  optional { ?s1 <urn:q> ?t1 }
  ?s2 <urn:r> ?o2
  optional { 
    ?s2 <urn:s> ?t2
    filter(?t1 = ?t2)
  }
}

Assuming no literals in the graph, can one take advantage of the equality condition and rewrite it to

select * {
  ?s1 <urn:p> ?o1
  optional { ?s1 <urn:q> ?t1 }
  ?s2 <urn:r> ?o2
  optional { 
    ?s2 <urn:s> ?t1
    bind(?t1 as ?t2)
  }
}

? If yes, what's the argument? If not, why not?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment