Skip to content

fix(daemon): enable case-sensitive LIKE to avoid full table scans - #2658

Closed
lsm wants to merge 1 commit into
devfrom
fix/db-scope-like-index
Closed

lsm wants to merge 1 commit into
devfrom
fix/db-scope-like-index

Conversation

@lsm

@lsm lsm commented Aug 21, 2026 •

Copy link
Copy Markdown
Owner

$(cat <<"EOF"

Summary

  • SQLite default case-insensitive LIKE cannot use a B-tree index for LIKE 'prefix%' patterns.
  • On the 29 GB sdk_messages table this caused full table scans and hung the Bun dev server.
  • Set PRAGMA case_sensitive_like = ON in the Database constructor for both the Bun (sqlite-compat.ts) and Node (sqlite-node.ts) implementations, so prefix LIKE filters use indexes.
  • Added a DatabaseCore test that verifies a prefix LIKE query plan uses SEARCH instead of SCAN.

Test plan

  • bun run lint passes
  • bun run typecheck passes
  • bun run knip passes
  • bun run check:no-comments passes
  • ./scripts/test-daemon.sh 4-space-storage passes (2256 tests)
  • ./scripts/test-daemon.sh 2-handlers-other passes (2031 tests)
  • bun run check has a pre-existing check:test-quality failure unrelated to this change

Generated with Devin
EOF
)


Open in Devin Review

SQLite default case-insensitive LIKE cannot use a B-tree index for
`LIKE 'prefix%'` patterns. On the 29 GB `sdk_messages` table this caused
full table scans and hung the Bun dev server. Setting
`PRAGMA case_sensitive_like = ON` on every `Database` connection makes
prefix LIKE filters use indexes instead.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 1 additional finding.

Open in Devin Review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: daadf79b63

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".


constructor(...args: ConstructorParameters<typeof BunDatabaseImpl>) {
super(...args);
this.exec('PRAGMA case_sensitive_like = ON');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve LIKE semantics outside indexed scope filters

Enabling this pragma on every database connection changes all ASCII LIKE expressions from SQLite's default case-insensitive behavior to case-sensitive matching, not just the generated session_id LIKE 'space:…%' predicate being optimized. In particular, the read-only connection created by createDbQueryMcpServer now silently omits mixed-case matches from agent-supplied queries such as WHERE title LIKE '%error%', and the daemon's other existing LIKE queries inherit the same compatibility change. Keep the connection-wide default and express the structural prefix filters with an indexable case-sensitive operation such as GLOB or explicit range bounds instead.

Useful? React with 👍 / 👎.

@lsm

lsm commented Sep 16, 2026

Copy link
Copy Markdown
Owner Author

Closing: dev sets case_sensitive_like only for db-query scratch databases. Applying it to the main database changes LIKE semantics app-wide, so this needs a decision and a fresh branch, not a rebase. Branch retained.

@lsm lsm closed this Sep 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant