Skip to content

Commit e39c099

Browse files
kevin-dpclaude
andcommitted
feat: warn when orderBy+limit or lazy join falls back to full load due to missing index
Adds console warnings when no index is found for: - orderBy + limit queries (order-by.ts) - lazy join loading (joins.ts) Both suggest creating an explicit index or enabling autoIndex: 'eager'. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent eabc81f commit e39c099

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

packages/db/src/query/compiler/joins.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,14 @@ function processJoin(
312312

313313
if (!loaded) {
314314
// Snapshot wasn't sent because it could not be loaded from the indexes
315+
const collectionId = followRefCollection.id
316+
const fieldPath = followRefResult.path.join(`.`)
317+
console.warn(
318+
`[TanStack DB]${collectionId ? ` [${collectionId}]` : ``} Join requires an index on "${fieldPath}" for efficient loading. ` +
319+
`Falling back to loading all data. ` +
320+
`Consider creating an index on the collection with collection.createIndex((row) => row.${fieldPath}) ` +
321+
`or enable auto-indexing with autoIndex: 'eager' and a defaultIndexType.`,
322+
)
315323
lazySourceSubscription.requestSnapshot()
316324
}
317325
}),

packages/db/src/query/compiler/order-by.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,17 @@ export function processOrderBy(
191191
index = undefined
192192
}
193193

194+
if (!index) {
195+
const collectionId = followRefCollection.id
196+
const fieldPath = followRefResult.path.join(`.`)
197+
console.warn(
198+
`[TanStack DB]${collectionId ? ` [${collectionId}]` : ``} orderBy with limit requires an index on "${fieldPath}" for efficient lazy loading. ` +
199+
`Falling back to loading all data. ` +
200+
`Consider creating an index on the collection with collection.createIndex((row) => row.${fieldPath}) ` +
201+
`or enable auto-indexing with autoIndex: 'eager' and a defaultIndexType.`,
202+
)
203+
}
204+
194205
orderByAlias =
195206
firstOrderByExpression.path.length > 1
196207
? String(firstOrderByExpression.path[0])

0 commit comments

Comments
 (0)