Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Request: SQLite compiler falls back to full-table reads for zero/one-argument AND and OR

未关闭
#1,994 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
68/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
sqlite, typescript
领域
database

调研方向

Start by locating the SQLite persistence SQL compiler and inspect its handling of and/or expressions with zero or one argument. Check the existing compiler tests and the downstream regression assertion for the generated SQL. Done means one-argument predicates compile directly, empty and/or become true/false predicates, and unsupported children retain fallback behavior.

由索引模型根据 Issue 内容生成。

描述

Problem

The SQLite persistence compiler marks and and or expressions with fewer than two arguments as unsupported.

loadSubsetInternal then omits the SQL WHERE clause, reads and deserializes the entire collection, and filters the rows in JavaScript.

Results can still be correct, but a selective query—or a query that should return no rows—does unnecessary work over the whole cached table.

Versions

  • @tanstack/db-sqlite-persistence-core: 0.4.0
  • @tanstack/browser-db-sqlite-persistence: 0.2.25
  • @tanstack/db: 0.11.0

The same compiler checks are present in upstream main inspected on October 2, 2026.

Reproduction

Populate a persisted collection with many rows and instrument the SQL passed to its driver:

import { IR } from '@tanstack/db'

const predicate = new IR.Func('eq', [
  new IR.PropRef(['id']),
  new IR.Value('row-1'),
])

await adapter.loadSubset(collectionId, {
  where: new IR.Func('and', [predicate]),
})

await adapter.loadSubset(collectionId, {
  where: new IR.Func('or', [predicate]),
})

await adapter.loadSubset(collectionId, {
  where: new IR.Func('or', []),
})

Source inspection shows that each expression is rejected by the SQL compiler. The resulting collection read has no WHERE clause.

The empty or case is particularly wasteful: the final result is empty, but the adapter first reads every persisted row.

Expected behavior

Compile these expressions consistently with the core evaluator:

  • One-argument and or or: compile the contained predicate.
  • Empty and: compile a true predicate.
  • Empty or: compile a false predicate.

Unsupported child expressions should retain the existing fallback behavior.

Downstream workaround

We add these cases to the SQLite compiler. An existing downstream regression assertion checks that an empty-result initialization query includes WHERE (0 = 1) rather than reading the entire cache.

This report is based on source inspection; downstream tests were not rerun for this report.

Related issue

#506 discusses zero/one-argument support in the public query API. This report specifically concerns SQL compilation and full-table fallback in the persistence adapter.

主要语言
TypeScript
星标
3.9k
派生
268
平均合并
1 天 3 小时
30 天内合并 PR
148

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

TanStack/db 的其他 Issue

查看 TanStack/db 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。