Speed up search query update after each transaction

Contains two optimizations, which will greatly affect initial sync for
an account with a large number of contacts.

- When selecting from search_index, we used two columns from different tables:
'raw_contacts.contact_id IN (...) OR data.raw_contact_id IN (...)'.
But this is really equivalent to
'... OR raw_contacts._id IN (...)' as we inner join the two tables.

The latter is pretty much faster as both columns are in the same table and
each has an index.

Bug 5842620

- When we replace a search_index row, we first try UPDATE and if no rows are
affected then INSERT.  But this UPDATE is pretty slow; on a test device it can
easily take >10ms, and with a 10K contacts database it took >80ms.  (INSERT
is pretty fast; it's typically ~1ms.)

Let's first bulk DELETE all affected rows, then INSERT.  The DELETE takes
roughly the same time as the previous UPDATE, but we only need 1 DELETE
per transaction, not per row contact.

Bug 5887648

Change-Id: I549ea2b47d7058bfba96a861236295f682d88c10
1 file changed