We establish an algorithmic framework for query answering and enumeration in first-order logic with counting on effectively nowhere dense classes of relational structures. Our main technical contribution is an algorithm that, after almost-linear-time preprocessing on a structure $A$ from such a class and a first-order formula $φ(\bar{x}, \bar{y})$, can answer the following queries in constant time: given a tuple $\bar{v} \in A^{|\bar{x}|}$, output the number of tuples $\bar{w} \in A^{|\bar{y}|}$ satisfying $A \models φ(\bar{v},\bar{w})$. In database terms, this is constant-time evaluation of grouped counting queries. Building on this, we achieve constant-time query answering and constant-delay enumeration for the recently introduced clique-guarded first-order logic with counting (cgFOC) [van Bergerem, Lange, and Schweikardt, MFCS 2026] on effectively nowhere dense classes. These results unify and generalise previous work on nowhere dense classes, namely first-order testing and enumeration [Schweikardt, Segoufin, and Vigny, JACM 2022] and the evaluation of the counting logic FOC1 [Grohe and Schweikardt, PODS 2018]. Moreover, under the assumption $\mathrm{FPT} \neq \mathrm{AW}[*]$, our results are essentially optimal: they do not extend to subgraph-closed graph classes beyond the nowhere dense ones, slight generalisations of the clique-guarding mechanism are intractable even on very simple sparse classes, and very restricted fragments of cgFOC are already intractable on very simple dense classes.
翻译:暂无翻译