1: \begin{definition}
2:
3: Let $q=(n,k_1,\ldots,k_n,C,W,P,P_0)$ be an agnostic SQL query as in Definition \ref{def:SQL bag set}. The set $W$ generates an equivalence relation $\sim$ on $C$; let $C':=C/\sim$ be the quotient and $\ell\taking C\to C'$ the induced function. Suppose that $C'$ has $r=|C'|$ many elements and that $P_0$ has $s=|P_0|$ many elements.
4:
5: We define the {\em categorical setup for $q$}, denoted $CS(q)=\mcS\To{F}\mcT\From{G}\mcU$ as follows.
6: $$
7: \parbox{2.2in}{\begin{center}$\mcS:=$\end{center}\fbox{\xymatrix{
8: \LMO{1}\ar@/_1pc/[ddrr]_{c_{1,1}}\ar@/^1pc/[ddrr]^{c_{1,k_1}}\ar@{}[ddrr]|\cdots&&\cdots&&\LMO{n}\ar@/_1pc/[ddll]_{c_{n,1}}\ar@/^1pc/[dlld]^{c_{n,k_n}}\\\\
9: &&\LMO{dom}}
10: }}
11: \parbox{.45in}{\xymatrix{~\ar[r]^F&~}}
12: \parbox{.9in}{\begin{center}$\mcT:=$\end{center}\fbox{\xymatrix{
13: \LMO{B'}\ar@/_1.5pc/[dd]_{c'_1}\ar@/_.5pc/[dd]_{c'_2}\ar@{}[dd]^\cdots\ar@/^1.5pc/[dd]^{c'_r}\\\\
14: \LMO{dom}
15: }}}
16: \parbox{.45in}{\xymatrix{~&~\ar[l]_G}}
17: \parbox{1in}{\begin{center}$\mcU:=$\end{center}\fbox{\xymatrix{
18: \LMO{B'}\ar@/_1.5pc/[dd]_{p_1}\ar@/_.5pc/[dd]_{p_2}\ar@{}[dd]^\cdots\ar@/^1.5pc/[dd]^{p_s}\\\\
19: \LMO{dom}
20: }}}
21: $$
22: Here, the functor $F$ sends $dom$ to $dom$, sends the other objects to $B$, and acts on morphisms by $\ell\taking C\to C'$; the functor $G$ sends $dom$ to $dom$, $B'$ to $B'$, and $P_0\to C'$ by the composite $P_0\To{P}C\To{\ell}C'$.
23:
24: We define the {\em categorical analogue of $q$}, denoted $CA(q)$, to be the FQL query $\Delta_G\Pi_F$.\footnote{The functor $\Delta_G\Pi_F$ is technically not in the correct $\Sigma\Pi\Delta$ order, but it is equivalent to a query in that order by Theorem \ref{thm:query comp}.}
25:
26: \end{definition}
27: