<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Query Planning for Evaluating SPARQL Property Paths</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Nikolay Yakovets</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Parke Godfrey</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Jarek Gryz</string-name>
          <email>jarekg@cse.yorku.ca</email>
          <xref ref-type="aff" rid="aff0">0</xref>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Department of Computer Science and Engineering, York University</institution>
          ,
          <country country="CA">Canada</country>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>Introduction &amp;</institution>
        </aff>
      </contrib-group>
      <abstract>
        <p>The extension of SPARQL in version 1.1 with property paths o ers a type of regular path query for RDF graph databases. Such queries are di cult to optimize and evaluate e ciently, however. We have embarked on a project, Waveguide, to build a cost-based optimizer for SPARQL queries with property paths. Waveguide builds a query plan| which we call a waveplan (WP)|which guides the query evaluation. There are numerous choices in the construction of a plan, and a number of optimization methods, so the space of plans for a query can be quite large. Execution costs of plans for the same query can vary by orders of magnitude. A WP's costs can be estimated, which opens the way to costbased optimization. We demonstrate that the plan space of Waveguide properly subsumes existing techniques and that the new plans it adds are relevant.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>Motivation</title>
      <p>
        Graph data is becoming rapidly prevalent with the rise of the Semantic Web,
social networks, and data-driven exploration in life sciences. There is a need
for natural, expressive ways to query over these graphs. Standards are coming
into place for this. The Resource Description Framework (RDF) [
        <xref ref-type="bibr" rid="ref9">9</xref>
        ] provides a
