Hi experts, I’m starting with Couchbase and I have some doubts about indexing and a N1QL query with two JOINs, this is my query:
SELECT twamp.date AS date, utp2.co_name AS rnc_name, utp.co_name AS wbts_name,
twamp.txtwampmessages AS tx_msg, twamp.losttwampmessages AS lost_msg FROM default as twamp JOIN default AS utp ON KEYS TO_STRING(twamp.wbts_id) JOIN default utp2 ON KEYS TO_STRING(twamp.rnc_id) WHERE utp.type="utp_data" AND twamp.type="twamp_data"
AND twamp.date >= 1469664000000 AND twamp.date <= 1569664900000 AND utp.co_name="WBTS-California";
This is the index that I’ve created:
CREATE INDEX rep_twamp ON default(type,date) WHERE (type = "twamp_data");
This is part of the EXPLAIN:
"#operator": "IndexScan",
"index": "rep_twamp",
"index_id": "48c2876997b32c37",
"keyspace": "default",
"namespace": "default",
"spans": [
{
"Range": {
"High": [
"\"twamp_data\"",
"1569664900000"
],
"Inclusion": 3,
"Low": [
"\"twamp_data\"",
"1469664000000"
]
}
}
],
"using": "gsi"
I’m trying to improve the query because it is taking lots of time. Regrading this example, is it possible to index by utp.co_name?
When I try to look for twamp.date the answer time is not bad, but when I try to look for twamp.date and utp.co_name is very slow, I think that it is beacause I’m not indexing utp.co_name.
Thanks for any comments!!!