Live data from Hacker News

How to Build Your Distributed Database

citusdata.com

21–24 of 24 posts

Re: How to Build Your Distributed Database

#21
post #20

Interesting... it's actually associativity that matters for this class of distributed query execution problems (in particular, for AVG). While a/b != b/a indeed violates commutativity, the reason AVG doesn't distribute is that AVG(a, b, c, d, e) != AVG(AVG(a, b), AVG(c, d, e)), i.e. (1 + 2 + 3 + 4 + 5)/5 != ((1 + 2)/2 + (3 + 4 + 5)/3)/2. Notice that we're not reversing the order of any operations, merely the way in w…

Perhaps I was missing the point, but my first thought with the AVG counterexample was to have each distributed query return (SUM, COUNT), both of which are nicely associative and commutative, and then only at final step do ((SUM of SUMS) / (SUM of COUNTS)).

Re: How to Build Your Distributed Database

#22
post #19
post #18

What's the SQL for the second optimized tree?

It's the same. That's the point :). You need to plan your queries much differently when your data is not in a single node.

I don't think it's the same. The filters have to be done in separate queries on both the tables, and then the results the joined.

Re: How to Build Your Distributed Database

#23
post #20

Interesting... it's actually associativity that matters for this class of distributed query execution problems (in particular, for AVG). While a/b != b/a indeed violates commutativity, the reason AVG doesn't distribute is that AVG(a, b, c, d, e) != AVG(AVG(a, b), AVG(c, d, e)), i.e. (1 + 2 + 3 + 4 + 5)/5 != ((1 + 2)/2 + (3 + 4 + 5)/3)/2. Notice that we're not reversing the order of any operations, merely the way in w…

(Ozgun from Citus Data)

In the blog post, I used the + operator and sum() aggregate function interchangeably to be brief. Actually, those two operations are related, but have different representations in distributed relational algebra. I updated the first footnote in the post to reflect that.

For your comment, we have in fact two questions. First, is the ExtendedOp commutative with the Collect operator? Second, if it isn't, what properties do our transformations need to respect so that we can pull up the Collect? (equivalence property and associativity)

It's hard to be comprehensive about distributed relational algebra in a blog post. For example, the given logical tree doesn't have enough operator primitives to express large table joins. If you'd like, I'd be happy to get together and chat more about the details.

Re: How to Build Your Distributed Database

#24
Interesting but missing a bit of rigor up to being wrong.

If we can compute a sum as a sum of sub-sums, or a count as sum of sub-counts, this is no because addition is commutative `a+b=b+a` (i.e order of operands doesn't matter), but because addition is associative `(a+b)+c=a+(b+c)` (i.e order of operations doesn't matter).

So we can define, `sum(a,b,..,z) = a+b+..+z` whatever is the order of the operations (say `(((a+b)+c)+..+z)` or `(a+(b+(c+...+z)))` or ...). And if we have to compute the sum of two lists xs and ys, we can compute either `sum(append(xs,ys))` or `sum(sum(xs),sum(ys))`.

Likewise, if we can "pull up Collect nodes and push down Computation nodes" in some cases this is not because the involved computation commutes, but because the operation is in some sense compatible with the collection structure and its collect operation.

What we need is an associative operation used to merge the results computed on parts of the collection, so:

  computation(merge_dataset(xs,ys)) = merge_results(computation(xs),computation(ys))

For summation and counting, the merge operation is addition. For filtering the merge operation is simply the former collection collect operation. So we have:

        sum(append(xs,ys)) = sum(sum(xs),sum(ys))
        count(append(xs,ys)) = sum(count(xs),count(ys))
        filter(append(xs,ys)) = append(filter(xs),filter(ys))

The abstract concept behind all this is monoid homomorphims (1) and, if you are looking for further readings, I wrote a post on how this concept is related to map-reduce and parallelism (2).

- (1) https://en.wikipedia.org/wiki/Monoid#Monoid_homomorphisms.

- (2) http://acidalie.free.fr/unfoldvalue/blog/map-reduce-spirit.h...

Post reply on HN