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
Unknown Object (File)
Mon, Nov 4, 3:05 AM
Unknown Object (File)
Wed, Oct 30, 6:40 PM
Unknown Object (File)
Tue, Oct 29, 10:12 AM
Unknown Object (File)
Tue, Oct 29, 12:59 AM
Unknown Object (File)
Sun, Oct 27, 11:10 PM
Unknown Object (File)
Sat, Oct 26, 5:58 PM
Unknown Object (File)
Sat, Oct 26, 12:27 AM
Unknown Object (File)
Mon, Oct 14, 4:42 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
Lint Not Applicable
Unit
Tests Not Applicable

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 ↗(On Diff #42313)

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