Page MenuHomePhabricator

[SQLite] Add target_message generated column and index
ClosedPublic

Authored by ashoat on Jul 15 2024, 2:15 PM.
Tags
None
Referenced Files
F3527550: D12759.diff
Tue, Dec 24, 5:38 AM
F3524757: D12759.id42366.diff
Mon, Dec 23, 2:24 PM
F3524743: D12759.id.diff
Mon, Dec 23, 2:24 PM
F3524738: D12759.diff
Mon, Dec 23, 2:24 PM
Unknown Object (File)
Mon, Dec 9, 5:10 PM
Unknown Object (File)
Nov 10 2024, 1:06 AM
Unknown Object (File)
Nov 4 2024, 3:05 AM
Unknown Object (File)
Oct 30 2024, 6:40 PM
Subscribers
None

Details

Summary

Generated colums in SQLite are described this way in the docs:

Generated columns (also sometimes called "computed columns") are columns of a table whose values are a function of other columns in the same row. Generated columns can be read, but their values can not be directly written. The only way to change the value of a generated column is to modify the values of the other columns used to calculate the generated column.

I found them from this blog post, which explains how to use a generated column and index to efficiently query on the contents of a JSON column in SQLite. I found that blog post from this Reddit comment.

Test Plan
  1. I confirmed I could compile and run this on both iOS and web
  2. I checked the EXPLAIN QUERY PLAN for the query I use this index for (in a later diff) and it showed the index being used:

Screenshot 2024-07-15 at 5.15.00 PM.png (654×1 px, 314 KB)

Diff Detail

Repository
rCOMM Comm
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp
1401 ↗(On Diff #42302)

Since we added a new column, all the LEFT JOIN'd media got shifted to the right

We could avoid having to do this if we replaced SELECT * with an explicit list on line 1384. Open to doing that if people think it's a good idea

Harbormaster returned this revision to the author for changes because remote builds failed.Jul 15 2024, 2:34 PM
Harbormaster failed remote builds in B30340: Diff 42302!

Rebase, move it earlier in the stack, fix missing comma in create_schema for messages columns

Fix all the tabs and 3-spaces issues in SQLiteQueryExecutor.cpp

native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp
1401

Since we added a new column, all the LEFT JOIN'd media got shifted to the right

We could avoid having to do this if we replaced SELECT * with an explicit list on line 1384. Open to doing that if people think it's a good idea

native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp
1401 ↗(On Diff #42321)

Since we added a new column, all the LEFT JOIN'd media got shifted to the right

We could avoid having to do this if we replaced SELECT * with an explicit list on line 1384. Open to doing that if people think it's a good idea

This revision is now accepted and ready to land.Jul 16 2024, 3:45 AM