Skip to content

perf(sqlite): inject LIMIT / stop unbounded rawQuery then take(cap) #415

Description

@ZhuchkaTriplesix

Parent

Part of #414

Problem

SqliteSqlWorkspace calls conn.executerawQuery, which materializes all matching rows, then applies _resultMaxRows with .take(cap).

Unlike Postgres (injectSqlLimit), SQLite has no server-side LIMIT injection. Caps can be up to 100 000 rows (AppSettings), so peak memory is O(full result), not O(cap).

Evidence

  • lib/features/sqlite/sqlite_sql_workspace.dart (~159–179)
  • lib/core/database/sqlite_connection.dart (execute / rawQuery)

Related

Follow-up to partially closed #184 (Postgres/MySQL); SQLite was never covered.

Acceptance

  • SELECT-like queries are bounded with LIMIT (or equivalent cursor) before materializing into a List
  • Cap presets (incl. 100k) do not load more than cap rows into Dart memory
  • Regression test for LIMIT injection / bounded fetch
  • Docs note behavior for multi-statement / non-SELECT

Suggested fix

Inject LIMIT when safe (mirror injectSqlLimit), or use a streaming/cursor API and stop after cap rows.

Metadata

Metadata

Labels

coreCore library logic and servicesperformanceTheme parser epic label: performancesqliteSQLite database driver and workspace

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions