<!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>Merging and Partition for SPARQL Query Optimization</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Hongshen Yu</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Tenglong Ren</string-name>
          <email>tenglongren@tju.edu.cn</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Xiaowang Zhang</string-name>
          <email>xiaowangzhang@tju.edu.cn</email>
          <xref ref-type="aff" rid="aff0">0</xref>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Lulu Yang</string-name>
          <email>luluyang@tju.edu.cn</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Guopeng Zheng</string-name>
          <email>guopengzheng@tju.edu.cn</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="editor">
          <string-name>RDF Data, Merge Characteristic Sets, Predicate Correlation, Predicate Partitioning</string-name>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>College of Intelligence and Computing, Tianjin University</institution>
          ,
          <addr-line>Tianjin 300350</addr-line>
          ,
          <country country="CN">China</country>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>Tianjin Key Laboratory of Cognitive Computing and Application</institution>
          ,
          <addr-line>Tianjin</addr-line>
          ,
          <country country="CN">China</country>
        </aff>
      </contrib-group>
      <pub-date>
        <year>2022</year>
      </pub-date>
      <abstract>
        <p>Characteristic sets (CS) are used for storage and indexing, as the same CS tends to have a similar schema. While many methods based on CSs can improve query performance, especially for star queries, query performance will be seriously afected when the workload is complicated and produces many CSs. In this paper, we present CoPMP, merging CSs based on the correlations between predicates within the CSs and partitioning predicates. Our method captures the predicate correlation and merges CSs to reduce the number of CSs. The merging operation is driven by the cost model considering the predicate correlation and null values. In merging CSs, each predicate belongs to only a property set, i.e., predicate partitioning. Thus, CoPMP has the advantages of both property table and vertical partitioning for query optimization. We allocate merged tables into data blocks based on subject hash partitioning, considering that CS is from the same subject. Our extensive evaluation demonstrates the eficiency and scalability of our system.</p>
      </abstract>
      <kwd-group>
        <kwd>Optimization</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>1. Introduction</title>
      <p>
        Traditional RDF data storage schemes include triples store, vertical partitioning, and property
table. But these methods are not eficient enough when workloads are complicated. Recently
works show that Characteristic sets (CS) [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ] can capture the implicit schema of RDF data and
improve optimization. The CS for a subject is the set of predicates on the outgoing edges from
that subject. For the complicated datasets, Papastefanatos et al. [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ] point out that merging CSs
based on the hierarchical structure reduces the number of CSs. But it only works in subset
inclusion relations between property sets. In this paper, we introduce CoPMP, a distributed
query engine based on Spark, which combines predicate correlation with partitioning and
allocates tables to data partitions by subject. [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ] also considers predicate partition. But it is not
the same as the focus of this paper. Firstly, [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ] artificially sets a co-occurrence threshold and
uses a similarity coeficient similar to Jaccard to represent the degree of co-occurrence between
two predicates. Only when co-occurrence is greater than the threshold are two predicates
considered co-occurrence. In this paper, Two predicates are considered related as long as they
have the same subject. Secondly, When dividing predicates, [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ] stores all predicates that
cooccur with predicates, that is predicates with a degree of co-occurrence greater than a threshold,
into a set. However, based on CSs, this paper selects the CS with the greatest benefit as the
basic data table and tries to add all the predicates with the same subject as the predicates in
the selected CS. If the benefit of the table increases, then add the predicate. Finally, To obtain a
better predicate partitioning pattern, [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ] enumerates diferent co-occurrence thresholds. In
this paper, CSs are merged based on the heuristic cost function to obtain the optimal relation
pattern, which is the same idea as [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ], but the method is diferent.
      </p>
      <p>Figure 1 illustrates an overview of CoPMP architecture. Our contributions are as follows:
- We propose a new heuristic algorithm for merging CSs, which considers the correlation of
predicates and null values of the merged table.
- We ensure predicate partition in merging CSs, allowing CoPMP to benefit from vertical
partitioning and property tables without additional storage structures.
- Extensive experiments on synthetic and real-world RDF graphs have been conducted to verify
the eficiency and scalability of our method.</p>
      <sec id="sec-1-1">
        <title>RDF Data</title>
      </sec>
      <sec id="sec-1-2">
        <title>SPARQL</title>
        <sec id="sec-1-2-1">
          <title>Storage Builder</title>
        </sec>
        <sec id="sec-1-2-2">
          <title>Query Planner</title>
        </sec>
      </sec>
      <sec id="sec-1-3">
        <title>Characteristic sets</title>
      </sec>
      <sec id="sec-1-4">
        <title>Extractor</title>
      </sec>
      <sec id="sec-1-5">
        <title>Heuristic Merging Table Generator</title>
      </sec>
      <sec id="sec-1-6">
        <title>HDFS</title>
      </sec>
      <sec id="sec-1-7">
        <title>Query Parse</title>
        <sec id="sec-1-7-1">
          <title>Query Decompose</title>
        </sec>
      </sec>
      <sec id="sec-1-8">
        <title>Join Optimizer</title>
      </sec>
    </sec>
    <sec id="sec-2">
      <title>2. CoPMP</title>
      <p>Algorithm 1: CSsMerge
Output: schemaSet
for each schema ∈CSs do</p>
      <p>pts.add(schema);
end
while !pts.isEmpty() do
Consider two extremes, (i) a CS corresponds to a property table, and (ii) all CSs
are merged into a property table.</p>
      <p>One leads to many tables and joins, and the
other to excessive NULLs.</p>
      <p>Thus, we need to find a Pareto equilibrium between
fewer tables and null values when we merge CSs based on predicate correlation.
Input: Characteristic Sets CSs,   ,   , a property table set  ← ∅
;
compute the cost of the schema;
schema remove predicate p, if p is marked;
select a schema with the lowest cost</p>
      <p>;
select a predicate pmax with max Predicate Frequency;
pts.remove(schema);
for each predicate p and PC(p, pmax) = true do
if 
end
let schemaTmp = schema.add(p);
compute the</p>
      <p>of schemaTmp;

&lt;</p>
      <p>then
schema = shemaTmp;  
mark predicate p;</p>
      <p>=   ;
end
schemaSet.add(schema);
end
return schemaSet;
However, enumerating the combination of all related predicates is computationally hard. For
this reason, we rely on a heuristic algorithm for approximating the problem. We introduce a
function to find the current minimum cost in the merging process. Predicate frequency   (
the number of sets(CSs) in which   appear. Predicate co-occurrence  (
 ,   ) is the number of
diferent sets in which predicate   ,   that appear together. We design a cost model to measure
the data table  . The column field of the table  is the set of predicates. And  
is predicate
 ) is
with max  
,   
and</p>
      <p>are functions measuring the null values and correlation.
cost( ) =
  ( )
( )
=</p>
      <p>∑  
(  ) +   ( max) −</p>
      <p>(  ,  max)
∑ ∑</p>
      <p>(  ,  )
 min( (  ), (  ))
/ 2
(1)
The main idea behind the heuristic merging in algorithm 1 is to iterate over the predicates
co-occurring with the</p>
      <p>in the lowest cost CS. If adding these predicates comes with a
smaller cost, merge them, and update the cost and property set. We choose  
instead of
enumerating all predicates because predicate combinations are too large.</p>
      <p>Query Planner Query Planner generates an optimal query plan for a given SPARQL query
to be further executed. Query Decompose module decomposes the query into star subqueries.
Moreover, we can search candidate triples by indexing the constant predicate based on predicate
partitioning. Finally, we join the subqueries to get the result of the query.</p>
    </sec>
    <sec id="sec-3">
      <title>3. Evaluation</title>
      <p>
        We implement the experiment on a cluster with five machines. Each machine is equipped with
24G RAM, 2TB disk, and a 6 core Intel Xeon E5-2420 processor. The cluster runs Cloudera 5.13.3
with Spark 2.4.4 on Ubuntu 16.04 LTS. We compare CoPMP with S2RDF [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ] and Sempala [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ].
S2RDF uses ExtVP, which is based on vertical partitioning, and Sempala is based on the property
table. We choose S2RDF and Sempala as the comparison system to show that CoPMP has the
advantages of property table and vertical partition at the same time. The tests were run using
the synthetic dataset WatDiv [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ] and real-world dataset DBpedia [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ]. For the Watdiv benchmark,
we generate datasets with Watdiv100M, Watdiv300M, and Watdiv500M to test the system’s
scalability and employ four types of queries snowflake(S), linear(L), star(S), and complex(C).
Due to DBpedia’s absence of query templates, we designed four queries that combine query
types. Figure 2 ∼ 4 show the average query time obtained on the Watdiv and Figure 1 shows
the response time on the DBpedia. The results show that CoPMP proved more eficient than
Sempala and S2RDF. Sempala needs to scan a big table each time since it stores triples with a
unified property table, which results in a slow response. S2RDF precompute semi-join tables to
reduce data shufling. However, if the query does not appear in a semi-join table, the query can
be expensive with VP tables. CoPMP merges CSs based on predicate correlation and predicate
partitioning. Based on predicate partitioning, CoPMP can quickly find candidate triples since
each predicate exists in only one table, similar to S2RDF. Also, CoPMP decomposes the query
into star subqueries, thereby reducing joins with the benefits of property tables, but without
scanning a single table containing all the data like Sempala. The results show that CoPMP
benefits vertical partitioning and property tables.
      </p>
      <p>S2RDF Sempala CoPMP</p>
      <p>S2RDF Sempala CoPMP
