Hi, i’m having the same problem.
I’m using CouchBase 5.1
I create this index: CREATE INDEX idx_tenant_type_publication_instant ON CONTENT (tenant, main.type, main.sysAttrs.publicationInstant DESC) using GSI;
for this query:
SELECT CONTENT.*
FROM CONTENT
use index (idx_tenant_type_publication_instant)
WHERE main.type IN [“foo”,“bar”,“axe”] AND tenant IN [“ox”]
ORDER BY main.sysAttrs.publicationInstant LIMIT 4
Without the order by my query is <100ms but with it goes >500 ms almost a 1,5s
this is my plan text:
{
“#operator”: “Sequence”,
“#stats”: {
“#phaseSwitches”: 2,
“execTime”: “1.538µs”,
“kernTime”: “469.802618ms”
},
“~children”: [
{
“#operator”: “Authorize”,
“#stats”: {
“#phaseSwitches”: 4,
“execTime”: “2.334µs”,
“kernTime”: “468.913966ms”,
“servTime”: “718.769µs”
},
“privileges”: {
“List”: [
{
“Target”: “default:CONTENT”,
“Priv”: 7
}
]
},
“~child”: {
“#operator”: “Sequence”,
“#stats”: {
“#phaseSwitches”: 3,
“execTime”: “2.184µs”,
“kernTime”: “468.908077ms”
},
“~children”: [
{
“#operator”: “Sequence”,
“#stats”: {
“#phaseSwitches”: 2,
“execTime”: “1.217µs”,
“kernTime”: “468.806533ms”
},
“~children”: [
{
“#operator”: “IndexScan2”,
“#stats”: {
“#itemsOut”: 2971,
“#phaseSwitches”: 11887,
“execTime”: “4.149843ms”,
“kernTime”: “287.400432ms”,
“servTime”: “10.354564ms”
},
“index”: “idx_tenant_type_publication_instant”,
“index_id”: “f19975e5ad13e5db”,
“index_projection”: {
“primary_key”: true
},
“keyspace”: “CONTENT”,
“namespace”: “default”,
“spans”: [
{
“exact”: true,
“range”: [
{
“high”: ““jht””,
“inclusion”: 3,
“low”: ““jht””
},
{
“high”: ““interview””,
“inclusion”: 3,
“low”: ““interview””
}
]
},
{
“exact”: true,
“range”: [
{
“high”: ““jht””,
“inclusion”: 3,
“low”: ““jht””
},
{
“high”: ““live””,
“inclusion”: 3,
“low”: ““live””
}
]
},
{
“exact”: true,
“range”: [
{
“high”: ““jht””,
“inclusion”: 3,
“low”: ““jht””
},
{
“high”: ““story””,
“inclusion”: 3,
“low”: ““story””
}
]
}
],
“using”: “gsi”,
“#time_normal”: “00:00.0145”,
“#time_absolute”: 0.014504407
},
{
“#operator”: “Fetch”,
“#stats”: {
“#itemsIn”: 2971,
“#itemsOut”: 2971,
“#phaseSwitches”: 11903,
“execTime”: “4.837686ms”,
“kernTime”: “10.607591ms”,
“servTime”: “434.135885ms”
},
“keyspace”: “CONTENT”,
“namespace”: “default”,
“#time_normal”: “00:00.4389”,
“#time_absolute”: 0.438973571
},
{
“#operator”: “Sequence”,
“#stats”: {
“#phaseSwitches”: 5,
“execTime”: “1.967µs”,
“kernTime”: “468.7965ms”
},
“~children”: [
{
“#operator”: “Filter”,
“#stats”: {
“#itemsIn”: 2971,
“#itemsOut”: 2971,
“#phaseSwitches”: 11889,
“execTime”: “117.121154ms”,
“kernTime”: “351.468913ms”
},
“condition”: “((((CONTENT
.main
).type
) in [“interview”, “live”, “story”]) and ((CONTENT
.tenant
) in [“jht”]))”,
“#time_normal”: “00:00.1171”,
“#time_absolute”: 0.117121154
},
{
“#operator”: “InitialProject”,
“#stats”: {
“#itemsIn”: 2971,
“#itemsOut”: 2971,
“#phaseSwitches”: 11891,
“execTime”: “139.025981ms”,
“kernTime”: “329.761066ms”
},
“result_terms”: [
{
“expr”: “CONTENT
”,
“star”: true
}
],
“#time_normal”: “00:00.1390”,
“#time_absolute”: 0.139025981
}
],
“#time_normal”: “00:00.0000”,
“#time_absolute”: 0.000001967
}
],
“#time_normal”: “00:00.0000”,
“#time_absolute”: 0.0000012170000000000002
},
{
“#operator”: “Order”,
“#stats”: {
“#itemsIn”: 2971,
“#itemsOut”: 4,
“#phaseSwitches”: 5955,
“execTime”: “7.174595ms”,
“kernTime”: “461.682339ms”
},
“limit”: “4”,
“sort_terms”: [
{
“expr”: “(((CONTENT
.main
).sysAttrs
).publicationInstant
)”
}
],
“#time_normal”: “00:00.0071”,
“#time_absolute”: 0.007174595
},
{
“#operator”: “Limit”,
“#stats”: {
“#itemsIn”: 4,
“#itemsOut”: 4,
“#phaseSwitches”: 21,
“execTime”: “2.903µs”,
“kernTime”: “468.868924ms”
},
“expr”: “4”,
“#time_normal”: “00:00.0000”,
“#time_absolute”: 0.000002903
},
{
“#operator”: “FinalProject”,
“#stats”: {
“#itemsIn”: 4,
“#itemsOut”: 4,
“#phaseSwitches”: 23,
“execTime”: “3.682µs”,
“kernTime”: “468.891346ms”
},
“#time_normal”: “00:00.0000”,
“#time_absolute”: 0.000003682
}
],
“#time_normal”: “00:00.0000”,
“#time_absolute”: 0.000002184
},
“#time_normal”: “00:00.0007”,
“#time_absolute”: 0.000721103
},
{
“#operator”: “Stream”,
“#stats”: {
“#itemsIn”: 4,
“#itemsOut”: 4,
“#phaseSwitches”: 15,
“execTime”: “2.76µs”,
“kernTime”: “469.79477ms”
},
“#time_normal”: “00:00.0000”,
“#time_absolute”: 0.00000276
}
],
“~versions”: [
“2.0.0-N1QL”,
“5.1.0-5552-enterprise”
],
“#time_normal”: “00:00.0000”,
“#time_absolute”: 0.000001538
}