How can I get a full explain plan for a simple SPARQL query?
Virtuoso Comercial Release 6.4 and Virtuoso Open Source 6.1.5 ISQL offers 2 new modes for analyzing SPARQL queries:
- Translate a sparql query into the correspondent sql:
SQL> SET SPARQL_TRANSLATE ON; SQL> SELECT * FROM <graph> WHERE {?S a ?O}; SQL> SET SPARQL_TRANSLATE OFF;
- Analyze a given SQL query:
SQL> SET EXPLAIN ON; SQL> SELECT * FROM TABLE WHERE field = 'text'; SQL> SET EXPLAIN OFF;
- The quivalent is
explainwhich is much more difficult to use since you cannot just cut and past a query as all quotes need to be doubled inside the explain (' ... '):
SQL> explain('select * from table where field = ''text''');
- The quivalent is
Here is simple example of how to combine the two options to get a full explain plan for a simple SPARQL query:
- Assume the following query:
SELECT * FROM <http://dbpedia.org> WHERE { ?s a ?o } LIMIT 10
- Connect using the ISQL command line tool to your database and execute:
SQL> SET BLOBS ON; -- in case output is very large SQL> SET SPARQL_TRANSLATE ON; SQL> SELECT * FROM <http://dbpedia.org> WHERE {?s a ?o} LIMIT 10; SPARQL_TO_SQL_TEXT VARCHAR _______________________________________________________________________________ SELECT TOP 10 __id2i ( "s_1_0-t0"."S" ) AS "s", __ro2sq ( "s_1_0-t0"."O" ) AS "o" FROM DB.DBA.RDF_QUAD AS "s_1_0-t0" WHERE "s_1_0-t0"."G" = __i2idn ( __bft( 'http://dbpedia.org' , 1)) AND "s_1_0-t0"."P" = __i2idn ( __bft( 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type' , 1)) OPTION (QUIETCAST) 1 Rows. -- 1 msec. SQL> SET SPARQL_TRANSLATE OFF;
- Use mouse to select the above query output and paste it after the
SET EXPLAIN ON;command. After pasting in the command, followed by the ENTER key:
SQL> SET EXPLAIN ON; SQL> SELECT TOP 10 __id2i ( "s_1_0-t0"."S" ) AS "s", __ro2sq ( "s_1_0-t0"."O" ) AS "o" FROM DB.DBA.RDF_QUAD AS "s_1_0-t0" WHERE "s_1_0-t0"."G" = __i2idn ( __bft( 'http://dbpedia.org' , 1)) AND "s_1_0-t0"."P" = __i2idn ( __bft( 'http://www.w3.org/1999/02/22-rdf-syn tax-ns#type' , 1)) OPTION (QUIETCAST) ; REPORT VARCHAR _______________________________________________________________________________ { from DB.DBA.RDF_QUAD by RDF_QUAD_POGS 4.5e+05 rows Key RDF_QUAD_POGS ASC ($22 "s_1_0-t0.S", $21 "s_1_0-t0.O") inlined <col=556 P = #type > row specs: <col=554 G = #http://dbpedia.org > After code: 0: $25 "s" := Call __id2i ($22 "s_1_0-t0.S") 5: $26 "o" := Call __ro2sq ($21 "s_1_0-t0.O") 10: BReturn 0 Select (TOP 10 ) ($25 "s", $26 "o", <$24 "<DB.DBA.RDF_QUAD s_1_0-t0>" spec 5>) } 13 Rows. -- 1 msec. SQL> SET EXPLAIN OFF;