arXiv:2610.38860cs.DSOct 2026

Manuscript Offprint

arXiv:2610.38860

Fast Perfect L2L_2 Sampling

David P. Woodruff, Samson Zhou

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

Abstract

Perfect L2L_2 sampling is a powerful primitive for turnstile data streams, allowing algorithms to extract an index with probability proportional to its squared frequency, with applications to dynamic join size estimation, query optimization, heavy-hitters, sampling from self-joins, and real-time monitoring of evolving datasets. The setting p=2p=2 is also the largest pp for which LpL_p sampling can be achieved in polylogarithmic space. However, existing space-optimal perfect samplers rely on explicit polynomial duplication, requiring inefficient polynomial update times per stream arrival. Resolving a open question left by Swartworth, Woodruff, and Zhou [FOCS 2025], we present a perfect L2L_2 sampler that achieves an expected polylog(nn) update time while maintaining an optimal O~(log⁡3n)\tilde{\mathcal{O}}(\log^3 n) bits of space.

1 Introduction

The scale of modern data systems often makes it infeasible to store or repeatedly process an entire dataset. In many settings, such as network monitoring and large-scale database systems, data instead arrives as a continuous stream of updates. The streaming model of computation formalizes this setting by requiring algorithms to process the input using memory far smaller than the size of the data itself. In the standard turnstile model, the stream implicitly defines a high-dimensional frequency vector x∈Rnx \in \mathbb{R}^n that is initialized to the all zeros vector and evolves through updates of the form xi←xi+Δx_i \leftarrow x_i + \Delta, where Δ\Delta may be positive or negative. This model naturally captures dynamic settings in which data is both inserted and deleted, such as updates to database records or changes in network traffic.

A central goal in the streaming model is to design primitives that extract useful information from the frequency vector while respecting stringent space constraints. One particularly powerful primitive is LpL_p sampling, which returns an index i∈[n]i \in [n] with probability proportional to (1±ε)⋅∣xi∣p∥x∥pp+1poly(n)(1 \pm \varepsilon) \cdot \frac{|x_i|^p}{\|x\|_p^p} + \frac{1}{\text{poly}(n)}. Informally, an LpL_p sampler selects coordinates according to their contribution to the pp-th frequency moment, biasing the sample toward larger entries as pp increases. The sampler is called perfect if ε=0\varepsilon = 0 and approximate otherwise. Because LpL_p sampling captures structure in the frequency vector beyond global aggregates by extracting representative coordinates according to the geometry induced by the LpL_p norm, LpL_p sampling has emerged as a powerful primitive in a variety of sublinear

*Carnegie Mellon University and Google Research. dwoodruf@andrew.cmu.edu. David P. Woodruff is supported in part by Office of Naval Research award number N000142112647 and a Simons Investigator Award.

†Texas A&M University. samsonzhou@gmail.com. Samson Zhou is supported in part by NSF CCF-2335411 and gratefully acknowledges funding provided by the Oak Ridge Associated Universities (ORAU) Ralph E. Powe Junior Faculty Enhancement Award.

and streaming algorithms. In particular, it has found applications in a broad spectrum of settings, including network monitoring and anomaly detection [EV03, HNG+07, GKMS01, TLJ10, MCS+06], distributed computation frameworks [CMYZ12, TW11, JSTW19, WZ12, CF14], database query processing tasks [HNSS96, LNS90, GM98, CG19, Olk93, Haa16, LN95, HS92], and techniques for compact representation and summarization of large datasets [FKV04, DRVW06, DV07, ADK09, IMMM14, MIGR19, CPW20, IMGR20, MRWZ20, JWZ22, MWZ22, GMS23, MT23, LSW+26]. Despite this broad applicability, the complexity and behavior of LpL_p sampling depend strongly on the choice of pp, and different regimes require fundamentally different algorithmic ideas.

Among the family of LpL_p samplers, the case p=2p=2 occupies a particularly important position. From a geometric perspective, the L2L_2 norm underlies Euclidean structure and is therefore deeply connected to many algorithmic techniques based on linear algebra and sketching. Within database systems, the second frequency moment F2=∥x∥22F_2 = \|x\|_2^2 corresponds directly to self-join size, making L2L_2 sampling a natural primitive for approximate query processing, join estimation, and regression over joins without explicitly materializing them, where sampling-based techniques are commonly used [JSWY21]. Moreover, it is used in a number of subroutines such as streaming algorithms for LpL_p norm estimation for p>2p>2 [WZ21, WXZ25]. Thus, progress on L2L_2 sampling directly influences the complexity of a much broader class of problems. In particular, p=2p=2 is the largest exponent for which polylogarithmic space LpL_p sampling is possible, as Ω~(n1−2/p)\tilde{\Omega}(n^{1-2/p}) space is necessary for p>2p>2 [GLW+25, WXZ25, JLY26].