data model for graph data. An RDF store is a set of triples that describes a
directed, edge-labeled multi-graph. A triple, hs; r; oi, denotes an edge from node
\s" (the subject ) to node \o" (the object ), with the edge labeled by \r" (the role,
also called label or predicate). The SPARQL query language [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ] correspondingly
provides a formal means to query over RDF stores. A query de nes sub-graph
match criteria; its evaluation over an RDF store returns all embedded sub-graphs
or variable bindings meeting the criteria. For example, the query
?friend :friendOf Charles .
(Q1)
evaluates to a list of people (nodes binding to variable \?friend") who are friends
of (role \:friendOf") \Charles" (a named node, so a constant).
      </p>
      <p>
        In its latest version, 1.1, SPARQL's expressiveness is extended with property
paths [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ]. This e ectively introduces the concept of regular path queries (RPQs)|
well studied before the advent of RDF and SPARQL|into the query language.
Instead of specifying the path of interest explicitly between nodes, one may now
specify it implicitly via a regular expression. For example, the query
?friend :friendOf+ Charles .
(Q2)
evaluates to a list of people who are friends of \Charles", or friends of people
who are friends of \Charles", and so forth (that is, a transitive closure over
\:friendOf").
      </p>
      <p>While SPARQL provides the expressiveness we desire, such queries are more
challenging to optimize well. Query Q1 could be evaluated just by extracting
the triples with \r = :friendOf" and \o = Charles". For even a slightly more
complicated query, however, it may not be straightforward to nd a plan to
evaluate it e ciently. Q2 is more challenging in requiring transitive closure over
\:friendOf" with respect to the graph.</p>
      <p>
        Property path evaluation is a tale of two methods: two quite di erent
approaches appear in the literature. For RPQs, the seminal work [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ] which
introduced the G+ query language shows how to use a nite state machine e ectively
as a plan to guide the graph walk for the query's evaluation. We call this approach
FA. Subsequent work on RPQs has followed this idea.
      </p>
      <p>
        SPARQL with property paths is much more recent. Systems for SPARQL
query evaluation have followed the second approach, based primarily on the
seminal work of [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ]. These extend the relational algebra to accommodate the
translation of a property path's regular expression, and then use dynamic
programming over the (extended) relational-algebra parse to devise a plan. Added
is an \ " operator, which provides the transitive closure over a relation to
accommodate regular expressions' Kleene star. Thus, we call this approach -RA,
the relational algebra extended by \ " [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ].
      </p>
      <p>Which approach is better? We shall show that the e ective \plan spaces"
that result from FA and -RA are incomparable. Sometimes, for a given query
and graph, an FA plan will be the better choice. Other times, an -RA plan
will be. Our goal is to formalize the notion of plan space for both, to be able
to choose the best plan. We shall show that a richer plan space can be had
that properly subsumes FA and -RA, and o ers more plans existing in neither
(\mixed" plans), which sometimes are the best plans.</p>
      <p>
        We have designed a system called Waveguide [
        <xref ref-type="bibr" rid="ref12">12</xref>
        ] with the goal to provide
viable cost-based query optimization and evaluation for SPARQL over RDF
stores that is on par with the state of the art for relational database systems.
In [
        <xref ref-type="bibr" rid="ref12">12</xref>
        ], we address the rst but critical step of this endeavor, de ning a plan
space|the space of query plans, waveplans (WPs)|for SPARQL queries. We
focus on single-path, property-path queries, essentially the RPQ fragment of
SPARQL 1.1. We consider a set semantics|the distinct directive in each query|
and thus do not consider aggregation.
      </p>
      <p>
        In [
        <xref ref-type="bibr" rid="ref12">12</xref>
        ], our contributions are as follows.
1. plan space.
      </p>
      <p>(a) Summarize the state of the art for evaluation of RPQs and SPARQL
property paths.
(b) Establish why none su ces.
(c) Devise Waveguide's plan space, and demonstrate that it subsumes the
state of the art, and extends beyond it.
(d) Model the cost factors that determine the e ciency of plans, and present
the powerful optimizations o ered by Waveguide plans.
2. performance study.</p>
      <p>(a) Provide a microbenchmark over a pertinent RPQ template with realistic
queries over real RDF stores / graphs.
(b) Substantiate the optimizations of our approach.</p>
      <p>(c) Justify the necessity of the richer plan space.
2</p>
    </sec>
    <sec id="sec-2">
      <title>Approach</title>
      <p>Work on property-path evaluation has been remiss in not drawing the connection
to RPQs. How do the FA and -RA approaches compare? Does one subsume the
other? Or are they incomparable? If so, a combined approach might be superior.
A generalized approach might o er new plans that neither FA nor -RA can
produce with superior performance.</p>
      <p>Both the FA and -RA approaches e ectively provide evaluation plans for
property-path queries. However, the plan spaces that are implicit in these
approaches have not been considered. In FA, choosing a di erent (but still correct)
automaton for the plan might o er a signi cantly more e cient plan. In
systems taking the -RA approach, planning is done over the -RA expression tree
that results from the property path's translation, but no planning speci c to the
semantics of property paths takes place.</p>
      <p>
        In [
        <xref ref-type="bibr" rid="ref12">12</xref>
        ], we show the approaches of FA and -RA are, indeed, incomparable.
We next describe Waveguide, which is a generalized approach to query
planning and evaluation for SPARQL property-path queries, and which properly
subsumes the FA and -RA approaches. We discuss Waveguide's evaluation
model, present Waveguide's plans, and we show that Waveguide's plan space
properly subsumes FA [ -RA.
      </p>
      <p>Waveguide's evaluation strategy is based on an iterative search algorithm,
and variations thereof. In Waveguide, we perform path search e ciently while
simultaneously recognizing the path expressions. Waveguide's input is a graph
database G and a waveplan PQ which guides a number of search wavefronts that
explore the given graph. We introduce the term wavefront to refer to a part of the
plan that evaluates breadth- rst during the evaluation. This graph exploration,
driven by an iterative search procedure, is inspired by the semi-nave bottom-up
strategy used in the evaluation of linear recursive expressions based on xpoint,
as is done for the operator for -RA.</p>
      <p>The key idea is, given a seed |a set of nodes in the graph from which this
wavefront begins its search|as a start, to expand repeatedly the search
wavefronts until no new answers are produced; i.e., we reach a xpoint. Each search
wavefront is guided by an automaton in the plan, a nite state machine based
on an NFA. This is akin to the FA approach. Di erent, though, from NFAs which
are used as recognizers of regular expressions on strings, wavefront automata
have features directed to the evaluation of regular expressions over graphs.</p>
      <p>
        In [
        <xref ref-type="bibr" rid="ref12">12</xref>
        ], we present a cost framework for Waveguide search, search cost
factors that can magnify the cost (properties of the graph and of resulting
prepaths computed during evaluation), and optimization methods that are enabled
by WPs which address the search factors, in turn.
      </p>
      <p>
        We prototype a system [
        <xref ref-type="bibr" rid="ref11">11</xref>
        ] that implements Waveguide methodology to
benchmark waveplans to study their performance. In this Waveguide system,
resource-intensive tasks are delegated to PostgreSQL via SQL and procedural
SQL routines.
      </p>
      <p>
        We test our implementation of Waveguide by running a collection of
realistic path queries over real-world datasets YAGO2s [
        <xref ref-type="bibr" rid="ref10">10</xref>
        ] and DBPedia [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ]. We
generate path queries based on data patterns we identi ed in real-world graphs.
The goal of these experiments is to verify the gains o ered by Waveguide
optimizations, and show that they correspond to our cost framework and analysis.
Further, we design a microbenchmark to analyze the performance of the
Waveguide prototype in comparison with two RDF stores: Virtuoso [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ] and Jena
TDB [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ].
      </p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <given-names>R.</given-names>
            <surname>Agrawal</surname>
          </string-name>
          . Alpha:
          <article-title>An extension of relational algebra to express a class of recursive queries</article-title>
          .
          <source>Software Engineering</source>
          , IEEE Transactions on,
          <volume>14</volume>
          (
          <issue>7</issue>
          ):
          <volume>879</volume>
          {
          <fpage>885</fpage>
          ,
          <year>1988</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <given-names>J. J.</given-names>
            <surname>Carroll</surname>
          </string-name>
          , I. Dickinson,
          <string-name>
            <given-names>C.</given-names>
            <surname>Dollin</surname>
          </string-name>
          ,
          <string-name>
            <given-names>D.</given-names>
            <surname>Reynolds</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Seaborne</surname>
          </string-name>
          , and
          <string-name>
            <given-names>K.</given-names>
            <surname>Wilkinson</surname>
          </string-name>
          .
          <article-title>Jena: implementing the semantic web recommendations</article-title>
          .
          <source>In Proceedings of the 13th international World Wide Web conference on Alternate track papers &amp; posters</source>
          , pages
          <volume>74</volume>
          {
          <fpage>83</fpage>
          . ACM,
          <year>2004</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          <article-title>3. The DBpedia knowledge base</article-title>
          . http://dbpedia.org/.
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <string-name>
            <given-names>O.</given-names>
            <surname>Erling</surname>
          </string-name>
          and
          <string-name>
            <surname>I. Mikhailov.</surname>
          </string-name>
          <article-title>Virtuoso: RDF Support in Native RDBMS</article-title>
          .
          <source>Semantic Web Information Management</source>
          ,
          <volume>1</volume>
          :
          <fpage>501</fpage>
          ,
          <year>2010</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <given-names>S.</given-names>
            <surname>Harris</surname>
          </string-name>
          and
          <string-name>
            <given-names>A.</given-names>
            <surname>Seaborne</surname>
          </string-name>
          .
          <source>SPARQL 1</source>
          .
          <article-title>1 query language</article-title>
          .
          <source>W3C Recommendation</source>
          . http://www.w3.org/TR/sparql11-query/,
          <year>2013</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          6.
          <string-name>
            <given-names>K.</given-names>
            <surname>Losemann</surname>
          </string-name>
          and
          <string-name>
            <given-names>W.</given-names>
            <surname>Martens</surname>
          </string-name>
          .
          <article-title>The complexity of evaluating path expressions in SPARQL</article-title>
          .
          <source>In Proceedings of the 31st symposium on Principles of Database Systems</source>
          , pages
          <fpage>101</fpage>
          {
          <fpage>112</fpage>
          . ACM,
          <year>2012</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          7.
          <string-name>
            <given-names>A.</given-names>
            <surname>Mendelzon</surname>
          </string-name>
          and
          <string-name>
            <given-names>P.</given-names>
            <surname>Wood</surname>
          </string-name>
          .
          <article-title>Finding regular simple paths in graph databases</article-title>
          .
          <source>SIAM Journal on Computing</source>
          ,
          <volume>24</volume>
          (
          <issue>6</issue>
          ):
          <volume>1235</volume>
          {
          <fpage>1258</fpage>
          ,
          <year>1995</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          8.
          <string-name>
            <given-names>E.</given-names>
            <surname>Prud'Hommeaux</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Seaborne</surname>
          </string-name>
          , et al.
          <article-title>SPARQL query language for RDF</article-title>
          .
          <source>W3C Recommendation</source>
          ,
          <volume>15</volume>
          ,
          <year>2008</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          9. W3C:
          <article-title>Resource Description Framework (RDF)</article-title>
          . http://www.w3.org/TR/rdfconcepts/,
          <year>2004</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          10.
          <article-title>YAGO2s: A high-quality knowledge base</article-title>
          . http://yago-knowledge.org/resource/. Max Planck Institut Informatik.
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          11.
          <string-name>
            <given-names>N.</given-names>
            <surname>Yakovets</surname>
          </string-name>
          ,
          <string-name>
            <given-names>P.</given-names>
            <surname>Godfrey</surname>
          </string-name>
          , and
          <string-name>
            <surname>J. Gryz.</surname>
          </string-name>
          <article-title>WAVEGUIDE: evaluating SPARQL property path queries</article-title>
          .
          <source>In Proceedings of the 18th International Conference on Extending Database Technology, EDBT</source>
          <year>2015</year>
          , Brussels, Belgium, March
          <volume>23</volume>
          -27,
          <year>2015</year>
          ., pages
          <volume>525</volume>
          {
          <fpage>528</fpage>
          ,
          <year>2015</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref12">
        <mixed-citation>
          12.
          <string-name>
            <given-names>N.</given-names>
            <surname>Yakovets</surname>
          </string-name>
          ,
          <string-name>
            <given-names>P.</given-names>
            <surname>Godfrey</surname>
          </string-name>
          , and
          <string-name>
            <given-names>J.</given-names>
            <surname>Gryz</surname>
          </string-name>
          .
          <article-title>Evaluation of SPARQL Property Paths via Recursive SQL</article-title>
          .
          <source>In Proceedings of the annual ACM SIGMOD conference (SIGMOD'16)</source>
          , San Francisco, USA,
          <year>June 2016</year>
          . ACM.
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>