Uploaded image for project: 'Blazegraph (by SYSTAP)'
  1. Blazegraph (by SYSTAP)
  2. BLZG-5678

VALUES query not optimized correctly

    XMLWordPrintable

    Details

      Description

      This query is very slow and times out:

      SELECT ?item ?item2 ?inv WHERE {
        VALUES ?collection {wd:Q28045665 wd:Q28045660 wd:Q28045674 wd:Q2066737 wd:Q18600731 } . #  The different collections
        ?inv1statement pq:P195 ?collection . 
        ?inv2statement pq:P195 ?collection . 
        ?item p:P217 ?inv1statement .
        ?inv1statement ps:P217 ?inv .
        ?item2 p:P217 ?inv2statement .
        ?inv2statement ps:P217 ?inv .
        FILTER(?item!=?item2)
      
        } LIMIT 500
      

      However, if we rewrite it manually expanding VALUES as set of UNION, if executes sub-second:

      SELECT ?item ?item2 ?inv WHERE {
      { ?inv1statement pq:P195 wd:Q28045665 . } union
      { ?inv1statement pq:P195 wd:Q28045660 . } union
      { ?inv1statement pq:P195 wd:Q28045674 . } union
      { ?inv1statement pq:P195 wd:Q2066737 . } union
      { ?inv1statement pq:P195 wd:Q18600731 . }
      
        ?item p:P217 ?inv1statement .
        ?inv1statement ps:P217 ?inv .
      
      { ?inv2statement pq:P195 wd:Q28045665 . } union
      { ?inv2tatement pq:P195 wd:Q28045660 . } union
      { ?inv2statement pq:P195 wd:Q28045674 . } union
      { ?inv2statement pq:P195 wd:Q2066737 . } union
      { ?inv2statement pq:P195 wd:Q18600731 . }
      
        ?item2 p:P217 ?inv2statement .
        ?inv2statement ps:P217 ?inv .
        FILTER(?item!=?item2)
      
        } LIMIT 500
       

      Will attach query plans for both cases.

        Attachments

          Activity

            People

            Assignee:
            michaelschmidt michaelschmidt
            Reporter:
            stasmalyshev stasmalyshev
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated: