Reducing Data Transfer in Parallel Processing of SQL Window Functions Fabio´ Coelho, Jose´ Pereira, Ricardo Vilac¸a and Rui Oliveira INESC TEC & Universidade do Minho, Braga, Portugal Keywords: Window Functions, Reactive Programming, Parallel Systems, OLAP, SQL. Abstract: Window functions are a sub-class of analytical operators that allow data to be handled in a derived view of a given relation, while taking into account their neighboring tuples. We propose a technique that can be used in the parallel execution of this operator when data is naturally partitioned. The proposed method benefits the cases where the required partitioning is not the natural partitioning employed. Preliminary evaluation shows that we are able to limit data transfer among parallel workers to 14% of the registered transfer when using a naive approach. 1 MOTIVATION s e l e c t rank() OVER(Partition By A Order By B) from t a b l e Window functions (WF) are a sub-group of analyti- Listing 1: Window Function example. cal functions that allow to easily formulate analyti- With the Big Data trend and growing volume of data, cal queries over a derived view of a given relation R. the need for real-time analytics is increasing, thus re- They allow operations like ranking, cumulative aver- quiring systems to produce results directly from pro- ages or time series to be computed over a given data duction data, without having to transform, conform partition. Each window function is expressed in SQL and duplicate data as systems currently do. Therefore, by the operator OVER, which is complemented with parallel execution becomes the crux of several hybrid a partition by (PC), an order by (OC) and a grouping databases that fit in the category of Hybrid Transac- clause (GC). A given analytical query may hold sev- tional and Analytical Processing (HTAP). These sys- eral analytical operators, each one bounded by a given tems typically need to leverage all parallelization and window function. Each partition or ordering clause optimization opportunities, being usually deployed in represents one, or a combination of columns from a a distributed mesh of computing nodes, where data given relation R. and processing are naturally partitioned. In one of Despite its relavance, optimizations considering the methods to query such systems, each node com- this operator are almost nonexisting in the literature. putes the results for the data partitions they hold, con- The work by (Cao et al., 2012) or (Zuzarte et al., tributing to the overall final result. Nonetheless, the 2003) are some of the execeptions. Respectively, the data partitioning is usually achieved by means of a first overcomes optimization challenges related with single primary column in a relation. This impacts having multiple window functions in the same query, mainly cases where the partitioning clause does not while the second presents a more broad use of win- match the natural partitioning, thus compromising the dow functions, showing that it is possible to use them final result for a sub group of non-cumulative analyt- as a way to avoid sub-queries and reducing execution ical operators, as all members of a distinct partition time down from quadratic time. need to be handled by a single entity. A naive solu- Listing 1 depicts a SQL query where the analyt- tion would be to forward the partition data among all ical operator rank is bounded by a window function, nodes, but the provision of such a global view in every which holds a partition and ordering clause respec- node would compromise bandwidth and scalability. tively for columns A and B. The induced partitioning Data distribution is among one of the cornerstones of is built from each group of distinct values in the parti- a new class of data substrates that allows data to be tion clause and ordered through the order by clause. A sliced into a group of physical partitions. In order single value corresponding to the analytical operator to split a relation, there are usually two main trends, is added to each row in the derived relation. namely: Vertical (Navathe et al., 1984) and Hori- 343 Coelho, F., Pereira, J., Vilaça, R. and Oliveira, R. Reducing Data Transfer in Parallel Processing of SQL Window Functions. In Proceedings of the 6th International Conference on Cloud Computing and Services Science (CLOSER 2016) - Volume 1, pages 343-347 ISBN: 978-989-758-182-3 Copyright c 2016 by SCITEPRESS – Science and Technology Publications, Lda. All rights reserved DataDiversityConvergence 2016 - Workshop on Towards Convergence of Big Data, SQL, NoSQL, NewSQL, Data streaming/CEP, OLTP and OLAP zontal (Sadalage and Fowler, 2012) partitioning. To nodes, producing unnecessary use of bandwidth and do so, the relation needs to be split either by using processing power. (e.g.) range or hash partitioning. Hashing algorithms In this position paper we show that if data distri- are used to split a given domain – which is usually bution of each column in a relation is approximately achieved through a primary key in database notation known beforehand, the system is able to adapt and – into a group of buckets with the same cardinality of save network and processing resources by forward- the number of computing nodes. An hash algorithm is ing data to the right nodes. The knowledge needed is defined by an hash function (H) that makes each com- the cardinality and size (in bytes) in each tuple par- puting node accountable for a set of keys, allowing to tition rather than considering the actual tuple value map which node is responsible for a given key. as seen in common use of database indexes. This The distributed execution of queries leverages on knowledge would then be used by an Holistic shuf- data partitioning as a way to attain gains associated fler which according to the partitioning considered by with parallel execution. Nevertheless, the partition- the ongoing window function would instruct workers ing strategies typically rely on a primary table key to to handle specific partitions, minimizing data transfer govern the partitioning, which only benefits the cases among workers. where the partitioning of a query matches that same key. When the query has to partition data according to a different attribute in a relation, it becomes likely that the members of each partition will not all reside 2 STATISTICS in the same node. Histograms are commonly used by query optimizers select rank() OVER (partition by A) from table as they provide a fairly accurate estimate on the data distribution, which is crucial for the query planner. PK A B PK A B PK A B An histogram is a structure which allows to map keys 1 1 1 2 1 1 3 2 1 1 1 2 2 2 3 3 2 1 to their observed frequencies. Database systems use 1 2 1 2 2 3 3 2 3 these structures to measure the cardinality of keys or 1 3 1 2 3 1 3 2 3 key ranges. Relying on statistics such as histograms node #1 node #2 node #3 takes special relevance in workloads where data is Figure 1: Data partitioning among 3 workers. skewed (Poosala et al., 1996), a common character- istic of non synthetic data, as their absence would Figure 1 presents the result from hash partitioning induce the query optimizer to consider uniformity a Relation into 3 workers according to the primary across partitions. key (PK). The query presented holds a window oper- While most database engines use derived ap- ator that should produce a derived view induced by proaches of the previous technique, they only allow to partitioning attribute A. establish an insight regarding the cardinality of given Non-cumulative aggregations such as rank require attributes in a relation. When considering a query all members of a given partition to be collocated, in engine that has to generate parallel query execution order not to incur in the cost of reordering and recom- plans to be dispatched to distinct workers, each one puting the aggregate after the reconciliation of results holding a partition of data; such histograms do not among nodes. However, different partitions do not completely present a technique that could be used to share this requirement, thus enabling different parti- enhance how parallel workers would share prelimi- tions to be processed in different locations. To ful- nary and final results. This is so as they only introduce fill the data locality requirement, rows need to be for- and insight about the cardinality of each partition key. warded in order to reunite partitions. In order to minimize bandwidth usage, thus reducing The shuffle operator arises as way to reunite parti- the amount of traded information, the histogram also tions and to reconcile partial computations originated needs to reflect the volume of data existing in each by different computing nodes. The shuffler in each node. To understand the relevance of having an intu- computing node has to be aware of the destination ition regarding the row size, please consider that we where to send each single row, or if it should not send have 2 partitions with exactly the same cardinality of it at all. Typically, this is achieved by using the mod- rows that need to be shuffled among workers. From ular arithmetic operation of the result of hashing the this point of view the cost of shuffling each row is the partition key over the number of computing nodes. same. However, if the first row has an average size However, this strategy is oblivious to the volume of of 10 bytes, and the second 1000 bytes, then shuf- data each node holds of each partition. In the worst fling the second implies transferring 100 times more case, it might need relocate all partitions to different data over the network.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages5 Page
-
File Size-