<!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>Counting Triangles under Updates?</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Ahmet Kara</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Hung Q. Ngo</string-name>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Milos Nikolic</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Dan Olteanu</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Haozhe Zhang</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>RelationalAI</string-name>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>University of Oxford</institution>
        </aff>
      </contrib-group>
      <abstract>
        <p>We consider the problem of maintaining the result of the triangle count query Q( ) = ;sum R(A; B) on S(B; C) on T (C; A) under single-tuple updates to the input relations R, S, and T . The relations are given as key-payload maps whose keys are tuples over relation schemas, payloads are tuple multiplicities, and key lookups are (amortized) O(1)-time operations. A single-tuple update R(a; b) = f (a; b) 7! p g to relation R maps a key (a; b) to a nonzero payload p (positive for inserts and negative for deletes); updates to S and T are analogous. The nave maintenance approach recomputes the triangle count from scratch after each update. Computing this query using worst-case optimal join algorithms [5] takes O(N 1:5) time, where N is the current size of the input database. To incrementally maintain the triangle count under single-tuple updates, existing incremental view maintenance (IVM) approaches need linear time. For instance, under the update R to R, the classical IVM [2] computes the delta query ;sum R(a; b) on S(b; C) on T (C; a) in O(N ) time because it needs to intersect two lists of possibly linearly many C-values that are paired with b in S and with a in T . The factorized IVM [6] materializes the view VST (B; A) = B;A;sum S(B; C) on T (C; A) using O(N 2) space. It then computes the delta query ;sum R(a; b) on VST (b; a) in O(1) time; however, updates to S and T still require O(N ) time to maintain the triangle count Q and view VST . This raises the question of whether the triangle count can be maintained in sublinear time. Recent work proves that no algorithm can maintain Q in time O(N 0:5 ) for any &gt; 0, under reasonable complexity-theoretic assumptions [1]. An algorithm with sublinear maintenance time for Q is not yet known. This work introduces IVM , an IVM approach that maintains the triangle count in amortized sublinear time. IVM partitions each input relation into two parts, heavy and light, based on the degrees of data values, the database size, and a parameter . It then adapts the maintenance strategy to di erent heavy-light combinations of parts of the input relations to achieve worst-case sublinear maintenance. As the database evolves under updates, IVM rebalances the partitions to account for a new database size and updated degrees of data values. While this rebalancing may take superlinear time, it remains sublinear per update. Given a database of size N and 2 [0; 1], IVM maintains the triangle count in O(N maxf ;1 g) amortized time while using O(N 1+minf ;1 g) space. It thus de nes a continuum of approaches exhibiting a space-time tradeo based on .</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>-</title>
      <p>? An extended version of this work is available online [3].</p>
      <p>
        Materialized View De nition
Q( ) = Su;v;w2fh;lg ;sum Ru(A; B) no Sv(B; C) no Tw(C; A)
VRS(A; C) = A;C;sum Rh(A; B) no Sl(B; C)
VST (B; A) = B;A;sum Sh(B; C) no Tl(C; A)
VT R(C; B) = C;B;sum Th(C; A) no Rl(A; B)
O(
        <xref ref-type="bibr" rid="ref1">1</xref>
        )
O(N 1+min f ;1 g)
O(N 1+min f ;1 g)
O(N 1+min f ;1 g)
      </p>
      <p>Setting = 0:5 gives O(N 0:5) amortized worst-case optimal time and O(N 1:5)
space utilization. Existing IVM approaches are extreme points in this continuum
of approaches de ned by IVM . For instance, to recover classical IVM, we set
2 f0; 1g to achieve O(N ) update time and O(N ) space utilization; to recover
factorized IVM, we set distinct parameters for each relation (cf. [3] for details).
IVM can also count all triangles in a static database in worst-case optimal time
O(N 1:5) by inserting N tuples, one at a time, into initially empty relations.
2</p>
    </sec>
    <sec id="sec-2">
      <title>Adaptive Maintenance Strategy</title>
      <p>We split each input relation into two disjoint parts, called heavy and light parts.
Given R 2 [0; 1], an A-value a is heavy in R if j A=aRj N R , where N is the
database size; otherwise, it is light. We partition R into Rh and Rl such that
Rh = f t 2 R j t:A is heavy g and Rl = R n Rh; similarly, we partition S on B,
and T on C. In the following, we assume that = R = S = T is xed.</p>
      <p>We decompose the query Q into skew-aware views expressed over the relation
parts: Quvw( ) = ;sum Ru(A; B) on Sv(B; C) on Tw(C; A), where u; v; w 2 fh; lg.
The query Q is thus a union (sum) of partial counts: Q( ) = Su;v;w2fh;lg Quvw( ).</p>
      <p>We adapt the maintenance strategy to each skew-aware view to ensure
