virtuoso-opensource icon indicating copy to clipboard operation
virtuoso-opensource copied to clipboard

Unexpected results for query with many optionals

Open achort opened this issue 2 years ago • 1 comments

I am using Virtuoso version 07.20.3237 prebuilt binary for Windows. Loading in a named graph the following data

<http://example.com/resource/acronyms/bf8f>	<http://example.com/shortForm>	"TEST" .
<http://example.com/resource/acronyms/bf8f>	<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>	<http://example.com/Acronym> .
<http://example.com/resource/organisations/52f7>	<http://example.com/hasSite>	<http://example.com/resource/sites/852c> .
<http://example.com/resource/organisations/52f7>	<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>	<http://example.com/Organisation> .
<http://example.com/resource/organisations/52f9>	<http://example.com/hasAcronym>	<http://example.com/resource/acronyms/bf8f> .
<http://example.com/resource/organisations/52f9>	<http://example.com/hasSite>	<http://example.com/resource/sites/53ed> .
<http://example.com/resource/organisations/52f9>	<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>	<http://example.com/Organisation> .
<http://example.com/resource/sites/03b7>	<http://example.com/hasNUTS1code>	<http://data.europa.eu/nuts/code/BE1> .
<http://example.com/resource/sites/03b7>	<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>	<http://example.com/AdministrativeArea> .
<http://example.com/resource/sites/2bab>	<http://example.com/hasNUTS2code>	<http://data.europa.eu/nuts/code/BE10> .
<http://example.com/resource/sites/2bab>	<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>	<http://example.com/AdministrativeArea> .
<http://example.com/resource/sites/2cf8>	<http://example.com/hasNUTS3code>	<http://data.europa.eu/nuts/code/BE100> .
<http://example.com/resource/sites/2cf8>	<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>	<http://example.com/AdministrativeArea> .
<http://example.com/resource/sites/2d31>	<http://example.com/hasNUTS1code>	<http://data.europa.eu/nuts/code/EL3> .
<http://example.com/resource/sites/2d31>	<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>	<http://example.com/AdministrativeArea> .
<http://example.com/resource/sites/53ed>	<http://example.com/hasGeographicalLocation>	<http://example.com/resource/sites/03b7> .
<http://example.com/resource/sites/53ed>	<http://example.com/hasGeographicalLocation>	<http://example.com/resource/sites/2bab> .
<http://example.com/resource/sites/53ed>	<http://example.com/hasGeographicalLocation>	<http://example.com/resource/sites/2cf8> .
<http://example.com/resource/sites/53ed>	<http://example.com/hasGeographicalLocation>	<http://example.com/resource/sites/e470> .
<http://example.com/resource/sites/53ed>	<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>	<http://example.com/Site> .
<http://example.com/resource/sites/7154>	<http://example.com/hasNUTS0code>	<http://data.europa.eu/nuts/code/EL> .
<http://example.com/resource/sites/7154>	<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>	<http://example.com/AdministrativeArea> .
<http://example.com/resource/sites/852c>	<http://example.com/hasGeographicalLocation>	<http://example.com/resource/sites/2d31> .
<http://example.com/resource/sites/852c>	<http://example.com/hasGeographicalLocation>	<http://example.com/resource/sites/7154> .
<http://example.com/resource/sites/852c>	<http://example.com/hasGeographicalLocation>	<http://example.com/resource/sites/9cae> .
<http://example.com/resource/sites/852c>	<http://example.com/hasGeographicalLocation>	<http://example.com/resource/sites/e670> .
<http://example.com/resource/sites/852c>	<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>	<http://example.com/Site> .
<http://example.com/resource/sites/9cae>	<http://example.com/hasNUTS3code>	<http://data.europa.eu/nuts/code/EL303> .
<http://example.com/resource/sites/9cae>	<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>	<http://example.com/AdministrativeArea> .
<http://example.com/resource/sites/e470>	<http://example.com/hasNUTS0code>	<http://data.europa.eu/nuts/code/BE> .
<http://example.com/resource/sites/e470>	<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>	<http://example.com/AdministrativeArea> .
<http://example.com/resource/sites/e670>	<http://example.com/hasNUTS2code>	<http://data.europa.eu/nuts/code/EL30> .
<http://example.com/resource/sites/e670>	<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>	<http://example.com/AdministrativeArea> .

and asking the query

SELECT *
WHERE
  { VALUES ?c_0 {   <http://example.com/resource/organisations/52f7> <http://example.com/resource/organisations/52f9> }
    ?c_0  a                     <http://example.com/Organisation>
    OPTIONAL
      { ?c_0    <http://example.com/hasAcronym>  ?c_0_0 .
        ?c_0_0  a                     <http://example.com/Acronym>
        OPTIONAL
          { ?c_0_0  <http://example.com/shortForm>  ?r0 }
      }
    OPTIONAL
      { ?c_0    <http://example.com/hasSite>  ?c_1_0 .
        ?c_1_0  a                     <http://example.com/Site>
        OPTIONAL
          { ?c_1_0    <http://example.com/hasGeographicalLocation>  ?c_1_2_0 .
            ?c_1_2_0  a                     <http://example.com/AdministrativeArea>
            OPTIONAL
              { ?c_1_2_0  <http://example.com/hasNUTS0code>  ?r8 }
            OPTIONAL
              { ?c_1_2_0  <http://example.com/hasNUTS1code>  ?r9 }
            OPTIONAL
              { ?c_1_2_0  <http://example.com/hasNUTS2code>  ?r10 }
            OPTIONAL
              { ?c_1_2_0  <http://example.com/hasNUTS3code>  ?r11 }
          }
      }
  }

I get the result

c_0 c_0_0 r0 c_1_0 c_1_2_0 r8 r9 r10 r11
http://example.com/resource/organisations/52f9 http://example.com/resource/acronyms/bf8f
"TEST"
http://example.com/resource/sites/53ed http://example.com/resource/sites/2cf8 http://data.europa.eu/nuts/code/BE100
http://example.com/resource/organisations/52f9 http://example.com/resource/acronyms/bf8f
"TEST"
http://example.com/resource/sites/53ed http://example.com/resource/sites/2bab http://data.europa.eu/nuts/code/BE10
http://example.com/resource/organisations/52f9 http://example.com/resource/acronyms/bf8f
"TEST"
http://example.com/resource/sites/53ed http://example.com/resource/sites/03b7 http://data.europa.eu/nuts/code/BE1
http://example.com/resource/organisations/52f9 http://example.com/resource/acronyms/bf8f
"TEST"
http://example.com/resource/sites/53ed http://example.com/resource/sites/e470 http://data.europa.eu/nuts/code/BE
http://example.com/resource/organisations/52f7 http://example.com/resource/sites/852c http://example.com/resource/sites/9cae http://data.europa.eu/nuts/code/EL303
http://example.com/resource/organisations/52f7 http://example.com/resource/sites/852c http://example.com/resource/sites/e670
http://example.com/resource/organisations/52f7 http://example.com/resource/sites/852c http://example.com/resource/sites/2d31
http://example.com/resource/organisations/52f7 http://example.com/resource/sites/852c http://example.com/resource/sites/7154 http://data.europa.eu/nuts/code/EL

which seems to miss the bindings for r9 and r10 resulting from the triples

<http://example.com/resource/sites/2d31>	<http://example.com/hasNUTS1code>	<http://data.europa.eu/nuts/code/EL3> .
<http://example.com/resource/sites/e670>	<http://example.com/hasNUTS2code>	<http://data.europa.eu/nuts/code/EL30> .

corresponding to the first resource the VALUES statement.

However, when asking the query

SELECT *
FROM <http://cordis.com/test>
WHERE
  { VALUES ?c_0 {   <http://example.com/resource/organisations/52f7>  }
    ?c_0  a                     <http://example.com/Organisation>
    OPTIONAL
      { ?c_0    <http://example.com/hasAcronym>  ?c_0_0 .
        ?c_0_0  a                     <http://example.com/Acronym>
        OPTIONAL
          { ?c_0_0  <http://example.com/shortForm>  ?r0 }
      }
    OPTIONAL
      { ?c_0    <http://example.com/hasSite>  ?c_1_0 .
        ?c_1_0  a                     <http://example.com/Site>
        OPTIONAL
          { ?c_1_0    <http://example.com/hasGeographicalLocation>  ?c_1_2_0 .
            ?c_1_2_0  a                     <http://example.com/AdministrativeArea>
            OPTIONAL
              { ?c_1_2_0  <http://example.com/hasNUTS0code>  ?r8 }
            OPTIONAL
              { ?c_1_2_0  <http://example.com/hasNUTS1code>  ?r9 }
            OPTIONAL
              { ?c_1_2_0  <http://example.com/hasNUTS2code>  ?r10 }
            OPTIONAL
              { ?c_1_2_0  <http://example.com/hasNUTS3code>  ?r11 }
          }
      }
  }

that is including only the first one of the values in the initial VALUES statement, I get the result

c_0 c_0_0 r0 c_1_0 c_1_2_0 r8 r9 r10 r11
http://example.com/resource/organisations/52f7 http://example.com/resource/sites/852c http://example.com/resource/sites/9cae http://data.europa.eu/nuts/code/EL303
http://example.com/resource/organisations/52f7 http://example.com/resource/sites/852c http://example.com/resource/sites/e670 http://data.europa.eu/nuts/code/EL30
http://example.com/resource/organisations/52f7 http://example.com/resource/sites/852c http://example.com/resource/sites/2d31 http://data.europa.eu/nuts/code/EL3
http://example.com/resource/organisations/52f7 http://example.com/resource/sites/852c http://example.com/resource/sites/7154 http://data.europa.eu/nuts/code/EL

which is correct since it includes the bindings for the r9 and r10 variables (together with the ones for r8, r11) corresponding to the first resource of the initial VALUES statement.

achort avatar Nov 27 '23 09:11 achort

We are looking into this ...

HughWilliams avatar Nov 27 '23 11:11 HughWilliams

This issue has been resolved in the latest stable/7 branch and Virtuoso_Open_Source_for_Windows.exe installer ...

HughWilliams avatar Mar 04 '24 11:03 HughWilliams