MapReduce - view takes over 20+ seconds with skip value


#1

Hello,

I’m having hard time optimizing my view.

I have the following view

function (doc, meta) {
        
    if (
        // conditions
    ) {

        doc.values.enabledProductTypes.forEach(function(item) {

            // index enabled item only
            if (item.enabled === true) {
                emit(item.productTypeId, parseInt(doc.id));
            }

        });

    }
}

Reduce: _count

Without any key set, reduce outputs 48 millions.

When I set a key then I get 3 millions records.

the following works just fine.

/_design/creatives/_view/idsByProductTypeId?connection_timeout=60000&inclusive_end=true&key=4&limit=6&skip=0&stale=ok&reduce=false

When I set skip to 3,000,000, then the view takes over 20+ seconds.

/_design/creatives/_view/idsByProductTypeId?connection_timeout=60000&inclusive_end=true&key=4&limit=2000&skip=3000000&stale=ok&reduce=false

How do I make skip faster?

Update1: Looks like there is no way around it, except setting startkey_docid according to http://blog.couchbase.com/pagination-couchbase