arXiv:2610.40620cs.DBOct 2026

Manuscript Offprint

arXiv:2610.40620

Tessera: Fast Join-Aggregates over Skewed Sparse Relations in Database Engines

Gyuyeong Kim

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

ABSTRACT

Join-aggregate queries count or sum matching rows for each pair of values, often over skewed sparse relations in which a few values are frequent and most pairs of values never co-occur. Conventional execution plans materialize billions of intermediate join rows, taking minutes to tens of minutes per query. Recent matrix-based solutions reformulate these queries as matrix multiplication to reduce or avoid this materialization. However, they remain slow because they either store result cells for non-matching pairs or still materialize intermediate join rows for infrequent values. We present Tessera, a skew-aware join-aggregate operator for database engines that avoids both sources of overhead. Specifically, Tessera computes a sparse matrix product directly over the engine's rows, emits only nonzero cells as result rows, and prunes values that cannot meet the query's threshold before multiplication begins. It also offloads the dense block formed by pairs of the most frequent values to a CPU matrix accelerator when that block is dense enough. Experimental results show that Tessera is faster than the fastest existing system by 2.8×2.8\times to 18.8×18.8\times. In addition, Tessera outperforms DuckDB's execution plans by up to 1,802×1,802\times.

Artifact Availability:

The source code is available at https://github.com/GyuyeongKim/Tessera-public.

1 INTRODUCTION

Many analytics questions ask how often two things occur together. For example, an analyst asks which words appear in the same documents, which movies the same users rate, which products the same customers buy, or how many friends two users share. In SQL, this is a join-aggregate query. It joins a relation with itself, or with a second relation, on a shared key, and then groups the joined rows by one attribute from each side to count or sum them. Many of these queries retain only strong pairs whose counts meet a threshold, such as words that co-occur in at least 100 documents, or rank among the top k. Join-aggregates appear in decision-support benchmarks [47, 50] and are used to build set similarity joins and item-to-item recommendation [39, 45]. In these use cases, the execution time of a join-aggregate matters. This is because an analyst waits for each answer before asking the next question, and a recommender recomputes its item similarities every time it retrains on new data.

The relations behind these questions are skewed and sparse. Value frequencies are heavy-tailed [15], with a few values, such as common words or popular movies, in many rows and most values in few. Most pairs of values also never co-occur, since no key holds both of them. We call them non-matching pairs. For example, in a collection of 300K news articles [43], 89% of the pairs of words never appear in the same article. However, current database engines perform join-aggregates slowly on such relations. For example, counting word co-occurrence over the news articles produces 20 billion joined rows, and an analytical engine such as DuckDB [44] builds and aggregates every one of them.

Prior work reduces or avoids intermediate join rows by computing a join-aggregate as a matrix product and accelerates queries by speeding up multiplication [19, 28, 29, 35]. However, these designs remain inefficient on skewed sparse relations. Specifically, join-project algorithms [19, 28] multiply frequent values as a dense matrix but still materialize join rows for rare values. Meanwhile, in-database linear algebra [35] and tensor-core databases [29] keep dense results with cells for non-matching pairs. These costs limit the benefit of faster multiplication, even with recent on-CPU matrix accelerators (e.g., Intel AMX [34]). In this context, we ask: how can a database engine speed up the whole join-aggregate on skewed sparse relations?

To answer this question affirmatively, we present Tessera, a high-performance skew-aware join-aggregate operator for database engines. Our key insight is that skew packs repeated computation into a small dense core of frequent values, while the long tail of rare values accounts for most result cells. Therefore, accelerating the core pays off only when processing the long tail and writing the results are also cheap. Based on this insight, Tessera splits the values at a dense frontier, which separates the dense core of frequent values from the long tail. Inside the frontier, a matrix accelerator multiplies the pairs of frequent values as dense tiles. Beyond it, a sparse path computes only the nonzero result cells of rarer values and does most of the work. Tessera chooses the frontier for each query by comparing the cost of each accelerator tile with that of the sparse products it replaces.

Realizing this design raises four technical challenges. First, the rare values and the output carry most of the work, and the result may not fit in the engine's memory budget. Furthermore, a query that keeps only the pairs whose counts meet a threshold usually does as much work as one that keeps all pairs, since the threshold applies only after each cell is computed. Second, the best frontier depends on the relation and on the query, because the accelerator pays for whole tiles and pruning changes which values remain. Third, the matrix accelerator multiplies dense tiles, but even the dense core is mostly zeros, and a dense copy of it grows with the number of rows. Lastly, the operator must run inside engines that differ in how they plan queries and manage resources.

Tessera addresses these challenges with the following mechanisms. First, the sparse path runs Gustavson's sparse product algorithm [26] on the engine's rows and adds products into counters instead of building joined rows ( §3.2§3.2). It writes only the nonzero cells, which spill to files when they exceed the engine’s memory limit. Before any product, it drops the values that cannot reach the threshold, and a stricter query therefore runs faster. Second, a cost model scans the rows once, and Tessera picks the frontier with the lowest predicted runtime after pruning ( §3.3§3.3). If no block is dense enough, the accelerator costs only this scan. Third, Tessera groups rows that share frequent values and skips tiles without useful products ( §3.4§3.4). As a result, the accelerator’s work follows its nonzero tiles rather than the size of the core. Lastly, each engine reaches Tessera through a C interface and a small adapter built on its extension hooks for plans, scans, and typed output ( §3.5§3.5).

Tessera is readily deployable. We integrate Tessera into four database engines as extensions, DuckDB, PostgreSQL [49], SQLite [23], and Spark [7]. In DuckDB, PostgreSQL, and Spark, the adapter rewrites the plan of a join-aggregate, whose query therefore needs no change. Users can install Tessera through each engine's own package channel. We conduct a series of experiments and find that Tessera outperforms the fastest existing system by 2.8×2.8\times to 18.8×18.8\times. In all four engines, Tessera is faster than their own plans, especially by up to 1,802×1,802\times in DuckDB.

In summary, this work makes the following contributions:

  • We show that on skewed sparse relations, a faster multiplication, even on a matrix accelerator, gains little, since existing matrix-based designs still spend their work on non-matching pairs and on the rows of rare values.

  • We design Tessera, a skew-aware operator that runs a sparse product on the engine’s rows and returns rows, prunes values before the product, and gives a matrix accelerator the dense core that a cost model sizes for each query.

  • We implement Tessera in four database engines and show that it outperforms both existing matrix-based systems and the engines' own plans.

References (42)