arXiv:2611.04519cs.DBNov 2026

Manuscript Offprint

arXiv:2611.04519

Order-Dependent Complexity of Enumeration and Direct Access for Conjunctive Queries on Dynamic Data

Antoine Amarilli, Nofar Carmeli, Clémence Dumoulin

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

Abstract

This note studies the fine-grained complexity of ranked enumeration and ranked direct access of conjunctive query answers over a dynamic database. We focus on lexicographically sorted answers, defined by an ordering on the query's free variables.

From the literature, when no particular order is required, we know that when the query is self-join-free and q-hierarchical, we can build a data structure for enumeration (resp. direct access) with linear (resp. linearithmic) preprocessing and constant (resp. logarithmic) update time in the size of the database. For enumeration (resp. direct access), this data structure yields an algorithm that enumerates all query answers (resp. that returns the kthk^{\text{th}} query answer) with constant delay (resp. logarithmic access time). Our goal is to extend these results to ranked enumeration and ranked direct access, with the ranking function defined by a lexicographic order.

We define a property on the order over the variables of QQ, which we call being hierarchy-consistent. Given a user-specified query and hierarchy-consistent order, we first propose, for ranked enumeration under updates, an algorithm with linear preprocessing and logarithmic update time that enumerates all the query answers according to the user-specified order with constant delay. Moreover, for ranked direct access under updates, we propose an algorithm with linear preprocessing and logarithmic update time that returns the kthk^{\text{th}} tuple according to the user-specified order with logarithmic access time.

In contrast, given a user-specified query and non-hierarchy-consistent order, we show a lower bound for ranked direct access under updates.

1 Introduction

For a conjunctive query (or CQ) QQ, given a database DD, materializing the answers Q(D)Q(D) can be costly: the number of answers ∣Q(D)∣|Q(D)| can be up to ∣D∣∣Q∣|D|^{|Q|}. Producing or holding the full answer set at once is therefore often impractical. Instead, it is more natural to find approaches that allow us to access partial information about the query result without materializing it. In particular, we may want to access the kthk^{\text{th}} answer to QQ on DD, or to enumerate the answers one by one without repetitions.

These tasks are typically formalized in database theory in two ways. The first one is enumeration: rather than producing all tuples at once, an enumeration algorithm outputs them one by one, with a guarantee of bounded delay between two consecutive tuples. The second one is direct access: this is the task of outputting, on an input kk, the kthk^{\text{th}} answer for QQ over DD.

It is well-known from the work of Bagan, Durand, and Grandjean [BDG07] that we can enumerate the answers to self-join-free CQs with linear preprocessing and constant delay in data complexity provided that these queries satisfy the so-called acyclic free-connex condition; this restriction is (conditionally) necessary within the class of self-join-free CQs, and a characterization of tractable CQs with self-joins is still open [CS23, RCCS26]. What is more, Brault-Baron [BB13] has shown that direct access was possible with linearithmic preprocessing and logarithmic access time in data complexity. We also note the line of work on factorized databases [OS16], which represent query results compactly using a structure derived from the query, and enumerate the answers with constant delay when no particular order is required or when the user-defined order is compatible with this structure.

The literature has then extended these questions along two independent axes: supporting efficient updates to the underlying database (and updating the structure used for enumeration or direct access without recomputing it from scratch); and providing results in a specific order (e.g., in some lexicographic order specified by the user). The goal of the present work is to bridge these two directions. We present existing results on each of them in turn.

First, in the dynamic setting, [BKS17] show that q-hierarchical conjunctive queries can be enumerated with constant delay and constant update time after linear preprocessing, and that for self-join-free CQs this classification is (conditionally) optimal. An analogous result for direct access is shown in [Kep20]. Further works have investigated which guarantees could be provided for CQs beyond this class; this is not the focus of the present work, but we review these directions nevertheless. Dynamic Yannakakis [IUV17] maintains constant-delay enumeration for all free-connex queries (i.e., more generally than q-hierarchical conjunctive queries) with a more costly update time (namely, it is linear in the input database). This was then refined in [WHDY23] with an update cost that depends on the update sequence, which becomes constant for insertion-only sequences.

We now review the different types of data structures that are used to show efficient enumeration and direct access guarantees on dynamic data; we will re-use some of them in the present work. [Kep20] use a circuit-like structure that stores the assignments of each variable of the q-tree in AVL trees. Circuits could also describe such a structure, but they are not so convenient to maintain in the dynamic setting, given that the domain of assignments is not fixed and updates add or remove edges of the circuit. In contrast, [KLN+25] use view-trees, whose interface and implementation can be defined separately; we re-use the structure of view-trees in the present paper. In all these works, the answers are produced in an arbitrary order determined by the data structure, and ranked enumeration or ranked direct access under updates is not handled.

Second, for ranked enumeration or direct access in the static setting, where answers are output according to a ranking function, an important earlier work is [TGR25]. For acyclic free-connex queries, they build a data structure in linearithmic data complexity, after which the answers to Q on D can be enumerated in any lexicographic order with logarithmic delay between consecutive tuples. Ranked direct access, which returns the k-th answer in the user-defined order, has been studied by [CTG+23], who also build a data structure in quasilinear time, with logarithmic access time. Circuits, which are compact representations of the answers, have also been used for direct access, for conjunctive queries with negation [CCIS26], and for enumeration beyond conjunctive queries through knowledge compilation [Hu26]. None of these works considers updates to the database.

Hence, our contribution sits at the intersection of these two lines of work: which orders can we support in the dynamic setting? Since we consider the dynamic setting, we build on the dichotomy established by [Kep20] (and [BKS17] for enumeration), which identifies q-hierarchical queries as the class for which linear preprocessing, constant delay or logarithmic access, and constant updates are possible under updates. We therefore restrict our attention to this class of queries, and we maintain the answers with view-trees [KLN+25].

Contributions. This note presents the preliminary results that we have obtained for ranked enumeration and ranked direct access to conjunctive queries under updates. We focus on q-hierarchical queries, because otherwise intractability holds (for self-join-free queries, and conditionally) even in the absence of ranking functions. We study lexicographic orders defined by an order on the query's free variables, and introduce a condition on such orders, called being hierarchy-consistent. We show that, for hierarchy-consistent orders, we can perform ranked enumeration and ranked direct access following a lexicographic ordering, with the same favorable guarantees as in the case without a specific ordering, up to a logarithmic update time instead of constant update time for enumeration. By contrast, we show that, for non-hierarchy-consistent orders, a conditional intractability result rules out efficient ranked direct access.

Paper structure. The paper is organized as follows: Section 2 introduces the notations and concepts necessary to understand the paper. In Section 3, we define the data structure used for ranked enumeration and ranked direct access in the dynamic setting, and give an algorithm to build it. In Section 4, we define a property on the user-defined order, called hierarchy-consistency, and give two algorithms for ranked enumeration and ranked direct access in the dynamic setting when the order satisfies this property, with bounds in combined complexity. In Section 5, we show that when the order does not satisfy this property, ranked direct access in the dynamic setting is conditionally not achievable, in data complexity, with polynomial preprocessing, sublinear access time, and sublinear update time.