Givens Rotations for QR Decomposition, SVD and PCA over Database Joins

This article introduces FiGaRo , an algorithm for computing the upper-triangular matrix in the QR decomposition of the matrix defined by the natural join over relational data. FiGaRo ’s main novelty is that it pushes the QR decomposition past the join. This leads to several desirable properties. For acyclic joins, it takes time linear in the database size and independent of the join size. Its execution is equivalent to the application of a sequence of Givens rotations proportional to the join size. Its number of rounding errors relative to the classical QR decomposition algorithms is on par with the database size relative to the join output size. The QR decomposition lies at the core of many linear algebra computations including the singular value decomposition (SVD) and the principal component analysis (PCA). We show how FiGaRo can be used to compute the orthogonal matrix in the QR decomposition, the SVD and the PCA of the join output without the need to materialize the join output. A suite of experiments validate that FiGaRo can outperform both in runtime performance and numerical accuracy the LAPACK library Intel MKL by a factor proportional to the gap between the sizes of the join output and input.


Introduction
This paper revisits the fundamental problem of computing the QR decomposition: Given a matrix A ∈ R m×n , its (thin) QR decomposition is the multiplication of the orthogonal matrix Q ∈ R m×n and the upper-triangular matrix R ∈ R n×n [30].This decomposition originated seven decades ago in works by Rutishauser [47] and Francis [21].There are three classical algorithms for QR decomposition: Gram-Schmidt and its modified version [28,52], Householder [31], and Givens rotations [24].
QR decomposition lies at the core of many linear algebra techniques and their machine learning applications [55,26,53] such as the matrix (pseudo) inverse and the least squares used in the closed-form solution for linear regression.In particular, the upper-triangular matrix R shares the same singular values with A; its singular value decomposition can be used for the principal component analysis of A; it constitutes a Cholesky decomposition of A T A, which is used for training (non)linear regression models using gradient descent [51]; the product of its diagonal entries equals (ignoring the sign) the determinant of A, the product of the eigenvalues of A, and the product of the singular values of A.
In the classical linear algebra setting, the input matrix A is fully materialized and the process that constructs A is irrelevant.Our database setting is different: A is not materialized and instead defined symbolically by the join of the relations in the input database.Our goal is to compute the QR decomposition of A without explicitly constructing A. This is desirable in case A is larger than the input database.By pushing the decomposition past the join down to the input relations, the runtime improvement is proportional to the size gap between the materialized join output and the input database.This database setting has been used before for learning over relational data [40].Joins are used to construct the training dataset from all available data sources and are unselective by design (the more labelled samples available for training, the better).This is not only the case for manyto-many joins; even key-fkey joins may lead to large (number of values in the) output, where data functionally determined by a key in a relation is duplicated in the join output as many times as this key appears in the join output.By avoiding the materialization of this large data matrix and by pushing the learning task past the joins, learning can be much faster than over the materialized matrix [40].Prior instances of this setting include pushing sum aggregates past joins [59,34] and the computation of query probability in probabilistic databases [41].
This article introduces FiGaRo, an algorithm for computing the upper-triangular matrix R in the QR decomposition of the matrix A defined by the natural join of the relations in the input database.The acronym FiGaRo stands for Factorized Givens Rotations with the letters a and i swapped.
FiGaRo enjoys several desirable properties.
1. FiGaRo's execution is equivalent to a sequence of Givens rotations over the join output.Yet instead of effecting the rotations individually as in the classical Givens QR decomposition, it performs fast block transformations whose effects are the same as for long sequences of rotations.
2. FiGaRo takes time linear in the input data size and independently of the size of the (potentially much larger) join output for acyclic joins.It achieves this by pushing the computation past the joins.
3. Its transformations can be applied independently and in parallel to disjoint blocks of rows and also to different columns.This sets it apart from inherently sequential mainstream methods for QR decomposition of materialized matrices such as Gram-Schmidt.
4. FiGaRo can outperform both in runtime performance and accuracy the LAPACK library Intel MKL by a factor proportional to the gap between the join output and input sizes, which is up to three orders of magnitude in our experiments (Sec.9).We show this to be the case for both key -foreign key joins over two real-world databases and for many-to-many joins of one real-world and one synthetic database.We considered matrices with 2M-125M rows (84M-150M rows in the join matrix) and both narrow (up to 50 data columns) and wide (thousands of data columns).
The choice of the join tree can significantly influence the performance (up to 47x).
FiGaRo is more accurate than MKL as it introduces far less rounding errors in case the join output is larger than the input database.
In Sec. 8, we further extended FiGaRo to compute: the orthogonal matrix Q in the QR decomposition of A, the singular value decomposition (SVD) of A, and the principal component analysis (PCA) of A. These computations rely essentially on the fast and accurate computation of the upper-triangular matrix R, are done without materializing A, can benefit from pushing past joins dot products that are computed once and reused several times, and are amenable to partial computation in case only some output vectors are needed, such as the top-k principal components.We show experimentally that these optimizations yield runtime and accuracy advantages of FiGaRo over Intel MKL.
For QR decomposition, we designed an accuracy experiment of independent interest (Appendix A).The accuracy of an algorithm for QR decomposition is commonly based on how close the computed matrix Q is to an orthogonal matrix.We introduce an alternative approach that allows for a fragment R fixed of the upper-triangular matrix R to be chosen arbitrarily and to serve as ground truth.Two relations are defined based on R fixed .We then compute the QR decomposition of the Cartesian product of the two relations and check how close R fixed is to the corresponding fragment from the computed upper-triangular matrix.
Our work complements prior work on linear algebra computation powered by database engines [37,61,49,18,7] and on languages that unify linear algebra and relational algebra [32,22,16].No prior work considered the interaction of QR decomposition with database joins.This requires a redesign of the decomposition algorithm from first principles.FiGaRo is the first approach to take advantage of the structure and sparsity of relational data to improve the performance and accuracy of QR decomposition.The sparsity typically accounts for blocks of zeroes in the data.In our work, sparsity is more general as it accounts for blocks of arbitrary values that are repeated many times in the join output.FiGaRo avoids such repetitions: It computes once over a block of values and reuses the computed result instead of recomputing it at every repetition.
We introduce FiGaRo in several steps.We first explain how it works on the materialized join (Sec.4) and then on the unmaterialized join modelled on any of its join trees (Sec.6).FiGaRo requires the computation of a batch of group-by counts over the join.This can be done in only two passes over the input data (Sec.5).To obtain the desired upper-triangular matrix, FiGaRo's output is further post-processed (Sec.7).
This article extends a conference paper [43] with three new contributions.FiGaRo was extended to also compute: the orthogonal matrix Q in the QR decomposition of A, an SVD of A, and the PCA of A (Sec. 8).This extension was implemented and benchmarked against mainstream approaches based on Intel MKL for both runtime performance and accuracy (Sec.9).The article also extends the introductory example (Sec.1.1) and the related work (Sec.10).

Givens Rotations on the Cartesian Product
We next showcase the main ideas behind FiGaRo and start with introducing a (special case of) Givens rotation.A 2 × 2 Givens rotation matrix is a matrix G = cos θ − sin θ sin θ cos θ for some angle θ (see Def. 1 for the definition of the general d × d case).If θ is selected appropriately, applying a Givens rotation introduces zeros in matrices.Consider a matrix , where a, b are real numbers with b ̸ = 0. We can visualize B as a vector in the two-dimensional Cartesian coordinate system.The matrix multiplication GB represents the application of the rotation G to B: its effect is to rotate the vector B counter-clockwise through the angle θ about the origin.We can choose θ such that the rotated vector lies on the x-axis, so, having 0 as second component: if we choose θ such that sin θ = − sign(a)b When applied to matrices that represent the output of joins, Givens rotations can compute the QR decomposition more efficiently than for arbitrary matrices.We sketch this  next for the Cartesian product of two unary relations.Consider the matrices S = where represents the Cartesian product of these two unary relations, so, their natural join.We would like to compute the upper-triangular matrix R in the QR decomposition of A: A = QR. 1he classical Givens rotations algorithm constructs the upper-triangular matrix R from A by using Givens rotations to zero each cell below the diagonal in A. A sequence of Givens rotations can be used to set all entries below the diagonal of any matrix A to 0, thus obtaining an upper triangular matrix.The left multiplication of these rotation matrices yields the orthogonal matrix Q in the QR decomposition of A. This approach needs time quadratic in the input S and T: it involves applying 2pq − 3 rotations, one rotation for zeroing each cell below the diagonal in A. This takes 13(2pq − 3) multiplication, division, square, and square root operations.In contrast, FiGaRo constructs R from S and T in linear time using 30(p + q) such operations.
Suppose we use Givens rotations to introduce zeros in the first column of the block  .So, we want to apply Givens rotations to a matrix column that consists of a single value and our goal is to set every occurrence of this value to 0, apart of the first one.
This setting is sketched in Figure 1: we have a matrix that consists of a single column and all entries are equal to the same value s.Using Givens rotations, all but the first entry need to be set to 0. The first rotation is applied to the first and the second occurrence of s, so to a vector that has the value s in both components.This vector therefore has an angle of 45 degrees to the x-axis, independent of the value of s.So, the rotation angle θ is independent of s.We see this also when we calculate sin θ = − sign(s)s 2 as explained above.The result of the rotation is that the second occurrence of s is set to 0, the first occurrence becomes sign(s) For the second rotation, we choose θ based on the value √ 2s of the first entry and the value s of the third entry of the first column, with the aim of setting the latter to 0. The corresponding rotation with sin θ = − 1 3 and cos θ = 2 3 sets the first entry to √ 3s.This argument can be continued for larger columns: the rotation, which is used to set the k-th occurrence of s to 0, has sin θ = − 1 k and cos θ = k−1 k .We emphasize again that these rotations do not depend on the value s but only on the number of such values.

So, to set for the block
all occurrences of the value s 1 , apart the first, to 0, we can use a series of Givens rotations with sin θ = − 1 2 , . . ., − 1 q and cos θ = 1 2 , . . ., q−1 q , respectively.The same applies to all other blocks A i as well, so the same sequence of rotation angles can also be used to introduce zeros in the first column of every matrix A i .
Insight 1.For the matrix A i , there is a sequence G s of Givens rotations that sets the first occurrence of s i to s i √ q and all other occurrences to 0. G s is independent of the values in A i .
The blocks A i have a second column, each consisting of the same values t 1 , . . ., t q .As the same rotations are applied to each A i , the corresponding results have the same values t ′ j throughout all blocks.They do not depend on the values s i , so they can be computed from T alone.In Sec. 3, we show that this is possible in time O(q).Insight 2. G s yields the same values t ′ 1 , . . ., t ′ q in each matrix A ′ i .These values can be computed once.Among the blocks A ′ i , there are p occurrences of the row 0 t ′ j , for each 2 ≤ j ≤ q, and p rows of the form s i √ q t ′ 1 .These rows can be grouped to have the same structure as the blocks A i above: the second column consists of the same value t ′ j .So, rotations analogous to G s can be applied to these blocks to yield one row 0 t ′ j √ p and p − 1 rows 0 0 for each j ≥ 2, as well as one row s ′ 1 √ q t ′ 1 √ p and p − 1 rows s ′ i √ q 0 .The values s ′ i can be computed from S in time O(p) the same way as mentioned above and detailed in Sec. 3.
When all mentioned rotations are applied, we obtain the matrix A ′′ that consists of the blocks We observe the following four key points: (1) The matrix A ′′ has only p + q non-zero values.We do not need to represent all zero rows as they are not part of the result R.
(2) The values in A ′′ can be computed in one pass over S and T. We need to compute: √ p, √ q, and the values s ′ 1 , . . ., s ′ p , t ′ 1 , . . ., t ′ q .
(3) Our linear-time computation of the non-zero entries in A ′′ yields the same result as quadratically many Givens rotations.
(4) We see in Sec. 3 that the computation of the values in A ′′ does not require taking the squares of the input values, as done by the Givens QR decomposition.This means less rounding errors that would otherwise appear when squaring very large or very small input values.
So far, A ′′ is not upper-triangular.We obtain R from A ′′ using a post-processing step that applies a sequence of p + q − 3 rotations to zero all but the top three remaining non-zero values.
In summary, FiGaRo needs O(p + q) time to compute R in our example.Including post-processing, the number of needed squares, square roots, multiplications and divisions is at most 4(p + q), 3(p + q), 17(p + q) and 6(p + q), respectively.In contrast, the Givens QR decomposition works on the materialized Cartesian product and needs O(pq) time and computes 4pq squares, 2pq square roots, 16pq multiplications and 4pq divisions.
The linear-time behaviour of FiGaRo holds not only for the example of a Cartesian product, but for matrices defined by any acyclic join over arbitrary relations.In contrast, the runtime of any algorithm, which works on the materialized join output, as well as its square, square root, multiplication, and division computations are proportional to the size of the join output.

The FiGaRo algorithm: Setup
Relations and Joins.A database D consists of a set S 1 , . . ., S r of relations.Each relation has a schema (Z 1 , . . ., Z k ), which is a tuple of attribute names, and contains a set of tuples over this schema.We denote tuples (Z 1 , . . ., Z ℓ ) of attribute names by Z and tuples (z 1 , . . ., z ℓ ) of values by z.For every relation S i , we denote by Xi the tuple of its key (join) attributes and by Ȳi the tuple of the data (non-join) attributes.We allow key values of any type, e.g., categorical, while the data values are real numbers.We denote by Xij the join attributes common to both relations S i and S j .We consider the natural join of all relations in a database and write X and Ȳ for the tuple of all key and data attributes in the join output.A database is fully reduced if there is no dangling input tuple that does not contribute to the join output.A join is (α-)acyclic if and only if it admits a join tree [1]: In a join tree, each relation is a node and there is a path between the nodes for two relations S i and S j if all nodes along that path correspond to relations whose keys include Xij .
From Relations to Matrices.For a natural number n, we write [n] for the set {1, . . ., n}.Matrices are denoted by bold upper-case letters, (column) vectors by bold lower-case letters.Let a matrix A with m rows and n columns, a row index i ∈ [m] and a column index j ∈ [n].Then A[i : j] is the entry in row i and column j, A[i :] is the i-th row, A[: j] is the j-th column of A, and |A| is the number of rows in A. For sets I ⊆ [m] and J ⊆ [n], A[I : J] is the matrix consisting of the rows and columns of A indexed by I and J, respectively.
Each relation S i is encoded by a matrix S i that consists of all rows (x i , ȳi ) ∈ S i .The relation representing the output of the natural join of the input relations is encoded by the matrix A whose rows (x, ȳ) are over the key attributes X and data attributes Ȳ .We keep the keys and the column names as contextual information [16] to facilitate convenient reference to the data in the matrix.For ease of presentation, in this paper we use relations and matrices interchangeably following our above mapping.We use relational algebra over matrices to mean over the relations they encode.
We use an indexing scheme for matrices that exploits their relational nature.We refer to the matrix columns by their corresponding attribute names.We refer to the matrix rows and blocks by tuples of key and data values.Consider for example a ternary relation S with attribute names X, Y 1 , Y 2 .We represent this relation as a matrix S such that for every tuple (x, y 1 , y 2 ) ∈ S there is a matrix row S[x, y 1 , y 2 :] = x y 1 y 2 with entries S[x, y 1 , y 2 : X] = x, S[x, y 1 , y 2 : Y 1 ] = y 1 , and S[x, y 1 , y 2 : Y 2 ] = y 2 .We also use row indices that are different from the content of the row.We use * to denote sets of indices.For example, S[x, * : X, Y 1 ] denotes the block that contains all rows of S whose identifier starts with x, restricted to the columns X and Y 1 .
Input.The input to FiGaRo consists of (1) the set of matrices S 1 , . . ., S r , one per relation in the input fully-reduced database D, and (2) a join tree τ of the acyclic natural join of these matrices (or equivalently of the underlying relations). 2utput.FiGaRo computes the upper-triangular matrix R in the QR decomposition of the matrix block A[: Ȳ ], which consists of the data columns Ȳ in the join of the database relations.It first computes an almost upper-triangular matrix R 0 such that The QR decomposition always exists; whenever A has full rank, and R has positive diagonal values, the decomposition is unique [55, Chapter 4, Theorem 1.1].