sublinear update time. While most of these views admit sublinear delta
computation, few exceptions require linear-time maintenance. For these exceptions, IVM
precomputes the update-independent parts of delta queries as materialized views
and uses them to speed up the delta evaluation. Such auxiliary views also require
maintenance, yet their maintenance cost is sublinear for single-tuple updates.</p>
      <p>Figure 1 shows the materialized views used by IVM to maintain the triangle
count query. The size of the view VRS (A; C) is upper-bounded by the size of the
result of the join of Rh(A; B) and Sl(B; C) in two distinct ways. One can iterate
over all (a; b) pairs in Rh and then nd the C-values in Sl for each b. Since
Sl contains only tuples with light B-values, there are at most N distinct
Cvalues for each B-value. This gives an upper bound of O(jRhj N ) = O(N 1+ ).
Alternatively, one can iterate over all (b; c) pairs in Sl and then nd the
Avalues in Rh for each b. Since Rh contains only tuples with heavy A-values,
there are at most NN = N 1 distinct A-values. This gives an upper bound of
O(jSlj N 1 ) = O(N 2 ). The overall space complexity is the minimum of the
bounds. The space analysis for VST and VT R is analogous.</p>
      <p>We explain our adaptive strategy on a single-tuple update R (a; b) to
relation R. This update can a ect either the heavy or light part of R, hence the
Delta Evaluation Strategy
Q hh( ) = R (a; b) PC Th(C; a) Sh(b; C)
Q hl( ) = R (a; b) VST (b; a)
Q lh( ) = R (a; b) PC Th(C; a) Sl(b; C) or</p>
      <p>
        = R (a; b) PC Sl(b; C) Th(C; a)
Q ll( ) = R (a; b) PC Sl(b; C) Tl(C; a)
Q( ) = Q hh( ) + Q hl( ) + Q lh( ) + Q ll( )
VRS(a; C) = Rh(a; b) Sl(b; C)
VT R(C; b) = Rl(a; b) Th(C; a)
O(N min f ;1 g)
O(N 1 )
O(
        <xref ref-type="bibr" rid="ref1">1</xref>
        )
O(N )
O(
        <xref ref-type="bibr" rid="ref1">1</xref>
        )
O(N )
O(N 1 )
symbol; we assume that checking whether a is heavy or not in R is a
constanttime operation. Updates to the other two relations are handled similarly.
      </p>
      <p>Figure 2 shows the deltas of the views a ected by the update R (a; b) and
their time complexity when evaluated from left to right. In all but one case, the
complexity is determined by the number of C-values that need to be iterated
over. Computing the deltas involves multiplying the payloads of matching tuples
and, if C is not in the target view schema, summing them over C-values.</p>
      <p>
        We rst analyze the access patterns of the skew-aware delta views: (
        <xref ref-type="bibr" rid="ref1">1</xref>
        ) For
Q hh, we iterate over at most N 1 C-values in Th for the given a and then look
up in Sh for each (b; c); (
        <xref ref-type="bibr" rid="ref2">2</xref>
        ) For Q hl, we look up in the materialized view VST
for the given (a; b); (
        <xref ref-type="bibr" rid="ref3">3</xref>
        ) For Q lh, we either iterate over at most N 1 C-values
in Th for the given a and look up in Sl for each (b; c), or we iterate over at most
N C-values in Sl for the given b and look up in Th for each (c; a); (
        <xref ref-type="bibr" rid="ref4">4</xref>
        ) For Q ll,
we iterate over at most N C-values in Sl for the given b and then look up in Tl
for each (c; a). Then, summing these partial deltas and updating Q take constant
time. The views VRS and VT R, which facilitate updates to T and respectively
to S, are maintained for updates to distinct parts of R. Computing VRS and
updating VRS requires iterating over at most N C-values in Sl for the given
b; similarly, computing VT R and updating VT R involves at most N 1 heavy
C-values in Th. The nal step of IVM updates the (heavy or light) part of R
that corresponds to R in (amortized) O(
        <xref ref-type="bibr" rid="ref1">1</xref>
        ) time. Overall, IVM maintains the
views from Figure 1 under single-tuple updates to any of the input relations in
O(N maxf ;1 g) time using O(N 1+minf ;1 g) space.
      </p>
      <p>An insert (a; b) into R may promote a from light to heavy in R or may
increase the heavy-light threshold such that some A-values change from heavy
to light. Without rebalancing the partitions, our assumptions on the number of
B-values paired with a or the number of heavy A-values may become invalid.</p>
      <p>IVM loosens the partition threshold to amortize the cost of rebalancing
over multiple updates. Instead of the actual database size N , the threshold now
depends on a variable M for which the invariant b 41 M c N &lt; M always holds.
If the database size violates one of the limits, we perform major rebalancing
where we double or halve M to satisfy the invariant again, repartition the input
relations using the new threshold M , and recompute the auxiliary views. The
time complexity of this operation is O(M 1+minf ;1 g), which is amortized over
at least d 41 M e updates between two major rebalancing steps.</p>
      <p>IVM also enforces the following two invariants: The number of tuples with
