240 likes | 339 Views
SPARQL Query Graph Model (How to improve query evaluation?). Ralf Heese and Olaf Hartig Humboldt-Universität zu Berlin. A Posting in a Newsgroup. Question:
E N D
SPARQL Query Graph Model(How to improve query evaluation?) Ralf Heese and Olaf Hartig Humboldt-Universität zu Berlin
A Posting in a Newsgroup • Question: • A series of SPARQL queries of the form:… WHERE { {?family <http://dad> ?d . ?d <http://name> "Peter" .}{?family <http://mom> ?m . ?m <http://name> "Robin" .} … • My queries runs very slowly • Simple queries on a database of 10,000 trees describing families • Answer: • Put the more specific part of the query first; it makes a significant difference. … • Reply: • … My time went from 33000ms 150ms. … Date: Mar 8, 2006 http://groups.yahoo.com/group/jena-dev/message/21436 Ralf Heese, SPARQL Query Graph Model
One query, many ways to execute {?family <http://dad> ?d .?d <http://name> "Peter" .} {?family <http://mom> ?m .?m <http://name> "Robin" .} {?family <http://pet> ?p .?p <http://name> "Toller" .} {?family <http://mom> ?m .?m <http://name> "Robin" .} {?family <http://dad> ?d .?d <http://name> "Peter" .} {?family <http://pet> ?p .?p <http://name> "Toller" .} {?family <http://mom> ?m .?m <http://name> "Robin" .} {?family <http://pet> ?p .?p <http://name> "Toller" .} {?family <http://dad> ?d .?d <http://name> "Peter" .} Ralf Heese, SPARQL Query Graph Model
Outline • Query processing in databases • SPARQL query graph model (SQGM) • Transforming SQGMs • Evaluation • Conclusion Ralf Heese, SPARQL Query Graph Model
SPARQL Query Graph Model Tasks of the query engine Query parsing Query rewriting Query Processing in Databases SPARQL Query Graph Model Transforming SQGMs Evaluation Conclusion Internal representationof the query QEP execution QEP generation QEP = Query Execution Plan Ralf Heese, SPARQL Query Graph Model
SPARQL Query Graph Model Advantages Query Processing in Databases SPARQL Query Graph Model Transforming SQGMs Evaluation Conclusion Extensible to new concepts of the query language Supports all phases of query processing Adaptable to changes of the query language Store additional information needed for query processing Ralf Heese, SPARQL Query Graph Model
Body Head Basic Structures • Directed graph • Operation • Head: provided variables • Body: operation details • Dataflow • connects the input andthe output of two operations Query Processing in Databases SPARQL Query Graph Model Transforming SQGMs Evaluation Conclusion Ralf Heese, SPARQL Query Graph Model
?n Select ?c ?s Join ?c ?n ?s Join ?c ?s rdf:type ub:GraduateStudent ?s ?s ub:takesCourse ?c ?s ?c ?s ?s ub:name ?n ?n Constructing an SQGM SELECT ?n ?cFROM http://example.org/university.rdfWHERE { ?s rdf:type ub:GraduateStudent . OPTIONAL { ?s ub:takesCourse ?c .} ?s ub:name ?n .} Query Processing in Databases SPARQL Query Graph Model Transforming SQGMs Evaluation Conclusion ?n ?c ?s ?c ?s ?n ?s ?c ?s optional http://example.org/university.rdf Ralf Heese, SPARQL Query Graph Model
Variable providing operations Graph providing operations Variable dataflows Graph dataflows ?n Select ?c ?n ?c ?s Join ?c ?n ?s ?c ?s ?n Join ?s ?c ?s ?c ?s optional ?s ?s rdf:type ub:GraduateStudent ?s ub:takesCourse ?c ?s ?c ?s ?s ub:name ?n ?n Operation Types and Dataflow Types Query Processing in Databases SPARQL Query Graph Model Transforming SQGMs Evaluation Conclusion http://example.org/university.rdf Ralf Heese, SPARQL Query Graph Model
Query Rewriting • Goals • More efficient evaluation of a query • Provide more options for the generation of query plans, e.g., • Data access strategy • Join order • Selection of indexes • Means • Rule-based transformation, i.e., restructuring of the query, detection of redundancies and contradictions • Heuristic = set of rules Query Processing in Databases SPARQL Query Graph Model Transforming SQGMs Evaluation Conclusion Ralf Heese, SPARQL Query Graph Model
Select ?n ?c ?s Join ?c ?n Join ?s ?c ?s rdf:type ub:GraduateStudent ?s ?s ?s ub:takesCourse ?c ?c ?s ub:name ?n ?s ?n Heuristic: Combine Basic Graph Pattern Basic graph pattern cannot be merged But these could be merged if they wereoperands of the same join operation. Query Processing in Databases SPARQL Query Graph Model Transforming SQGMs Evaluation Conclusion Apply transformation rules to the SQGM ?n ?c ?s ?c ?s ?n ?s ?c ?s optional http://example.org/university.rdf Ralf Heese, SPARQL Query Graph Model
?n Select ?c ?s Join ?c ?n ?s Join ?n ?s rdf:type ub:GraduateStudent ?s ub:name ?n ?s ?n ?s rdf:type ub:GraduateStudent ?s ?s ub:takesCourse ?c ?s ?c ?s ?s ub:name ?n ?n Next Step Apply another transformation rule Query Processing in Databases SPARQL Query Graph Model Transforming SQGMs Evaluation Conclusion ?n ?c ?s ?n ?s ?c ?s optional ?s ?n http://example.org/university.rdf Ralf Heese, SPARQL Query Graph Model
Prototype • Setup • Jena Semantic Web Framework • ARQ – SPARQL query processor for Jena • RDF graphs stored on secondary storage • Extended by • SPARQL query graph model • Rule engine Query Processing in Databases SPARQL Query Graph Model Transforming SQGMs Evaluation Conclusion Ralf Heese, SPARQL Query Graph Model
Interaction between ARQ and SQGM extension ARQ SQGM extension SPARQL Query Query Processing in Databases SPARQL Query Graph Model Transforming SQGMs Evaluation Conclusion Construction ofan ARQ query model Translation intoan SQGM Rewriting ofthe SQGM Generation of a Query Execution Plan Translation intoan ARQ model Execution of the QEP Query result Ralf Heese, SPARQL Query Graph Model
Evaluation –Setup • RDF Data • A set of 41 SPARQL queries • Different combinations of graph patterns including OPTIONAL, FILTER and UNION Query Processing in Databases SPARQL Query Graph Model Transforming SQGMs Evaluation Conclusion Generator UBA (v.1.7) of Lehigh University Benchmarks http://swat.cse.lehigh.edu/projects/lubm/ Ralf Heese, SPARQL Query Graph Model
Evaluation –Results • Measured query execution time of a selected query • Factor 2.4 • Time needed for transformation between models< 1 ms • Average time savings of approx. 87% • Only one case with slightly higher execution time Query Processing in Databases SPARQL Query Graph Model Transforming SQGMs Evaluation Conclusion 5.8 2.5 39.4 16.4 77.9 32.3 SELECT ?n ?cFROM http://example.org/university.rdfWHERE { ?s rdf:type ub:GraduateStudent . OPTIONAL { ?s ub:takesCourse ?c .} ?s ub:name ?n .} Ralf Heese, SPARQL Query Graph Model
Explanation for the Result • Fast path algorithm of Jena • Perform pattern matching within the underlying relational database • Match multiple filtered basic graph patterns WHERE { ?s rdf:type ub:GraduateStudent . OPTIONAL { ?s ub:takesCourse ?c .} ?s ub:name ?n .} Fast path not applicable WHERE { ?s rdf:type ub:GraduateStudent . ?s ub:name ?n . OPTIONAL { ?s ub:takesCourse ?c .} } Fast path applicable Ralf Heese, SPARQL Query Graph Model
Conclusion and Future Work • SQGM: a query model for SPARQL • Supporting all phases of query processing • Easy to extend • Transformation rules and heuristics for SQGMs • Implementation illustrated the potential of SQGMs Outlook • Develop further heuristics to rewrite SPARQL queries • Integrate index selection into the query optimization Query Processing in Databases SPARQL Query Graph Model Transforming SQGMs Evaluation Conclusion Ralf Heese, SPARQL Query Graph Model