Heads and Tails
Given a matrix, the classical Givens QR decomposition algorithm repeatedly zeroes the values below its diagonal.Each zero is obtained by one Givens rotation.In case the matrix encodes a join output, a pattern emerges: The matrix consists of blocks representing the Cartesian products of arbitrary matrices and one-row matrices (see Fig. 2(a)).The effects of applying Givens rotations to such blocks are captured using so-called heads and tails.Before we introduce these notions, we recall the notion of Givens rotations.
Definition 1 (Givens rotation).A d × d Givens rotation matrix is obtained from the d-dimensional identity matrix by changing four entries: G[i : i] = G[j : j] = cos θ, G[i : j] = − sin θ and G[j : i] = sin θ, for some pair i, j of indices and an angle θ.
We denote such a d-dimensional rotation matrix for given i, j and θ by Giv d (i, j, sin θ, cos θ).□ A rotation matrix is orthogonal.The result B = GA of the product of a rotation G and a matrix A ∈ R d×d is A except for the i-th and the j-th rows, which are subject to the counterclockwise rotation through the angle θ about the origin of the 2-dimensional Cartesian coordinate system: for each column c, B[i The following notions are used throughout the paper.Given matrices S ∈ R m 1 ×n 1 and T ∈ R m 2 ×n 2 , their Cartesian product S × T is the matrix with We now define the head and tail of a matrix, which we later use to express the Givens rotations over Cartesian products of matrices.
Definition 2 (Head and Tail).Let A be a matrix from R m×n .
The head H(A) ∈ R 1×n of A is the one-row matrix The tail T (A) ∈ R (m−1)×n of A is the matrix (for j ∈ [m − 1]) Let a matrix A that represents the Cartesian product of a one-row matrix S and an arbitrary matrix T. Then A is obtained by extending each row in T with the one-row S, as in Fig. 2(a).As exemplified in Sec.1.1, if all but the first occurrence of S in A is to be replaced by zeros using Givens rotations, the specific sequence of rotations only depends on the number of rows of T and not on the entries of S. The result of these rotations can be described by the head and tail of T.
, for all i ∈ {2, . . ., m}, be a Givens rotation matrix and let G = R m • • • R 2 be the orthogonal matrix that is the product of the rotations R m to R 2 .
The matrix U = GA obtained by applying the rotations R i to A is: .
In other words, the application of the m − 1 rotations to A yields a matrix with four blocks: the head and tail of T, S scaled by the square root of the number m of rows in T,   and zeroes over m − 1 rows and n 1 columns.So instead of applying the rotations, we may compute these blocks directly from S and T.
We also encounter cases where blocks of matrices do not have the simple form depicted in Fig. 2(a), but where the multiple copies of the one-row matrix S are scaled by different real numbers v 1 to v m , as in Fig. 2(b).In these cases, we cannot compute heads and tails as in Lemma 3 to capture the effect of a sequence of Givens rotations.However, a generalized version of heads and tails can describe these effects, as defined next.
Definition 4 (Generalized Head and Tail).For any vector v ∈ R m >0 and matrix A ∈ R m×n , the generalized head H(A, v) ∈ R 1×n and generalized tail T (A, v) ∈ R (m−1)×n of A weighted by v are: If v is the vector of ones, then ||v|| 2 = √ m and the generalized head and generalized tail become the head and tail, respectively.
We next generalize Lemma 3, where we consider each copy of S in A weighted by a positive scalar value from a weight vector v: the i-th row of T is appended by v i S, for some positive real v i , see Fig. 2(b).This scaling is expressed using the Kronecker product ⊗.Here again, to set all but the first (scaled) occurrences of S to zero using Givens rotations, we use that these rotations are independent of S and only depend on the scaling factors v and the number of rows in T. We use H(A, v) and T (A, v) to construct the result of applying the rotations to A.
, and T ∈ R m×n 2 be given and let , for all i ∈ {2, . . ., m}, be a Givens rotation matrix and let G be the orthogonal matrix Algorithm 1: Computing generalized tails in linear time.
The generalized head and tail can be computed in linear time in the size of the input matrix A. Lemma 6.Given any matrix A ∈ R m×n and vector v ∈ R m >0 , the generalized head H(A, v) and the generalized tail T (A, v) can be computed in time O(mn).
The statement is obvious for generalized heads H(A, v).We give the explanation for the tail.
Given the ℓ 2 -norm ||v[1, . . ., j]|| 2 of the vector v restricted to the first j entries, we can compute the same norm of v, now restricted to the first j + 1 entries, in constant time.Likewise, the sum , where i goes up to j, can be reused to compute the sum of these rows up to j + 1 in time proportional to the row length n.See Alg. 1 for details.
The following lemma follows immediately from Def. 4.
Lemma 7.For any matrix A ∈ R m×n , any vector v ∈ R m >0 , and any numbers k ∈ R and ℓ ∈ R >0 , the following holds: 4 Example: Rotations on a join output Sec.1.1 shows how to transform a Cartesian product of two matrices into an almost uppertriangular matrix by applying Givens rotations.Sec. 3 subsequently shows how the same result can be computed in linear time from the input matrices using the new operations head and tail, whose effects on matrices of a special form are summarized in Lemmas 3 and 5.
Towards an algorithm for the general case, this section gives an example of applying Givens rotations to a matrix that represents the natural join of four input relations.The insights gained from this example lead to the formulation of the FiGaRo algorithm.
(e) Join tree τ Our approach is as follows.The result of joining two relations is a union of Cartesian products: for each join key x, all rows from the first relation that have x as their value for the join attributes are paired with all rows from the second relation with x as their join value.Sec.1.1 and 3 explain how to process Cartesian products.Then we take the union of their results, so, accumulate the resulting rows in a single matrix.
Figure 3 sketches the input matrices S 1 , . . ., S 4 and the join tree τ used in this section.We explain S 1 , the other matrices are similar.The matrix S 1 in Figure 3(a) has a column X 12 that represents the key attribute common with the matrix S 2 .It contains two distinct values a 1 and a 2 for its join attribute X 12 .For each a j , there is one vector S for every tuple (a j , b k , c ℓ ) of join keys, with j, k, l ∈ {1, 2}.As mentioned in Sec. 2, we want to transform the matrix A[ Ȳ ], i.e., the projection of A to the data columns Ȳ , into a matrix R 0 that is almost upper-triangular.In particular, the number of rows with nonzero entries in R 0 needs to be linear in the size of the input matrices.We do this by repeatedly identifying parts of the matrix A[ Ȳ ] that have the form depicted in Figure 2 and by applying Lemmas 3 and 5 to these parts.Recall that each of these applications corresponds to the application of a sequence of Givens rotations.The matrix A[: Ȳ ] contains the rows with the following Cartesian product associated with the join keys (a 1 , b 1 , c 1 ): In turn, this Cartesian product is the union of Cartesian products and respectively S b 1 3 .The latter products have the form depicted in Figure 2(a): the Cartesian product of a one-row matrix [t 1 t 2 t 3 ] and an arbitrary matrix S c 1 4 .By applying Lemma 3 to each of them, we obtain the following rows, where we use This matrix contains one copy of T (S c 1 4 ) for every choice of t 1 , t 2 , t 3 .More copies of T (S c 1 4 ) arise when we analogously apply Lemma 3 to the rows of A[: Ȳ ] associated with join keys (a j , b k , c 1 ) that are different from (a 1 , b 1 , c 1 ).In total, the number of copies of T (S c 1 4 ) we obtain is so, the size of the join of all matrices except S 4 , where the attribute X 24 is fixed to c 1 .We denote this number by Φ • 4 (c 1 ).We apply more Givens rotations to the rows of the form [0 0 0] × T (S c 1 4 ).These are again Cartesian products, namely the Cartesian products of the zero matrix of dimension Φ • 4 (c 1 ) × 3 and each row t of T (S c 1 4 ).We can apply again Lemma 3 to these Cartesian products and obtain the rows The rows that only consist of zeros can be discarded, rows with non-zero entries become part of the (almost upper-triangular) result matrix R 0 .
We now turn back to the remaining rows, which are of the form As above, we view these rows as unions of (column-permutations of) Cartesian products , respectively.The corresponding applications of Lemma 3 yield the rows Considering also the rows that we analogously obtain for join keys 3 ) in total, and j∈{1,2} |S 3 ).We apply further Givens rotations to the rows that consist of zeros and the scaled copies of T (S b 1 3 ).For each row t of T (S b 1 3 ), we apply this time Lemma 5 to the matrix of all scaled copies of t and three columns of zeros.The result contains some all-zero rows and one row with entry t scaled by the ℓ 2 norm of the vector of the original scaling factors.This factor is the square root of which, similarly as above, is the size of the join of all matrices except S 3 , where the attribute X 23 is fixed to b 1 .We denote this number by Φ • 3 (b 1 ).In summary, the result of applying Lemma 5 contains, besides some all-zero rows, the rows The remaining columns are processed analogously.Up to now, the transformations result in all-zero rows, rows that contain the scaled tail of a part of an input matrix with other columns being 0, and one row for every join key (a j , b k , c ℓ ), for j, k, ℓ ∈ {1, 2}.We give the resulting rows for a j = a 1 , where for k, ℓ ∈ {1, 2} we use We observe that the entries in the column Y 1 only differ by the scaling factors α kℓ .It follows that we can apply Lemma 5, with The first row of the result is the generalized head of the above rows.For column Y 1 , this The term under the square root is the size of the join of all matrices in the subtree of S 3 in τ , where X 12 is fixed to a 1 .We denote this number by Φ ↓ 3 (a 1 ).We skip the discussion for the other columns.
The remaining rows are formed by the generalized tail.Column Y 1 has only zeros.For , v), and analogously for the columns Y 2 and Y 3 .
Figure 4: Count queries used by FiGaRo, defined over the join tree τ of the r input matrices S 1 , . . ., S r .Xi are the join attributes of S i and Xp are the join attributes that S i has in common with its parent in τ .Φ • i gives the number of tuples in the join of all relations except S i , grouped by the attributes Xi .Φ ↑ i and Φ ↓ i give the number of tuples in the join of the relations that are in the subtree of S i in τ respectively not in this subtree, grouped by the attributes Xp .Remark 8. Suppose S 1 would have another child S 5 in τ , so, S 1 would also have the join attributes X 15 .Then we would get one scaled copy of T 4,a 1 for every value of X 15 that occurs together with the value a 1 for X 12 .We would then apply Lemma 5 again.The scaling factor for T 4,a 1 we obtain in the general case is the square root of the size of the join of all relations that are not in the subtree of S 3 in τ , where X 12 is fixed to a 1 .In the simple case considered here, this value is |S a 1 1 |.
To sum up, the resulting non-zero rows are of the following form: The number of rows of type ( 1) is bounded by the overall number of rows in the input matrices minus the number of different join keys, as the tail of a matrix has one row less than the input matrix.The number of rows of type ( 2) is bounded by the number of different values for the join attributes (X 12 , X 23 , X 24 ) minus the number of different values for X 12 .The number of rows of type (3) is bounded by the number of different values for the join attribute X 12 .Together, the number of non-zero rows is bounded by the overall number of rows in the input matrices, as desired.

