Slow index update

24 views
Skip to first unread message

wbi...@attic.nl

unread,
Feb 3, 2018, 12:55:33 PM2/3/18
to Couchbase Mobile
I have a view with the following map function:

self.viewReservation = [_database viewNamed: @"reservation"];
[self.viewReservation setMapBlock: MAPBLOCK({
  if ([doc[@"doctype"] isEqualToStringCaseInsensitive: "reservation"]) {
    id date = doc[@"startsOn"];
    if (date) emit(date, nil);
    }
  }) version: @"5.0"];

When a reservation (i.e. document with doctype='reservation') is updated, with the field 'startsOn' remaining unchanged, a very large number (100's) of queries are executed by Couchbase, taking up a considerable amount of time:

2018-02-03 17:44:33.560334+0100 Nappkin[964:899162] Couch Query: CBLQuery[reservation]: running...
2018-02-03 17:44:33.561043+0100 Nappkin[964:899162] Couch View: Checking indexes of (reservation) for reservation
2018-02-03 17:44:33.562430+0100 Nappkin[964:899162] Couch View: Updating indexes of (reservation) from #356 to #357 ...
2018-02-03 17:44:33.564358+0100 Nappkin[964:899162] Couch View: ...Finished re-indexing (reservation) to #357 (deleted 1, added 1)
2018-02-03 17:44:33.566567+0100 Nappkin[964:899162] Couch Query: Query reservation: SELECT key, value, docid, revs.sequence, revid, json FROM 'maps_14', revs, docs WHERE 1 AND key >= ? AND key <= ? AND revs.sequence = 'maps_14'.sequence AND docs.doc_id = revs.doc_id ORDER BY key, docid LIMIT ? OFFSET ?
Arguments: (
    <22323031 382d3032 2d303354 30303a30 303a3030 2b303130 3022>,
    <22323031 382d3032 2d303454 30303a30 303a3030 2b303130 3022>,
    "-1",
    0
)
2018-02-03 17:44:33.568991+0100 Nappkin[964:899162] Couch Query: Query reservation: Returning iterator
2018-02-03 17:44:33.583188+0100 Nappkin[964:899162] Couch Query: CBLQuery[reservation]: running...
2018-02-03 17:44:33.584727+0100 Nappkin[964:899162] Couch View: Checking indexes of (reservation) for reservation
2018-02-03 17:44:33.585985+0100 Nappkin[964:899162] Couch Query: Query reservation: SELECT key, value, docid, revs.sequence, revid, json FROM 'maps_14', revs, docs WHERE 1 AND key >= ? AND key <= ? AND revs.sequence = 'maps_14'.sequence AND docs.doc_id = revs.doc_id ORDER BY key, docid LIMIT ? OFFSET ?
Arguments: (
    <22323031 382d3032 2d303354 30303a30 303a3030 2b303130 3022>,
    <22323031 382d3032 2d303454 30303a30 303a3030 2b303130 3022>,
    "-1",
    0
)
[etc...]

What is causing these queries? 

Thanks,
Willem
(Couchbase-lite 1.4.1)

wbi...@attic.nl

unread,
Feb 4, 2018, 3:48:24 PM2/4/18
to Couchbase Mobile
I have posted the complete View/Query log here (including a few similar lines for other views related to 'reservation' that seem normal) just to be sure:

The queries appear to be exactly the same.

Jens Alfke

unread,
Feb 6, 2018, 8:08:20 PM2/6/18
to Couchbase Mobile
The question is, who is running those queries? I don't think it's CBL; do you have code that runs queries in response to change notifications?

I would set a breakpoint at -[CBLQuery run:] and see who calls it.

—Jens

wbi...@attic.nl

unread,
Feb 6, 2018, 10:33:49 PM2/6/18
to Couchbase Mobile
Ouch - I see whats going on (through redirectLogging)
I should have turned on Query logging long before...
Thx!
Reply all
Reply to author
Forward
0 new messages