Previous work. Despite its central role, constructing efficient LpL_p samplers has been well-studied in the streaming literature. In the insertion-only setting, the classical reservoir sampling technique [Vit85] gives an exact L1L_1 sampler using O(log⁡n)\mathcal{O}(\log n) bits of space with no distortion, both multiplicative and additive. However, beyond the L1L_1 case or outside insertion-only streams, the problem becomes significantly more complex and the question of whether such samplers exist was explicitly posed by [CMR05], and subsequently resolved in the affirmative for p≤2p\leq 2 in the approximate setting [MW10]. These initial constructions used poly (1ε,log⁡n)\left(\frac{1}{\varepsilon}, \log n\right) space, and were later improved to near-optimal bounds by [AKO11] and by [JST11], achieving roughly O(1εmax⁡(1,p)log⁡2n)\mathcal{O}\left(\frac{1}{\varepsilon^{\max(1,p)}} \log^2 n\right) space for p∈(0,2)p\in(0,2) and O(1ε2log⁡3n)\mathcal{O}\left(\frac{1}{\varepsilon^2} \log^3 n\right) for p=2p=2. While these results established near-optimal space complexity for approximate sampling, they left open finer questions regarding distortion and randomness requirements. This gap was later resolved by [JW18], who introduced the first perfect LpL_p samplers for p∈(0,2)p\in(0,2) with O~(log⁡2n)\tilde{\mathcal{O}}\left(\log^2 n\right) space and for p=2p=2 with O~(log⁡3n)\tilde{\mathcal{O}}\left(\log^3 n\right) space.

Update time. Despite resolving the space complexity, the algorithms of [JW18] and related work [CG19] suffer from a severe computational bottleneck, duplicating each coordinate nCn^C times and assigning each copy an independent exponential weight. Consequently, a single update requires Ω(nC)\Omega(n^C) structural operations, so that the update time per element is polynomial in nn, which can be prohibitively large in many settings. This sparked work on fast perfect LpL_p sampling. For insertion-only streams, [PW25] achieved O(1)\mathcal{O}(1) update time for p≤1p\leq 1 in the random oracle model. Subsequently, [SWZ25] introduced a continuous simulation framework for general turnstile streams, achieving polylogarithmic update time for p<2p<2. Unfortunately, the framework of [SWZ25] does not extend to the critical case p=2p=2, where the limiting behavior underlying the continuous simulation approach changes qualitatively and the techniques used for p<2p<2 no longer apply (see Section 3 for more details).

At first glance, this distinction may appear to be merely a change of regime. However, the situation is less clear from a complexity perspective. Indeed, while a combination of techniques from [JLY26, SW26] showed an Ω(log⁡3n)\Omega(\log^3 n) space lower bound for perfect L2L_2 sampling, perfect samplers for p<2p<2 are known using only O~(log⁡2n)\tilde{\mathcal{O}}\left(\log^2 n\right) space [JW18, SWZ25]. Thus, it is natural to ask whether the additional memory complexity of the L2L_2 regime fundamentally obstructs fast algorithms, or whether one can still achieve polylogarithmic update time while maintaining optimal space.

Our contributions. In this paper, we resolve the open question of whether perfect L2L_2 sampling admits both optimal space and fast update time in the turnstile model. We introduce a new approach for implementing perfect L2L_2 sampling without relying on the explicit polynomial duplication used in previous constructions to achieve the first perfect L2L_2 sampler with expected polylogarithmic update time and optimal space complexity.

Theorem 1.1. Given a sequence of turnstile updates defining a frequency vector x∈Rnx \in \mathbb{R}^n, and a failure probability parameter δ∈(0,1)\delta \in (0,1), there exists a perfect L2L_2 sampler that outputs a failure symbol ⊥\perp with probability at most δ\delta. Conditioned on returning an index i∗∈[n]i^* \in [n],

Pr[i∗=j]=xj2∥x∥22±1poly(n).\mathbf{Pr}\left[i^*=j\right]=\frac{x_j^2}{\|x\|_2^2}\pm\frac{1}{\mathrm{poly}(n)}.

The algorithm uses O~(log⁡3nlog⁡1δ)\tilde{\mathcal{O}}\left(\log^3 n \log \frac{1}{\delta}\right) bits of space and processes each stream update in polylog(nn) time in expectation.

We remark that the output ⊥\perp corresponds to a failure event that occurs with probability at most δ\delta; this is standard in perfect sampling constructions and can be reduced arbitrarily by repetition without affecting the conditional sampling guarantee. Conceptually, our result shows that the additional complexity of the L2L_2 regime does not fundamentally obstruct efficient algorithms. Although the methods developed for p<2p<2 do not directly extend to p=2p=2, we show that this qualitative change in behavior need not incur an algorithmic penalty. Thus, despite occupying a distinct space complexity regime, perfect L2L_2 sampling remains achievable with both optimal space and efficient updates.

References (45)