Scaling Factors as Count Queries
The example in Sec.1.1 applies Givens rotations to a Cartesian product.The resulting matrix uses scaling factors that are square roots of the numbers of rows of the input matrices.These numbers can be trivially computed directly from these matrices.In case of a matrix defined by joins, as seen in the preceding Sec. 4, these scaling factors are defined by group-by count queries over the joins.FiGaRo needs three types of such count queries at each node in the join tree.They can be computed together in linear time in the size of the input matrices.This section defines these queries and explains how to compute them efficiently.
We define the count queries Φ • i , Φ ↑ i and Φ ↓ i for each input matrix S i in a given join tree τ (i ∈ [r]).Fig. 4 depicts graphically the meaning of these count queries: They give the sizes of joins of subsets of the input matrices, grouped by various join attributes of S i : Φ ↑ i and Φ ↓ i join all matrices above and respectively below S i in the join tree τ , while Φ • i joins all matrices except S i .
Each of these aggregates can be computed individually in time linear in the size of the input matrices using standard techniques for group-by aggregates over acyclic joins [59,42].This section shows how to further speed up their evaluation by identifying and executing common computation across all these aggregates.This reduces the necessary number of scans of each of the input matrices from O(r) scans to two scans.
We recall our notation: τ be the join tree; Xi are the join attributes of S i and Xij are the common join attributes of S i and its child S j in τ .We assume that: each matrix S i is sorted on the attributes Xi ; and a child S j of S i in τ is first sorted on the attributes Xij .
We first initialize the counts rows_per_key i (x i ) for each matrix S i and value xi for its join attributes Xi .These counts give the number of those rows in S i that contain the join key xi for the columns Xi .This step is done in one pass over the sorted matrices and takes linear time in their size.The aggregates Φ ↓ i are computed in the same data pass.The computation of the aggregates Φ • i and Φ ↑ i is done in a second pass over the matrices.We utilize the following relationships between the aggregates.Computing Φ ↓ i : This aggregate gives the size of the join of the matrices in the subtree of S i in τ grouped by the join attributes Xp that are common to S i and its parent in τ .If S i is a leaf in τ , then Xp = Xi and Φ ↓ i (x i ) = rows_per_key i (x i ).If S i is not a leaf in τ , then we compute the intermediate aggregate which gives the size of the join of the same matrices as Φ ↓ i , but grouped by Xi instead of Xp .The reason for computing Θ ↓ i is that it is useful for other aggregates as well, as discussed later.This aggregate can also be expressed as where xij is the projection of xi to the join attributes Xij .The aggregate Φ ↓ i (x p ) is obtained by summing all values Θ ↓ i (x i ) such that xi projected to Xp equals xp .All aggregates Φ ↓ 1 , . . ., Φ ↓ r can thus be computed in a bottom-up traversal of the join tree τ and in one pass over the sorted matrices.Computing Φ ↑ i : This aggregate is defined similarly to Φ ↓ i , where the join is now over all matrices that are not in the subtree of S i in the join tree τ .It is computed in a top-down traversal of τ .
Assume Φ ↑ i (x p ) is already computed, where xp is a value for the join attributes Xp that S i has in common with its parent in τ .The intermediate aggregate full_join_size gives the size of the join over all matrices, grouped by Xi .For the root S 1 of τ , we set full_join_size 1 (x 1 ) = Θ ↓ 1 (x 1 ).We next define aggregates full_join_size ij (x ij ) that give the size of the join of all matrices for each value of the join attributes Xij that are common to S i and its child S j .They can be computed by summing up the values full_join_size i (x i ) for the keys Algorithm 2: Computing the count aggregates for FiGaRo.compute-counts(matrices S 1 , . . ., S r , join tree τ ) , rows_per_key i and Θ ↓ i are initially empty ordered maps, for every matrix S i (for the root S r of τ , Φ ↓ r , Φ ↑ r do not exist).
foreach child S j of S i in τ do pass 1 (j) foreach value xi of the join attributes Xi of S i do foreach child S j of S i in τ do ▷ let xij be the projection of xi onto Xij , the join attributes shared between S i and S j if S i is not the root of τ then ▷ let xp be the projection of xi onto the join attributes shared between S i and its parent in foreach value xi of the join attributes Xi of S i do if S i is not the root of τ then ▷ let xp be the projection of xi onto the join attributes shared by S i and its parent in xi that agree with xij on Xij .Since this size is the product of , where Φ ↓ j is already computed.For all children S j of S i , we can compute all sums full_join_size ij together in one pass over S i .

Computing Φ •
i : This aggregate gives the size of the join of all matrices except S i , grouped by the attributes Xi .If S i is a leaf in τ , then Φ • i = Φ ↑ i by definition.For a non-leaf S i , we re-use the values full_join_size i (x i ) defined above.This value is very similar to Φ • i (x i ), but also depends on the size rows_per_key i (x i ).More precisely, we need to divide full_join_size i (x i ) by rows_per_key i (x i ) to obtain Φ • i (x i ).Alg. 2 gives the procedure compute-counts for shared computation of the three aggregate types.First, in a bottom-up pass of the join tree τ , it computes the aggregates Θ ↓ i and Φ ↓ i .Then, it computes Φ ↑ i and Φ • i in a top-down pass over τ .The view full_join_size i is defined depending on whether S i is the root.For every child S j , the value full_join_size i is added to Φ ↑ j (x ij ).The division by Φ ↓ j (x ij ) is done just before the recursive call.Before that call, Φ • i is computed.
Lemma 9. Given the matrices S 1 , . . ., S r and the join tree τ , the aggregates and with two passes over these matrices.
We parallelize Alg. 2 by executing the loops starting in lines 7 and 15 in parallel for different values xi .Atomic operations are used for the assignments in lines 13 and 22 to handle concurrent write operations of different threads.

FiGaRo: Pushing rotations past joins
We are now ready to introduce FiGaRo.Alg. 3 gives its pseudocode.It takes as input the matrices S 1 , . . ., S r and a join tree τ of the natural join of the input matrices.It computes an almost upper-triangular matrix R 0 with at most rows such that R 0 can be alternatively obtained from the natural join of the input matrices by a sequence of Givens rotations.It does so in linear time in the size of the input matrices.In contrast to the example in Sec. 4, FiGaRo does not require the join output A to be materialized.Instead, it traverses the input join tree bottom-up and computes heads and tails of the join of the matrices under each node in the join tree.
FiGaRo uses the following two high-level ideas.First, the join output typically contains multiple copies of an input row, where the precise number of copies depends on the number of rows from other matrices that share the same join key.When using Givens rotations to set all but the first occurrence of a value to zero, this first occurrence will be scaled by some factor, which is given by a count query (Sec.5).FiGaRo applies the scaling factor directly to the value, without the detour of constructing the multiple copies and getting rid of them again.
Second, all matrix head and tail computations can be done independently on the different columns of the input matrix.FiGaRo performs them on the input matrix, where these columns originate, and combines the results, including the application of scaling factors, in a bottom-up pass over the join tree τ .
The algorithm.FiGaRo manages two matrices Data and Out.The matrix Out holds the result of FiGaRo, the matrix Data holds (generalized) heads that will be processed further in later steps.The algorithm proceeds recursively along the join tree τ , starting from the root.It maintains the invariant that after the computation finished for a non-root node S i of the join tree, Data contains exactly one row for every value of the join attributes that are shared between S i and its parent in τ .
For a matrix S i , FiGaRo first iterates over all values xi of its join attributes Xi .For each xi it computes head and tail of the matrix S xi i that is obtained by selecting all rows of S i that have the join key xi and then by projecting these rows onto the data columns Ȳi .The tail is multiplied with the scaling factor Φ • i (x i ) and written to the output Out, Algorithm 3: FiGaRo computes the almost upper-triangular matrix R 0 from the input matrices S 1 , . . ., S r with join tree τ .
FiGaRo (input matrices S 1 , . . ., S r , join tree τ , index i)  foreach child S j of S i in τ do project_away_join_attributes: ▷ Let Xp be the join attributes shared between S i and its parent in τ .So far, Data has one row for every value of Xi .Reduce this to one row for every value of Xp .
foreach value xp of the join attributes Xp in S i do where T k = 0 if S k is not in the subtree of S i in τ ; else adding zeros to other columns.The head is stored in the matrix Data.The scaling factor

|S xi
i | that, as per Lemma 3, is applied to other columns, is stored in the vector scales.If S i is a leaf in the join tree τ , then the invariant is satisfied.
If S i is not a leaf in the join tree τ , then the algorithm is recursively called for its children.Any output of the recursive calls is written to Out.The recursive call for the child S j also returns a matrix Data j that contains columns Ȳk with computed heads corresponding to this column, for all k such that S k is in the subtree of S j in τ , as well as scaling factors scales j .As to the maintained invariant, Data j contains exactly one row for every value of the join attributes Xij that are shared between S i and S j .
The contents of the matrices Data and Data j are joined.More precisely, for each join value xi of the attributes Xi of S i , the entry Data[x i : Ȳk ] is set to the entry Data j [x ij : Ȳk ], where xij is the projection of xi onto Xij .Also, scaling factors are applied to the different columns of Data.For the columns Ȳk , all scaling factors from scales and from the vectors scales j need to be applied, for all j such that S k is not in the subtree of S j .In the case of Ȳi , all factors from the vectors scales j are applied, but not from scales.
If S i is not the root of the join tree, rows of Data are aggregated in the procedure project_away_join_attributes to satisfy the invariant.Before entering the loop of Line 28, Data contains one row for every value xi of the join attributes Xi of Si .The number of rows is reduced in project_away_join_attributes such that there is only one row for every value xp of the join attributes Xp that are shared between S i and its parent in τ .To do so, FiGaRo iterates over all values xp of these attributes.For each xp it takes the rows of Data for the keys xi that agree with xp on Xp , and computes their generalized head and tail.The generalized tail is scaled by the factor Φ ↑ i (x p ) and written to Out, adding zeros for other columns.The matrix Data is overwritten with the collected generalized heads.So, the invariant is satisfied now.The scaling factor Φ ↓ i (x p ) equals the scaling factor that is applied to other columns as per Lemma 5, and is stored.
The next theorem states that indeed the result of FiGaRo is an almost upper-triangular matrix with a linear number of non-zero rows.It also states the runtime guarantees of FiGaRo.
Theorem 10.Let the matrices S 1 , . . ., S r represent fully reduced relations and let τ be any join tree of the natural join over these relations.Let A be the matrix representing this natural join.Let M be the overall number of rows and N be the overall number of data columns in the input matrices S i .
On input (S 1 , . . ., S r ,τ ,1), FiGaRo returns a matrix R 0 in O(M N ) time such that: (1) R 0 has at most M rows, (2) there is an orthogonal matrix Q such that We can parallelize FiGaRo by executing the loop starting in line 12 of Alg. 3 in parallel for different values xi , similarly for the loops starting in lines 28 and 21.As the executions are independent, no synchronization between the threads is necessary.
Comparison with Sec. 4. We exemplify the execution of FiGaRo using the same input as in Sec. 4 and depicted in Fig. 3.We will obtain the same result R 0 as in that section, modulo permutations of rows.
After the initial call of FiGaRo(S 1 , . . ., S 4 , τ, 1), at first heads and tails of S 1 are computed.We skip the explanation of this part and focus on the following recursive call of FiGaRo(S 1 , . . ., S 4 , τ, 2).When computing the heads and tails of S 2 , at first the matrices ) are padded with zeros and written to Out, for all j, k, ℓ ∈ {1, 2}.
Then, the entry Data[a j b k c ℓ : After joining the results and applying the scaling factors, the rows Data[a j b k c ℓ :] are as follows for every j, k, ℓ ∈ {1, 2}, with ) Notice the similarity to the corresponding rows from Sec. 4.There we obtained, for j = 1 and with H(S a 1 1 ), and the columns H(S c ℓ 4 ).
For j = 1, the only difference in the columns Y 2 to Y 4 is in the scaling factors α kℓ and β 1kℓ , which only differ by the factor |S a 1 1 |.The join attributes X 23 and X 24 are then projected away, as they do not appear in the parent S 1 of S 2 .Observe that the vectors that are used for defining the generalized heads and tails are the same here and in Sec. 4. For example, the part of scales that corresponds to , the vector used in Sec. 4.
So, the generalized heads and tails for the rows of Data associated with join keys a 1 and a 2 , respectively, have the same results as in Sec. 4 for the columns Y 2 to Y 4 , modulo the factor |S a 1 1 |.This factor equals Φ ↑ 2 (a 1 ), which FiGaRo applies to the generalized tails.That factor is also applied to the generalized heads in Data, namely by the procedure process_and_join_children in the call FiGaRo(S 1 , . . ., S 4 , τ, 1), after the call of FiGaRo for S 2 terminates.There, also the column Y 1 is added.The rows in the final result of FiGaRo(S 1 , . . ., S 4 , τ, 1) are then the same as in Sec. 4.

