Good Morning,
Query:
SELECT content.content.id FROM content
WHERE content.type=“metadata” AND ANY v IN content.content.tenantIDs SATISFIES v=7 END AND content.content.publishStatus=“published” ORDER by content.content.publishedAt DESC LIMIT 50
Index Definitions:
CREATE INDEX newest
ON content
(type
,(distinct (array v
for v
in ((self.content
).tenantIDs
) end)),((self.content
).publishStatus
),((self.content
).publishedAt
) DESC,((self.content
).id
)) WHERE (type
= “metadata”) WITH { “defer_build”:true, “nodes”:[ “xxx.xxx.xxx.xxx”,“xxx.xxx.xxx.xxx” ], “num_replica”:1 }
CREATE INDEX newestResNa
ON content
(type
,(distinct (array v
for v
in ((self.content
).tenantIDs
) end)),((self.content
).resourceName
),((self.content
).publishStatus
),((self.content
).publishedAt
) DESC,((self.content
).id
)) WHERE (type
= “metadata”) WITH { “nodes”:[ “xxx.xxx.xxx.xxx”,“xxx.xxx.xxx.xxx” ], “num_replica”:1 }
The query uses "newestResNa " instead of “newest”, which makes no sense for me.
Querytime with index newestResNa: >400ms (and some times much slower, up to some seconds)
Querytime with index newest: < 30ms (stable, always fast).
Couchbase 6.0 uses “newest”. We didn’t change anything, just upgraded the database. I can reproduce this. Our staging environmend (CB 6.5) uses the wrong index, prod environment (CB 6.0) uses the correct index. Of course a “USE INDEX (newest)” fixes this and everything is ok. But still, the choosed index makes no sense for me.
A query that makes sense for “newestResNa”-Index is fast, as expected ans uses the correct index.
SELECT content.content.id FROM content
WHERE content.type=“metadata” AND ANY v IN content.content.tenantIDs SATISFIES v=7 END AND content.content.resourceName=“articles” AND content.content.publishStatus=“published” ORDER by content.content.publishedAt DESC LIMIT 50
Do I something wrong? Or is this maybe a bug in the new query optimizer? I can open a enterprise ticket about this, but I thought this could be interesting for other users, so I opened a forum thread.
Thanks, Pascal