@@ -88,6 +88,31 @@ export class QuerierGraphBuilder {
8888 * This works by first processing subterms related to the source set selected from. If the subterm is a row expression,
8989 * we add it as a filter to the row processor or parameter lookup. If it is a match expression, we create a partition
9090 * key and obtain the value by recursively applying this algorithm to resolve the other side.
91+ *
92+ * To visualize this algorithm, consider the following example query:
93+ *
94+ * ```SQL
95+ * SELECT * FROM comments c, issues i, users u
96+ * WHERE u.user_id = auth.user_id() AND c.issue_id = i.id AND u.id = i.owner_id AND u.is_admin
97+ * ```
98+ *
99+ * First, {@link resolvePrimaryInput} is called, which calls {@link resolveResultSet} on `comments c`. While resolving a
100+ * result set, we extract conditions mentioning that result set. In this case, the only such expression is
101+ * `c.issue_id = i.id`. Because this is an {@link EqualsClause}, we know we need to introduce a parameter (in this case,
102+ * `c.issue_id` because that's the half depending on the current result set). We then look at the other half and
103+ * recursively resolve `issues i` (via {@link resolvePointLookup}). When we're done resolving that, we add `i.id` as to
104+ * {@link PendingExpandingLookup.usedOutputs}.
105+ *
106+ * To resolve `issues i`, we extract the only remaining expression mentioning it, `u.id = i.owner_id`. We once again
107+ * recursve to resolve `users u` and will add `u.id` as a used output.
108+ *
109+ * Finally, we find `u.user_id = auth.user_id()` and `u.is_admin`. The first expression creates a parameter, but doesn't
110+ * need to resolve any further result sets since the input depends on connection data. The second expression only
111+ * depends on the row itself, so we add it as a static condition to only create parameter lookups for rows matching that
112+ * condition.
113+ *
114+ * This algorithm gives us the bucket creator as well as parameter lookups with their partition keys and values, which
115+ * is the sync plan.
91116 */
92117class PendingQuerierPath {
93118 // Terms in the And that have not yet been handled.
0 commit comments