Uploaded image for project: 'Apache Jena'
  1. Apache Jena
  2. JENA-780

Single use extend expressions could be substituted directly for their later usage

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: In Progress
    • Minor
    • Resolution: Unresolved
    • Jena 2.12.0
    • None
    • ARQ, Optimizer
    • None

    Description

      This RFE is a follow on from JENA-779, the query with a sub-optimal plan there uses a BIND to create a value which is then only used once in a subsequent filter.

      Actually that query uses it twice but I think the general approach I am trying to describe in this RFE bears consideration. In this case it seems like it would be possible to substitute the extend expression for the bound variable in the filter expression.

      Simplified variant of original query such that the bound value is only used once:

      SELECT DISTINCT ?uri
      {
        { ?uri ?p ?o }
        UNION
        {
          ?sub ?p ?uri
          FILTER(isIRI(?uri))
        }
        BIND(str(?uri) as ?s)
        FILTER(STRSTARTS(?s, "http://"))
      }
      

      Rewritten query:

      SELECT DISTINCT ?uri
      {
        { ?uri ?p ?o }
        UNION
        {
          ?sub ?p ?uri
          FILTER(isIRI(?uri))
        }
        FILTER(STRSTARTS(str(?uri), "http://"))
      }
      

      Which avoids an extend expression whose value is only used once and will ultimately be thrown away.

      From a Transform standpoint this is likely awkward to implement in a pure transform since it requires knowledge about the query structure above the FILTER i.e. whether the bound variable is used elsewhere and so would need to use before and after visitors to track that additional state but I think this is a feasible optimisation.

      Attachments

        1. JENA-780.patch
          29 kB
          Rob Vesse

        Issue Links

          Activity

            People

              rvesse Rob Vesse
              rvesse Rob Vesse
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated: