Virtuoso SQL query of a SPARQL query in iSQL

2019-07-31 09:40发布

问题:

I was going through this link, which uses EXPLAIN() to show us the SQL query that Virtuoso generates(uses internally) for the input SPARQL query. I tried it on my Virtuoso 7.x version and found that I get a different output. I am not able to understand the output fully. Would it be possible to explain what this output from iSQL means and how I would interpret a SQL query from this?

The SPARQL query is

SPARQL SELECT DISTINCT ?s FROM <http://dbpedia.org> WHERE {
?s a <http://dbpedia.org/ontology/Cricketer> . 
?s <http://dbpedia.org/property/testdebutyear> ?o . 
};

The output I get is

{ 
Subquery 27 
{ 
RDF_QUAD   3.2e+03 rows(s_1_2_t1.S)
 inlined  P =  #/testdebutyear  G =  #/dbpedia.org 
RDF_QUAD unq       0.8 rows (s_1_2_t0.S)
 inlined  P =  ##type  ,  S = s_1_2_t1.S ,  O =  #/Cricketer  ,  G =  #/dbpedia.org 
Distinct (s_1_2_t0.S)

After code:
      0: s :=  := artm s_1_2_t0.S
      4: BReturn 0
Subquery Select(s)
}

After code:
      0: s := Call __ro2sq (s)
      5: BReturn 0
Select (s)
}

20 Rows. -- 2 msec.

How do I find the SQL query in this case? Is there a command or link that I am missing?

回答1:

To answer your specific question, you might read further down the same page you pointed to above, to where it talks specifically about how to "Translate a SPARQL query into the correspondent SQL."

This is also discussed on another feature-specific page.

(Also note, the sample output on both these pages came from Virtuoso 6.x, while you're running 7.x, so your output will likely still differ.)

Here's what I got from my local Virtuoso 7.2.4 (Commercial Edition) --

SQL> SET SPARQL_TRANSLATE ON ; 
SQL> SELECT DISTINCT ?s FROM <http://dbpedia.org> WHERE { ?s a <http://dbpedia.org/ontology/Cricketer> . ?s <http://dbpedia.org/property/testdebutyear> ?o . } ; 
SPARQL_TO_SQL_TEXT
LONG VARCHAR
_______________________________________________________________________________

 SELECT  __ro2sq ("s_1_2_rbc"."s") AS "s" FROM (SELECT DISTINCT "s_1_2_t0"."S" AS "s"
  FROM DB.DBA.RDF_QUAD AS "s_1_2_t0"
    INNER JOIN DB.DBA.RDF_QUAD AS "s_1_2_t1"
    ON (
      "s_1_2_t0"."S" = "s_1_2_t1"."S")
  WHERE
    "s_1_2_t0"."G" = __i2idn ( __bft( 'http://dbpedia.org' , 1))
    AND 
    "s_1_2_t0"."P" = __i2idn ( __bft( 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type' , 1))
    AND 
    "s_1_2_t0"."O" = __i2idn ( __bft( 'http://dbpedia.org/ontology/Cricketer' , 1))
    AND 
    "s_1_2_t1"."G" = __i2idn ( __bft( 'http://dbpedia.org' , 1))
    AND 
    "s_1_2_t1"."P" = __i2idn ( __bft( 'http://dbpedia.org/property/testdebutyear' , 1))
OPTION (QUIETCAST)) AS "s_1_2_rbc"

1 Rows. -- 3 msec.
SQL> SET SPARQL_TRANSLATE OFF ;

NOTE -- this feature is only available in the command-line iSQL; it is not found in the browser-based iSQL interface.

All that said... I strongly suggest you ask us your initial questions going forward, instead of likely getting distracted by XY Problems. There's fairly little to understand about the single table of quad data (DB.DBA.RDF_QUAD), which has 2 full and 3 partial indexes by default, which are sufficient for most typical uses, all as discussed in the documentation.

The Virtuoso Users mailing list is often a better resource for Virtuoso-specific questions than here, where you tend to get a fair amount of guessing responses.

(ObDisclaimer: I work for OpenLink Software, producer of Virtuoso.)