Post-processing
The output of FiGaRo is so far not an upper-triangular matrix, but a matrix R 0 consisting of linearly many rows in the size of the input matrices.The transformation of R 0 into the final upper-triangular matrix R is the task of a post-processing step that we describe in this section.This step can be achieved by general techniques for QR factorization, such as Householder transformations and textbook Givens rotations approaches.The approach we present here exploits the structure of R 0 , which has large blocks of zeros.
The non-zero blocks of R 0 are either tails of matrices (see line 13 of Alg.3), generalized tails of sets of matrices (line 29), or the content of the matrix Data at the end of the execution of FiGaRo (line 8).In a first post-processing step, these blocks are uppertriangularized individually and potentially arising all-zero rows are discarded.In a second post-processing step, the resulting block of rows is transformed into the upper-triangular matrix R.
In both steps we need to make blocks of rows upper-triangular, i.e., we need to compute their QR decomposition.This can be done using off-the-shelf Householder transformations.We implemented an alternative method dubbed THIN [27,12].It first divides the rows of a block among the available threads, each thread then applies a sequence of Givens rotations to bring its share of rows into upper-triangular form.Then THIN uses a classical parallel Givens rotations approach [26, p. 257] on the collected intermediate results to obtain the final upper-triangular matrix.
All approaches need time O(M N 2 ), where M is the number of rows and N is the number of columns of the input R 0 to post-processing.While the main part of FiGaRo works in linear time in the overall number of rows and columns of the input matrices (Theorem 10), post-processing is only linear in the number of rows.
8 From R to Q, SVD and PCA The previous sections focus on computing the upper-triangular matrix R ∈ R n×n in the QR decomposition of the matrix A ∈ R m×n representing the join output with m tuples and n data attributes.Using R and the non-materialized join matrix A, this section shows how to compute the orthogonal matrix Q in the QR decomposition of A, the singular value decomposition of A, and the principal component analysis of A.

