Problemcore
Distributed query processing problem
Also called distributed query optimization.
Compute a query over relations stored at several sites while minimizing data shipped, response time or total cost.
The distributed query processing problem asks how to compute a query when its relations, or the fragments of its relations, are stored at different sites of a network. The answer does not depend on where the data is, but the cost does: a plan must also say at which site each operator runs and which data moves between sites. Moving data costs time and bandwidth, so the classic goal is to ship as little data as possible; other cost models count the total work of all sites, or the response time when the sites work in parallel. The problem contains centralized query optimization, and so it is NP-hard in general. The main tools are the rewriting of a query on the fragments, the choice of join order and join site, and semijoins that reduce a relation before it is sent.
In plain words
A question asks about tables that are kept in different cities. To answer it, some data must travel from one city to another, and travel is slow and costly. The same answer can be found in many ways. You can send a whole table to the city of another table and combine them there. Or you can first send only a short list of the values that matter, so that the other city sends back only the rows that match. You can also skip the pieces of a table that cannot hold an answer at all. The problem is to choose the way that sends the least data, or that does the least total work, or that gives the answer the soonest. There are very many ways, so systems use good rules and estimates, not a full search.
Definition
Input.
- A query over global relations, for example a select, project and join query in relational algebra.
- A fragmentation of each global relation, horizontal, vertical or both, and an allocation of the fragments and their copies to sites, as on the page of the data allocation problem.
- The site where the result is needed.
- Statistics for a cost model: sizes, selectivities and the costs of local work and of messages.
Output. A distributed plan: a tree of operators on fragments, each operator at a site, with a transfer operator for each edge between two sites. The plan must compute on every database that matches the fragmentation, with bag semantics, and must deliver the result to the result site.
Cost. One of the following, with estimates from cardinality estimation.
- Communication cost. The number of bytes, or the number of messages and bytes, sent between sites. This is the model of SDD-1, which was built for slow wide area networks.
- Total cost. The sum of the local processor and disk work at all sites and the communication cost.
- Response time. The time from the start of the query to the last row of the result, where work at different sites can overlap.
The goal is a plan of least estimated cost. Most systems split the work into four steps: decomposition rewrites the query in algebra on the global relations, localization replaces each global relation by its fragments and removes the fragments that cannot contribute, global optimization chooses the join order, the sites and the transfers, and local optimization chooses the plan at each site.
Variants
- Wide area or local network. On a slow network, communication dominates and the cost counts only shipped data. On a fast network, local work matters as much, and the total cost or the response time is used.
- Data shipping, query shipping or hybrid shipping. The plan can bring the data to the site of the query, send the query to the data, or mix the two, as Kossmann (2000) surveys.
- Parallel query processing. In a shared-nothing parallel system, all sites are in one cluster and the goal is the response time. Plans repartition the data with exchange operators and run joins such as the parallel hash join on all nodes at once.
- One round of communication. In massively parallel models, the goal is the largest amount of data that any one server receives. The hypercube shares join computes a multiway join in one round.
- Autonomous sites. In a federation of independent databases, the optimizer has few statistics and the sites can refuse some plans, so plans adapt during execution.
Examples
Localization. The relation is fragmented by branch into at site 1, at site 2 and at site 3. The query becomes . The predicates of and contradict , so localization reduces the query to , which runs at site 2 alone.
Shipping a relation or a semijoin. The query is , with the result needed at site 2. The relation is at site 1, with 1000 rows of 20 bytes each. The relation is at site 2, and its column has 50 distinct values of 4 bytes each. Assume that 100 rows of have a value that occurs in .
| plan | data shipped |
|---|---|
| send to site 2 and join there | bytes |
| send to site 1, compute , send it to site 2 and join | bytes |
The semijoin plan ships about a ninth of the data. If 900 rows of matched, the semijoin plan would ship bytes, and its saving would be small. Algorithms such as SDD-1 estimate this benefit for each semijoin and use a semijoin only when the benefit is larger than its cost. A Bloom join sends a Bloom filter in place of , which is smaller but lets some extra rows through.
A cyclic query that semijoins cannot reduce. Let , and . Each pair of relations shares one attribute, and on it both relations have the values , so every semijoin keeps every row. But is empty: and give rows with , and has no row with . So a semijoin program must send all six rows, although the result is empty.
Known algorithms
- Semijoin programs. SDD-1 (Bernstein, Goodman, Wong, Reeve and Rothnie 1981) adds the semijoin with the largest estimated benefit while the benefit is larger than the cost, and then sends the reduced relations to the site that holds the most data. It is a hill climbing heuristic.
- Full reducers for tree queries. For a tree query, an acyclic query in the sense of acyclic hypergraphs, two passes of semijoins over a join tree remove every row that is not in the result. The Yannakakis algorithm adds a join pass and computes the query in time linear in the input and the output.
- Join ordering with sites. The dynamic programming of centralized join ordering extends to plans in which each join also has a site and each input is shipped whole or row by row. The search space is larger, so large queries use greedy or randomized search.
- Bloom joins. A Bloom join is a semijoin with a compact, lossy filter; it costs less to send, and the false positives are removed by the final join.
- Repartitioning joins. In parallel and cluster systems, both inputs are hashed on the join key and sent to the nodes, as in the parallel hash join and the reduce-side join; a small input is sent to all nodes instead, as in the map-side join.
| Algorithm | Time | Space | Properties | Code |
|---|---|---|---|---|
| SDD-1 semijoin optimization | O(q^3 e) worst | O(q e) extra | deterministicnot exactnot in placeofflineiterative | 1 language |
Bounds
Theorem (NP-hard). Distributed query optimization with the total cost is NP-hard. Proof. With one site, the communication cost is zero, and the problem is centralized join ordering, which is NP-hard by the results on join ordering NP-hardness.
Theorem (full reducers). A query has a full reducer, a semijoin program that removes every row that is not in the result on every database, if and only if it is a tree query. Bernstein and Chiu (1981) gave the full reducers for tree queries, and Bernstein and Goodman (1981) showed that cyclic queries have none. The triangle example above shows the cyclic case.
Optimality of the heuristics. SDD-1 and the other greedy semijoin methods do not find the cheapest plan in general; Bernstein et al. (1981) say that the result of Algorithm OPT is, in general, suboptimal. Their quality is a measurement, and it depends on the accuracy of the size estimates.
Reductions
From centralized query optimization. The one-site case is the centralized problem, as in the proof above. So every hardness result for join ordering also holds here.
To queries on fragments. A horizontally fragmented relation is the bag union of its fragments, and joins and selections distribute over bag unions: . A vertically fragmented relation is the join of its fragments on the key. Localization uses these rules to turn a query on global relations into a query on fragments, and then removes the terms that are empty by their predicates.
To acyclic join evaluation. For a tree query, the semijoin passes of a full reducer leave relations that join without empty intermediate rows, so the problem of what to ship reduces to acyclic join evaluation at the result site.
Applications
- Distributed database systems. SDD-1 and later distributed systems optimize queries over fragments stored at several sites, and the textbook of Özsu and Valduriez organizes the problem in the four steps above.
- Parallel databases and cloud data warehouses. Shared-nothing systems plan repartitioning and broadcast joins on clusters to cut the response time.
- Big data systems. Joins in MapReduce and its successors are distributed joins with a cost that counts the data shuffled between machines.
- Federated and mediator systems. Queries over independent sources send subqueries to the sources and combine the answers.
References
- Donald Kossmann, The state of the art in distributed query processing, ACM Computing Surveys 32(4), 2000, pages 422 to 469, the survey of the architectures, the cost models and the techniques of distributed query processing
- Philip A. Bernstein, Nathan Goodman, Eugene Wong, Christopher L. Reeve and James B. Rothnie Jr., Query processing in a system for distributed databases (SDD-1), ACM Transactions on Database Systems 6(4), 1981, pages 602 to 625, the cost model that counts only the data sent between sites, and Algorithm OPT, which builds a semijoin program and then sends the reduced relations to one site
- Philip A. Bernstein and Dah-Ming W. Chiu, Using semi-joins to solve relational queries, Journal of the ACM 28(1), 1981, pages 25 to 40, tree queries and the semijoin programs that fully reduce them
- Philip A. Bernstein and Nathan Goodman, Power of natural semijoins, SIAM Journal on Computing 10(4), 1981, pages 751 to 771, the power of semijoin programs on cyclic queries, which in general have no full reducer
- M. Tamer Özsu and Patrick Valduriez, Principles of Distributed Database Systems, fourth edition, Springer, 2020, Chapter 4, Distributed Query Processing (query decomposition, data localization, join ordering in distributed queries, and semijoin based algorithms)
Where this leads
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag E70YMS Edit this page History Report an error Markdown