Enumeration Complexity of Conjunctive Queries with Functional Dependencies
Extracted source text Ā· arXiv 1712.07880
\documentclass[a4paper,UKenglish]{lipics-v2016}
\usepackage{amsmath,amsthm,amsopn,amssymb}
\usepackage{verbatim}
\usepackage{tikz}
\usepackage{bm}
\usetikzlibrary{calc}
\usetikzlibrary{positioning}
%\usepackage{cite}
\usepackage[appendix=append]{apxproof}
\newcommand{\wdpt}{wdPT\xspace}
\newcommand{\wdpts}{wdPTs\xspace}
\newcommand{\TW}{\text{\sf TW}}
\newcommand{\BI}{\text{\sf BI}}
\newcommand{\SBI}{\text{\sf SBI}}
\newcommand{\IFCA}{\text{\sf IFCA}}
\newcommand{\sab}{_{\alpha,\beta}}
\newcommand{\lTW}{\ell\text{-}\TW}
\newcommand{\gTW}{g\text{-}\TW}
\newcommand{\subs}{\sqsubseteq}
\newcommand{\var}{{\it var}}
\newcommand{\ivar}{{\it var}}
\newcommand{\idom}{{\it dom}}
\newcommand{\dltplus}{\Delta_{Q^+}}
\newcommand{\idiff}{{\it diff}}
\newcommand{\Ans}{{\rm Ans}}
\newcommand{\sol}{\mathsf{Sol}}
%% New Commands (too lazy to sort them now)
\newcommand{\SCQ}{\text{CQ}^{\neg}}
\newcommand{\domain}{\operatorname{domain}}
\newcommand{\DelayLog}{{\sf DelayLog_{qlin}}}
\newcommand{\Aplus}{\calA_{+}}
\newcommand{\Aminus}{\calA_{-}}
\newcommand{\arity}{\operatorname{arity}}
\newcommand{\atoms}{\operatorname{atoms}}
\newcommand{\free}{\operatorname{free}}
\newcommand{\tetra}[1]{\text{\sc Tetra}{\normalfont (}#1{\normalfont )}}
\newcommand{\contains}[1]{\text{\sc Contains}\langle#1\rangle}
\newcommand{\pDecide}[1]{\text{\sc Decide}\langle#1\rangle}
\newcommand{\qDecide}[2]{\text{\sc Decide}_{#2}\langle#1\rangle}
\newcommand{\tetpm}[1]{{\sf Tet_{pm}}{\normalfont (}#1{\normalfont )}}
%% Problem Names
\newcommand{\pCQEval}[1]{{\sc CQ-Eval}{\normalfont (}#1{\normalfont )}}
\newcommand{\pCQEnum}[1]{{\sc CQ-Eval}{\normalfont (}#1{\normalfont )}}
\newcommand{\pPosEval}{{\sc Pos-Eval}}
\newcommand{\pEval}[1]{{\sc Eval}{\normalfont (}#1{\normalfont )}}
\newcommand{\pMEval}[1]{{\sc Max-Eval}{\normalfont (}#1{\normalfont )}}
\newcommand{\ppEval}[1]{{\sc $p$-Eval}{\normalfont (}#1{\normalfont )}}
\newcommand{\ppMEval}[1]{{\sc $p$-Max-Eval}{\normalfont (}#1{\normalfont )}}
\newcommand{\pPartEval}[1]{{\sc Partial-Eval}{\normalfont (}#1{\normalfont )}}
\newcommand{\pEnum}[1]{\text{\sc Enum}\langle#1\rangle}
\newcommand{\qEnum}[2]{\text{\sc Enum}_{#2}\langle#1\rangle}
\newcommand{\pMEnum}[1]{{\sc Max-Enum}{\normalfont (}#1{\normalfont )}}
\newcommand{\ppEnum}[1]{{\sc $p$-Enum}{\normalfont (}#1{\normalfont )}}
\newcommand{\ppMEnum}[1]{{\sc $p$-Max-Enum}{\normalfont (}#1{\normalfont )}}
\newcommand{\pExtToMSol}[1]{{\sc Ext2Sol$_{m}$}{\normalfont (}#1{\normalfont )}}
\newcommand{\pStrPEval}[1]{{\sc ExtendSolution}{\normalfont (}#1{\normalfont )}}
\newcommand{\ppClique}{{\sc $p$-Clique}\xspace}
\newcommand{\ppDomSet}{{\sc $p$-Dominating Set}\xspace}
\newcommand{\pDomSet}{{\sc Dominating Set}\xspace}
\newcommand{\pEnumP}{{\sc Enum$_p$}\xspace}
%% Complexity Classes
% --- Decision Classes
\newcommand{\ptime}{\text{\sf PTIME}\xspace}
\newcommand{\FPT}{\text{\sf FPT}\xspace}
\newcommand{\W}[1]{\text{\sf W[#1]}\xspace}
\newcommand{\logcfl}{{\sc LogCFL}\xspace}
\newcommand{\NP}{{\sf NP}\xspace}
\newcommand{\coNP}{{\sf coNP}\xspace}
\newcommand{\DP}{{\sf DP}\xspace}
\newcommand{\SigmaP}[1]{\Sigma_{#1}^P}
\newcommand{\PiP}[1]{\ensuremath{{\Pi}_{#1}^{P}}\xspace}
% --- Enumeration Classes
\newcommand{\sDelayP}{{\sf SDelayP}\xspace}
\newcommand{\DelayP}{{\sf DelayP}\xspace}
\newcommand{\OutputP}{{\sf OutputP}\xspace}
\newcommand{\TotalP}{{\sf TotalP}\xspace}
\newcommand{\DelayC}{{\sf DelayC}}
\newcommand{\DelayClin}{{\sf DelayC_{lin}}}
\newcommand{\DelayLin}{{\sf DelayLin}}
\newcommand{\DelayFPT}{{\sf DelayFPT}\xspace}
\newcommand{\IncFPT}{{\sf IncFPT}\xspace}
\newcommand{\TotalFPT}{{\sf TotalFPT}\xspace}
\newcommand{\OutputFPT}{{\sf OutputFPT}\xspace}
%% Cal-Letters
\newcommand{\calO}{{\mathcal O}}
\newcommand{\calA}{{\mathcal A}}
\newcommand{\calB}{{\mathcal B}}
\newcommand{\calC}{{\mathcal C}}
\newcommand{\calD}{{\mathcal D}}
\newcommand{\D}{{\calD}}
\newcommand{\calE}{{\mathcal E}}
\newcommand{\calF}{{\mathcal F}}
\newcommand{\calG}{\mathcal{G}}
\newcommand{\calH}{{\mathcal H}}
\newcommand{\calI}{{\mathcal I}}
\newcommand{\calN}{{\mathcal N}}
\newcommand{\N}{\mathbb{N}}
\newcommand{\calQ}{{\mathcal Q}}
\newcommand{\calP}{{\mathcal P}}
\newcommand{\calR}{{\mathcal R}}
\newcommand{\calS}{{\mathcal S}}
\newcommand{\calT}{{\mathcal T}}
\newcommand{\U}{\mathbf{U}}
\newcommand{\X}{\mathbf{X}}
%%
\newcommand{\Cpf}{\calC_{\mathsf{pf}}}
\newcommand{\Clall}{\calC_{\mathsf{all}}}
\newcommand{\OMIT}[1]{}
\newcommand{\ra}{\rightarrow}
\newcommand{\PTNEXT}[1]{\operatorname{PTNEXT}(#1)}
\newcommand{\PTPARENT}[1]{\operatorname{PTPARENT}(#1)}
\newcommand{\tdnext}[1]{\operatorname{tdnext}(#1)}
\newcommand{\tdparent}[1]{\operatorname{tdparent}(#1)}
\newcommand{\isafe}{\mathit{safe}}
\newcommand{\iusafe}{\mathit{unsafe}}
\newcommand{\ifvar}{\operatorname{fvars}}
%% FPT Proof
\newcommand{\conn}{\mathit{CONN}}
\newcommand{\local}{\mathit{LOCAL}}
\newcommand{\bad}{\mathit{bad}}
\newcommand{\good}{\mathit{good}}
\newcommand{\Nmu}{\mathcal{N}_\mu}
\newcommand{\Mmu}{\mathcal{M}_\mu}
\newcommand{\nvar}{\mathit{nvar}}
\newcommand{\VN}{\vec{v}_{\mathcal{N}}}
\renewcommand{\appendixprelim}{\newpage\appendix{\Huge\textbf{APPENDIX}}}
\newcommand{\boxtheorem}{\hfill $\Box$}
\newcommand{\nop}[1]{}
\newcommand{\delay}[1]{\mathit{delay}(#1)}
\newcommand{\calM}{\mathcal{M}}
\newcommand{\bigO}{\mathcal{O}}
%opening
\title{Enumeration Complexity of Conjunctive Queries with Functional Dependencies\footnote{This
work was supported
by the German-Israeli Foundation for Scientific Research and Development (GIF), Grant no.~I-2436-407.6/2016
and
by the Austrian Science Fund
(FWF): W1255-N23, P25207-N23, P25518-N23.}}
\titlerunning{Enumeration Complexity of CQs with FDs}
\author[1]{Nofar Carmeli}
\author[2]{Markus Kr\"oll}
\affil[1]{Technion, Haifa, Israel, \texttt{snofca@cs.technion.ac.il}}
\affil[2]{TU Wien, Vienna, Austria, \texttt{kroell@dbai.tuwien.ac.at}}
\authorrunning{N. Carmeli, M. Kr\"oll}
\Copyright{Nofar Carmeli, Markus Kr\"oll}
\subjclass{H.2.3 Database Management ā Languages}
\keywords{Enumeration, Complexity, CQs}
% Author macros::end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Editor-only macros:: begin (do not touch as author)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\EventEditors{Benny Kimelfeld and Yael Amsterdamer}
%\EventNoEds{2}
%\EventLongTitle{21st International Conference on Database Theory (ICDT 2018)}
%\EventShortTitle{ICDT 2018}
%\EventAcronym{ICDT}
%\EventYear{2018}
%\EventDate{March 26-ā29, 2018}
%\EventLocation{Vienna, Austria}
%\EventLogo{}
%\SeriesVolume{98}
%\ArticleNo{11}
%%%% \DOI{10.4230/LIPIcs.xxx.yyy.p}% to be completed by the volume editor
% Editor-only macros::end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\theoremstyle{plain}
\newtheorem{fact}[theorem]{Fact}
\newtheorem{conjecture}[theorem]{Conjecture}
\newtheorem{observation}[theorem]{Observation}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem*{claim}{Claim}
\theoremstyle{definition}
\theoremstyle{plain}
\newtheoremrep{theorem}{Theorem}
\newtheoremrep{lemma}[theorem]{Lemma}
\newtheoremrep{proposition}[theorem]{Proposition}
\newtheoremrep{corollary}[theorem]{Corollary}
\begin{document}
\maketitle
\begin{abstract}
We study the complexity of enumerating the answers of Conjunctive Queries (CQs) in the presence of Functional Dependencies (FDs). Our focus is on the ability to list output tuples with a constant delay in between, following a linear-time preprocessing. A known dichotomy classifies the acyclic self-join-free CQs into those that admit such enumeration, and those that do not. However, this classification no longer holds in the common case where the database exhibits dependencies among attributes. That is, some queries that are classified as hard are in fact tractable if dependencies are accounted for. We establish a generalization of the dichotomy to accommodate FDs; hence, our classification determines which combination of a CQ and a set of FDs admits constant-delay enumeration with a linear-time preprocessing.
In addition, we generalize a hardness result for cyclic CQs to accommodate a common type of FDs. Further conclusions of our development include a dichotomy for enumeration with linear delay, and a dichotomy for CQs with disequalities. Finally, we show that all our results apply to the known class of ``cardinality dependencies'' that generalize FDs (e.g., by stating an upper bound on the number of genres per movies, or friends per person).
\end{abstract}
\section{Introduction}
When evaluating a non-boolean Conjunctive Query (CQ) over a database, the number of results can be huge.
Since this number may be larger than the size of the database itself, we need to use specific measures of
enumeration complexity to describe the hardness of such a problem. In this perspective, the best we
can hope for is to constantly output results, in such a way that the delay between them is unaffected by the size
of the database instance. For this to be possible, we need to allow a precomputation phase before printing
the first result, as linear time preprocessing is necessary to read the input instance.
A known dichotomy determines when the answers to self-join-free acyclic CQs can be enumerated with constant delay after linear time preprocessing~\cite{bdg:dichotomy}. This class of enumeration problems, denoted by $\DelayClin$, can be regarded as the most efficient class of nontrivial enumeration problems
and therefore current work on query enumeration has focused on this class \cite{Durand:2014:EAF:2594538.2594539,DBLP:conf/icdt/SegoufinV17,DBLP:conf/pods/BerkholzKS17}.
Bagan et al.\cite{bdg:dichotomy} show that a subclass of acyclic queries, called \emph{free-connex},
are exactly those that are enumerable in $\DelayClin$, under the common assumption that boolean
matrix multiplication cannot be solved in quadratic time.
An acyclic query is called free-connex if the query remains acyclic when treating the head of the query as
an additional atom.
This and all other results in this paper hold under the RAM model~\cite{Strozecki2010}.
The above mentioned dichotomy only holds when applied to databases with no additional assumptions, but oftentimes this is not the case. In practice, there is usually a connection between different attributes, and \emph{Functional Dependencies} (FDs) and \emph{Cardinality Dependencies} (CDs) are widely used to model situations where some attributes imply others. As the following example shows, these constraints
also have an immediate effect on the complexity of enumerating answers for queries over such a schema.
\begin{example}\label{example:fd-dif1}
For a list of actors and the production companies they work with,
we have the query: $Q(actor,production)\leftarrow \text{Cast}(movie,actor), \text{Release}(movie,production)$.
At first glance, it appears as though this query is not in $\DelayClin$, as it is acyclic but not free-connex. Nevertheless, if we take the fact that a movie has only one production company into account,
we have the FD $\text{Release}:movie\rightarrow production$, and the enumeration problem becomes easy:
we only need to iterate over all tuples of $\text{Cast}$ and replace the $movie$ value with the single $production$ value that the relation $\text{Release}$ assigns to it. This can be done in linear time by first sorting (in linear time~\cite{DBLP:journals/amai/Grandjean96})
both relations according to $movie$.
\qed
\end{example}
Example~\ref{example:fd-dif1} shows that
the dichotomy by Bagan et al.~\cite{bdg:dichotomy} does not hold in the presence of FDs.
In fact, we believe that dependencies between attributes are so common in real life, that
ignoring them in such dichotomies can lead to missing a significant portion of the tractable cases.
Therefore, to get a realistic picture of the enumeration complexity of CQs, we have to take dependencies into account.
The goal of this work is to generalize the dichotomy to fully accommodate FDs.
Towards this goal,
we introduce an extension of a query $Q$ according to the FDs. The extension is called the FD-extended query, and denoted $Q^+$.
In this extension, each atom, as well as the head of the query, contains all variables that can be implied by its variables according to some FD.
This way, instead of classifying every combination of CQ and FDs directly, we encode the dependencies within the extended query, and use the classification of $Q^+$ to gain insight regarding $Q$.
This approach draws inspiration from the proof of a dichotomy in the complexity of \emph{deletion propagation}, in the presence of FDs~\cite{Kimelfeld:2012:DCD}.
However, the problem and consequently the proof techniques are fundamentally different.
The FD-extension is defined in such a way that if $Q$ is satisfied by an assignment,
then the same assignment also satisfies the extension $Q^+$, as the underlying instance is bound
by the FDs.
In fact, we can show that enumerating the solutions of $Q$ under FDs can be reduced to enumerating the solutions of $Q^+$. Therefore, tractability of $Q^+$ ensures that $Q$ can be efficiently solved as well. By using the positive result in the known dichotomy, $Q^+$ is tractable w.r.t enumeration if it is free-connex.
Moreover, it can be shown that the structural restrictions of acyclicity and free-connex are closed
under taking FD-extensions. Hence, the class of
all queries $Q$ such that $Q^+$ is free-connex is an extension of the class of free-connex queries, and this extension is in fact proper.
We denote the classes of queries $Q$ such that $Q^+$ is acyclic or free-connex as FD-acyclic respectively FD-free-connex.
To reach a dichotomy, we now need to answer the following question: Is it possible that $Q$ can be enumerated efficiently even if $Q^+$ is not free-connex?
To show that an enumeration problem is not within a given class, enumeration complexity has few tools to offer. One such tool is a notion of completeness
for enumeration problems~\cite{DBLP:conf/lata/CreignouKPSV17}. However, this notion focuses on problems with a complexity corresponding to higher classes of the polynomial hierarchy. So in order to deal with this problem, Bagan et al.~\cite{bdg:dichotomy} reduced the matrix multiplication problem to enumerating the answers to any query that is acyclic but not free-connex.
This reduction fails, however, when dependencies are imposed on the data, as the constructed database instance does not necessarily satisfy the underlying dependencies.
As it turns out, however, the structure of the FD-extended query $Q^+$ allows us to extend this reduction
to our setting.
By carefully expanding the reduced instance such that on the one hand, the dependencies
hold and on the other hand, the reduction can still be performed within linear time, we establish a dichotomy.
That is, we show that the tractability of enumerating the answers of a self-join-free
query $Q$ in the presence of FDs is exactly characterized by the structure of $Q^+$: Given an FD-acyclic query $Q$,
we can enumerate the answers to $Q$ within the class $\DelayClin$ iff $Q$ is FD-free-connex.
The resulting extended dichotomy, as well as the original one, brings insight to the case of acyclic queries.
Concerning unrestricted CQs, providing even a first solution of a query in linear time is impossible in general.
This is due to the fact that the parameterized complexity of answering boolean CQs,
taking the query size as the parameter,
is $\mathsf{W}[1]$-hard \cite{DBLP:journals/jcss/PapadimitriouY99}.
This does not imply, however,
that there are no cyclic queries with the corresponding enumeration problems in $\DelayClin$.
The fact that no such queries exist requires an additional proof, which was presented by Brault-Baron~\cite{bb:thesis}. This result holds under a generalization of the triangle finding problem, which is considered not to be solvable within linear time \cite{DBLP:conf/focs/WilliamsW10}.
As before, this proof does no longer apply in the presence of FDs. Moreover, it is possible for $Q$ to be cyclic and $Q^+$ acyclic. In fact, $Q^+$ may even be free-connex, and therefore tractable in $\DelayClin$.
We show that, under the same assumptions used by Brault-Baron~\cite{bb:thesis}, the evaluation problem for a
self-join-free CQ in the presence of unary FDs where $Q^+$ is cyclic cannot be solved in linear time.
As linear time preprocessing is not enough to achieve the first result,
a consequence is that enumeration within $\DelayClin$ is impossible in that case.
This covers all types of CQs and shows a full dichotomy, at least for the case of unary FDs.
The results we present here are not limited to FDs.
CDs (Cardinality Dependencies) \cite{DBLP:journals/pvldb/CaoFWY14,DBLP:conf/icalp/ArapinisFG16}
are a generalization of FDs, denoted $(R_i:A\rightarrow B,c)$. Here, the right-hand side does not have to be unique for every assignment to the left-hand side, but there can be at most $c$ different values to the variables of $B$ for every value of the variables of $A$. FDs are in fact a special case of CDs where $c=1$. Constraints of that form appear naturally in many applications. For example: a movie has only a handful of directors, there are at most 200 countries, and a person is typically
limited to at most 5000 friends in (some) social networks.
We show that all results described in this paper also apply to CDs.
Moreover, we show how our results can be easily used to yield additional results, such as a dichotomy for CQs with disequalities, and a dichotomy to evaluate CQs with linear delay.
\subparagraph*{Contributions.}
Our main contributions are as follows.
\begin{itemize}
\item We extend the class of queries that can be evaluated in $\DelayClin$ by incorporating the FDs.
This extension is the class of FD-free-connex CQs.
\item We establish a dichotomy for the enumeration complexity of self-join-free
FD-acyclic CQs. Consequently, we get a dichotomy for self-join-free acyclic CQs under FDs.
\item We show a lower bound for FD-cyclic CQs. In particular, we get a dichotomy for all self-join-free CQs in the presence of unary FDs.
\item We extend our results to CDs.
\end{itemize}
This work is organized as follows: In Section~\ref{sec:Preliminaries}
we provide definitions and state results that we will use.
Section~\ref{sec:extending} introduces the notion of FD-extended queries
and establishes the equivalence between a query and its FD-extension.
The generalized version of the dichotomy is shown in Section~\ref{sec:Positive}.
In Section~\ref{sec:cyclic}, a lower bound
for cyclic queries under unary FDs is shown, and Section~\ref{section:cardinalitydep} shows that all results from the previous sections extend to CDs. Concluding remarks are given in Section~\ref{section:conclusion}.
Full proofs for all of our results are given in the appendix.
\section{Preliminaries} \label{sec:Preliminaries}
In this section we provide preliminary definitions as well as state results that we will use throughout this paper.
\subparagraph*{Schemas and Functional Dependencies.}
A {\em schema} $\calS$ is a pair $(\calR,\Delta)$ where $\calR$ is a finite set $\{R_1,\ldots,R_n\}$ of {\em relational symbols} and $\Delta$ is a set of {\em Functional Dependencies} (FDs).
We denote the {\em arity} of a relational symbol $R_i$
as $\arity(R_i)$. An FD $\delta\in\Delta$ has the form
$R_i\colon A\rightarrow B$, where $R_i\in\calR$ and $A,B$ are non-empty with $A,B\subseteq\{1,\ldots,\arity(R_i)\}$.
Let $\idom$ be a finite set of constants. A database $I$ over schema $\calS$ is called an
{\em instance} of $\calS$, and it consists of a finite relation $R_i^I\subseteq\idom^{\arity(R_i)}$ for every relational symbol $R_i\in\calR$, such that all FDs in $\Delta$ are {\em satisfied}.
An FD $\delta=R_i\colon A\rightarrow B$ is said to be satisfied if, for all tuples $u,v\in R_i^{I}$ that are
equal on the indices of $A$, $u$ and $v$ are equal on the indices of $B$.
Here we assume that all FDs are of the form
$R_i\colon A\rightarrow b$, where $b\in\{1,\ldots,\arity(R_i)\}$, as we can replace an FD of the form $R_i\colon A\rightarrow B$ where $|B|>1$ by the set of FDs $\{R_i\colon A\rightarrow b\mid b\in{B}\}$.
If $|A|=1$, we say that $\delta$ is a {\em unary} FD.
\subparagraph*{Conjunctive Queries.}
Let $\ivar$ be a set of variables disjoint from $\idom$.
A {\em Conjunctive Query} (CQ) over a schema $\calS=(\calR,\Delta)$ is an expression of the form
$Q(\vec{x}) \leftarrow R_1(\vec{v}_1), \dots, R_m(\vec{v}_m)$, where $R_1,\ldots,R_m$ are relational symbols of $\calR$, the tuples $\vec{x}, \vec{v}_1,\ldots, \vec{v}_m$ hold variables, and every variable in $\vec{x}$ appears in at least one of $\vec{v}_1,\ldots, \vec{v}_m$.
We often denote this query as
$Q(\vec{x})$ or even $Q$. Define the variables of $Q$ as
$\ivar(Q)=\bigcup_{i=1}^{m} \vec{v}_i$,
and define the {\em free variables}
of $Q$ as $\free(Q)=\vec{x}$.
We call $Q(\vec{x})$ the head of $Q$, and the atomic formulas $R_i(\vec{v}_i)$ are called {\em atoms}.
We further use $\atoms(Q)$ to denote the set of atoms of Q.
A CQ is said to contain {\em self-joins} if some relation symbol appears in more than one atom.
For the {\em evaluation} $Q(I)$ of a CQ $Q$ with free variables $\vec{x}$ over a database $I$,
we define $Q(I)$ to be the set of all \emph{mappings}
$\mu|_{\vec{x}}$ such that $\mu$ is a homomorphism from
$R_1(\vec{v}_1), \dots , R_m(\vec{v}_m)$ into $I$, where $\mu|_{\vec{x}}$
denotes the restriction (or projection) of $\mu$ to the variables
$\vec{x}$.
The problem $\qDecide{Q}{\Delta}$ is, given a database instance $I$, determining whether such a mapping exists.
Given a query $Q$ over a schema $\calS=(\calR,\Delta)$, we often identify an FD $\delta\in\Delta$ as a mapping between variables. That is, if $\delta$ has the form
$R_i:A\rightarrow b$ for $A=\{a_1,\ldots,a_{|A|}\}$,
we sometimes denote it by $R_i\colon\{\vec{v}_i[a_1],\ldots,\vec{v}_i[a_{|A|}]\}\rightarrow\vec{v}_i[b]$, where $\vec{u}[k]$ is the $k$-th variable of $\vec{u}$. To distinguish between these two representations, we usually
denote subsets of integers by $A,B,C,\ldots$, integers by $a,b,c,\ldots$, and
variables by letters from the end of the alphabet.
\subparagraph*{Hypergraphs.}
A {\em hypergraph} $\calH=(V,E)$ is a pair consisting of a set $V$ of {\em vertices}, and a set $E$ of non-empty subsets of $V$ called {\em hyperedges} (sometimes {\em edges}).
A \emph{join tree} of a hypergraph $\calH=(V,E)$ is a tree $T$ where the nodes are the hyperedges of $\calH$, and the {\em running intersection} property holds, namely: for all $u \in V$ the set $\{e \in E \mid u \in e\}$ forms a connected subtree in $T$.
A hypergraph $\calH$ is said to be {\em acyclic} if there exists a join tree for $\calH$.
Two vertices in a hypergraph are said to be {\em neighbors} if they appear in the same edge.
A {\em clique} of a hypergraph is a set of vertices, which are pairwise neighbors in $\calH$.
A hypergraph $\calH$ is said to be {\em conformal} if every clique of $\calH$ is contained in some edge of $\calH$.
A {\em chordless cycle} of $\calH$ is a tuple $(x_1,\ldots,x_n)$ such that the set of neighboring pairs of variables of $\{x_1,\ldots,x_n\}$ is exactly $\{\{x_i,x_{i+1}\}\mid 1\leq i\leq n-1\}\cup\{\{x_n,x_1\}\}$. It is well known (see~\cite{DBLP:journals/jacm/BeeriFMY83})
that a hypergraph is acyclic iff it is conformal and contains no chordless cycles.
A {\em pseudo-minor} of a hypergraph $\calH=(V,E)$ is a hypergraph obtained from $\calH$ by a finite series of the following operations:
(1) {\em vertex removal}: removing a vertex from $V$ and from all edges in $E$ that contain it.
(2) {\em edge removal}: removing an edge $e$ from $E$ provided that some other $e'\in E$ contains it.
(3) {\em edge contraction}: replacing all occurrences of a vertex $v$ (within every edge) with a vertex $u$, provided that $u$ and $v$ are neighbors.
\subparagraph*{Classes of CQs.}
To a CQ $Q$ we associate a hypergraph $\calH(Q)=(V,E)$ where the vertices $V$ are the variables of $Q$ and every hyperedge $E$ is a set of variables occurring in a single atom of $Q$, that is $E=\{\{v_1,\ldots,v_n\}\} \mid R_i(v_1,\ldots,v_n)\in\atoms(Q)\}$. With a slight abuse of notation, we also identify atoms
of $Q$ with edges of $\calH(Q)$.
A CQ $Q$ is said to be {\em acyclic} if $\calH(Q)$ is acyclic, and it is said to be {\em free-connex} if both $Q$ and $(V, E\cup\{\free(Q)\})$ are acyclic.
A {\em head-path} for a CQ $Q$ is a sequence of variables $(x,z_1,\ldots,z_k,y)$ with $k\geq 1$, such that:
(1) $\{x,y\}\subseteq \free(Q)$
(2) $\{z_1,\ldots,z_k\}\subseteq V\setminus\free(Q)$
(3) It is a {\em chordless path} in $\calH(Q)$, that is, two succeeding variables appear together in some atom, and no two non-succeeding variables appear together in an atom.
Bagan et al.~\cite{bdg:dichotomy} showed that
an acyclic CQ has a head-path iff it is not free-connex.
\subparagraph*{Enumeration Complexity.}
Given a finite alphabet $\Sigma$ and binary relation $R\subseteq\Sigma^*\times\Sigma^*$,
we denote by $\pEnum{R}$ the {\em enumeration problem} of given an instance $x\in\Sigma^*$, to output all $y\in\Sigma^*$ such that $(x,y)\in R$.
In this paper we adopt the \emph{Random Access Machine} (RAM) model (see \cite{Strozecki2010}). Previous results in the field assume different variations of the RAM model. Here we assume that the length of memory registers is linear in the size of value registers, that is, the accessible memory is polynomial.
For a class $\calC$ of enumeration problems, we say that $\pEnum{R}\in\calC$, if there is a RAM that
-- on input $x\in\Sigma^*$-- outputs all $y\in\Sigma^*$ with
$(x,y)\in R$ without repetition such that the first output is computed in time $p(|x|)$ and the delay
between any two consecutive outputs after the first is $d(|x|)$, where:
\begin{itemize}
\item For $\pEnum{R}\in\DelayClin$, we have $p(|x|)\in O(|x|)$ and $d(|x|)\in O(1)$.
\item For $\pEnum{R}\in\DelayLin$, we have $p(|x|),d(|x|)\in O(|x|)$.
\end{itemize}
Let $\pEnum{R_1}$ and $\pEnum{R_2}$ be enumeration problems. We say that there is an {\em exact reduction} from $\pEnum{R_1}$ to $\pEnum{R_2}$, written as $\pEnum{R_1}\leq_e\pEnum{R_2}$, if there are
mappings $\sigma$ and $\tau$ such that for every $x\in\Sigma^*$
the mapping $\sigma(x)$ is computable in $O(|x|)$,
for every $y\in\Sigma^*$ with $(\sigma(x),y)\in R_2$, $\tau(y)$ is computable in constant time and
$\{\tau(y)\mid y\in\Sigma^*\text{ with }(\sigma(x),y)\in R_2\} =
\{y'\in\Sigma^*\mid (x,y')\in R_1\}$ in multiset notation.
Intuitively, $\sigma$ is used to map instances of $\pEnum{R_1}$ to instances of $\pEnum{R_2}$,
and $\tau$ is used to map solutions to $\pEnum{R_2}$ to solutions of $\pEnum{R_1}$.
An enumeration class $\calC$ is said to be \emph{closed under exact reduction} if for
every $\pEnum{R_1}$ and $\pEnum{R_2}$ such that $\pEnum{R_1}\leq_e\pEnum{R_2}$ and $\pEnum{R_2}\in\calC$, we have $\pEnum{R_1}\in\calC$.
Bagan et al.~\cite{bdg:dichotomy} proved that $\DelayClin$ is closed under exact reduction.
The same proof holds for any meaningful enumeration complexity class that guarantees generating all unique answers with at least linear preprocessing time and at least constant delay between answers.
\subparagraph*{Enumerating Answers to CQs.}
For a CQ $Q$ over a schema $\calS=(\calR,\Delta)$, we denote by $\qEnum{Q}{\Delta}$ the enumeration problem $\pEnum{R}$, where $R$ is the binary relation between instances $I$ over $\calS$ and sets of mappings $Q(I)$. We consider the size of the query as well as the size of the schema to be fixed.
Bagan et al.~\cite{bdg:dichotomy} showed that a self-join-free acyclic CQ is in $\DelayClin$ iff it is free-connex:
\begin{theorem}[\cite{bdg:dichotomy}]\label{theorem:originalDichotomy}
Let $Q$ be an acyclic CQ without self-joins over a schema $\calS=(\calR,\emptyset)$.
\begin{enumerate}
\item If $Q$ is free-connex, then $\qEnum{Q}{\emptyset}\in\DelayClin$.
\item If $Q$ is not free-connex, then $\qEnum{Q}{\emptyset}\not\in\DelayClin$, assuming the product of
two $n \times n$ boolean matrices cannot be computed in time $O(n^2)$.
\end{enumerate}
\end{theorem}
\section{FD-Extended CQs}\label{sec:extending}
In this section, we formally define the extended query $Q^+$.
We then discuss the relationship between $Q$ and $Q^+$: their equivalence w.r.t.~enumeration
and the possible structural differences between them.
As a result, we obtain that if $Q^+$ is in a class of queries that allows for tractable enumeration,
then $Q$ is tractable as well.
We first define $Q^+$.
The {\em extension} of an atom $R(\vec{v})$ according to an
FD $S\colon A\rightarrow b$ where $S(\vec{u})\in\atoms(Q)$
is possible if $\vec{u}[A]\subseteq\vec{v}$
but $\vec{u}[b]\notin\vec{v}$. In that case, $\vec{u}[b]$ is added to the variables of $R$.
The {\em FD-extension} of a query is defined by iteratively extending all
atoms as well as the head according to every possible dependency in the schema, until a fixpoint is reached.
The schema extends accordingly: the arities of the relations increase as their corresponding atoms extend, and dummy variables are added to adjust to that change in case of self-joins. The FDs apply in every relation that contains all relevant variables.
\begin{definition}\label{definition:fdextended}[(FD-Extended Query)]
Let $Q(\vec{w}) \leftarrow R_1(\vec{v_1}), \dots, R_m(\vec{v_m})$ be a CQ
over a schema $\calS=(\calR,\Delta)$.
We define two types of extension steps:
\begin{itemize}
\item The extension of an atom $R_i(\vec{v_i})$ according to an FD $R_j\colon A\rightarrow b$.\\
Prerequisites: $\vec{v_j}[A]\subseteq \vec{v_i}$ and $\vec{v_j}[b]\notin \vec{v_i}$.\\
Effect: The arity of $R_i$ increases by one, and $R_i(\vec{v_i})$ is replaced by $R_i(\vec{v_i},\vec{v_j}[b])$.
In addition, every $R_k(\vec{v_k})$ such that $R_k$=$R_i$ and $k\neq i$ is replaced with $R_k(\vec{v_k},t_k)$, where $t_k$ is a fresh variable.
\item The extension of the head $Q(\vec{w})$ according to an FD $R_j\colon A\rightarrow b$.\\
Prerequisites: $\vec{v_j}[A]\subseteq \vec{w}$ and $\vec{v_j}[b]\notin \vec{w}$.\\
Effect: The head is replaced by $Q(\vec{w},\vec{v_j}[b])$.
\end{itemize}
The {\em FD-extension} of $Q$ is the query $Q^+(\vec{y})\leftarrow R_1^+(\vec{u_m}), \dots, R_m^+(\vec{u_m})$, obtained by performing all possible extension steps on $Q$ according to FDs of $\Delta$ until a fixpoint is reached. The extension is defined over the schema $\calS^+=(\calR^+,\dltplus)$, where $\calR^+$ is $\calR$ with the extended arities, and $\dltplus=\{R_i^+\colon C\to d \mid\exists (R_j\colon A\rightarrow b)\in\Delta\text{ s.t. }
\vec{u_i}[C]=\vec{v_j}[A]\text{ and }\vec{u_i}[d]=\vec{v_j}[b]\}$.
\end{definition}
Given a query, its FD-extension is unique up to a permutation of the added variables, and renaming of the new variables.
As the order of the variables and the naming make no difference w.r.t.~enumeration, we can treat the FD-extension as unique.
\begin{example}
Consider a schema with $\Delta=\{R_1\colon 1\rightarrow 2, R_3\colon 2,3\rightarrow 1\}$, and the query $Q(x)\leftarrow R_1(x,y),R_2(x,z),R_2(u,z),R_3(w,y,z)$.
As the FDs are $x\rightarrow y$ and $yz\rightarrow w$, the FD-extension is
$Q^+(x,y)\leftarrow R_1^+(x,y),R_2^+(x,z,y,w),R_2^+(u,z,t_1,t_2), R_3^+(w,y,z)$.
We first apply $x\rightarrow y$ on the head,
and then $x\rightarrow y$ and consequently $yz\rightarrow w$ on $R_2(x,z)$.
These two FDs now appear in the schema also for $R_2$, and the FDs of the extended schema are
$\dltplus=\{R_1^+\colon 1\rightarrow 2, R_2^+\colon 1\rightarrow 3, R_2^+\colon 3,2\rightarrow 4, R_3^+\colon 2,3\rightarrow 1\}$.
\qed
\end{example}
We later show that the enumeration complexity of a CQ $Q$ over a schema with FDs only depends on the structure of $Q^+$, which is implicitly given by $Q$. Therefore, we introduce the notions of acyclic and free-connex queries for FD-extensions:
\begin{definition}
Let $Q$ be a CQ over a schema $\calS=(\calR, \Delta)$, and let $Q^+$ be its FD-extension.
\begin{itemize}
\item We say that $Q$ is {\em FD-acyclic}, if $Q^+$ is acyclic.
\item We say that $Q$ is {\em FD-free-connex}, if $Q^+$ is free-connex.
\item We say that $Q$ is {\em FD-cyclic}, if $Q^+$ is cyclic.
\end{itemize}
\end{definition}
The following proposition shows that the classes of acyclic queries and free-connex queries are both closed under constructing FD-extensions.
\begin{propositionrep}\label{prop:plusstructure}
Let $Q$ be a CQ over a schema $\calS=(\calR,\Delta)$.
\begin{itemize}
\item If the query $Q$ is acyclic, then it is FD-acyclic.
\item If the query $Q$ is free-connex, then it is FD-free-connex.
\end{itemize}
\end{propositionrep}
\begin{proof}
We prove that if $Q$ is acyclic, then $Q^+$ is also acyclic (the case where $Q$ is free-connex follows along the same lines).
Denote by $Q=Q_0,Q_1,\ldots,Q_n=Q^+$ a sequence of queries such that $Q_{i+1}$ is the result of extending all possible relations of $Q_i$ according to a single FD $\delta\in\Delta$. By induction, it suffices to show that if $Q_i$ is acyclic, then $Q_{i+1}$ is acyclic as well.
So consider an acyclic query $Q_i(\vec{w}) \leftarrow R_1(\vec{v}_1), \dots, R_m(\vec{v}_m)$ extended to the query $Q_{i+1}(\vec{t}) \leftarrow R_1(\vec{u}_1), \dots, R_m(\vec{u}_m)$ according to the FD $\delta=R_j\colon \vec{x}\rightarrow y$. Further let $T_i=(V_i,E_i)$ be the join tree of $\calH(Q_i)$.
We claim that the same tree (but with the extended atoms), is a join tree for $Q_{i+1}$. More formally, define $T_{i+1}=(V_{i+1},E_{i+1})$ such that $V_{i+1}=\{R_k(\vec{u}_k)\mid 1\leq k\leq m\}$ and $E_{i+1}=\{(R_k(\vec{u}_k),R_l(\vec{u}_l))\mid(R_k(\vec{v}_k),R_l(\vec{v}_l))\in E_i\}$. Next we show that the running intersection property holds in $T_{i+1}$, and therefore it is a join tree of $Q_{i+1}$.
For the new variables introduced in the extension, every such variable appears only in one atom, so the subtree of $T_{i+1}$ containing such a variable contains one node and is trivially connected.
For any other variable $w\neq y$, the attribute $w$ appears in the same atoms in $Q$ and $Q^+$. Therefore, the subgraph of $T_{i+1}$ containing $w$ is isomorphic to the subgraph of $T_{i}$ containing $w$, and since $T_i$ is a join tree, it is connected.
It is left to show that the subtree of $T_{i+1}$ containing $y$ is connected.
let $R_j$ be the atom in $Q$ containing $\delta$. Note that $R_j$ corresponds to vertices in $T_i$ and $T_{i+1}$ containing $\vec{x}$ and $y$.
Let $R_k$ be some vertex in $T_{i+1}$ containing $y$.
We will show that all vertices $S_1,\ldots,S_r$ on the path between $R_k$ and $R_j$ contain $y$.
If $y$ appears in the vertex $R_k$ in $T_i$, then it also appears in $S_1,\ldots,S_r$ since $T_i$ is a join tree. Since the extension doesn't remove occurrences of variables, $y$ appears in these vertices in $T_{i+1}$ as well.
Otherwise, $y$ was added to $R_k$ via $\delta$. Since $T_i$ is a join tree, the vertices $S_1,\ldots,S_r$ all contain the variables $\vec{x}$. Thus by the definition of $Q_{i+1}$, $y$ is added to each of $S_1,\ldots,S_r$ (if it was not already there) in $T_{i+1}$. Thus also the subtree of $T_{i+1}$ containing $y$ is connected. Therefore $T_{i+1}$
is indeed a join tree.
\end{proof}
Example~\ref{example:fd-dif1} shows that the converse of the proposition above does not hold.
This means that, by Theorem~\ref{theorem:originalDichotomy}, there are queries $Q$ such that we can enumerate the answers to $Q^+$ in $\DelayClin$, but we cannot enumerate the answers to $Q$ with the same complexity,
if we do not assume the FDs.
The following lemma shows that enumerating the answers of $Q$ (when relying on the FDs)
is in fact equally hard as enumerating the answers of $Q^+$.
\begin{theoremrep}\label{thm:qpEquiv}
Let $Q$ be a CQ over a schema $\calS=(\calR,\Delta)$, and let $Q^+$ be its FD-extended query. Then $\qEnum{Q}{\Delta}\leq_e\qEnum{Q^+}{\dltplus}$
and $\qEnum{Q^+}{\dltplus}\leq_e\qEnum{Q}{\Delta}$.
\end{theoremrep}
\begin{proofsketch}
We first sketch the reduction $\qEnum{Q}{\Delta}\leq_e\qEnum{Q^+}{\dltplus}$.
Given an instance $I$ for the problem $\qEnum{Q}{\Delta}$, we set $\sigma(I)=I^+$ as described next.
We start by removing tuples that interfere with the extended dependencies. For every dependency $R_j\colon X\rightarrow y$ and every atom $R_k(\vec{v_k})$ that contains the variables $X\cup\{y\}$, we only keep tuples of $R_k^I$ that agree with some tuple of $R_j^I$ over the values of $X\cup\{y\}$.
Next, we follow the extension of the schema, and in each step we extend some $R_i^I$ to $R_i^{I'}$ according to some FD $R_j\colon X\rightarrow y$.
For each tuple $t\in R^I_i$, if there is no tuple $s\in R^I_j$ that agrees with $t$ over the values of $X$, then we remove $t$ altogether.
Otherwise, we copy $t$ to $R^{I'}_i$ and assign $y$ with the same value that $s$ assigns it.
Given an answer $\mu\in Q^+(\sigma(I))$, we set $\tau(\mu)$ to be the projection of $\mu$ to $\free(Q)$.
To show that $\qEnum{Q^+}{\dltplus}\leq_e\qEnum{Q}{\Delta}$, we describe the construction of an instance $\sigma(I^+)$ by ``reversing'' the extension steps. If an atom was extended, we simply remove the added attribute. If the head was extended using some $R_j\colon X\rightarrow y$, then for each tuple in $R_j^{I^{i+1}}$ that assigns $y$ and $X$ with the values $y_0$ and $\vec{x}_0$ respectively, we add the value $y_0$ to a lookup table with pointer $(X,\vec{x}_0,y)$.
For every $\mu\in Q(\sigma(I^+))$, $\tau(\mu)$ is defined
as $\mu$ extended by the values from the lookup table.
\end{proofsketch}
\begin{proof}
Let $Q(\vec{p}) \leftarrow R_1(\vec{v}_1), \dots, R_m(\vec{v}_m)$ and
$Q^+(\vec{q})\leftarrow R_1^+(\vec{u}_m), \dots, R_m^+(\vec{u}_m)$.
We first show that $\qEnum{Q}{\Delta}\leq_e\qEnum{Q^+}{\dltplus}$.
Given an instance $I$ for the problem $\qEnum{Q}{\Delta}$, we set $\sigma(I)=I^+$ as described next.
We start by removing tuples that interfere with the extended dependencies. For every dependency
$\delta=R_j\colon X\rightarrow y$ and every atom $R_k(\vec{v}_k)$ that contains
the corresponding variables (i.e., $X\cup\{y\}\subseteq \vec{v}_k$),
we correct $R_k$ according to $\delta$:
We only keep tuples of $R_k^I$ that agree with some tuple of $R_j^I$ over the values of
$X\cup\{y\}$.
We say that a tuple $t_a\in R_a^I$ agrees with a tuple $t_b\in R_b^I$ on the value of a variable $z$ if for every pair of indices $i_a,i_b$ such that $\vec{v_a}[i_a]=\vec{v_b}[i_b]=z$ we have that $t_a[i_a]=t_b[i_b]$.
This check can be done in linear time by first sorting both $R_j^I$ and $R_k^I$ according to
$X\cup\{y\}$, and then performing one scan over both of them.
Next, we follow the extension of the schema, and in each step we extend some $R_i^I$ to $R_i^{I'}$ according to some FD $R_j\colon X\rightarrow y$ as described in Definition~\ref{definition:fdextended}.
For each tuple $t\in R^I_i$, if there is no tuple $s\in R^I_j$ that agrees with $t$ over the values of $X$, then we remove $t$ altogether.
Otherwise, we copy $t$ to $R^{I'}_i$ and assign $y$ with the same value that $s$ assigns it.
We say that a tuple $t\in R_a^I$ assigns a variable $z$ with the value $u_a$ if for every index $i_a$ such that $\vec{v}_a[i_a]=z$ we have that $t[i_a]=u_a$.
Given an answer $\mu\in Q^+(\sigma(I))$, we set $\tau(\mu)$ to be the projection of $\mu$ to $\free(Q)$. The projection $\tau(\mu)$ is computable in constant time.
For the correctness, we need to show that $Q(I)=\{\mu|_{\free(Q)}:\mu|_{\free(Q^+)}\in Q^+(\sigma(I))\}$ in multiset notation.
The easy direction is that if $\mu|_{\free(Q^+)}\in Q^+(\sigma(I))$ then $\mu|_{\free(Q)}\in Q(I)$.
Since $\mu$ is a homomorphism from $Q^+$ to $\sigma(I)$, and since all tuples of $\sigma(I)$ appear (perhaps projected) in $I$, then $\mu$ is also a homomorphism from $Q$ to $I$.
We now show the opposite direction, that if $\mu|_{\free(Q)}\in Q(I)$ then $\mu|_{\free(Q^+)}\in Q^+(\sigma(I))$.
Consider a sequence of queries $Q=Q_0,Q_1,\ldots,Q_n=Q^+$ such that each one is the result of extending an atom or the head of the previous query according to an FD $R_j\colon X\rightarrow y$.
We claim that if $\mu|_{\vec{p}_i}$ is an answer for $Q_i(\vec{p}_i)$, then $\mu|_{\vec{p}_{i+1}}$ is an answer for $Q_{i+1}(\vec{p}_{i+1})$. This claim is trivial in case the head was extended. Note also that there cannot be two answers $\mu|_{\vec{p}_{i+1}}$ and $\mu'|_{\vec{p}_{i+1}}$ to $Q_{i+1}$ such that $\mu|_{\vec{p}_{i}}=\mu'|_{\vec{p}_{i}}$, as the added variable $v$ is bound by the FD to have only one possible value.
Now consider the case where an atom $R_k(\vec{v}_k)$ was extended since $X\subseteq\vec{v}_k$. Denote by $t_k$ and $t_j$ the tuples that are mapped by $\mu$ from $R_k$ and $R_j$ respectively. The construction guarantees that $t_k$ and $t_j$ agree on the value of $y$, so $\mu$ can still map the extended $R_k$ to the extended $t_k$. In case of self-joins, other atoms with the relation $R_k$ are extended with a new and distinct variable, and the new variable can be mapped to any value appearing in the extension. Therefore if $\mu|_{\free(Q)}\in Q(I)$ then $\mu|_{\free(Q^+)}\in Q^+(\sigma(I))$.
To show that $\qEnum{Q^+}{\dltplus}\leq_e\qEnum{Q}{\Delta}$, we now define the mapping $\sigma$ between instances. Let $I^+$ be an instance of $Q^+$.
First, we ``clean'' $I^+$ from any tuples that disagree with original FDs. That is, for every FD $R_j\colon X\rightarrow y$ and every atom $R_k^+(\vec{u}_k)$ such that $X\cup\{y\}\subseteq\vec{u}_k$, remove all tuples $t\in R_k^{+I^+}$ that agree with some tuple $s\in R_j^{+I^+}$ over $X$ but disagree with $s$ over $y$. This can be done in linear time by first sorting both $R_k^{+I^+}$ and $R_j^{+I^+}$ according to $X$. Next, we construct a lookup table $T$. For every $y\in\free(Q^+)\setminus\free(Q)$ added to the head due to an FD $R_j\colon X\rightarrow y$, denote by $\vec{x}$ a vector containing the variables of $X$ in lexicographic order,
for each tuple in $R_j^{+I^+}$ that assigns $y$ and $\vec{x}$ with the values $y_0$ and $\vec{x}_0$ respectively, we add the value $y_0$ to the lookup table with pointer $(\vec{x},\vec{x}_0,y)$. Note that due to the FD, a pointer cannot map to two different values. Lastly, we project the relations $\calR^{+I^+}$ to ${\calR}$.
These steps result in the construction of an instance $\sigma(I^+)= I$ and a lookup table $T$ in linear time.
Given $\mu|_{\free(Q)}\in Q(\sigma(I^+))$, we now define $\tau(\mu|_{\free(Q)})$. We define a mapping $\nu_\mu$ for the variables added to the head using the lookup table. For every $y\in\free(Q^+)\setminus\free(Q)$ added due to some FD $R_j\colon X\rightarrow y$, we add $(y,T[(\vec{x},\mu[\vec{x}],y)])$ to $\nu_\mu$.
We define $\tau(\mu|_{\free(Q)})=\mu|_{\free(Q)}\cup\nu_\mu$.
Note that $\tau$ is computable in constant time since we can use the lookup table in constant time.
We need to show that $Q^+(I^+)=\{\tau(\mu|_{\free(Q)}):\mu|_{\free(Q)}\in Q(\sigma(I^+))\}$ in multiset notation.
First we claim that given $\mu|_{\free(Q)}\in Q(\sigma(I^+))$, we have that $\tau(\mu|_{\free(Q)})=\mu|_{\free(Q^+)}$.
If $\nu_\mu$ maps $y$ to $T[(\vec{x},\mu[\vec{x}],y)]$, then $y\in\free(Q^+)\setminus\free(Q)$ was added to the head due to some FD $R_j\colon X\rightarrow y$, and there is some tuple in $R_j^{+I^+}$ that assigns $y$ and $\vec{x}$ with the values $T[(\vec{x},\mu[\vec{x}],y)]$ and $\mu[\vec{x}]$ respectively. Due to the dependency, all tuples of $R_j^{+I^+}$ which assign $\vec{x}$ with $\mu[\vec{x}]$, also assign $y$ with $T[(\vec{x},\mu[\vec{x}],y)]$, and this is also true in $R_j^{I}$.
%This includes any tuple that is mapped by $\mu$ from $R_j$.
Therefore $\mu$ also maps $y$ to $T[(\vec{x},\mu[\vec{x}],y)]$. This means that $\tau(\mu|_{\free(Q)})=\mu|_{\free(Q)}\cup\nu_\mu=\mu|_{\free(Q^+)}$.
We now show the first direction, that given $\mu|_{\free(Q)}\in Q(\sigma(I^+))$ we have that $\tau(\mu|_{\free(Q)})\in Q^+(I^+)$.
We now claim that $\mu$ is (a subset of) a homomorphism from $Q^+$ to $I^+$.
We know that $\mu$ is a homomorphism from $Q$ to $I$.
For any $1\leq i\leq m$, denote by $t_i$ the tuple $t_i=\mu(\vec{v}_i)$.
If an atom $R_k$ was extended due to an FD $R_j\colon X\rightarrow y$, then $t_j$ and the extension of $t_k$ must agree on $y$, otherwise this $t_k$ would have been deleted in the cleaning phase.
In case of self-joins, additional atoms $R_i$ such that $R_i=R_k$ may have been extended with new variables. As each new variable has only one occurrence, the extension of these atoms does not interfere with $\mu$, as the new variables can map to any value present in the tuple that was mapped by $\mu$ from $R_i$. We conclude that $\tau(\mu|_{\free(Q)})=\mu|_{\free(Q^+)}\in Q^+(I^+)$.
The second direction is that given $\mu|_{\free(Q^+)}\in Q^+(I^+)$, we have that $\mu|_{\free(Q)}\in Q(\sigma(I^+))$ and $\tau(\mu|_{\free(Q)})=\mu|_{\free(Q^+)}$.
It is only left to show that $\mu|_{\free(Q)}\in Q(\sigma(I^+))$.
Indeed, if $\mu$ maps an atom $R_i^+(\vec{u}_i)$ to a tuple $t\in R_i^{I^+}$, then it maps $R_i(\vec{v}_i)$ to the same (perhaps projected) tuple in $R_i^I$.
This tuple was not removed during the cleaning phase, as the only removed tuples do not have a tuple of $R_j^{I^+}$ agreeing with them on the value of $y$, and therefore $\mu$ cannot map $R_i^{I^+}$ to them.
\end{proof}
The direction $\qEnum{Q}{\Delta}\leq_e\qEnum{Q^+}{\dltplus}$ of Theorem~\ref{thm:qpEquiv} proves that
FD-extensions can be used to expand tractable enumeration classes, as the following corollary states.
\begin{corollaryrep}\label{cor:posExtension}
Let $\calC$ be an enumeration class that is closed under exact reduction.
Let $Q$ be a CQ and let $Q^+$ be its FD-extended query.
If $\qEnum{Q^+}{\dltplus}\in\calC$, then $\qEnum{Q}{\Delta}\in\calC$.
\end{corollaryrep}
\begin{proof}
According to Theorem~\ref{thm:qpEquiv}, $\qEnum{Q}{\Delta}\leq_e\qEnum{Q^+}{\dltplus}$.
Since $\qEnum{Q^+}{\dltplus}\in\calC$ and $\calC$ is closed under exact reduction, we have that $\qEnum{Q}{\Delta}\in\calC$.
\end{proof}
Since free-connex queries are in $\DelayClin$ and $\DelayClin$ is closed under exact
reduction, if $Q$ is an FD-free-connex query, then the corresponding enumeration problem is in $\DelayClin$.
This follows from Theorem~\ref{theorem:originalDichotomy} and the fact that
$\qEnum{Q^+}{\dltplus}\leq_e\qEnum{Q^+}{\emptyset}$.
\begin{corollaryrep}\label{cor:realpositiveresult}
Let $Q$ be a CQ over a schema $\calS=(\calR,\Delta)$.
If $Q$ is FD-free-connex, then $\qEnum{Q}{\Delta}\in\DelayClin$.
\end{corollaryrep}
\begin{proof}
According to Theorem~\ref{theorem:originalDichotomy}, we have that $\qEnum{Q^+}{\emptyset}\in\DelayClin$ as $Q^+$ is free-connex.
Given an instance over the schema $(\calR,\dltplus)$, the same instance is also over $(\calR,\emptyset)$, and any query has the same answers over both schemas.
Therefore, we have the reduction $\qEnum{Q^+}{\dltplus}\leq_e\qEnum{Q^+}{\emptyset}$ by using the identity mapping.
Overall, we conclude that $\qEnum{Q}{\dltplus}\in\DelayClin$, and using Corollary~\ref{cor:posExtension} we get that $\qEnum{Q}{\Delta}\in\DelayClin$
\end{proof}
We can now revisit Example~\ref{example:fd-dif1}.
The query $Q(x,y)\leftarrow R_1(z,x), R_2(z,y)$ is not free-connex.
Therefore, disregarding the FDs, according to Theorem~\ref{theorem:originalDichotomy} it is not in $\DelayClin$.
However, given $R_2\colon z\rightarrow y$, the FD-extended query is
$Q^+(x,y)\leftarrow R_1^+(z,y,x), R_2^+(z,y)$. As it is free-connex, enumerating $Q^+$ is in $\DelayClin$
by Corollary~\ref{cor:realpositiveresult}.
\section{A Dichotomy for Acyclic CQs} \label{sec:Positive}
In this section, we characterize which self-join-free FD-acyclic queries are in $\DelayClin$. We use the notion of FD-extended queries defined in the previous section to establish a dichotomy stating that enumerating the answers to an FD-acyclic query is in $\DelayClin$ iff the query is FD-free-connex. We will prove the following theorem:
\begin{theoremrep}\label{thm:acyclicDichotomy}
Let $Q$ be an FD-acyclic CQ without self-joins over a schema $\calS=(\calR,\Delta)$.
\begin{itemize}
\item If $Q$ is FD-free-connex, then $\qEnum{Q}{\Delta}\in\DelayClin$.
\item If $Q$ is not FD-free-connex, then $\qEnum{Q}{\Delta}\not\in\DelayClin$, assuming that
the product of two $n \times n$ boolean matrices cannot be computed in time $O(n^2)$.
\end{itemize}
\end{theoremrep}
\begin{proof}
The positive case for this dichotomy was given in Corollary~\ref{cor:realpositiveresult}. The lower bound is a consequence of Theorem~\ref{thm:qpEquiv} and Lemma~\ref{lemma:acyclicgeneralfdnegative}, stating that $\qEnum{\Pi}{\emptyset}\leq_e\qEnum{Q^+}{\dltplus}$ and $\qEnum{Q^+}{\dltplus}\leq_e\qEnum{Q}{\Delta}$. Therefore having $\qEnum{Q}{\Delta}\in\DelayClin$ would mean that $\qEnum{\Pi}{\emptyset}\in\DelayClin$, which is in contradiction to the conjecture.
\end{proof}
The positive case for the dichotomy was described in Corollary~\ref{cor:realpositiveresult}. Note that the restriction of considering only self-joins-free queries is required only for the negative side. This assumption is standard~\cite{bdg:dichotomy,bb:thesis,Kimelfeld:2012:DCD}, as it allows to assign different atoms with different relations independently.
The hardness result described here builds on that of Bagan et al.~\cite{bdg:dichotomy} for databases
that are assumed not to have FDs, and it relies on the hardness of \emph{the boolean matrix multiplication problem}.
This problem is defined as the enumeration $\qEnum{\Pi}{\emptyset}$ of the query
$\Pi(x,y)\leftarrow A(x,z),B(z,y)$ over the schema $(\{A,B\},\emptyset)$ where $A,B\subseteq\{1,\ldots,n\}^2$.
It is strongly conjectured that this problem is not computable in $O(n^2)$ time
and currently, the best known algorithms require $O(n^\omega)$ time for
some $2.37< \omega< 2.38$~\cite{MatrixMultiplication, MatrixMultiplication2}.
The original proof describes an exact reduction $\qEnum{\Pi}{\emptyset}\leq_e\qEnum{Q}{\emptyset}$.
Since $Q$ is acyclic but not free-connex, it contains a head-path $(x,z_1,\ldots,z_k,y)$. Given an instance of the
matrix multiplication problem, an instance of $\qEnum{Q}{\emptyset}$ is constructed, where the variables
$x$,$y$ and $z_1,\ldots,z_k$ of the head-path respectively encode the variables $x$, $y$ and $z$ of $\Pi$, while all
other variables of $Q$ are assigned constants. This way, $A$ is encoded by an atom containing $x$ and
$z_1$, and $B$ is encoded by an atom containing $z_k$ and $y$. Atoms containing some $z_i$ and
$z_{i+1}$ only propagate the value of $z$. Since $x$ and $y$ are in $free(Q)$, but $z_i$ are not,
the answers to $Q$ correspond to those of $\Pi$.
As no atom of $Q$ contains both $x$ and $y$, the instance can be constructed in linear time.
Constant delay enumeration for $Q$ after linear time preprocessing would result in the computation of the answers of $\Pi$ in $O(n^2)$ time.
FDs restrict the relations that can be assigned to atoms. This means that the reduction cannot be freely performed on databases with FDs, and the proof no longer holds. The following example illustrates where the reduction fails in the presence of FDs.
\begin{example}
The CQ from Example~\ref{example:fd-dif1} has the form $Q(x,y)\leftarrow R_1(z,x),R_2(z,y)$
with the single FD $\Delta=\{R_2\colon z\rightarrow y\}$.
In the previous section, we show that it is in $\DelayClin$, so the reduction should fail.
Indeed, it would assign $R_2$ with the same relation as $B$ of the matrix multiplication problem,
but this may have two tuples with the same $z$ value and different $y$ values.
Therefore, the construction does not yield a valid instance of $\qEnum{Q}{\Delta}$.\qed
\end{example}
We now give a detailed sketch of a modification of this construction that shows that $\qEnum{\Pi}{\emptyset}\leq_e\qEnum{Q^+}{\dltplus}$. Any violations of the FDs are fixed by carefully picking more variables other than those of the head-path to take the roles of $x$,$y$ and $z$ of the matrix multiplication problem. This is done by introducing the sets $V_x$,$V_y$ and $V_z$ which are subsets of $\var(Q)$. We say
that a variable $\beta$ {\em plays the role} of $\alpha$, if $\beta\in V_{\alpha}$.
To clarify the explanation of the reduction, we start by describing a restricted case, where all FDs are unary. The basic idea in the case of general FDs will remain the same, but it will require a more involved construction of the sets $V_\alpha$.
\subsection{Unary Functional Dependencies}
For the unary case, we define the sets $V_x, V_y$ and $V_z$ to be the sets of variables that iteratively imply $x$, $y$ and some $z_i$ respectively. That is, for $\alpha\in\{x,y,z_1,\ldots,z_k\}$ we first set $V_\alpha:=\{\alpha\}$, and then apply $V_\alpha:=V_\alpha\cup\{\gamma\in\ivar(Q)\mid\gamma\rightarrow\beta\in\dltplus\wedge\beta\in V_\alpha\}$ until a fixpoint is reached. We then define $V_z:=V_{z_1}\cup\cdots\cup V_{z_k}$.
\subparagraph*{The Reduction.}
Let $I=(A^I,B^I)$ be an instance of $\qEnum{\Pi}{\emptyset}$.
In order to define $\sigma(I)$, we describe how to construct the relation $R^I$ for every atom $R(\vec{v})\in\atoms(Q^+)$.
If $\var(R)\cap V_y=\emptyset$, then every tuple $(a,c)\in A^I$ is copied to a tuple in $R^I$. Variables in $V_x$ get the value $a$, variables in $V_z$ get the value $c$, and variables that play no role are assigned a constant $\bot$.
That is, we define
$R^{\sigma(I)}=\{(f(v_1,a,c),\ldots,f(v_k,a,c))\mid (a,c)\in A^I\}$, where:
\begin{equation*}
f(v_i,a,c) = \left\{
\begin{array}{ll}
a &\text{ if }v_i\in V_x\setminus V_z,\\
c &\text{ if }v_i\in V_z\setminus V_x,\\
(a,c) &\text{ if }v_i\in V_x\cap V_z,\\
\bot &\text{otherwise.}
\end{array}
\right.
\end{equation*}
Otherwise, $\var(R)\cap V_y\neq\emptyset$, and we show that $\var(R)\cap V_x=\emptyset$. In this case we define the relation similarly with $B^I$. Given a tuple $(c,b)\in B^I$, the variables of $V_y$ get the value $b$, and those of $V_z$ are assigned with $c$.
\begin{example}
Consider the FD-extended query $Q^+(x,y,v)\leftarrow R(u,x,z),S(v,y,z)$ with $\dltplus=\{R\colon u\rightarrow x,R\colon u\rightarrow z,S\colon y\rightarrow v\}$.
Using the head-path $(x,z,y)$, the reduction will set $V_x=\{x,u\}$, $V_y=\{y\}$, $V_z=\{z,u\}$.
Given an instance of the matrix multiplication problem with relations $A$ and $B$, every tuple $(a,c)\in A$ will result in a tuple $((a,c),a,c)\in R$, and every tuple $(c,b)\in B$ will result in a tuple $(\bot,b,c)\in S$.\qed
\end{example}
We now outline the correctness of this reduction:
\begin{description}
\item [Well-defined reduction:] For an atom $R$, either we have $\var(R)\cap V_y=\emptyset$ or $\var(R)\cap V_x=\emptyset$.
That is, no atom contains variables from both $V_x$ and $V_y$.
Due to the definition of $Q^+$, this atom would otherwise also contain both $x$ and $y$.
However, they cannot appear in
the same relation according to the definition of a head-path.
The reduction is therefore well defined, and it can be constructed in linear time via copy and projection.
\item [Preserving FDs:] The construction ensures that if an FD $\gamma\rightarrow\alpha$ exists, then $\gamma$ has all the roles of $\alpha$. Therefore, either $\alpha$ has no role
and corresponds to the constant $\bot$, or every value that appears in $\alpha$ also appears in $\gamma$.
In any case, all FDs are preserved.
\item [1-1 mapping of answers:] If a variable of $V_z$ would appear in the head of $Q^+$, then by the definition of $Q^+$, some $z_i$ will be in the head as well. This cannot happen according to the definition of a head-path.
Therefore, the head only encodes the $x$ and $y$ values of the matrix multiplication problem,
so two different solutions to $\qEnum{Q^+}{\dltplus}$ must differ in either $x$ or $y$,
and correspond to different solutions of $\qEnum{\Pi}{\emptyset}$.
For the other direction, the head necessarily contains the variables $x$ and $y$.
Therefore, two different solutions to $\qEnum{\Pi}{\emptyset}$ also correspond to different solutions of $\qEnum{Q^+}{\dltplus}$.
\end{description}
\subsection{General Functional Dependencies}
Next we show how to lift the idea of this reduction to the case of general FDs.
In the case of unary FDs,
we ensure that the construction does not violate a given FD $\gamma\rightarrow\alpha$,
by simply encoding the values of $\alpha$ to $\gamma$.
In the general case, when allowing more than one variable on the left-hand side of an FD $\gamma_1,\ldots,\gamma_k\rightarrow\alpha$,
we must be careful when choosing the variables $\gamma_j$ to which we copy the values of $\alpha$. Otherwise, as the following example shows, we will not be able to construct the instance in linear time.
\begin{example}
Consider the query
$Q(x,y)\leftarrow R_1(x,z,t_1),R_2(z,y,t_1,t_2)$
over a schema with the FD $R_2\colon t_1t_2\rightarrow y$.
Note that $Q=Q^+$ is acyclic but not free-connex, and that $(x,z,y)$ is a head-path in $\calH(Q^+)$.
To repeat the idea shown in the unary case and ensure that the FDs still hold,
the variable on the right-hand side of every FD is encoded to the variables on the left-hand side.
If we encode $y$ to $t_1$, then $R_1$ would contain the encodings of $x$, $y$ and $z$.
This means that its size will not be linear in that of the matrix multiplication instance,
and we cannot hope for linear time construction.
On the other hand, if we choose to encode $y$ only to $t_2$, the reduction works.
\qed
\end{example}
In the following central lemma, we describe a way of carefully picking the variables to which we assign roles, such that all FDs hold and yet the instance can be constructed in linear time.
The idea is that we consider the join-tree of $Q^+$ and define $V_x$ and $V_y$ to hold variables that appear only in disjoint parts of this tree. This ensures that no atom contains variables of each. The property of a join-tree is used to guarantee that $V_x$ and $V_y$ are inclusive enough to correct all FD violations.
\begin{figure}[t]
\begin{center}
\begin{tikzpicture}[node distance = 0.14]
%outer rectangle representing H(Q)
\node[rectangle, rounded corners, draw, minimum width=39.8em, minimum height=4em]
(H) at (0,0) {};
%nodes for the dashed lines within H(Q)
\node (dotleft1) [left=4.1 of H.north] {};
\node (dotleft2) [left=4.1 of H.south] {};
\node (dotright1) [right=3.98 of H.north] {};
\node (dotright2) [right=3.98 of H.south] {};
%caption nodes
\node (Tx) [below left = 0 and 5 of H.south] {$T_x$};
\node (Ty) [below right = 0 and 5 of H.south] {$T_y$};
\node (Tz) [below = 0 of H.south] {$T_\text{mid}$};
%nodes of the s-path and vx,vy
\node[rectangle, rounded corners, draw, thick, inner sep = 3] (e1) [below right= -0.6 and 0.65 of H.west] {$e(x,z_1)$};
\node (d1r) [right = of e1] {$\ldots$};
\node (d1l1) [left=0.3 of e1] {};
\node (d1l2) [above left= -0.2 and 0.3 of e1] {};
\node (d1l3) [below left= -0.2 and 0.3 of e1] {};
\node[rectangle, rounded corners, draw, thick, inner sep = 3] (vx) [right = of d1r] {$sep_x$\phantom{)}\!\!};
\node (d2r1) [right= of vx] {$\ldots$};
\node (d2d1) [below= 0.3 of vx] {};
\node (d2d2) [below left= 0.3 and -0.2 of vx] {};
\node (d2d3) [below right= 0.3 and -0.2 of vx] {};
\node[rectangle, rounded corners, draw, thick, inner sep = 3] (e2) [right = of d2r1] {$e(z_1,z_2)$};
\node (d3r1) [right= of e2] {$\ldots$};
\node (d3d1) [below= 0.3 of e2] {};
\node (d3d2) [below left= 0.3 and -0.6 of e2] {};
\node (d3d3) [below right= 0.3 and -0.6 of e2] {};
\node[rectangle, rounded corners, draw, thick, inner sep = 3] (e3) [right = of d3r1] {$e(z_{k-1},z_k)$};
\node (d4r1) [right= of e3] {$\ldots$};
\node (d4d1) [below= 0.3 of e3] {};
\node (d4d2) [below left= 0.3 and -0.8 of e3] {};
\node (d4d3) [below right= 0.3 and -0.8 of e3] {};
\node[rectangle, rounded corners, draw, thick, inner sep = 3] (vy) [right = of d4r1] {$sep_y$\phantom{)}\!\!};
\node (d5r1) [right= of vy] {$\ldots$};
\node (d5d1) [below= 0.3 of vy] {};
\node (d5d2) [below left= 0.3 and -0.2 of vy] {};
\node (d5d3) [below right= 0.3 and -0.2 of vy] {};
\node[rectangle, rounded corners, draw, thick, inner sep = 3] (e4) [right = of d5r1] {$e(z_k,y)$};
\node (d6r1) [right=0.3 of e4] {};
\node (d6r2) [above right= -0.2 and 0.3 of e4] {};
\node (d6r3) [below right= -0.2 and 0.3 of e4] {};
\draw[dashed] (dotleft1.center) -- (dotleft2.center);
\draw[dashed] (dotright1.center) -- (dotright2.center);
\draw[thick] (e1) -- (d1r);
\draw[thick] (e1.west) -- (d1l1);
\draw[thick] (e1.west) -- (d1l2);
\draw[thick] (e1.west) -- (d1l3);
\draw[thick] (vx) -- (d1r);
\draw[thick] (vx) -- (d2r1);
\draw[thick] (vx.south) -- (d2d1);
\draw[thick] (vx.south) -- (d2d2);
\draw[thick] (vx.south) -- (d2d3);
\draw[thick] (e2) -- (d2r1);
\draw[thick] (e2) -- (d3r1);
\draw[thick] (e2.south) -- (d3d1);
\draw[thick] (e2.south) -- (d3d2);
\draw[thick] (e2.south) -- (d3d3);
\draw[thick] (e3) -- (d3r1);
\draw[thick] (e3) -- (d4r1);
\draw[thick] (e3.south) -- (d4d1);
\draw[thick] (e3.south) -- (d4d2);
\draw[thick] (e3.south) -- (d4d3);
\draw[thick] (vy) -- (d4r1);
\draw[thick] (vy) -- (d5r1);
\draw[thick] (vy.south) -- (d5d1);
\draw[thick] (vy.south) -- (d5d2);
\draw[thick] (vy.south) -- (d5d3);
\draw[thick] (e4) -- (d5r1);
\draw[thick] (e4.east) -- (d6r1);
\draw[thick] (e4.east) -- (d6r2);
\draw[thick] (e4.east) -- (d6r3);
\end{tikzpicture}
\end{center}
\caption{Join tree $T$ of $\calH(Q^+)$ for head-paths of length greater than $3$. The subtrees $T_x$, $T_y$ and $T_\text{mid}$ are disjoint, and are separated by the nodes $sep_x$ and $sep_y$.}
\label{fig:generalnegative1}
\end{figure}
\begin{lemmarep}\label{lemma:reductionsets}
Let $Q$ be a CQ with no self-joins over a schema $\calS=(\calR,\Delta)$, such that $Q^+$ is acyclic but not free-connex.
Denote a head-path of $Q^+$ by $(x,z_1,\ldots,z_k,y)$.
Then there exist sets of variables $V_x$, $V_y$, $V_z$ such that:
\begin{enumerate}
\item\label{lemmaitem:xyzinVxVyVz} $x\in V_x$, $y\in V_y$, $\{z_1,\ldots z_k\}\subseteq V_z$.
\item\label{lemmaitem:leftsideconsistent} For all $U\rightarrow v\in\dltplus$ such that $v\in V_\alpha$ with $\alpha\in\{x,y,z\}$, we have $U\cap V_\alpha\neq\emptyset$.
\item\label{lemmaitem:disjointVxVy} For every $R\in\atoms(Q^+)$, we have $\var(R)\cap V_y=\emptyset$ or $\var(R)\cap V_x=\emptyset$.
\item\label{lemmaitem:disjointVz} $V_z\cap\free(Q^+)=\emptyset$
\end{enumerate}
\end{lemmarep}
\begin{proofsketch}
We first define a partition of the atoms of $Q$ into three sets: $T_x$, $T_y$ and $T_\text{mid}$
(where $T_\text{mid}$ might be empty).
Let $T$ be a join tree of $\calH(Q^+)$, and denote the hyperedges on the head-path by $e(x,z_1),\ldots,e(z_k,y)$.
Note that, by definition, each hyperedge of the head-path is a vertex of $T$. By the running intersection property of $T$, we can conclude that there is a simple path $P$ from $e(x,z_1)$ to $e(z_k,y)$ in $T$, such that $e(z_1,z_2),\ldots,e(z_{k-1},z_k)$ lie on that path in the order induced by the head-path.
Let $sep_x$ be the first node on the path $P$ that does not contain $x$. This exists because $e(z_k,y)$ does not contain $x$, as the head-path is chordless. Similarly, let $sep_y$ be the last node on $P$ that does not contain $y$.
Let $T_x$ be the set of nodes $v$ in $T$ such that the unique path from $v$ to $e(x,z_1)$ does not go through $sep_x$.
Similarly, let
$T_y$ be the set of nodes $w$ in $T$ such that the unique path from $w$ to $e(z_k,y)$ does not go through $sep_y$.
Next set $T_\text{mid}=V(T)\setminus(T_x\cup T_y)$.
Note that the nodes of $T$ are exactly $T_x\cup T_\text{mid}\cup T_y$, and we can show that this union is disjoint (see Figure~\ref{fig:generalnegative1}).
Also note that $e(x,z_1)\in T_x$ and $e(z_k,y)\in T_y$, but $T_\text{mid}$ may be empty if the head-path is of length three. Therefore, we established a partition of the atoms to two or three sets.
Next we define the sets of variables $V_x, V_y$ and $V_z$.
To do so, for $w\in\var(Q)$, denote $\mathsf{Implies}(w)=\{u\in\ivar(Q)\mid u\in U\text{ with }U\rightarrow w\in\dltplus\}$. Intuitively, $\mathsf{Implies}(w)$ is the set of all variables on the left-hand
side of FDs that have $w$ on the right-hand side.
We now define $V_x$ to contain $x$, and recursively to contain variables that imply those of $V_x$,
but we do not take variables that appear outside of $T_x$.
$V_y$ is defined symmetrically.
$V_z$ is defined to contain $z_1,\ldots,z_k$, and recursively contain variables that imply those of $V_z$, but now we do not take variables that appear in the head of the query.
More formally, we recursively define:
\begin{itemize}
\item $\bm{V_x}$: Base $V_x:=\{x\}$; Rule $V_x:=V_x\cup\{t\in\mathsf{Implies}(w)\mid w\in V_x\}\setminus\var(T_y\cup T_\text{mid})$
\item $\bm{V_y}$: Base $V_y:=\{y\}$; Rule $V_y:=V_y\cup\{t\in\mathsf{Implies}(w)\mid w\in V_y\}\setminus\var(T_x\cup T_\text{mid})$
\item$\bm{V_z}$: Base $V_z:=\{z_1,\ldots z_k\}$; Rule $V_z:=V_z\cup\{t\in\mathsf{Implies}(w)\mid w\in V_z\}\setminus\free(Q^+)$
\end{itemize}
We now prove that $V_x$, $V_y$ and $V_z$ meet the requirements of the lemma.
\begin{enumerate}
\item The first claim is immediate from the definition of the sets.
\item We first show the claim for $\alpha=x$.
Let $\delta = U\rightarrow v\in\dltplus$, and let $e(U,v)$ be an atom containing all variables of $\delta$. As $v\in V_x$, we know that $e(U,v)\notin T_y\cup T_\text{mid}$, therefore $e(U,v)\in T_x$.
Assume by contradiction that $U\cap V_x = \emptyset$.
Let $u\in U$. By definition of $V_x$, this means that $u\in\ivar(e_u)$ for some $e_u\in T_y\cup T_\text{mid}$.
As $T_x$, $T_y$ and $T_\text{mid}$ are disjoint, we have that $e_u\notin T_x$, which means that the path between $e_u$ and $e(x,z_1)$ goes through $sep_x$. This means that the path from $e_u$ to $e(U,v)$ goes through $sep_x$ too, otherwise the concatenation of this path with the path from $e(U,v)$ to $e(x,z_1)$ would result in a path from $e_u$ to $e(x,z_1)$ not going through $sep_x$. By the running intersection property, $u\in\ivar(sep_x)$.
Since this is true for all for all $u\in U$,
it follows that $v\in\ivar(sep_x)$ by definition of $Q^+$, contradicting the fact that $v\in V_x$.
The case $\alpha=y$ is symmetric.
Now for the case where $\alpha= z$. If
$U\cap V_z=\emptyset$, then $U\subseteq\free(Q^+)$, and
by the definition of $Q^+$, $z_i\in\free(Q^+)$, which is a contradiction to the fact that
$v\in\ivar(Q)\setminus\free(Q^+)$.
\item
Let $R\in\atoms(Q^+)$.
If $R\in T_x$, then by definition of $V_y$ we have that $\var(R)\cap V_y=\emptyset$. Otherwise, $R\in T_y\cup T_\text{mid}$, and similarly $\var(R)\cap V_x=\emptyset$.
\item
By definition of $V_z$, it does not contain any variables of $\free(Q^+)$.
\qedhere
\end{enumerate}
\end{proofsketch}
\begin{proof}
We now show that the sets $T_x$ and $T_y$ are disjoint. Assume by contradiction that $v\in T_x\cap T_y$. Let $P_x$ be the unique simple path from $v$ to $e(x,z_1)$, and recall that since $v\in T_x$ it does not go through $sep_x$. Similarly let $P_y$ be the unique simple path from $v$ to $e(z_k,y)$ that does not go through $sep_y$.
We first claim that there exists some node $w$ that appears in all three paths $P$, $P_x$ and $P_y$. Take $w$ to be the first node on $P_x$ that is also in $P$ and set $P_x^w$ to
be the simple path from $v$ to $w$.
Such a node $w$ exists because the last node of $P_x$ is $e(x,z_1)$ which is in $P$.
Further set $P^w$ to be the simple path from $w$ to $e(z_k,y)$.
Concatenating the paths $P_x^w$ and $P^w$,
we obtain a simple path from $v$ to $e(z_k,y)$. Since the simple paths in a tree are unique, this is exactly $P_y$. Therefore $w$ is also in $P_y$, and the claim is proven.
Our second claim is that if a node $u$ is in both $P$ and $P_x$, then the relation it represents contains the variable $x$. Assume by contradiction that such a node $u$ does not contain $x$. Then $u$ is a node on $P$ not containing $x$, and by definition of $sep_x$, the simple path from $u$ to $e(x,z_1)$ contains $sep_x$. As this path is a subpath of $P_x$,
$P_x$ contains $sep_x$, in contradiction to the fact that $v\in T_x$.
Symmetrically, we prove that if a node is in both $P$ and $P_y$, then the
relation it represents contains the variable $y$.
Combining the two claims, we have found a node $w$ that represents a relation that contains both $x$ and $y$, in contradiction to the fact that a head-path is chordless by definition. Therefore we conclude that $T_x$ and $T_y$ are indeed disjoint.
\end{proof}
With the sets $V_x,V_y,V_z$ at hand, we can now perform the reduction between the two problems for general FDs.
The reduction is based on the case of unary FDs, but with the sets defined according to Lemma~\ref{lemma:reductionsets}. Requirements 1 and 4 on the sets guarantee a one-to-one mapping between the results of the two problems, requirement 2 guarantees that all FDs are preserved, and requirement 3 guarantees linear time construction.
\begin{lemmarep}\label{lemma:acyclicgeneralfdnegative}
Let $Q$ be a CQ with no self-joins over a schema $\calS=(\calR,\Delta)$.
If $Q^+$ is acyclic and not free-connex, then $\qEnum{\Pi}{\emptyset}\leq_e\qEnum{Q^+}{\dltplus}$.
\end{lemmarep}
\begin{proof}
Let $I_{A,B}=(A^I,B^I)$ be an instance of $\qEnum{\Pi}{\emptyset}$ over domain $\calD=\{1,\ldots,n\}$.
We define an instance $\sigma(I_{A,B})$ of $\qEnum{Q^+}{\dltplus}$ based on the sets $V_x,V_y,V_z$
from Lemma~\ref{lemma:reductionsets} and the relations $A^I$ and $B^I$.
Since $Q^+$ is acyclic but not free-connex, it contains some head-path $(x,z_1,\ldots,z_k,y)$.
Thus for every $R^+\in\atoms(Q^+)$, exactly one of the following 5 statements is true:
\begin{enumerate}
\item $\{x,z_1\}\subseteq\var(R^+)$,
\item $\{z_s,z_{s+1}\}\subseteq\var(R^+)\quad\text{ for some}1\leq s\leq k-1$,
\item $\{z_k,y\}\subseteq\var(R^+)$,
\item $|\{x,y,z_1,\ldots,z_k\}\cap\var(R^+)|=1$,
\item $\{x,y,z_1,\ldots,z_k\}\cap\var(R^+)=\emptyset$.
\end{enumerate}
\smallskip\noindent
In the following, we say that $R^+\in\atoms(Q^+)$ belongs to the category $i$, $i\in\{1,\ldots,5\}$, if the statement $i$ above is satisfied
by $R^+$.
To define the instance $\sigma(I_{A,B})$, we first fix the functions $f_A$ and $f_B$:
\begin{align*}
f_A(v_i,a,b) &= \left\{
\begin{array}{lr}
a & : v_i\in V_x\setminus V_z\\
c & : v_i\in V_z\setminus V_x\\
(a,c) & : v_i\in V_{x}\cap V_z\\
\bot & : \text{otherwise}
\end{array}
\right.,\qquad
f_B(v_i,c,b) &= \left\{
\begin{array}{lr}
c & : v_i\in V_z\setminus V_y\\
b & : v_i\in V_y\setminus V_z\\
(c,b) & : v_i\in V_{y}\cap V_z\\
\bot & : \text{otherwise}
\end{array}
\right.
\end{align*}
We partition all relational atoms of $Q^+$ into two disjoint
sets $\calR_A^+$ and $\calR_B^+$.
The set $\calR_A^+$ is defined as $\{R^+\in\atoms(Q^+)\mid \var(R^+)\cap V_y=\emptyset\}$ and $\calR_B^+$ is $\atoms(Q^+)\setminus\calR_A^+$.
Note that by points $\ref{lemmaitem:xyzinVxVyVz}$ and $\ref{lemmaitem:disjointVxVy}$ of Lemma~\ref{lemma:reductionsets},
all atoms of category $1$ are in $\calR_A^+$, whereas all atoms of category $3$ are
in $\calR_B^+$.
To obtain an instance $\sigma(I_{A,B})$ of $\qEnum{Q^+}{\Delta^+}$, we apply $f_A$ to all atoms in
$\calR_A^+$ and $f_B$ to all atoms in $\calR_B^+$, that is
\begin{equation*}
(R^+)^{\sigma(I_{A,B})}=
\left\{
\begin{array}{ll}
\{(f_A(v_1,a,c),\ldots,f_A(v_p,a,c))\mid (a,c)\in A^I\}&\text{ for }R^+(v_1,\ldots,v_p)\in \calR_A^+,\\
\{(f_B(v_1,c,b),\ldots,f_B(v_p,c,b))\mid (c,b)\in B^I\}&\text{ for }R^+(v_1,\ldots,v_p)\in \calR_B^+.
\end{array}
\right.
\end{equation*}
This instance can be constructed in linear time.
We now claim that $\sigma(I_{A,B})$ is indeed a database over the schema $(\calR^+,\dltplus)$, as
all the FDs of $\dltplus$ are preserved. Let $\delta = R_j^+\colon U\rightarrow v\in\dltplus$.
If $v\notin V_x\cup V_y\cup V_z$,
then $\delta$ holds as $v$ is always assigned the single value $\bot$.
Next assume that $v\in V_{x}\setminus V_{z}$.
By point~\ref{lemmaitem:leftsideconsistent} of Lemma~\ref{lemma:reductionsets},
there is some $u\in U$ such that $u\in V_x$. Thus in every tuple in $(R_j^+)^{\sigma(I_{A,B})}$,
if $v$ is assigned the value $a$, then $u$ is either assigned the value $a$ or $(a,c)$ for some $c\in\{1,\ldots,n\}$
and in either case the FD $\delta$ holds. The cases where $v\in V_{z}\setminus (V_{x}\cup V_{y})$
and $v\in V_{y}\setminus V_{z}$ can be shown along the same lines.
Next assume that $v\in V_{x}\cap V_{z}$.
Then again by point~\ref{lemmaitem:leftsideconsistent} of Lemma~\ref{lemma:reductionsets}
there are some $u_1,u_2\in U$ such that
$u_1\in V_{x}$ and $u_2\in V_{z}$ and for every tuple in
$(R_j^+)^{\sigma(I_{A,B})}$,
if $v$ is assigned the value $(a,c)$, then $u_1$ is either assigned the value $a$ or $(a,c)$
and $u_2$ is either assigned the value $c$ or $(a,c)$.
Again the case $v\in V_{y}\cap V_{z}$ can be shown analogously. The case
where $v\in V_x\cap V_y$ cannot occur due to point~\ref{lemmaitem:disjointVxVy}
of Lemma~\ref{lemma:reductionsets}.
The mapping $\tau$ is defined as a projection onto the
variables $x$ and $y$. This projection can be computed in constant time. The head-path $(x,z_1\ldots,z_k,y)$
guarantees that all answers to $\qEnum{Q^+}{\dltplus}$ correspond to answers to $\qEnum{\Pi}{\emptyset}$, and vice versa.
Indeed, let $\mu=\{(x,a), (y,b), (z,c)\}$
such that $\mu|_{\{x,y\}} \in\Pi(I_{A,B})$.
Then, we show that
$\mu'|_{\free(Q^+)}\in Q^+(\sigma(I_{A,B}))$, with
\begin{equation*}
\mu'(\zeta)= \left\{
\begin{array}{ll}
a & : \zeta\in V_x\setminus V_z,\\
b & : \zeta\in V_y\setminus V_z,\\
c & : \zeta\in V_z\setminus (V_x\cup V_y),\\
(a,c) & : \zeta\in V_z\cap V_x,\\
(c,b) & : \zeta\in V_z\cap V_y,\\
\bot & : \text{otherwise}.
\end{array}
\right.
\end{equation*}
Since $\mu|_{\{x,y\}} \in\Pi(I_{A,B})$ we have that $(a,c)\in A^I$ and $(c,b)\in B^I$.
Consider any atom $R^+(v_1,\ldots,v_p)$ of $Q^+$ and first assume that $\var(R^+)\cap V_y=\emptyset$,
meaning $R^+(v_1,\ldots,v_p)\in \calR_A^+$.
Then,
$(\mu'(v_1),\ldots,\mu'(v_p))=(f_A(v_1,a,c),\ldots,f_A(v_p,a,c))\in (R^+)^{\sigma(I_{A,B})}$.
Next assume that $\var(R^+)\cap V_y\neq\emptyset$, meaning $R^+(v_1,\ldots,v_p)\in \calR_B^+$.
By point~\ref{lemmaitem:disjointVxVy} of Lemma~\ref{lemma:reductionsets}, we have that $\var(R^+)\cap V_x=\emptyset$. Then,
$(\mu'(v_1),\ldots,\mu'(v_p))=(f_B(v_1,c,b),\ldots,f_B(v_p,c,b))\in (R^+)^{\sigma(I_{A,B})}$.
Next assume that $\mu'|_{\free(Q^+)}\in Q^+(\sigma(I_{A,B}))$, where $\mu'$ is a mapping on
the variables of $Q^+$. Let $R^+$ be an atom of category 1 (such an atom exists by the definition
of the head-path). By point~\ref{lemmaitem:disjointVxVy}
of Lemma~\ref{lemma:reductionsets} we have $\var(R^+)\cap V_y=\emptyset$ and $R^+\in \calR_A^+$.
By point~\ref{lemmaitem:xyzinVxVyVz}
of Lemma~\ref{lemma:reductionsets} we have $x\in V_x$ and $z_1\in V_z$. Moreover, as $V_z\cap\free(Q^+)=\emptyset$
by point~\ref{lemmaitem:disjointVz}
of Lemma~\ref{lemma:reductionsets} and $x$ is a head variable, $x\in V_x\setminus V_z$. Thus there
exists some $(a,c)\in A^I$ such that $\mu'(x)=f_A(x,a,c)=a$ and $\mu'(z_1)=f_A(z_1,a,c)\in\{a,(a,c)\}$.
Similarly, there
exists some $(b,c')\in B^I$ such that $\mu'(y)=f_B(y,c',b)=b$ and
$\mu'(z_k)=f_B(z_k,c',b)\in\{c',(c',b)\}$. It remains to show that $c=c'$. If $k=1$, then $z_1=z_k$ and thus
$c=c'$. Otherwise, there exists some atom $R_1^+$ in category $2$ with $\{z_1,z_2\}\subseteq\var(R_1^+)$.
If $R_1^+\in\calR_A$, then $\mu'(z_1),\mu'(z_2)\in\{c,(a,c)\}$ and if $R_1^+\in\calR_B$, then
$\mu'(z_1),\mu'(z_2)\in\{c,(c,b)\}$. Inductively, we get that $\mu'(z_{k-1}),\mu'(z_k)\in\{c,(c,b)\}$
or $\mu'(z_{k-1}),\mu'(z_k)\in\{c,(a,c)\}$ and thus $c=c'$.
Note that there is a 1-1 correspondence between solutions. Given $\mu|_{\{x,y\}} \in\Pi(I_{A,B})$, $\mu'|_{\free(Q^+)}$ is uniquely defined, since $V_z\cap \free(Q^+)=\emptyset$ by point~\ref{lemmaitem:disjointVz}
of Lemma~\ref{lemma:reductionsets}.
For the other direction, since $\{x,y\}\subseteq\free(Q^+)$, a mapping $\mu'|_{\free(Q^+)}\in Q^+(\sigma(I_{A,B}))$ corresponds to only one $\mu|_{\{x,y\}}\in\Pi(I_{A,B})$.
\end{proof}
This lemma, along with Theorem~\ref{thm:qpEquiv}, establishes the hardness result in Theorem~\ref{thm:acyclicDichotomy}. This result does not contradict the dichotomy given in Theorem~\ref{theorem:originalDichotomy}: If for a given query $Q$ we have that $Q^+$ is acyclic but not free-connex, then $Q$ cannot be free-connex by Proposition~\ref{prop:plusstructure}.
Note that Theorem~\ref{thm:acyclicDichotomy}, just like the dichotomy presented by Bagan et al.~\cite{bdg:dichotomy}, also applies for CQs with disequalities. The extension for such a query is performed as before, ignoring the disequalities. The equivalence described in Theorem~\ref{thm:qpEquiv} still holds, and the proof remains intrinsically the same. The proof of the hardness result presented here also remains similar, with the sole difference that during the construction we take a different and disjoint domain for each variable. This guarantees that all possible disequalities are preserved.
\section{Cyclic CQs} \label{sec:cyclic}
In the previous section, we established a classification of FD-acyclic CQs, but we did not
consider FD-cyclic queries. A known result states that, under certain assumptions, self-join-free cyclic
queries are not in $\DelayClin$~\cite{bb:thesis}. In this section, we therefore explore how
FD-extensions can be used to obtain some insight on the implications of this result in the
presence of FDs. We show that (under the same assumptions) self-join-free FD-cyclic queries that contain
only unary FDs cannot be evaluated in linear time. For schemas containing only unary FDs,
this extends the dichotomy presented in the previous section to all CQs,
and also proves a dichotomy for the queries that can be enumerated in linear delay.
We will prove the following theorem:
\begin{theoremrep}\label{thm:cyclicHardness}
Let $Q$ be a CQ with no self-joins over a schema $\calS=(\calR,\Delta)$, where $\Delta$ only contains unary FDs. If $Q$ is FD-cyclic, then $\qDecide{Q}{\Delta}$ cannot be solved in linear time,
assuming that the $\tetra{k}$ problem cannot be solved in linear time for any $k$.
\end{theoremrep}
\begin{proof}
For the sake of a contradiction assume that for a query $Q$ which is FD-cyclic $\qDecide{Q}{\Delta}$ can be solved in linear time. Since we can use the reduction given in the proof of Theorem~\ref{thm:qpEquiv} to reduce any instance of $\qDecide{Q^+}{\dltplus}$ to an instance of $\qDecide{Q}{\Delta}$, $\qDecide{Q^+}{\dltplus}$ can be decided in linear time as well. As $Q^+$ is cyclic, there exists a pseudo-minor $\calH_{pm}\in\tetpm{Q^+}$ which is isomorphic to $\tetra{k}$ for some $k\geq3$. Applying the results from Lemma~\ref{lemma:simple-pm}, we get this $\tetra{k}$ problem is solvable in linear time.
\end{proof}
As before,
the initial hardness proof for cyclic queries no longer holds in the presence of FDs, and we modify
the reduction to fix any violations of the FDs.
We start by describing the assumption used to obtain the conditional lower bounds.
We define $\tetra{k}$ to be the hypergraph with the vertices $\{1,\ldots,k\}$ and the edges $\{\{1,\ldots,k\}\setminus\{i\}\mid i\in\{1,\ldots,k\}\}$.
Let $\calH$ be a hypergraph. With a slight abuse of notation, we also denote by $\tetra{k}$ the decision problem of whether $\calH$ contains a subhypergraph isomorphic to $\tetra{k}$.
Note that $\tetra{3}$ is the problem of deciding whether a graph contains a triangle,
which is strongly believed to be not solvable within time
linear in the size of the graph
\cite{DBLP:conf/focs/WilliamsW10}.
The generalization of this assumption is that the $\tetra{k}$ problem cannot be solved in time
linear in the size of the graph for any $k$. This is a stronger assumption than
we used in Section~\ref{sec:Positive}, as the $\tetra{3}$ can be reduced to the
matrix multiplication problem~\cite{DBLP:conf/focs/WilliamsW10}.
We will show that if $Q^+$ is cyclic and only unary FDs are present,
the problem $\tetra{k}$ for some $k$ can be reduced to $\qDecide{Q^+}{\dltplus}$.
\begin{definition}\label{def:tetpm}
Let $\calH$ be a cyclic hypergraph. We denote by $\tetpm{\calH}$ the pseudo-minors of $\calH$
isomorphic to $\tetra{k}$ for some $k$, which are obtained in one of the following ways:
\begin{enumerate}
\item Vertex removal steps followed by all possible edge removals.
\item Vertex and edge removal steps that lead to a chordless cycle, followed by edge contraction and edge removal steps that result in a $\tetra{3}$.
\end{enumerate}
Given a query $Q$, we define $\tetpm{Q}=\tetpm{\calH(Q)}$.
\end{definition}
\begin{toappendix}
The following result is a part of a theorem in~\cite{bb:thesis}:
\begin{lemma}[\cite{bb:thesis}, Theorem 11]\label{lemma:acyclicEquivalence}
Let $\calH$ be a hypergraph. If $\calH$ is cyclic, then $\calH$ admits some $\tetra{k}, k\geq3$ as a pseudo-minor.
\end{lemma}
\begin{proof}
If $\calH$ has a chordless cycle $C$ as an induced subgraph, then $\tetra{3}$ is a pseudo-minor obtained by removing vertices not in $C$ and a repeated use of edge-contraction, followed by performing all possible edge removals.
If $\calH$ does not contains a chordless cycle, since it is not acyclic, it is non-conformal.
Consider its smallest non-conformal clique. The clique is not included in any edge (since it is non-conformal), and it is a $\tetra{k}$ because of its minimality. Therefore removing all vertices other than the clique, and then performing all possible edge removals, results in a graph isomorphic to some $\tetra{k}$.
\end{proof}
\end{toappendix}
Brault-Baron~\cite{bb:thesis} showed that if $\calH$ is cyclic, then $\tetpm{\calH}\neq\emptyset$. This proof is provided in the appendix.
For the reduction we will present next, we first need to show that for an FD-cyclic query $Q$, no pseudo-minor in $\tetpm{Q^+}$ contains all variables of any FD $X\rightarrow y$. Here,
we assume that $\Delta$ only contains non-trivial FDs, meaning
$y\notin X$.
\begin{lemmarep}\label{lemma:fd-pm}
Let $Q$ be an FD-cyclic CQ with no self-joins over a schema $\calS=(\calR,\Delta)$. For every $\calH_{pm}=(V,E)\in\tetpm{Q^+}$ and non-trivial $X\rightarrow y\in\dltplus$, we have
$X\cup\{y\}\not\subseteq V$.
\end{lemmarep}
\begin{proofsketch}
Assume by contradiction that the variables of the FD $\delta=X\rightarrow y$ are all part of the pseudo-minor $\calH_{pm}$.
Note that the variables $X\cup\{y\}$ must appear in a common edge that corresponds to the atom that defines
$\delta$. We distinguish between two cases. %according to the two types of pseudo-minors present in $\tetpm{Q^+}$.
If $\calH_{pm}$ is obtained only by vertex removal and edge removal steps, then by the definition of $\tetra{k}$ it also contains an edge $e$ with $X\subseteq e$ and
$y\not\in e$. However, this contradicts the fact that $Q^+$ is an FD-extension, as every edge containing $X$ must also contain $y$.
The other case is that $\calH_{pm}$ is a $\tetra{3}$ obtained by edge contraction steps performed on a cycle $C$. Then $X\cup\{y\}$ is contained in a single edge in $C$, as none of the vertices $X\cup\{y\}$ have been deleted. Thus, we have that $|X|=1$ and we can denote $X=\{x\}$. As $C$ is a cycle, it contains an edge $e$ with $x\in e$ and $y\not\in e$, which contradicts the fact that $Q^+$ is an FD-extension.
\end{proofsketch}
\begin{proof}
We start with an observation regarding the FDs.
Let $\delta=X\rightarrow y\in\dltplus$, and let $\calH'$ be some hypergraph obtained from $\calH(Q^+)$ by a sequence of vertex removals and edge removals.
Note that in $\calH(Q^+)$ some edge contains the vertices $X\cup\{y\}$, and by the construction of $Q^+$, every edge that contains $X$ must also contain $y$.
These properties still hold after any sequence of vertex removals and edge removals as long as none of the vertices $X\cup\{y\}$ are removed.
Therefore if none of the vertices $X\cup\{y\}$ were removed, there must be an edge in $\calH'$ containing all of them, and every edge in $\calH'$ containing $X$ also contains $y$.
We distinguish two cases. In the first case, $\calH_{pm}$ is a $\tetra{k}$ obtained from $\calH(Q^+)$ by a sequence of vertex removals and edge removals. If $X\cup\{y\}\subseteq V$, then by the definition of $\tetra{k}$ it should contain the edge $V\setminus \{y\}$. Such an edge cannot exist since it contains all of $X$ but not $y$. Therefore, such a $\tetra{k}$ cannot contain all of $X\cup\{y\}$, and in this case we conclude that $X\cup\{y\}\not\subseteq V$.
In the second case, $\calH_{pm}$ is a $\tetra{3}$ obtained by edge contraction steps performed on a cycle $C$, where $C$ is a result of a sequence of vertex removals and edge removals performed on $\calH(Q^+)$. If none of $X\cup\{y\}$ were removed, some edge of $C$ must contain all of them. Since all edges are of size $2$ it must be that $|X|=1$. Denote $X=\{x\}$. Since we consider a cycle containing both $x$ and $y$, there should be at least one edge containing $x$ but not containing $y$. Since we showed it is not possible, such a cycle cannot contain all of $X\cup\{y\}$. Reducing this cycle to size 3 via a series of edge contractions results in a $\tetra{3}$ that does not contain all of $X\cup\{y\}$. So in this case as well, we have that $X\cup\{y\}\not\subseteq V$.
\end{proof}
We are now ready to establish the reduction.
Given a pseudo-minor of $\tetpm{Q^+}$ isomorphic to some $\tetra{k}$, we can reduce the problem of checking whether a hypergraph contains a subhypergraph
isomorphic to $\tetra{k}$ to finding a boolean answer to $Q^+$.
\begin{lemmarep}\label{lemma:simple-pm}
Let $Q$ be an FD-cyclic CQ with no self-joins over a schema $\calS=(\calR,\Delta)$, where $\Delta$ only contains unary FDs. Let $\calH_{pm}\in\tetpm{Q^+}$ be a pseudo-minor of $\calH(Q^+)$ isomorphic to $\tetra{k}$. Then, %$\contains{H_{pm}}\leq_m \qDecide{Q^+}{\dltplus}$.
$\tetra{k}\leq_m \qDecide{Q^+}{\dltplus}$, and this reduction can be computed in linear time.
\end{lemmarep}
\begin{proofsketch}
Given an input hypergraph $\calG$ for the $\tetra{k}$ problem, we define an instance $I$ of $\qDecide{Q^+}{\dltplus}$.
We consider a sequence $\calH(Q^+)=\calH_1,\calH_2,\ldots,\calH_t=\calH_{pm}$ of pseudo-minors, each one obtained by performing one operation over the previous one.
We define the instance $I$ inductively, by first generating relations that correspond to the edges of $\calH_{pm}$, and then ``reversing'' the operations.
For every edge $e$ of $\calH_{pm}$, we define a relation $R_e^{t}$ that contains all edges of $\calG$ that have the same size as $e$.
We then construct the relations $R_e^{i}$ of $\calH_i$ given the relations
$R_e^{i+1}$ of $\calH_{i+1}$.
We make the following case distinction:
If an edge $e$ was removed as some $e'$ contains it, then the relation $R_e$ is added as a projection of $R_{e'}$.
If $\calH_{i+1}$ is obtained from $\calH_i$ by an edge contraction in which a vertex $v$ is replaced by $u$, then the values corresponding to $u$ in every tuple are copied to the index of $v$.
If a vertex $v$ is removed, then it is assigned with a constant value, and then the following steps are performed on every tuple to correct any FD violations. First, the values of all variables implied by $v$ are concatenated to its value, and then the new value of $v$ is concatenated to all variables implying it.
Since $Q^+$ is an FD-extension, and since only unary FDs are present, we can conclude that whenever a vertex is removed, if $x$ implies $y$, then $y$ is present in every edge containing $x$. This fact guarantees that for the FD-correction steps can be performed.
This construction defines relations that correspond to $\calH(Q^+)$, which form $I$ in such a way that $\calG$ has a subhypergraph isomorphic to $\calH_{pm}$ iff $Q^+(I)\neq \emptyset$.
Compliance to any FDs included in $\calH_i$ is shown by induction on the sequence, and the induction base holds trivially due to Lemma~\ref{lemma:fd-pm}.
\end{proofsketch}
\begin{proof}
Given an input hypergraph $\calG$ for the $\tetra{k}$ problem, we define an instance $I$ of $\qDecide{Q^+}{\dltplus}$.
We consider a sequence of pseudo-minors which starts in $\calH(Q^+)$ and ends in $\calH_{pm}$, each pseudo-minor is obtained by performing one operation over the previous one: $\calH(Q^+)=\calH_1,\calH_2,\ldots,\calH_t=\calH_{pm}$.
We define the instance $I$ inductively, by ``reversing'' the operations.
{\bf Constructing $I$.}
We first generate relations that correspond to the edges of $\calH_{pm}$.
For every edge $e$ of $\calH_{pm}$, we define a relation
$R_e^{t}$ that contains all edges of $\calG$ that have the same size as $e$.
Let $<$ be a total order on the vertices of $G$. A tuple of $R_e^{t}$ will hold the vertices of such an edge sorted by $<$.
We now describe the step that constructs the relations $R_e^{i}$ of $\calH_i$ given the relations
$R_e^{i+1}$ of $\calH_{i+1}$.
This eventually defines relations that correspond to $\calH(Q^+)$, and forms $I$.
We distinguish three cases according to the type of operation.
\begin{itemize}
\item {\em edge removal}: Let $e$ be the edge removed, and let $e'$ be an edge containing it.
Set the relation $R_e^{i}$ to be a copy of the relation for $R_{e'}^{i+1}$ projected accordingly.
Then for every $e''\in \calH_{i+1}$, set $R_{e''}^i=R_{e''}^{i+1}$.
\item {\em edge contraction}: Let $v$ be the vertex replaced by its neighbor $u$.
For any edge $e\in\calH_{i}$ contracting to an edge $e'\in\calH^{i+1}$,
we distinguish between two cases:
\begin{itemize}
\item If $u,v\in e$, then $R_{e}^{i}$ is a copy of $R_{e'}^{i+1}$, and the attribute $v$ in every
tuple is assigned a copy of the value of $u$.
\item Otherwise, we set $R_{e}^{i}=R_{e'}^{i+1}$.
\end{itemize}
For any other edge $e''\in \calH_{i}$, set $R_{e''}^i=R_{e''}^{i+1}$.
\item {\em vertex removal}: Let $v$ be the vertex removed, and let
$e\in\calH_{i}$ be an edge containing $v$, resulting in an edge $e'\in \calH_{i+1}$.
Then expand $R_{e'}^{i+1}$ to $R_{e}^{i}$ by copying $R_{e'}^{i+1}$, and
assign $v$ with a constant $\bot$ in every tuple. Next
apply the following FD-correction steps on $v$:
\begin{enumerate}
\item
Construct a list of the variables implied by $v$. This list is defined recursively by
$\text{ImpliedBy}(v)=\{v\}$ and $\text{ImpliedBy}(v)=\{w\mid t\rightarrow w\in\dltplus,t\in\text{ImpliedBy}(v)\}$. Then, for each $w\in\text{ImpliedBy}(v)\setminus\{v\}$, concatenate the values of $w$ to $v$ in every tuple containing $v$.
That is, if $R^i(\vec{u})$ is an atom such that $\vec{u}[k]=v$ and $\vec{u}[j]=w$, then in every tuple $t\in R^i$, the value of $t[k]$ is replaced with $(t[k],t[j])$.
\item
After the value of $v$ is determined,
consider the set of variables implying $v$. This set is defined by $\text{Implies}(v)=\{v\}$ and
$\text{Implies}(v)=\{u\mid u\rightarrow t\in\dltplus,t\in\text{Implies}(v)\}$.
Then, for each $u\in\text{Implies}(v)\setminus\{v\}$, concatenate the values of $v$ to $u$ in every tuple containing $u$.
\end{enumerate}
For any edge $e''\in\calH_i$ not containing $v$, set $R_{e''}^i=R_{e''}^{i+1}$.
\end{itemize}
{\bf Linear time construction.}
Since $Q^+$ is an FD-extension and only unary FDs are present, we are guaranteed that if $x$ implies $y$, then $y$ is present in every edge of $\calH(Q^+)$ where $x$ appears. This property is preserved under vertex removal and edge removal operations (as long as $x$ and $y$ are not removed), which are the only operations that were possibly performed between $\calH(Q^+)$ and any pseudo-minor on which we perform vertex-removal. Therefore on any graph where we perform the FD-correction steps, we have that if $x$ implies $y$ then $y$ is present in every edge where $x$ appears, thus the update required by any $w\in\text{ImpliedBy}(v)$ or $u\in\text{Implies}(v)$
requires only the corresponding relation.
The overall construction of the instance $I$ can be done in linear time, since there is a constant number of pseudo-minor
operations, each resulting in a linear number of computational steps.
{\bf $I$ is an instance of $\calS$.}
We show that $I$ preserves the FDs in $\dltplus$ using induction. We claim that for each pseudo-minor $\calH_i$ all FDs $x\rightarrow y$ such that $x,y\in V(\calH_i)$ hold.
By Definition~\ref{def:tetpm}, there exists some $j$ such that the operations of $\calH_1,\ldots,\calH_j$ are only vertex removals and edge removals, $\calH_j$ is either a $\tetra{k}$ or a chordless cycle, and the operations of $\calH_j,\ldots,\calH_t$ are only edge contractions and edge removals.
In the proof of Lemma~\ref{lemma:fd-pm}, we see that $\calH_j$ and therefore all
of $\calH_j,\ldots,\calH_t$ do not contain all variables of any FD.
Therefore our claim trivially holds for $\calH_j,\ldots,\calH_t$.
We now describe the step constructing $\calH_i$ from $\calH_{i+1}$, where $1\leq i\leq j-1$, and consider an FD $\delta = x \rightarrow y$ such that $x,y\in V(\calH_i)$. There are three cases:
\begin{itemize}
\item If $x,y\in V(\calH_{i+1})$, then by the induction assumption $\delta$ holds in $\calH_{i+1}$. If $\calH_{i+1}$ is obtained by edge removal, then the only new relation in $\calH_i$ is a projection of a relation of $\calH_{i+1}$, and therefore all FDs hold. We now address the case that $\calH_{i+1}$ is obtained by vertex removal.
If the value of $y$ remains the same in $R_e^{i+1}$ as it is in $R_e^{i}$, we are done by the induction assumption. Otherwise, $y$ has changed due to the second FD-correction step, and the vertex removed is some $z$ such that $y \rightarrow z$.
In this case, since $x$ also implies $z$, both $x$ and $y$ are concatenated with the same values, and $\delta$ still holds.
\item If $x\not\in V(\calH_{i+1})$, then $\calH_{i+1}$ is obtained by the removal of the vertex $x$, and the first FD-correction step ensures that $x$ contains a copy of the values of $y$ in every tuple where they both appear. Therefore $\delta$ holds.
\item If $y\not\in V(\calH_{i+1})$, then $\calH_{i+1}$ is obtained by the removal of the vertex $y$, and the second FD-correction step ensures that $x$ contains a copy of the values of $y$, and $\delta$ holds.
\end{itemize}
{\bf Correctness.}
Denote by $Q_i$ and $I_i$ the query corresponding to $\calH_i$ and the instance we defined for it respectively.
As shown in~\cite[Lemma 20]{bb:thesis}, there is a solution to $Q_t(I_t)$ iff there exists a subhypergraph of $\calG$ isomorphic to $\calH_{pm}$, and in fact every mapping $\mu$ that can be used for the evaluation corresponds to such a subhypergraph.
We now claim that every mapping used for evaluating $Q_{i+1}(I_{i+1})$ corresponds to a mapping that can be used for $Q_{i}(I_{i})$, and vice versa.
This was already shown in case $\calH_{i+1}$ is obtained by $\calH_{i}$ via edge contraction \cite[Lemma 15]{bb:thesis} or edge removal \cite[Lemma 14]{bb:thesis}.
It was also shown for the case of vertex removal~\cite[Lemma 13]{bb:thesis} if we simply assign the new vertex with a constant, and skip the FD-correction steps.
Let $\calH_{i+1}$ be a pseudo-minor obtained from $\calH_i$ via vertex removal, and denote by $I_i^0$ the instance constructed from $I_{i+1}$ as described but without performing the FD-correction steps. It is left to show that a mapping $\mu^0$ that satisfies $Q_i(I_i^0)$ corresponds to a mapping $\mu$ that satisfies $Q_i(I_i)$, and vice versa. This will conclude that $\calG$ has a subhypergraph isomorphic to $\calH_{pm}$ iff $Q^+(I)\neq \emptyset$.
We show this by induction, considering one FD-correction step involving one variable at a time.
First consider the first FD-correction step on a vertex $v$ implying $w$. If $\mu^0$ maps $v$ to some value $a_v$ and $w$ to $a_w$, then we define $\mu$ to be the same as $\mu^0$ but mapping $v$ to $(a_v,a_w)$.
This $\mu$ is indeed a valid evaluation of $Q_i(I_i)$.
The only change between $I_i^0$ and $I_i$ is that in $I_i$, $a_w$ is concatenated to all occurrences of $a_v$.
Every atom in $Q_i$ containing $v$ also contains $w$, therefore every tuple in $I_i^0$ containing $a_v$ also contains $a_w$. Since every $\mu^0$ also contains a mapping of $w$ to $a_w$, the tuple that was used in the evaluation of $\mu^0$ in $I_i^0$ results in a tuple that can be used in the evaluation of $\mu$ in $I_i$.
The same argument holds similarly for the opposite direction and for the second FD-correction step. For the opposite direction, if $\mu$ maps $v$ to $(a_v,a_w)$, then $\mu^0$ is defined to map $v$ to $a_v$. For the second FD-correction step, if $\mu^0$ maps $u$ to $a_u$ and $v$ to $a_v$, then mapping $a$ to $(a_u,a_v)$ forms an evaluation for $Q_i(I_i)$, and vice versa.
\end{proof}
Theorem~\ref{thm:cyclicHardness} is an immediate consequence of Lemma~\ref{lemma:simple-pm}.
As in the previous section, by taking a disjoint domain for every variable in the proof of Lemma~\ref{lemma:simple-pm}, Theorem~\ref{thm:cyclicHardness} also holds for CQs with disequalities.
In terms of enumeration complexity, Theorem~\ref{thm:cyclicHardness} means that any enumeration algorithm for the answers of such a query cannot output a first solution (or decide that there is none) within linear time, and we get the following corollary.
\begin{corollaryrep}\label{cor:cyclicHardness}
Let $Q$ be a CQ with no self-joins over a schema $\calS=(\calR,\Delta)$, where $\Delta$ only contains unary FDs. If $Q$ is FD-cyclic, then $\qEnum{Q}{\Delta}\not\in\DelayClin$,
assuming that the $\tetra{k}$ problem cannot be solved in linear time for any $k$.
\end{corollaryrep}
\begin{proof}
Assume by contradiction that $\qEnum{Q}{\Delta}\in\DelayClin$. This means that finding a first answer to $Q$, or deciding that there is none, can be done in linear time. This contradicts Theorem~\ref{thm:cyclicHardness}.
\end{proof}
Less restrictive than constant delay enumeration, the class $\DelayLin$ consists of
enumeration problems that can be solved with a linear delay between solutions.
A lower bound for this class can be achieved similarly
to Corollary~\ref{cor:cyclicHardness}.
Regarding tractability, as acyclic CQs are in $\DelayLin$~\cite{bdg:dichotomy}, we conclude from Corollary~\ref{cor:posExtension} that FD-acyclic CQs are in this class as well.
Thus, we obtain a dichotomy stating that CQs are in $\DelayLin$ iff they are FD-acyclic.
\begin{theoremrep}\label{theorem:lineardelaydichomtomy}
Let $Q$ be a CQ with no self-joins over a schema $\calS=(\calR,\Delta)$, where $\Delta$ only contains unary FDs.
\begin{itemize}
\item If $Q$ is FD-acyclic, then $\qEnum{Q}{\Delta}\in\DelayLin$.
\item Otherwise (if $Q$ is FD-cyclic), $\qEnum{Q}{\Delta}\not\in\DelayLin$,
assuming that the $\tetra{k}$ problem cannot be solved in linear time for any $k$.
\end{itemize}
\end{theoremrep}
\begin{proof}
If $Q^+$ is acyclic, then $\qEnum{Q^+}{\emptyset}\in\DelayLin$~\cite{bdg:dichotomy}.
Since every instance that preserves $\dltplus$ also preserves $\emptyset$, the identity mapping gives us $\qEnum{Q^+}{\dltplus}\leq_e\qEnum{Q^+}{\emptyset}$.
According to Theorem~\ref{thm:qpEquiv}, $\qEnum{Q}{\Delta}\leq_e\qEnum{Q^+}{\dltplus}$. Therefore, $\qEnum{Q}{\Delta}\in\DelayLin$.
If $Q^+$ is cyclic, assume by contradiction that $\qEnum{Q}{\Delta}\in\DelayLin$. Using Theorem~\ref{thm:qpEquiv}, $\qEnum{Q^+}{\dltplus}\leq_e\qEnum{Q}{\Delta}$ and therefore $\qEnum{Q^+}{\dltplus}\in\DelayLin$ as well. This means that finding a first answer to $Q^+$, or deciding that there is none, can be done in linear time. This contradicts Theorem~\ref{thm:cyclicHardness}.
\end{proof}
We conclude this section with a short discussion about the extension of our results to general FDs. The following example shows that the proof for Theorem~\ref{thm:cyclicHardness} that was provided here cannot be lifted
to general FDs.
Exploring this extension is left for future work.
\begin{example}\label{exp:generalCyclic}
Consider the query $Q()\leftarrow R_1(x,y,u),R_2(x,w,z),R_3(y,v,z),R_4(u,v,w)$, over a schema with all possible two-to-one FDs in the relations $R_1$, $R_2$ and $R_3$. That is, $\Delta =\{ xy\rightarrow u, yu\rightarrow x, ux\rightarrow y,
zy\rightarrow v, yv\rightarrow z, vz\rightarrow y,
xz\rightarrow w, zw\rightarrow x, wx\rightarrow z\}$.
Note that $Q^+=Q$.
The hypergraph $\calH(Q^+)$ is cyclic, yet it is unclear whether $Q$ can be solved in linear time, and whether $\tetra{3}$ can be reduced to answering $Q^+$.
Using Lemma~\ref{lemma:fd-pm}, $\calH(Q^+)$ has triangle pseudo-minors that do not contain all variables of any FD. Consider for example the one obtained by removing all vertices other than $x,y,z$. A construction similar to that of Lemma~\ref{lemma:simple-pm} would assign $u$ with the values of $x$ and $y$, assign $v$ with the values of $y$ and $z$, and assign $w$ with the values of $x$ and $z$. This results in the edge $\{u,v,w\}$ containing all three values of any possible triangle, meaning that this edge cannot be constructed in linear time.
Other choices of triangle pseudo-minors lead to similar encoding problems.
\qed
\end{example}
\section{Cardinality Dependencies}\label{section:cardinalitydep}
In this last section, we show that the results of this paper also apply to CQs over schemas with cardinality dependencies.
{\em Cardinality Dependencies} (CDs)~\cite{DBLP:conf/icalp/ArapinisFG16,DBLP:journals/pvldb/CaoFWY14} are a generalization of FDs, where the left-hand side does not uniquely determine the right-hand side,
but rather provides a bound on the number of distinct values it can have.
Formally, $\Delta$ is the set of $CDs$ of a schema $\calS=(\calR,\Delta)$. Every $\delta\in\Delta$ has the form $(R_i\colon A\rightarrow B,c)$, where $R_i\colon A\rightarrow B$ is an FD and $c$ is a positive integer.
A CD $\delta$ is {\em satisfied} by an
instance $I$ over $\calS$, if
every set of tuples $S\subseteq(R_i)^I$ that agrees on the indices of $A$, but no pair of them agrees on all indices of $B$, contains at most $c$ tuples.
It follows from the definition that $\delta$ is an FD if $c=1$.
Denote by $\Delta^\text{FD}$ the FDs obtained from a set of CDs $\Delta$ by setting all $c$ values to one.
Given a query $Q$ over $\calS=(\calR,\Delta)$, we define the {\em CD-extended query} $Q^+$ of $Q$ to be the FD-extended query of $Q$ over $\calS=(\calR,\Delta^\text{FD})$.
The schema $\calS^+$ is defined with the original $c$ values, and the CDs are $\dltplus=\{(R_i^+\colon A\rightarrow b,c)\mid \exists(R_j\colon A\rightarrow B,c)\in \Delta, b\in B, A\cup\{b\}\subseteq\var(R_i^+)\}$.
Note that FD-extensions are indeed a special case of CD-extensions.
The hardness results extend to CDs because FDs are a special case of CDs.
Since every instance that preserves the FDs $\Delta^\text{FD}$ also preserves the CDs $\Delta$, we can conclude that $\qEnum{Q}{\Delta^{\text{FD}}}\leq_e\qEnum{Q}{\Delta}$.
When only FDs are present we can apply Theorem~\ref{thm:qpEquiv}, and get $\qEnum{Q^+}{\dltplus^{\text{FD}}}\leq_e\qEnum{Q}{\Delta^{\text{FD}}}$. Combining the two we get the following lemma.
\begin{lemmarep}\label{lemma:negCD}
Let $Q$ be a CQ over a schema $\calS=(\calR,\Delta)$, where $\Delta$ is a set of CDs,
and let $Q^+$ be the corresponding CD-extension. Then
$\qEnum{Q^+}{\dltplus^{\text{FD}}}\leq_e\qEnum{Q}{\Delta}$.
\end{lemmarep}
\begin{proof}
Every instance that preserves the FDs $\Delta^\text{FD}$ also preserves the CDs $\Delta$. Therefore, the reduction $\qEnum{Q}{\Delta^{\text{FD}}}\leq_e\qEnum{Q}{\Delta}$ can be performed using the identity mappings.
From Theorem~\ref{thm:qpEquiv} we get $\qEnum{Q^+}{\dltplus^{\text{FD}}}\leq_e\qEnum{Q}{\Delta^{\text{FD}}}$. This theorem can be applied because $\Delta^\text{FD}$ only contains FDs. Combining the two we get that $\qEnum{Q^+}{\dltplus^{\text{FD}}}\leq_e\qEnum{Q}{\Delta}$.
\end{proof}
Lemma~\ref{lemma:negCD} implies that all negative results presented in this paper hold for CDs.
In order to extend the positive results,
we need to show that the CD-extension is at least as hard as the original query w.r.t.~enumeration. We use a slight relaxation of exact reductions: For $\pEnum{R_1}\leq_{e'}\pEnum{R_2}$, instead of a bijection between the sets of outputs, one output of $\pEnum{R_1}$ corresponds to at most a constant number of outputs of $\pEnum{R_2}$.
\begin{lemmarep}\label{lemma:posCD}
Let $Q$ be a CQ over a schema $\calS=(\calR,\Delta)$, where $\Delta$ is a set of CDs,
and let $Q^+$ be the corresponding CD-extension. Then
$\qEnum{Q}{\Delta}\leq_{e'}\qEnum{Q^+}{\dltplus}$.
\end{lemmarep}
\begin{proofsketch}
When dealing with FDs, we assume that the right-hand side has only one variable, as we can use such FDs to describe all possible ones.
With CDs this no longer holds.
Nonetheless, every instance of the schema $\calS=(\calR,\Delta)$ is also an instance of $\calS^1=(\calR,\Delta^1)$, where
$\Delta^1=\{(R_i\colon A\rightarrow b,c)\mid (R_i\colon A\rightarrow B,c)\in\Delta,b\in{B}\}$.
Therefore, we can conclude that $\qEnum{Q}{\Delta}\leq_e\qEnum{Q}{\Delta^1}$.
We now show that $\qEnum{Q}{\Delta^1}\leq_{e'}\qEnum{Q^+}{\Delta^+}$.
The proof remains the same as in Theorem~\ref{thm:qpEquiv}, except now, for each tuple extended from $R^I_i$ to $R^{I^+}_i$
we can have at most $c$ new tuples. Since this process is only done a constant number of times, the construction still only
requires linear time, and the rest of the proof holds. Note that now one solution of $\qEnum{Q^+}{\Delta^+}$ may correspond to several
solutions of $\qEnum{Q}{\Delta^1}$, as some variables were possibly added to the head. However, as the possible values of the added head variables are bounded by CDs, the number of solutions of $Q^+$ that correspond to one solution of $Q$ is bounded by a constant.
\end{proofsketch}
\begin{proof}
Define $\Delta^1=\{(R_i\colon A\rightarrow b,c)\mid (R_i\colon A\rightarrow B,c)\in\Delta,b\in{B}\}$.
As every instance of the schema $\calS=(\calR,\Delta)$ is also an instance of $\calS^1=(\calR,\Delta^1)$, we can use the identity mappings to conclude that $\qEnum{Q}{\Delta}\leq_e\qEnum{Q}{\Delta^1}$.
We now show that $\qEnum{Q}{\Delta^1}\leq_{e'}\qEnum{Q^+}{\Delta^+}$.
Let $Q(\vec{p}) \leftarrow R_1(\vec{v}_1), \dots, R_m(\vec{v}_m)$ and
$Q^+(\vec{q})\leftarrow R_1^+(\vec{u}_m), \dots, R_m^+(\vec{u}_m)$.
We first show that $\qEnum{Q}{\Delta}\leq_e\qEnum{Q^+}{\dltplus}$.
Given an instance $I$ for the problem $\qEnum{Q}{\Delta}$, we set $\sigma(I)=I^+$ as described next.
We start by removing tuples that interfere with the extended dependencies. For every dependency
$\delta=(R_j\colon X\rightarrow y,c)\in\Delta^1$ and every atom $R_k(\vec{v}_k)$ that contains
the corresponding variables (i.e., $X\cup\{y\}\subseteq \vec{v}_k$),
we correct $R_k$ according to $\delta$:
We only keep tuples of $R_k^I$ that agree with some tuple of $R_j^I$ over the values of
$X\cup\{y\}$.
We say that a tuple $t_a\in R_a^I$ agrees with a tuple $t_b\in R_b^I$ on the value of a variable $z$ if for every pair of indices $i_a,i_b$ such that $\vec{v_a}[i_a]=\vec{v_b}[i_b]=z$ we have that $t_a[i_a]=t_b[i_b]$.
This check can be done in linear time by first sorting both $R_j^I$ and $R_k^I$ according to
$X\cup\{y\}$, and then performing one scan over both of them.
Next, we follow the extension of the schema, and in each step we extend some $R_i^I$ to $R_i^{I'}$ according to some CD $(R_j\colon X\rightarrow y,c)$ as described in the case of FDs.
For each tuple $t\in R^I_i$, if there is no tuple $s\in R^I_j$ that agrees with $t$ over the values of $X$, then we remove $t$ altogether.
Otherwise, we consider all values such $s$ tuples assign $y$. We say that a tuple $t\in R_a^I$ assigns a variable $z$ with the value $u_a$ if for every index $i_a$ such that $\vec{v}_a[i_a]=z$ we have that $t[i_a]=u_a$.
Denote those values by $a_1,\ldots,a_k$, and note that due to the CD, $k\leq c$.
We copy $t$ to $R^{I'}_i$ $m$ times, each time assigning $y$ with a different value of $a_1,\ldots,a_k$.
Given an answer $\mu\in Q^+(\sigma(I))$, we set $\tau(\mu)$ to be the projection of $\mu$ to $\free(Q)$. The projection $\tau(\mu)$ is computable in constant time.
For the correctness, we need to show that $Q(I)=\{\mu|_{\free(Q)}:\mu|_{\free(Q^+)}\in Q^+(\sigma(I))\}$, and that an element of the left-hand side may only appear a constant amount of times on the right-hand side.
The easy direction is that if $\mu|_{\free(Q^+)}\in Q^+(\sigma(I))$ then $\mu|_{\free(Q)}\in Q(I)$.
Since $\mu$ is a homomorphism from $Q^+$ to $\sigma(I)$, and since all tuples of $\sigma(I)$ appear (perhaps projected) in $I$, then $\mu$ is also a homomorphism from $Q$ to $I$.
We now show the opposite direction, that if $\mu|_{\free(Q)}\in Q(I)$ then $\mu|_{\free(Q^+)}\in Q^+(\sigma(I))$.
Consider a sequence of queries $Q=Q_0,Q_1,\ldots,Q_n=Q^+$ such that each one is the result of extending an atom or the head of the previous query according to a CD $(R_j\colon X\rightarrow y,c)$.
We claim that if $\mu|_{\vec{p}_i}$ is an answer for $Q_i(\vec{p}_i)$, then $\mu|_{\vec{p}_{i+1}}$ is an answer for $Q_{i+1}(\vec{p}_{i+1})$. This claim is trivial in case the head was extended. Note that there can be at most $c-1$ different answers $\mu'|_{\vec{p}_{i+1}}$ to $Q_{i+1}$ such that $\mu|_{\vec{p}_{i+1}}\neq\mu'|_{\vec{p}_{i+1}}$ but $\mu|_{\vec{p}_{i}}=\mu'|_{\vec{p}_{i}}$, as the added variable $y$ is bound by the CD to have at most $c$ possible values.
Now consider the case where an atom $R_k(\vec{v}_k)$ was extended since $X\subseteq\vec{v}_k$. Denote by $t_k$ and $t_j$ the tuples that are mapped by $\mu$ from $R_k$ and $R_j$ respectively. The construction guarantees that $t_j$ and some copy of $t_k$ agree on the value of $y$, so $\mu$ can still map the extended $R_k$ to an extended copy of $t_k$. In case of self-joins, other atoms with the relation $R_k$ are extended with a new and distinct variable, and the new variable can be mapped to any value appearing in the extension. Therefore if $\mu|_{\free(Q)}\in Q(I)$ then $\mu|_{\free(Q^+)}\in Q^+(\sigma(I))$, and at most a constant number of different $\mu|_{\free(Q^+)}$ are projected to the same $\mu|_{\free(Q)}$.
\end{proof}
$\DelayClin$ is closed under this type of reduction. To avoid printing duplicates, we store the printed results. This requires a polynomial amount of memory, where the power of the polynomial is $|\free(Q)|$.
Defining the classes of {\em CD-acyclic} and {\em CD-free-connex} queries similarly to the case with FDs,
we can use Lemma~\ref{lemma:negCD} and Lemma~\ref{lemma:posCD} with Theorem~\ref{thm:acyclicDichotomy} to generalize the dichotomy presented in Section~\ref{sec:Positive} to accommodate CDs.
\begin{theoremrep}\label{thm:dichotomyCDs}
Let $Q$ be a CD-acyclic CQ with no self-joins over a schema $\calS=(\calR,\Delta)$, where $\Delta$ is a set of CDs.
\begin{itemize}
\item If $Q$ is CD-free-connex, then $\qEnum{Q}{\Delta}\in\DelayClin$.
\item If $Q$ is not CD-free-connex, then $\qEnum{Q}{\Delta}\not\in\DelayClin$, assuming
that the product of two $n \times n$ boolean matrices cannot be computed in time $O(n^2)$.
\end{itemize}
\end{theoremrep}
\begin{proof}
If $Q^+$ is free-connex, then $\qEnum{Q^+}{\emptyset}\in\DelayClin$ according to Theorem~\ref{theorem:originalDichotomy}.
Since every instance that preserves $\dltplus$ also preserves $\emptyset$, the identity mapping defines the reduction $\qEnum{Q^+}{\dltplus}\leq_e\qEnum{Q^+}{\emptyset}$.
According to Lemma~\ref{lemma:posCD}, we have the reduction $\qEnum{Q}{\Delta}\leq_{e'}\qEnum{Q^+}{\dltplus}$. Therefore, $\qEnum{Q}{\Delta}\in\DelayClin$.
If $Q^+$ is cyclic, assume by contradiction that $\qEnum{Q}{\Delta}\in\DelayLin$. Using Lemma~\ref{lemma:negCD}, $\qEnum{Q^+}{\dltplus^\text{FD}}\leq\qEnum{Q}{\Delta}$ and therefore $\qEnum{Q^+}{\dltplus^\text{FD}}\in\DelayLin$ as well. According to Lemma~\ref{lemma:acyclicgeneralfdnegative} this means that $\qEnum{\Pi}{\emptyset}\in\DelayClin$, and the matrix multiplication problem can be solved in quadratic time.
\end{proof}
Similarly, we conclude the hardness of self-join-free CD-cyclic CQs over schemas that contain only unary CDs, of the form $(A\rightarrow B,c)$ with $|A|=1$. Combining Lemma~\ref{lemma:negCD} with Theorem~\ref{thm:cyclicHardness}, we have that
such queries cannot be evaluated in linear time, assuming that the $\tetra{k}$ problem cannot be solved in linear time for any $k$.
\section{Concluding Remarks}\label{section:conclusion}
Previous hardness results regarding the enumeration complexity of CQs no longer hold in the presence of dependencies.
In this paper, we have shown that some of the queries which where previously classified as hard are in fact tractable in the presence of FDs, and that the others remain intractable.
We have classified the enumeration complexity of self-join-free CQs according to their FD-extension. Under previously used complexity assumptions: a query is in $\DelayClin$ if its extension is free-connex, it is not in $\DelayClin$ if its extension is acyclic but not free-connex, and it is not even decidable in linear time if the schema has only unary FDs and its extension is cyclic.
In addition to our results on constant delay enumeration of CQs with FDs,
the tools provided here have immediate implications in other settings,
such as for CQs with disequalities, schemas with CDs, and other enumeration classes such as $\DelayLin$.
This work opens up quite a few directions for future work.
Our proof for the hardness of FD-cyclic CQs assumes that all FDs are unary.
The question of whether this result holds for general FDs, along with the classification of
Example~\ref{exp:generalCyclic}, remains open.
This result, as well as the original one given by Brault-Baron~\cite{bb:thesis} assumes the hardness of the \tetra{k} problem for every $k$. It will be interesting to see whether we can get the same result based on a weaker assumption.
Another possible direction involves CDs.
To show that enumerating CD-free-connex CQs can be done in $\DelayClin$, we require polynomial space to store all printed results. It is unclear whether there exists a solution that requires less space.
Finally, we wish to explore how the tools provided here can be used to extend other known results on query enumeration,
such as a dichotomy for enumerating CQs~\cite{bb:thesis} with negation, to accommodate FDs.
\bibliographystyle{plainurl}
\bibliography{references}
\end{document}
\begin{thebibliography}{10}
\bibitem{MatrixMultiplication2}
Amir Abboud and Virginia~Vassilevska Williams.
\newblock Popular conjectures imply strong lower bounds for dynamic problems.
\newblock In {\em Foundations of Computer Science (FOCS), 2014 IEEE 55th Annual
Symposium on}, pages 434--443. IEEE, 2014.
\bibitem{DBLP:conf/icalp/ArapinisFG16}
Myrto Arapinis, Diego Figueira, and Marco Gaboardi.
\newblock Sensitivity of counting queries.
\newblock In {\em 43rd International Colloquium on Automata, Languages, and
Programming, {ICALP} 2016, Rome, Italy}, pages 120:1--120:13, 2016.
\bibitem{bdg:dichotomy}
Guillaume Bagan, Arnaud Durand, and Etienne Grandjean.
\newblock On acyclic conjunctive queries and constant delay enumeration.
\newblock In {\em International Workshop on Computer Science Logic}, pages
208--222. Springer, 2007.
\bibitem{DBLP:journals/jacm/BeeriFMY83}
Catriel Beeri, Ronald Fagin, David Maier, and Mihalis Yannakakis.
\newblock On the desirability of acyclic database schemes.
\newblock {\em J. {ACM}}, 30(3):479--513, 1983.
\newblock URL: \url{http://doi.acm.org/10.1145/2402.322389}, \href
{http://dx.doi.org/10.1145/2402.322389} {\path{doi:10.1145/2402.322389}}.
\bibitem{DBLP:conf/pods/BerkholzKS17}
Christoph Berkholz, Jens Keppeler, and Nicole Schweikardt.
\newblock Answering conjunctive queries under updates.
\newblock In {\em Proceedings of the 36th {ACM} {SIGMOD-SIGACT-SIGAI} Symposium
on Principles of Database Systems, {PODS} 2017, Chicago, IL, USA, May 14-19,
2017}, pages 303--318, 2017.
\bibitem{bb:thesis}
Johann Brault-Baron.
\newblock {\em De la pertinence de lā{\'e}num{\'e}ration: complexit{\'e} en
logiques propositionnelle et du premier ordre}.
\newblock PhD thesis, Universit{\'e} de Caen, 2013.
\bibitem{DBLP:journals/pvldb/CaoFWY14}
Yang Cao, Wenfei Fan, Tianyu Wo, and Wenyuan Yu.
\newblock Bounded conjunctive queries.
\newblock {\em {PVLDB}}, 7(12):1231--1242, 2014.
\bibitem{DBLP:conf/lata/CreignouKPSV17}
Nadia Creignou, Markus Kr{\"{o}}ll, Reinhard Pichler, Sebastian Skritek, and
Heribert Vollmer.
\newblock On the complexity of hard enumeration problems.
\newblock In {\em Language and Automata Theory and Applications - 11th
International Conference, {LATA} 2017, Ume{\aa}, Sweden}, pages 183--195,
2017.
\bibitem{Durand:2014:EAF:2594538.2594539}
Arnaud Durand, Nicole Schweikardt, and Luc Segoufin.
\newblock Enumerating answers to first-order queries over databases of low
degree.
\newblock In {\em Proceedings of the 33rd ACM SIGMOD-SIGACT-SIGART Symposium on
Principles of Database Systems}, PODS '14, pages 121--131, 2014.
\bibitem{DBLP:journals/amai/Grandjean96}
Etienne Grandjean.
\newblock Sorting, linear time and the satisfiability problem.
\newblock {\em Ann. Math. Artif. Intell.}, 16:183--236, 1996.
\newblock URL: \url{https://doi.org/10.1007/BF02127798}, \href
{http://dx.doi.org/10.1007/BF02127798} {\path{doi:10.1007/BF02127798}}.
\bibitem{Kimelfeld:2012:DCD}
Benny Kimelfeld.
\newblock A dichotomy in the complexity of deletion propagation with functional
dependencies.
\newblock In {\em Proceedings of the 31st ACM SIGMOD-SIGACT-SIGAI Symposium on
Principles of Database Systems}, PODS '12, pages 191--202, New York, NY, USA,
2012. ACM.
\newblock URL: \url{http://doi.acm.org/10.1145/2213556.2213584}, \href
{http://dx.doi.org/10.1145/2213556.2213584}
{\path{doi:10.1145/2213556.2213584}}.
\bibitem{MatrixMultiplication}
Fran\c{c}ois Le~Gall.
\newblock Powers of tensors and fast matrix multiplication.
\newblock In {\em Proceedings of the 39th International Symposium on Symbolic
and Algebraic Computation}, ISSAC '14, pages 296--303, New York, NY, USA,
2014. ACM.
\newblock URL: \url{http://doi.acm.org/10.1145/2608628.2608664}, \href
{http://dx.doi.org/10.1145/2608628.2608664}
{\path{doi:10.1145/2608628.2608664}}.
\bibitem{DBLP:journals/jcss/PapadimitriouY99}
Christos~H. Papadimitriou and Mihalis Yannakakis.
\newblock On the complexity of database queries.
\newblock {\em J. Comput. Syst. Sci.}, 58(3):407--427, 1999.
\bibitem{DBLP:conf/icdt/SegoufinV17}
Luc Segoufin and Alexandre Vigny.
\newblock Constant delay enumeration for {FO} queries over databases with local
bounded expansion.
\newblock In {\em 20th International Conference on Database Theory, {ICDT}
2017, Venice, Italy}, pages 20:1--20:16, 2017.
\bibitem{Strozecki2010}
Yann Strozecki.
\newblock {\em Enumeration complexity and matroid decomposition}.
\newblock PhD thesis, Universit\'e Paris Diderot -- Paris 7, December 2010.
\newblock Available at \url{http://www.prism.uvsq.fr/~ystr/these_strozecki}.
\bibitem{DBLP:conf/focs/WilliamsW10}
Virginia~Vassilevska Williams and Ryan Williams.
\newblock Subcubic equivalences between path, matrix and triangle problems.
\newblock In {\em 51th Annual {IEEE} Symposium on Foundations of Computer
Science, {FOCS} 2010, Las Vegas, Nevada, {USA}}, pages 645--654, 2010.
\end{thebibliography}