Skip to content
Source
Sign inSign up
TanStack/db

Ordered window filtered through a LEFT-joined subquery requests its full source #2242

Send to my agent
Opendaveycodez(GitHub profile, opens in a new tab) opened this issue 0 comments

#1909 pages an ordered window whose cross-alias filter goes through exactly one LEFT join to a collection. The same filter through a LEFT join to a subquery that only filters one collection still sets requiresFullSource. An example is the existence check for "has a visible run":

const visibleRuns = new Query()
  .from({ run: runs })
  .where(({ run }) => not(eq(run.userId, 'admin')))
  .select(({ run }) => ({ k: run.seekId }))
  .distinct()

q.from({ seek: seeks })
  .leftJoin({ visible: visibleRuns }, ({ seek, visible }) => eq(seek.id, visible.k))
  .where(({ visible }) => not(isUndefined(visible.k)))
  .orderBy(({ seek }) => seek.updatedAt, 'desc')
  .limit(10)

The subquery is one collection with no joins, limit, offset or grouping. Its rows are lazy-loaded by key into that collection's source, so the joined-filter gate can wait on that source exactly as for a collection join.

Proposal: treat such a subquery join as a joined filter keyed by the subquery's source (joinedFilterSourceOf). Implemented on 0.15.2 with tests; the full suite passes.

Sign in to join this conversation.