Speed up VISIBLE_CONTACTS update
The delete used to easily take >1 second with 10K contacts.
Now it's just ~1ms.
It's one of the slowest processes during aggregation.
The old SQL looked like this:
DELETE FROM visible_contacts
WHERE _id NOT IN (SELECT _id FROM contacts WHERE [CONTACT_IS_VISIBLE] = 1)
and _id = CONTACT_ID_IN_QUESTION
The problem is the subquery, especially the [CONTACT_IS_VISIBLE] part, is
pretty slow but it queries *all* visible contact IDs at once,
But this really means "Remove CONTACT_ID_IN_QUESTION from visible_contacts,
if it's not visible."
DELETE FROM visible_contacts
WHERE _id IN
(SELECT _id FROM contacts
WHERE _id = CONTACT_ID_IN_QUESTION and [CONTACT_IS_VISIBLE] = 0)
(We use 'IN' rather than '=' here, because this method is used to
update visible_contacts for *all* contacts as well, in which case
we just remoev the the [_id = CONTACT_ID_IN_QUESTION] part from
the selection.)
Change-Id: I73d629f6b352d010eb1deabb7e23d12130be9b3d
1 file changed