SQlite FTS Queries Running Slow iOS 17.2.1 >=

As the title says, our app has begun running into a strange issue every time a user upgrades their iPhone to the latest iOS versions. It started in 17.2.1 and looks like it made a resurgence in 17.3. Post update the user's FullText Searches against the local sqlite db run egregiously slow. Fully re-installing the app and re-downloading all content seems to correct the issue, after which their searches come back in less than 500 ms tops. When the bug occurs searches can take upwards of 15 secs in some cases to complete... What makes no sense is why all of a sudden this is happening in 17.2.1 >=

Our app uses an old school approach (historic code we never removed) to create a local sqlite database from scratch on first app install in the user's device contentDir. this .db file is instantiated on each app load using the following:

private func sqliteOpenDB(url: URL) -> OpaquePointer? { var db: OpaquePointer?

    if sqlite3_open_v2(url.path, &db, SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE | SQLITE_OPEN_FULLMUTEX, nil) == SQLITE_OK {
        LoggingUtil.log(msg: "\(ContentFilestore.TAG): database file opened successfully")
        
        // You must enable foreign key constraints every time the db connects otherwise they're off by default and cascade deletes/fk's won't work
        sqlite3_exec(db, "PRAGMA foreign_keys = ON;", nil, nil, nil)
    } else {
        LoggingUtil.log(msg: "\(ContentFilestore.TAG) Error: unabled to open the database file")
    }
    
    return db;
}

Prior to iOA 17.2.1 we've never had an issue with this when a user's device upgraded the OS. Now this process continues to work without throwing an error or warning of any kind, but their FTS search db slows to a crawl. It also seems to be completely isolated to the FTS virtual table as well. The actual tables run just fine.

My question is did something major change in iOS 17.2.1 >= that I'm missing that would be causing virtual tables to lose their indexing or have some kind of issue that would cause this problem?

Do you ever run ANALYZE ?

Yes we run ANALYZE regularly, and no issues related to the FTS virtual table come back. What I've noticed is that if we drop any existing FTS virtual table on cold start and re-create it from the existing regular sqlite tables (our FTS virtual table is built from a combo of data in two regular SQLite tables). The search slowness resolves itself... It's not as if the OS is dropping the virtual table when the app is removed from memory. Otherwise we'd be seeing the search throwing errors that the table didn't exist etc. The table exists when the app comes back from from a cold state post OS upgrade. Queries against it just take 300% longer to complete. Once we DROP the existing virtual table and reload it, everything seems to work just fine until the next OS upgrade.

We never had this issue before iOS 17.2.1 so I'm just trying to ascertain what possible changed in the OS since then that is causing this issue to begin with.

Here is why https://sqlite.org/forum/forumpost/8ab195fd44e75ed0

SQlite FTS Queries Running Slow iOS 17.2.1 >=
 
 
Q