1.E+05
C</p>
      <p>F</p>
      <p>L</p>
      <p>S</p>
    </sec>
    <sec id="sec-4">
      <title>4. Conclusion and Future Work</title>
      <p>In this paper, we present a distributed query engine CoPMP that merges characteristic sets
based on predicate correlation and predicate partitioning. Moreover, we allocate the merged
table to the data partition based on the subject hash partition, which is the advantage of the CS
with the same subject in distributed storage. Also, our extensive experimental results show the
efectiveness of the CoPMP. In the future, we are planning to continue to extend the work to
Well-designed SPARQL and conduct a comprehensive experiment to validate the eficiency of
CoPMP.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <surname>Neumann</surname>
            ,
            <given-names>T.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Moerkotte</surname>
          </string-name>
          , G.:
          <article-title>Characteristic sets: Accurate cardinality estimation for RDF queries with multiple joins</article-title>
          .
          <source>In: ICDE</source>
          . pp.
          <fpage>984</fpage>
          -
          <lpage>994</lpage>
          (
          <year>2011</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <surname>Schätzle</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Przyjaciel-Zablocki</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Skilevic</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Lausen</surname>
          </string-name>
          , G.:
          <article-title>S2RDF: RDF querying with SPARQL on spark</article-title>
          .
          <source>In: VLDB</source>
          . pp.
          <fpage>804</fpage>
          -
          <lpage>815</lpage>
          (
          <year>2016</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <surname>Schätzle</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Przyjaciel-Zablocki</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Neu</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Lausen</surname>
          </string-name>
          , G.:
          <article-title>Sempala: Interactive sparql query processing on hadoop</article-title>
          .
          <source>In: ISWC</source>
          . pp.
          <fpage>164</fpage>
          -
          <lpage>179</lpage>
          (
          <year>2014</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <surname>Papastefanatos</surname>
            ,
            <given-names>G.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Meimaris</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Vassiliadis</surname>
            ,
            <given-names>P.</given-names>
          </string-name>
          :
          <article-title>Relational schema optimization for RDFbased knowledge graphs</article-title>
          .
          <source>In: Information Systems</source>
          . pp.
          <fpage>735</fpage>
          -
          <lpage>754</lpage>
          (
          <year>2022</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <surname>Aluç</surname>
            ,
            <given-names>G.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Hartig</surname>
            ,
            <given-names>O.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Özsu</surname>
            ,
            <given-names>M.T.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Daudjee</surname>
            ,
            <given-names>K.</given-names>
          </string-name>
          :
          <article-title>Diversified stress testing of RDF data management systems</article-title>
          .
          <source>In: ISWC</source>
          . pp.
          <fpage>197</fpage>
          -
          <lpage>212</lpage>
          (
          <year>2014</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <surname>Jens</surname>
            ,
            <given-names>L.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Robert</surname>
            ,
            <given-names>I.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Max</surname>
            ,
            <given-names>J.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Anja</surname>
            ,
            <given-names>J.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Dimitris</surname>
            ,
            <given-names>K.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Pablo</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Sebastian</surname>
            ,
            <given-names>H.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Mohamed</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Patrick</surname>
            ,
            <given-names>V.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Sören</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Christian</surname>
            ,
            <given-names>B.</given-names>
          </string-name>
          :
          <article-title>DBpedia - A Large-scale, Multilingual Knowledge Base Extracted from Wikipedia</article-title>
          .
          <source>In: Semantic Web</source>
          . pp.
          <fpage>167</fpage>
          -
          <lpage>195</lpage>
          (
          <year>2015</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          [7]
          <string-name>
            <surname>Guangxi</surname>
            ,
            <given-names>J.</given-names>
          </string-name>
          :
          <source>Optimizing Well-designed SPARQL Query Based on Constrained Pattern Tree[Master Thesis]</source>
          , Tianjin University,
          <year>2022</year>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>