How to correctly create index for subquery in couchbase server?

Viewed 75

How to do correct index for that query? I need to speed up this query.

SELECT q1, q2 
LET q1 = (Select ht.* FROM `mybucket` as mb WHERE mb.recdate IN (SELECT RAW MAX(recdate) FROM `mybucket` as mbt WHERE mbt.deviceID = "10101")), 
    q2 = (Select ht.* FROM `mybucket` as mb WHERE mb.recdate IN (SELECT RAW MAX(recdate) FROM `mybucket` as mbt WHERE mbt.deviceID = "10001"));
1 Answers

You have two parallel queries, each with a subquery. The two queries are very similar.

You might be able to do this with two indexes.

This one should fit the subquery in each case:

CREATE INDEX date_deviceid_idx on mybucket(deviceID, recdate)

And this one should fit the main query in each case:

CREATE INDEX ht_recdate_idx on mybucket(recdate, ht)
Related