SQLite Forum

Defragment a table ?
No.  Vacuum will re-pack and consolidate the index as well.

However, your code for "compressing" the table by rebuilding it reorganizes the table but not the additional index.  So if the additional index is being used for anything in the query then those pages are still not efficiently packed.

You need to drop and recreate the index, or do a reindex, to cause it to be rebuilt and packed.

Unless, of course, the queries you are talking about are only accessing table A through the rowid ... and not accessing the alternate index at all.