The Orthogonal Matrix Q
Using A = QR, we can compute the orthogonal matrix Q ∈ R m×n as follows: Q = AR −1 .The upper triangular matrix R admits an inverse, which is also upper triangular, in case the values along the diagonal are non-zero.To compute Q, we do not need to materialize A! Each row in A represents one tuple in the join result.We can enumerate the rows in A without materializing A using factorization techniques from prior work [44,42].This enumeration has the delay constant in the size of the input database and linear in the number n of the data attributes.The delay is the maximum of three times: the time to output the first tuple, the time between outputting one tuple and outputting the next tuple, and the time to finish the enumeration after the last tuple was outputted.Before the enumeration starts, we calibrate the input relations by removing the dangling tuples, i.e., tuples that do not contribute to any output tuple.For acyclic joins (as considered in this article), this calibration takes time linear in the size of the input database [1].To enumerate, we keep an iterator over the tuples of each relation.We construct an output tuple in a top-down traversal of the join tree, where for each tuple at the iterator of a relation P we consider the possible matching tuples at the iterators of the relations that are children of P in the join tree.
where r 1 , . . ., r n are column vectors.Let the rows in A be t 1 , . . ., t m .The cell Q(i, j) is the dot product ⟨t i , r j ⟩.Once R −1 is computed in O(n 3 ) time, we can enumerate the cells in Q with delay constant in the size of the input database and linear in the number n of data attributes.To construct the entire matrix Q, it then takes O(mn 2 ) time.
We further use an optimization that pushes the computation of Q past the enumeration of the join output to reduce the complexity from O(mn 2 ) to O(mnℓ), where ℓ is the number of relations in the database.The idea is to compute dot products of each tuple in each relation with selected fragments of each column vector in R −1 .Such dot products can then be reused in the computation of many cells in Q, as explained next.
We assign a unique index i ∈ [n] to each of the n data attributes.Let I be the set of indices of the data attributes in an input relation.For each tuple s in that relation, we compute the dot products ⟨s(I), r 1 (I)⟩, . . ., ⟨s(I), r n (I)⟩, where s(I) is the vector of the values for data attributes in s and r i (I) is the vector of those values in r i at indices in I. Let us denote these dot products computed using s as s.d 1 , . . ., s.d n .The cell (i, j) in Q is then the sum of the j-th dot products for the input tuples s 1 , . . ., s ℓ that make up the i-th output tuple in the enumeration: In case of categorical data attributes, such dot products can be performed even faster.Assume a data attribute X with k distinct categories, and a tuple s that has at position i the ℓ-th value of X.If we were to one-hot encode X in s, then s would include a vector v of k values in place of this category, where v(ℓ) = 1 and v(ℓ Given a k-dimensional vector r, which is part of a vector in R −1 , the dot product ⟨v, r⟩ is then r(ℓ).This can be achieved even without an explicit one-hot encoding of X, the index ℓ suffices.

Singular Value Decomposition
The singular value decomposition of A ∈ R m×n is given by A = UΣV T , where U ∈ R m×n is the orthogonal matrix of left singular vectors, Σ ∈ R n×n is the diagonal matrix with the singular values along the diagonal, and V ∈ R n×n is the orthogonal matrix of right singular vectors.We can compute the SVD of A without materializing A using FiGaRo as follows.
The first step computes the upper triangular matrix R ∈ R n×n in the QR decomposition of A: A = QR.
The second step computes the SVD of R as: There are several off-the-shelf SVD algorithms [11], we used the divide-and-conquer algorithm [29] as this was numerically the most accurate in our experiments.Note that computing the SVD takes time O(n 3 ) for R ∈ R n×n and O(mn 2 ) for A ∈ R m×n .The former computation time is much less than the latter, since n is the number of data columns in the database whereas m ≫ n is the size of the join output.
The SVD of A can then be computed using the SVD of R as follows: R , where U = QU R is orthogonal as it is the multiplication of two orthogonal matrices, Σ = Σ R , and V = V R .This means that the singular values of R, as given by Σ R , are also the singular values of A. The right singular vectors of A are also those of R, as given by V R .
The third and final step computes the left singular vectors of A: where we use that U −1 R U R = I n .The matrices V R and Σ R are as computed in the previous step.The inverse Σ −1 R of the diagonal matrix Σ R is a diagonal matrix that has the diagonal values σ −1 i,i corresponding to the diagonal values σ i,i in Σ R .The multiplication S = Σ −1 R V R takes time O(n 2 ).We are then left to perform the multiplication of the non-materialized matrix A with the n × n matrix S, for which we proceed as for computing Q in Sec.8.1.

Principal Component Analysis
Following standard derivations, we can compute the principal components (PCs) of A using the computation of the SVD of A explained in Sec.8.2.
We compute the eigenvalues and eigenvectors of The sought eigenvalues and their corresponding eigenvectors are the squares of the singular values and respectively the right singular vectors of A, or equivalently of the uppertriangular matrix R computed by FiGaRo.The PCs of A are these right singular vectors in V = V R .It takes O(n 3 ) to compute all these PCs from R; in contrast, it takes O(mn 2 ) to compute them directly from A.
A truncated SVD of A is U :,1:k Σ 1:k,1:k V T :,1:k , where we only keep the top-k largest singular values and their corresponding left and right singular vectors.This defines a k-dimensional linear projection of A: Among all possible sets of k n-dimensional vectors, the vectors in V :,1:k , which are the top-k PCs of A, preserve the maximal variance in A. Equivalently, they induce the lowest error ||A − AV :,1:k V T :,1:k || 2 for reconstructing A as a k-dimensional linear projection (Eckart-Young-Mirsky theorem [17,39]).Applications of PCA require the top-k PCs for some value of k and sometimes also the k-dimensional linear projection of A.

Experiments
We evaluate the runtime performance and accuracy of FiGaRo against Intel MKL 2021.2.0 using the MKL C++ API (MKL called from numpy is slower) and our custom implementations.We also benchmarked OpenBLAS 0.13.3 called from numpy 1.22.0built from source, but it was consistently slower (1.5x) than MKL, so we do not report its performance further.Both MKL and OpenBlAS implement the Householder algorithm for the QR decomposition of dense matrices [31].We also benchmarked THIN as a standalone algorithm to compute R (Sec.7).
We use the following naming conventions: FiGaRo-THIN and FiGaRo-MKL are FiGaRo with THIN and MKL post-processing, respectively.In the plots, we also precede the system names by SVD or PCA to denote their versions that compute SVD or PCA respectively.FiGaRo and THIN use row-major order for storing matrices, while MKL uses column-major order; we verified that they perform best for these orders.
Experimental Setup.All experiments were performed on an Intel Xeon Silver 4214 (24 physical/48 logical cores, 1GHz, 188GiB) with Debian GNU/Linux 10.We use g++ 10.1 for compiling the C++ code using the Ofast optimization flag.The performance numbers are averages over 20 consecutive runs.We do not consider the time to load the Retailer (R) Favorita (F) Yelp  database into RAM and assume that all relations and the join output are sorted by their join attributes.All systems use all cores in all experiments apart from Experiment 2. Datasets.We use three datasets.Retailer (R) [51] and Favorita (F) [19] are used for forecasting user demands and sales.Yelp (Y) [60] has review ratings given by users to businesses.The characteristics of these datasets (Table 1) are common in retail and advertising, where data is generated by sales transactions or click streams.Retailer has a snowflake schema, Favorita has a star schema.Both have key-fkey joins, a large fact table, and several small dimension tables.Yelp has a star schema with many-to-many joins.We also consider a one-hot-encoding version of 1% of these datasets (OHE), where some keys are one-hot encoded in new data columns.They yield wider matrices.Some plots show performance for a percentage of the join output.The corresponding input dataset is computed by projecting the fragment of the join output onto the schemas of the relations.When taking a percentage of an OHE dataset, we map an attribute domain to that percentage of it using division hashing.
We also use synthetic datasets of relations S, T ∈ R m×n , whose join is the Cartesian product.The data in each column follows a uniform distribution in the range [−3, 3).For accuracy experiments, we fix (part of) the output R fixed and derive the input relation S so that the QR decomposition of the Cartesian product agrees with R fixed .The advantage of this approach is that R fixed can be effectively used as ground truth for checking the accuracy of the algorithms.

Summary
The main takeaway of our experiments is that FiGaRo significantly outperforms its competitors in runtime for computing QR, SVD, and PCA, as well as in accuracy for computing R, by a factor proportional to the gap between the join output and input sizes.This factor is up to two orders of magnitude.This includes scenarios with key-fkey joins over real data with millions of rows and tens of data columns and with many-to-many joins over synthetic data with thousands of rows and columns.Whenever the join input and output sizes are very close, however, FiGaRo's benefit is small; we verify this by reducing the number of rows and increasing the number of columns of our real data.When the number of data columns is at least the square root of the number of rows, e.g., 1K columns and 1M rows in our experiments, the performance gap almost vanishes.This is to be expected, since the complexity of computing the matrix R increases linearly with the number of rows but quadratically with the number of columns.We further show that FiGaRo's performance depends on the join tree.Also, the accuracy of the orthogonal matrices Q and U computed by FiGaRo depends on the condition number of the datasets and can be better or worse than MKL.
Yet there is not one flavor of FiGaRo that performs best in all our experiments.In case of thin matrices, i.e., with less than 50 data columns in the join output, or for very sparse matrices, such as those obtained by one-hot encoding, FiGaRo-THIN is the best as its QR post-processing phase can exploit effectively the sparsity in the result of FiGaRo's Givens rotations.For dense and wide matrices, i.e., with hundreds or thousands of data columns, FiGaRo-MKL is the best as its QR post-processing phase uses MKL that parallelizes better than THIN.Therefore, the following experiments primarily focus on the performance (in both runtime and accuracy) of the best of the two algorithms, with brief notes on the performance of the other algorithm.This means that we use FiGaRo-MKL for the experiments with the synthetic datasets and FiGaRo-THIN for the real-world datasets and their OHE versions.
FiGaRo is the only algorithm that works directly on the input database, all others work on the materialized join output.For FiGaRo, we report the time to compute both the matrix decompositions and the join intertwined, whereas for the others we only report the time to compute the matrix decompositions over the precomputed join matrix.Table 1 gives the times for materializing the join for the three datasets; these join times are typically larger than the MKL compute times.

QR Decomposition
We first consider the task of computing the upper-triangular matrix R only.After that, we investigate the computation of the orthogonal matrix Q.
Experiment 1: Runtime performance for computing R. When compared to its competitors, FiGaRo performs very well for real data in case the join output is larger than its input.Fig. 5 (top) gives the runtime performance of FiGaRo-THIN, THIN, and MKL for the three real datasets as a function of the percentage of the dataset.The performance gap remains mostly unchanged as the data size is increased.Relative to MKL, FiGaRo-THIN is 2.9x faster for Retailer, 16.1x for Favorita and 120.5x for Yelp.MKL outperforms THIN, except for Favorita where the latter is 4.3x faster than the former.This is because Favorita has the smallest number of columns amongst the three datasets and THIN works particularly well on thin matrices.We do not show FiGaRo-MKL to avoid clutter; it consistently performs worse (up to 3x) than FiGaRo-THIN.
We  and output sizes are close.Fig. 5 (bottom) gives the runtime performance of FiGaRo-THIN, THIN, and MKL for the one-hot encoded fragments of the three real datasets as a function of the percentage of one-hot encoded columns.The strategy of FiGaRo to push past joins is less beneficial in this case, as it copies heads and tails along the join tree without a significant optimization benefit.Relative to MKL, it is 2.7x faster for Retailer and 3.1x faster for Favorita.The explanation for this speed-up is elsewhere: Whereas the speed-up in Fig. 5 (top) is due to structural sparsity, as enforced by the joins, here we have value sparsity due to the many zeros introduced by one-hot encoding.By sorting on the one-hot encoded attribute and allocating blocks with the same attribute value to each thread, we ensure that large blocks of zeros in the one-hot encoding will not be dirtied by the rotations performed by the thread.This effectively preserves many zeros from the input and reduces the number of rotations needed in post-processing to zero values in the output of FiGaRo.This strategy needs however to be supported by a good join tree: A relation with one-hot encoded attributes is sorted on these attributes and this order is a prefix of the sorting order used by its join with its parent relation in the join tree.
We further verified that more input rows allowed FiGaRo to scale better, but MKL ran out of memory.THIN and MKL have similar performance.For the Yelp OHE dataset, its size remains much less than its join result and FiGaRo outperforms MKL by 11x.
Pronounced benefits are obtained for many-to-many joins, for which the join output is much larger than the input.We verified this claim for the Cartesian products of two relations of thousands of rows and columns.FiGaRo outperforms MKL by up to three orders of magnitude on this synthetic data (Fig. 6).As expected, FiGaRo scales linearly with the number of rows, while MKL scales quadratically as it works on the materialized Cartesian product.The speed-up of FiGaRo over MKL increases as we increase the number of rows and columns of the two relations.For wide relations (2 12 columns), FiGaRo-MKL (shown in figure) is up to 10x faster than FiGaRo-THIN (not shown).
Most of the time for FiGaRo is taken by post-processing.Computing the batch of the group-by aggregates and the tails and heads of the input relations take under 10% of the overall time for OHE datasets, and about 50% for the original datasets.
Experiment 2: Multi-cores scalability.FiGaRo uses domain parallelism: It splits each input relation into as many contiguous blocks as available threads and applies the same transformation to each block independently.Fig. 7 shows the performance of FiGaRo-THIN as we vary the number of threads up to the number of available logical cores (48).The fastest speed-up increase is achieved up to 8 threads for all datasets and up to 16 threads for Retailer and Favorita.The speed-up still increases up to 48 threads, yet its slope gets smaller.This is in particular the case for the smallest dataset Yelp, for which FiGaRo-THIN only takes under 0.5 seconds using 8 threads.Experiment 3: Effect of join trees.The runtime of FiGaRo is influenced by the join tree.As in classical query optimization, FiGaRo prefers join trees such that the overall size of the intermediate results is the smallest.For our datasets, this translates to having the large fact tables involved earlier in the joins.We explain for Retailer, whose large and narrow fact table Inventory uses key-fkey joins on composite keys (item id, date, location) to join with the small dimension tables Locations, Weather, Item and Census.FiGaRo aggregates away join keys as it moves from leaves to the root of the join tree.By aggregating away join keys over the large table as soon as possible, it creates small intermediate results and reduces the number of copies of dimension-table tuples in the intermediate results to pair with tuples in the fact table.If the fact table would be the root, then FiGaRo would first join it with its children in the join tree and then  apply transformations, with no benefit over MKL as in both cases we would work on the materialized join output.Therefore, a bad join tree for Retailer has Inventory (I) as a root.In contrast, a good join tree first joins Inventory with Weather and Item, thereby aggregating away the item id and date keys and reducing the size of the intermediate result to be joined with Census and Location.As shown in Table 2, FiGaRo-THIN performs 8.06x faster using a good join tree instead of a bad one.For the OHE datasets, a key performance differentiator is the sorting order of the relations with one-hot encoded attributes, as explained in Experiment 1.For instance, the relation Inventory in the Retailer dataset (colored red in Table 2) has the one-hot encoded attribute product id.In a bad join tree, it is not sorted on this attribute: it joins with its parent relation Location on location id, so it is primarily sorted on location id.In a good join tree, Inventory is sorted on product id as it joins with its parent Item on product id.
Experiment 4: Runtime performance for computing Q. FiGaRo outperforms MKL for computing the orthogonal matrix Q (Fig. 8).For this experiment, FiGaRo takes as input the already computed R, while MKL takes as input the precomputed Household vectors, which are also based on R. The speed-up is 5.4x for Retailer, 3.7x for Favorita, and 13x for Yelp (Fig. 8 top).As we linearly increase the join matrix size, the runtime performance of FiGaRo and MKL increases linearly.For the OHE datasets, the speed-up is 1.9-6.7xfor Retailer, 1.9-10.5xfor Favorita, and 29-47x for Yelp (Fig. 8

bottom).
Experiment 5: Runtime performance for end-to-end QR decomposition.To complete the picture, Fig. 9 reports the performance for computing both R and Q.The input to FiGaRo-THIN is the database and to MKL is the materialized join output.As expected, FiGaRo-THIN clearly outperforms MKL for all considered datasets.#columns #rows 2 4 2 6 2 8 2 9  2.3e-15 1.8e-14 3.7e-14 2 10  3.5e-15 3.3e-14 1.3e-13 2 11  4.7e-15 4.3e-14 3.2e-13 2 12 6e-15 5.4e-14 5.2e-13 2 13  7.9e-15   Experiment 6: Accuracy of computed R. To assess the accuracy of computing R, we designed a synthetic dataset consisting of two relations and want to compute the uppertriangular R in the QR decomposition of their Cartesian product.The input relations are defined based on a given matrix R fixed such that R fixed is part of R. The construction is detailed in App. A. We report the relative error of the computed partial result Rfixed compared to the ground truth R fixed , where ∥•∥ F is the Frobenius norm.Table 3 (left) shows the error of FiGaRo-MKL as we vary the number of rows and columns of the two relations following a geometric progression.As the number of rows increases, the accuracy only changes slightly.The accuracy drops as the number of columns increases.The error remains however sufficiently close to the machine representation unit (10 −16 ).We also verified that FiGaRo-THIN's error is very similar.
We also computed the relative error for MKL.Table 3 (right) shows the result of dividing the relative errors of MKL and FiGaRo-MKL.A number greater than 1 means that FiGaRo-MKL is more accurate than MKL.The error gap increases with the number of rows and decreases with the number of columns.The latter is as expected, as postprocessing dominates the computation for wide matrices.FiGaRo-MKL is up to three orders of magnitude more accurate than MKL.
Experiment 7: Accuracy of computed Q.The accuracy of computing Q ∈ R m×n is given by the orthogonality error , where I ∈ R n×n is the identity matrix and ∥•∥ F is the Frobenius norm [30, p. 360].An orthogonality error of 0 is the ideal outcome, it means that Q is perfectly orthogonal.Fig. 10  MKL, FiGaRo-THIN and MKL.We disregard FiGaRo-THIN in the following analysis, as it is less accurate than FiGaRo-MKL in this experiment.This is as expected, as the THIN post-processing is far less optimized with respect to numerical stability than MKL.We see that FiGaRo-MKL is more accurate for Retailer (one order of magnitude) and Favorita (two orders of magnitude), but less accurate for Yelp (one order of magnitude).The reason is that the condition number [30] of the join matrix A influences the orthogonality of Q computed by FiGaRo.The condition number is the largest singular value of A divided by the smallest singular value of A. A very large condition number means that the smallest singular value is very close to 0, so, the matrix is almost singular [46,15].If this is the case for A, the same holds for the matrix R of its QR decomposition, as they have the same singular values.Recall that FiGaRo inverts R to compute Q (Sec.8), this step may introduce larger rounding errors when R is close to being singular.Table 4 gives the condition numbers and smallest singular values for the join matrix A for each of our three datasets and their OHE versions.Since Favorita has the smallest condition number, the orthogonality error of Q computed by FiGaRo-MKL is very low, i.e., Q is very close to an orthogonal matrix.In contrast, Yelp has the largest condition number and FiGaRo produces a less orthogonal matrix Q for this dataset.
Table 4 also shows that the condition numbers are much larger for the OHE versions of Retailer and Favorita (by a factor of 100x), while the condition number remains almost the same for the OHE version of Yelp.We therefore expect less accurate matrices Q computed by FiGaRo-MKL.This is indeed the case, as shown in Fig. 10 (bottom).Remarkably, MKL improves the orthogonality of Q in case of the OHE datasets relative to the original datasets, which suggests that it can effectively exploit the sparsity due to the one-hot encoding to avoid accumulating too many rounding errors.Table 5 gives the orthogonality error of Q for the Cartesian product of two relations as we vary their numbers of rows and columns.The condition numbers, the smallest singular values, and even the orthogonality vary in the same range as for Retailer original and OHE in Table 4.The orthogonality error for Q computed by FiGaRo-MKL remains rather low and is 1-100x lower than for MKL (Table 5 right).The gap between the two systems closes as we increase the number of columns.

Singular Value Decomposition
We extended FiGaRo to compute the SVD of the join matrix A as detailed in Sec. 8. We call this extension SVD-Fig.It works directly on the input database.We compare it against SVD-MKL, the divide&conquer approach of MKL that computes the QR decomposition of A and then bidiagonalizes the upper-triangular matrix R. When only singular values are computed, all methods use the dqds algorithm [20] to compute these values from the intermediate bidiagonal matrices.We also experimented with the QR iteration, the power iteration, and the eigendecomposition approaches.QR iteration performs similar to SVD-MKL, although for the OHE datasets it is one order of magnitude less accurate, where accuracy is measured as the orthogonality of the matrix U. Power iteration is at least one order of magnitude slower than SVD-Fig for achieving a comparable accuracy.In our tests, the orthogonality error of the eigendecomposition approach was much larger than for the other approaches.Experiment 9: Accuracy of computed SVD.We first investigate the orthogonality error for the truncated matrix U of left singular vectors as we vary the percentage of nontruncated columns (Fig. 12).The reason we look into the accuracy of truncated U is twofold.First, this is the largest matrix in the SVD of A. Second, its truncated version is used for PCA.When the percentage of non-truncated columns increases, the orthogonality error increases for SVD-Fig, for MKL it remains roughly the same.This is because the condition number of the join matrix A grows with the number of non-truncated columns.
We see a similar behaviour for the accuracy of the computed singular values.We finally investigate the accuracy for the synthetic dataset and considered different percentages of truncated columns in the matrix U.

Principal Component Analysis
Sec. 8 shows how to compute PCA using SVD.The top-k principal components of the join matrix A are the right singular vectors in V that correspond to the top-k largest singular values of A. Both V and the singular values of A are also of the upper-triangular matrix R computed by FiGaRo.The projection of A onto the k-dimensional space is given by U :,1:k Σ 1:k,1:k , where U :,1:k is the truncated matrix U of left singular vectors and the diagonal matrix Σ 1:k,1:k has the k largest singular values along the diagonal.Experiment 9 on the accuracy of the computed truncated U and the singular values carry over to PCA immediately.
Experiment 10: Runtime performance for computing PCA.Fig. 14 reports the runtimes to compute U :,1:k Σ 1:k,1:k for k = 10% of the number of data columns, i.e, k is 4 for Retailer, 3 for Favorita, and 5 for Yelp.PCA-Fig is the FiGaRo adaptation to PCA.It takes as input the database.PCA-MKL is a custom implementation that uses MKL to compute SVD from the join matrix A and then multiplies the truncated matrices U and Σ.For this experiment, we did not center the data.Fig. 14 shows a consistent gap of one order of magnitude between the two systems.This is similar to the performance reported in Fig. 11, since the most expensive computation is taken by the SVD.
FiGaRo can compute the principal components corresponding to the largest singular values in our experiments faster than MKL and with similar accuracy.FiGaRo is thus a good alternative to MKL in case of matrices defined by joins over relational data.

Related Work
Our work sits at the interface of linear algebra and databases and is the first to investigate QR decomposition over database joins using Givens rotations.It complements seminal seven-decades-old work on QR decomposition of matrices.Our motivation for this work is the emergence of machine learning algorithms and applications that are expressed using linear algebra and are computed over relational data.
Improving performance of linear algebra operations.Factorized computation [42] is a paradigm that uses structural compression to lower the cost of computing a variety of database and machine learning workloads.It has been used for the efficient computation of A T A over training datasets A created by feature extraction queries, as used for learning a variety of linear and non-linear regression models [51,36,50,33,40].It is also used for linear algebra operations, such as matrix multiplication and element-wise matrix and scalar operations [9].Our work also uses a factorized multiplication operator of the non-materialized matrix A and another materialized matrix for the computation of the orthogonal matrix Q in the QR decomposition of A and for the SVD and PCA of A. Besides structural compression, also value-based compression is useful for fast in-memory matrix-vector multiplication [18].Existing techniques for matrix multiplication, as supported by open-source systems like SystemML [7], Spark [62], and Julia [3], exploit the sparsity of the matrices.This calls for sparsity estimation in the form of zeroes [54].
The matrix layout can have a large impact on the performance of matrix computation in a distributed environment [38].Distributed database systems that can support linear algebra computation [37] may represent an alternative to high-performance computing efforts such as ScaLAPACK [10].There are distributed algorithms for QR decomposition in ScaLAPACK [58,8].
QR decomposition.There are three main approaches to QR decomposition of a materialized matrix A. The first one is based on Givens rotations [24], as also considered in our work.Each application of a Givens rotation to a matrix A sets one entry of A to 0. This method can be parallelized, as each rotation only affects two rows of A. It is particularly efficient for sparse matrices.One form of sparsity is the presence of many zeros.We show its efficiency for another form of sparsity: the presence of repeating blocks whose one-off transformation can be reused multiple times.
Householder transformations [31] are particularly efficient for dense matrices [30, p. 366].MKL and openblas used in our experiments implement this method.One Householder transformation sets all but one entry of a vector to 0, so the QR decomposition of an m × n matrix can be obtained using n transformations.Both Givens and Householder are numerically stable [30,Chapter 19].
The Gram-Schmidt process [28,52] computes the orthogonal columns of Q one at a time by subtracting iteratively from the i-th column of A all of its projections onto the previously computed i − 1 orthogonal columns of Q.A slightly modified variant [5] is numerically stable.The modified Gram-Schmidt is mathematically and numerically equivalent to applying Householder transformations to a matrix that is padded with zeros [6].
Implementing Givens rotations.There are several options on how to set the values c and s of a Givens rotation matrix in the presence of negative values.We follow the choice proposed by Bindel [4].Anderson [2] defends the original choice [24] of signs using numerical stability arguments.Gentleman [23] shows that one can compute an uppertriangular matrix R ′ and a diagonal matrix D without computing square roots such that R = D 1 2 R ′ .Stewart [55, p. 291] discusses in depth these fast rotations.SVD.The approach to computing the SVD that is closest to ours proceeds as follows [26, p. 285], [35].It computes the matrices R and Q in the QR decomposition of A, followed by the computation of the SVD of R = U R Σ R V T R .Finally, it computes the orthogonal matrix U = QU R .The SVD of A is then UΣ R V T R .Our approach does not compute Q but instead expresses it as a multiplication of the non-materialized A and the inverse of R. Further approaches use Householder transformations to transform A into a bidiagonal matrix [26, p. 284], [25], or compute the eigenvalue decomposition of the matrix A T A [26, p. 486], where the singular values are the square roots of the eigenvalues and the matrix V consists of the corresponding eigenvectors.All prior approaches require the input matrix A to be materialized.The existing approaches to computing an SVD of a bidiagonal matrix vary in terms of accuracy [11].When only singular values are required, the squareroot-free or dqds method is the most popular [48,20].The QR-iteration [13,14] and divide-and-conquer methods [29] are used in case also the left and right singular matrices are required.
PCA. Principal component analysis is a technique for reducing the dimensionality of a dataset [45].The approach taken in this paper to computing the PCA of a matrix A relies on the SVD of the upper-triangular matrix R in the QR decomposition of A. The novelty of FiGaRo over all prior approaches to PCA is that it does not require the materialization of A to compute R, in case A is defined by database joins.A further approach to PCA over database joins was recently proposed in the database theory literature, without a supporting implementation [33]: It uses the min-max theorem based on the Rayleigh quotient [56] and computes iteratively one eigenvector of A T A at a time.The benefit of that approach is that the computation of A T A can be pushed past joins and may take time less than materializing the matrix A representing the join result.

Conclusion
This article introduces FiGaRo, an algorithm that computes the QR decomposition of matrices defined by joins over relational data.By pushing the computation past the joins, FiGaRo can significantly reduce the number of computation steps and rounding errors.FiGaRo can also be used to compute singular value and eigenvalue decompositions as well as the principal component analysis of the non-materialized matrix representing the joins over relational databases.We experimentally verified that FiGaRo can outperform in runtime and in many cases also in accuracy the linear algebra package Intel MKL.In the future, we plan to extend FiGaRo to work with categorical data directly, to avoid one-hot encoding such data.
Let R S ∈ R n 1 ×n 1 be an arbitrary upper-triangular matrix.We arbitrarily choose a vector v = (v 1 , . . ., v m 1 ) T ∈ Q m 1 with ||v|| 2 = 1 and a m 2 × n 2 matrix T of natural numbers, where m 2 is square, so √ m 2 is a natural number.We set Q S to be the first n 1 columns of the orthogonal matrix of rational numbers [63] . . . . . . . . . . . . . . .
We obtain S as S = Q S R S .
It follows from Corollary 13 that there is an orthogonal matrix Q as well as matrices , as desired.Furthermore, if R S only consists of rational numbers then so do S, T and R S √ m 2 .When computing the QR decomposition of S × T we can compare the ground truth R S √ m 2 with the corresponding part of the computed result.
Setting the entry of the second row to 0. Setting the entry of the third row to 0.

Figure 1 :
Figure 1: Applying Givens rotations to a 1 × 3 matrix with all entries having the value s.

0
(a) Transformation of the Cartesian product of a one-row matrix S and an m-row matrix T.

0
(b) Generalization of the transformation at (a), where S is scaled by a vector v = (v 1 , . . ., v m ) of positive real numbers.

Figure 2 :
Figure 2: Visualization of Lemmas 3 and 5: Matrices and results of applying the (generalized) head and tail.

Figure 3 :
Figure 3: Matrices and join tree used in Sec. 4.

a j 1
of values for the data column Y 1 in S 1 .The rows of S 1 are the union of the Cartesian products [a j ] × S a j 1 , for all j ∈ {1, 2}.The output A of the natural join of S 1 , . . ., S 4 contains the Cartesian product

▷
Recursively applies FiGaRo to all children.Concatenates the results Out, joins the matrices Data and applies the factors scales foreach child S j of S i in τ do (Out j , Data j , scales j ) ← FiGaRo(S 1 , . . ., S r , τ, j)Out.append(Outj ) foreach value xi of the join attributes Xi in S i do ▷ let Xij be the join attributes shared between S i and S j and let xij be the projection of xi onto Xij .

a j b k c ℓ 2 |
. Next, the children S 3 and S 4 of S 2 in τ are processed and the intermediate results are joined.The recursive calls for the children return Data 3 [b k : Y 3 ] = H(S b k 3 ) and scales 3 [b k ] = |S b k 3 | as well as Data 4 [c ℓ : Y 4 ] = H(S c ℓ 4 ) and scales 4 [c ℓ ] = |S c ℓ 4 |; the matrices Out 3 , Out 4 contain as non-zero entries Φ • 3 (b k )T (S b k 3 ) and Φ • 4 (c ℓ )T (S c ℓ 4 ), respectively, for every k, ℓ ∈ {1, 2}.

Figure 6 :
Figure 6: Exp.1: Runtime performance of FiGaRo-MKL and MKL for computing R in the QR decomposition of the Cartesian product of two relations.The numbers of rows and columns are per relation; for relations of 2 13 rows columns and 2 12 , MKL's input is a 2 26 × 2 13 matrix.Left: Runtime performance of FiGaRo-MKL (sec).Right: Speed-up of FiGaRo-MKL over MKL (rounded to closest natural number).An empty cell means that MKL runs out of memory.

Figure 7 :. 3 :
Figure 7: Exp.2: Speed-up of multi-threading over single-threading for FiGaRo-THIN computation of R in the QR decomposition over the three datasets.

Figure 8 :
Figure 8: Exp.4: Runtime performance for computing the fully materialized Q for the original datasets R, F, Y (top) and their OHE versions (bottom).

Figure 9 :
Figure 9: Exp.5: Runtime performance for end-to-end QR decomposition for the original datasets R, F, Y (top) and their OHE versions (bottom).
FiGaRo-MKL relative to the ground truth.(Right) Division of relative error of MKL over the relative error of FiGaRo-MKL.The empty bottom-right cell is due to the out-of-memory error for MKL.

Figure 11 :
Figure 11: Exp.8: Runtime performance of SVD-Fig and MKL over the original datasets R, F and Y. Top: Only singular values (Σ) are computed.Bottom: The entire SVD is computed: U, Σ, V.

Figure 12 :
Figure 12: Exp.9: Orthogonality error for U computed by SVD-Fig and MKL for our datasets R, F and Y as we vary the percentage of non-truncated columns in U. Top: Original datasets.Bottom: OHE versions.

Figure 13 :
Figure 13: Exp.9: Error of SVD-Fig relative to MKL for computing the top k − 5 to k percent of the largest singular values of the join matrices for the original datasets.
Fig. 13 reports the relative error of a sliding window of 5% of the singular values as computed by SVD-Fig and by MKL, sliding over all singular values in decreasing order.For vectors v 1 and v 2 computed by SVD-Fig and respectively MKL, the relative error is ∥v 1 −v 2 ∥ F ∥v 2 ∥ F .The difference between the singular values as computed by SVD-Fig and MKL tends to be small for the largest singular values and increases for smaller singular values.Also, the singular values computed by SVD-Fig are closer to the values computed by MKL for the join matrices with smaller condition numbers such as Favorita, while for Retailer and Yelp they are more different.We observed similar behaviour for the OHE datasets.
9: (Left) Orthogonality error for the full U computed by SVD-Fig.(Right) Division of the orthogonality error of MKL by the orthogonality error of SVD-Fig, the result greater than one means SVD-Fig is more accurate.The right-bottom cell is empty as MKL ran out of memory.

Figure 14 :
Figure 14: Exp.10: Runtime performance of PCA-Fig and MKL for our datasets R, F, and Y.

▷
Out, Data are matrices, scales is a vector.All are initially empty.

▷
Compute heads and tails of S i , grouped by the columns Xi .Heads are written to Data, tails are scaled and written to Out.
foreach value xi of the join attributes Xi in S i do▷ Let S xii consist of all rows of S i with value xi for columns Xi , projected onto the data attributes Ȳi

Table 1 :
Characteristics of the datasets (original) and their one-hot encodings (OHE).
next consider the OHE versions of Retailer and Favorita, for which the join input

Table 4 :
depicts the orthogonality errors of the matrices Q constructed by FiGaRo-Exp.7: Condition numbers and smallest singular values for the three datasets and their OHE versions.

Table 5 :
Exp. 7: (Left) Orthogonality error of Q for FiGaRo-MKL over the Cartesian product.(Right) Division of orthogonality error of MKL by the orthogonality error of FiGaRo-MKL.The right-bottom cell is empty as MKL ran out of memory.

Table 7 .
Table 6 reports the orthogonality error of the matrix U truncated to 40% of columns.The matrix U computed by SVD-Fig is more orthogonal than the one computed by MKL, the reasoning is similar to the orthogonality of Q in Experiment 7. If we compute the entire matrix U, then SVD-Fig incurs a higher orthogonality error than MKL due to the large condition numbers, as shown in

Table 6 :
Exp. 9: (Left) Orthogonality error for U computed by SVD-Fig and truncated to 40% columns.(Right) Division of orthogonality error of MKL by the orthogonality error of SVD-Fig, the result greater than one means SVD-Fig is more accurate.The right-bottom cell is empty as MKL ran out of memory.