the same value of the partitioning attribute is less than 32 M in each light part
and at least 12 M in each heavy part. If any of the two invariants is violated, we
perform minor rebalancing where we move at most d 32 M e tuples from one part
to another and update the a ected views. The time complexity of this operation
is O(M +maxf ;1 g), which is amortized over at least d 21 M e updates between
two minor rebalancing steps for the same value of the partitioning attribute.</p>
      <p>In conclusion, both rebalancing steps together take O(M maxf ;1 g)
amortized time. Since each single-tuple update can be realized in time O(M maxf ;1 g)
and M = O(N ), IVM needs O(N maxf ;1 g) overall amortized time. The
extended version of this work presents a detailed complexity analysis of IVM [3].
3</p>
    </sec>
    <sec id="sec-3">
      <title>Beyond the Triangle Query</title>
      <p>IVM can be applied to any query but may not always yield asymptotic
improvements over existing approaches. It can achieve sublinear maintenance for the
counting variants of acyclic queries, e.g., 3-path and 4-path, and cyclic queries,
e.g., Loomis-Whitney and 4-cycle. Di erent semirings can be used to speci y
operations on the payloads [6]; we used here (Z; +; ; 0; 1) to express counting. An
early prototype implementation of IVM on top of DBToaster [4] shows several
factors performance improvement over classical and factorized IVM.
Acknowledgments. This project has received funding from the European Union's
Horizon 2020 research and innovation programme under grant agreement No
682588. The rst author acknowledges funding from Fondation Wiener Anspach.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <given-names>Christoph</given-names>
            <surname>Berkholz</surname>
          </string-name>
          , Jens Keppeler, and
          <string-name>
            <given-names>Nicole</given-names>
            <surname>Schweikardt</surname>
          </string-name>
          .
          <article-title>Answering Conjunctive Queries under Updates</article-title>
          .
          <source>In PODS</source>
          , pages
          <volume>303</volume>
          {
          <fpage>318</fpage>
          ,
          <year>2017</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <given-names>Rada</given-names>
            <surname>Chirkova</surname>
          </string-name>
          and
          <string-name>
            <given-names>Jun</given-names>
            <surname>Yang</surname>
          </string-name>
          .
          <source>Materialized Views. Found. &amp; Trends in DB</source>
          ,
          <volume>4</volume>
          (
          <issue>4</issue>
          ):
          <volume>295</volume>
          {
          <fpage>405</fpage>
          ,
          <year>2012</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <given-names>Ahmet</given-names>
            <surname>Kara</surname>
          </string-name>
          ,
          <string-name>
            <given-names>Hung Q.</given-names>
            <surname>Ngo</surname>
          </string-name>
          , Milos Nikolic, Dan Olteanu, and Haozhe Zhang.
          <article-title>Counting triangles under updates in worst-case optimal time</article-title>
          .
          <source>CoRR</source>
          , abs/
          <year>1804</year>
          .02780,
          <year>2018</year>
          . URL: http://arxiv.org/abs/
          <year>1804</year>
          .02780.
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <string-name>
            <given-names>Christoph</given-names>
            <surname>Koch</surname>
          </string-name>
          ,
          <string-name>
            <given-names>Yanif</given-names>
            <surname>Ahmad</surname>
          </string-name>
          , et al.
          <article-title>DBToaster: Higher-order Delta Processing for Dynamic, Frequently Fresh Views</article-title>
          . VLDB J.,
          <volume>23</volume>
          (
          <issue>2</issue>
          ):
          <volume>253</volume>
          {
          <fpage>278</fpage>
          ,
          <year>2014</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <surname>Hung</surname>
            <given-names>Q.</given-names>
          </string-name>
          <string-name>
            <surname>Ngo</surname>
            , Christopher Re, and
            <given-names>Atri</given-names>
          </string-name>
          <string-name>
            <surname>Rudra</surname>
          </string-name>
          . Skew Strikes Back:
          <article-title>New Developments in the Theory of Join Algorithms</article-title>
          .
          <source>SIGMOD Record</source>
          ,
          <volume>42</volume>
          (
          <issue>4</issue>
          ):5{
          <fpage>16</fpage>
          ,
          <year>2013</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          6.
          <string-name>
            <given-names>Milos</given-names>
            <surname>Nikolic</surname>
          </string-name>
          and
          <string-name>
            <given-names>Dan</given-names>
            <surname>Olteanu</surname>
          </string-name>
          .
          <article-title>Incremental View Maintenance with Triple Lock Factorization Bene ts</article-title>
          .
          <source>In SIGMOD</source>
          ,
          <year>2018</year>
          . (to appear).
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>