Database query processing requires algorithms for duplicate removal, grouping, and aggregation. Three algorithms exist: in-stream aggregation is most efficient by far but requires sorted input; sort-based aggregation relies on external merge sort; and hash aggregation relies on an in-memory hash table plus hash partitioning to temporary storage. Cost-based query optimization chooses which algorithm to use based on several factors including the sort order of the input, input and output sizes, and the need for sorted output. For example, hash-based aggregation is ideal for output smaller than the available memory (e.g., TPC-H Query 1), whereas sorting the entire input and aggregating after sorting are preferable when both aggregation input and output are large and the output needs to be sorted for a subsequent operation such as a merge join. Unfortunately, the size information required for a sound choice is often inaccurate or unavailable during query optimization, leading to sub-optimal algorithm choices. In response, this paper introduces a new algorithm for sort-based duplicate removal, grouping, and aggregation. The new algorithm always performs at least as well as both traditional hash-based and traditional sort-based algorithms. It can serve as a system's only aggregation algorithm for unsorted inputs, thus preventing erroneous algorithm choices. Furthermore, the new algorithm produces sorted output that can speed up subsequent operations. Google's F1 Query uses the new algorithm in production workloads that aggregate petabytes of data every day.
翻译:数据库查询处理需要重复清除、 分组和汇总的算法。 存在三种算法: 流中汇总效率最高, 但需要分类输入; 基于排序的汇总依赖于外部合并排序; 散列汇总依赖于一个内模的散列表, 加上散列分割到临时存储。 基于成本的查询优化选择了基于若干因素使用的算法, 包括输入、 输入和输出大小的排序顺序, 以及排序输出的需要。 例如, 基于散列的汇总对于小于现有记忆的产出( 例如, TPC- H Query 1)是理想的, 而排序后的整批次整合依赖于外部合并排序则更可取; 当聚合的输入和输出都很大, 而后排序则需要将产出排序到一个类似合并的操作中。 不幸的是, 在查询优化过程中, 需要的任意选择所需的大小信息往往不准确或不可用, 导致子优化的算法选择。 对此, 本文为基于排序的重复清除、 组合和汇总, 新的算法总是至少以总算法方式进行一次的排序,, 因此, 也只能用一种错误的算法的算法 。