Skip to content

Optimization: Use SQLite Generated Columns for JSON fields #6

@prosdev

Description

@prosdev

Context
We store document metadata in a JSON blob column (data) to maintain flexibility. However, querying deep into this JSON structure can become slow as the dataset grows.

Proposed Solution
Use SQLite's Generated Columns (Computed Columns) to index high-value fields without changing the application logic.

Example

ALTER TABLE documents ADD COLUMN vendor TEXT AS (json_extract(data, '$.vendor')) STORED;
CREATE INDEX idx_vendor ON documents(vendor);

Triggers for this work

  • Search queries by vendor/date become slow.
  • We need to sort by a field inside the JSON blob.

References

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions