Why
On occasion, a SPARQL query may return unexpected results, give poor results, hang, etc.
Possible causes — and thereby, solutions — for such issues may be found through analysis of the query compilation and execution plan, as well as the SPARQL-to-SQL translation, of the SPARQL query.
What
Virtuoso has an option which enables the user to obtain query compilation and execution plans, as well as SPARQL-to-SQL translations, for any SPARQL query they may run against the Virtuoso /sparql
endpoint.
How
Starting with engine build 3224
( 7.20.3224
and 8.00.3224
), the Virtuoso default /sparql
endpoint SPARQL Query Editor page includes a checkbox option labeled “ Generate SPARQL compilation report (instead of executing the query) .” When this box is checked, Virtuoso will do just that.
Virtuoso SPARQL Query Editor with Generate SPARQL compilation report enabled
Note that the “ Run query ” button text changes to “ Explain ” when the “ Generate SPARQL compilation report ” option is selected.
On clicking the “ Explain ” button, output similar to that below will be produced, showing the query compilation, execution plan, and SPARQL-to-SQL translation.
SPARQL query after parsing, optimization, and converting back into SPARQL
SELECT ?s
?p
?o
WHERE { ?s ?p ?o . }
SPARQL query translated to SQL
For security reasons, code responsible for graph-level security is not generated and some account-specific data are intentionally made wrong.
SELECT __id2in ( "s_3_0_t0"."S") AS "s",
__id2in ( "s_3_0_t0"."P") AS "p",
__ro2sq ( "s_3_0_t0"."O") AS "o"
FROM DB.DBA.RDF_QUAD AS "s_3_0_t0"
OPTION (QUIETCAST)
SQL execution plan
{
From RDF_QUAD_POGS 5.7e+03 rows
Key RDF_QUAD_POGS ASC (s_3_0_t0.S$31, s_3_0_t0.P$30, s_3_0_t0.O$29)
After code:
0: s$34 := Call __id2in (s_3_0_t0.S$31)
5: p$36 := Call __id2in (s_3_0_t0.P$30)
10: o$38 := Call __ro2sq (s_3_0_t0.O$29)
15: BReturn 0
Select (s$34, p$36, o$38)
}
Internal optimizer data
These data are primarily for OpenLink support, to get additional details about the query processing.
QUERY: (line 3) REQUEST TOP NODE (SELECT result-mode):
DEFAULT VALMODE FOR RETVALS: SQLVAL
RETVALS: ARRAY-OF-LONG OF NODES with 3 children: {
(line 4) VARIABLE: notNULL reference exported
NAME: UNAME 's' SELECT ID: UNAME 's_3_0' TABLE ID: LONG 0 EQUIV: LONG 1
(line 4) VARIABLE: notNULL IRI reference exported
NAME: UNAME 'p' SELECT ID: UNAME 's_3_0' TABLE ID: LONG 0 EQUIV: LONG 2
(line 4) VARIABLE: notNULL exported
NAME: UNAME 'o' SELECT ID: UNAME 's_3_0' TABLE ID: LONG 0 EQUIV: LONG 3
}
RETVALS SELECT ID: UNAME 's_3_0'
SOURCES: EMPTY ARRAY
PATTERN: (line 3) GRAPH PATTERN:WHERE gp
MEMBERS: ARRAY OF NODES with 1 children: {
(line 3) TRIPLE:
GRAPH: (line 3) BLANK NODE: notNULL+ IRI+ reference+ NAME: UNAME '_::default_3_1' SELECT ID: UNAME 's_3_0' TABLE ID: UNAME 's_3_0_t0' EQUIV: LONG 0
SUBJECT: (line 3) VARIABLE: notNULL+ reference+ exported (subject)
NAME: UNAME 's' SELECT ID: UNAME 's_3_0' TABLE ID: UNAME 's_3_0_t0' EQUIV: LONG 1
PREDICATE: (line 3) VARIABLE: notNULL+ IRI+ reference+ exported (predicate)
NAME: UNAME 'p' SELECT ID: UNAME 's_3_0' TABLE ID: UNAME 's_3_0_t0' EQUIV: LONG 2
OBJECT: (line 3) VARIABLE: notNULL+ exported (object)
NAME: UNAME 'o' SELECT ID: UNAME 's_3_0' TABLE ID: UNAME 's_3_0_t0' EQUIV: LONG 3
SELECT ID: UNAME 's_3_0'
TABLE ID: UNAME 's_3_0_t0'
TRIPLE CASES (1 of them) <http://www.openlinksw.com/schemas/virtrdf#DefaultQuadMap>
}
FILTERS: EMPTY ARRAY
SELECT ID: UNAME 's_3_0'
EQUIVS: 0 1 2 3
EQUIVS:
#0: ( 0 subv (1 bindings, 1 nest.nonnull), 0 recv, 1 gspo, 0 const, 0/0 opt/uap, 0 subq: _::default_3_1 in s_3_0_t0; notNULL IRI reference)
#1: ( 0 subv (1 bindings, 1 nest.nonnull), 0 recv, 1 gspo, 1 const, 0/0 opt/uap, 0 subq: s in s_3_0_t0 s_3_0; notNULL reference exported)
#2: ( 0 subv (1 bindings, 1 nest.nonnull), 0 recv, 1 gspo, 1 const, 0/0 opt/uap, 0 subq: p in s_3_0_t0 s_3_0; notNULL IRI reference exported)
#3: ( 0 subv (1 bindings, 1 nest.nonnull), 0 recv, 1 gspo, 1 const, 0/0 opt/uap, 0 subq: o in s_3_0_t0 s_3_0; notNULL exported)