Hi,
I’m using Couchbase 4.5.1-2844 Enterprise Edition (build-2844).
I have an index myTestIndex
on fields field1
and field2
.
CREATE INDEX myTestIndex ON \
my-data` (field1, field2)`
When I run a simple query, depending on using AND or OR operator, the plan changes totally, and the performance with it (AND is fast, OR is slow).
~50 000 documents.
AND:
SELECT * from \
my-data` WHERE field1=“value1” AND field2="value2"~14ms execution
EXPLAIN SELECT * from `my-data` WHERE field1=“value1” AND field2=“value2”`
[
{
"plan": {
"#operator": "Sequence",
"~children": [
{
"#operator": "IndexScan",
"index": "myTestIndex",
"index_id": "9bbe2a824e011185",
"keyspace": "my-data",
"namespace": "default",
"spans": [
{
"Range": {
"High": [
"\"value1\"",
"\"value2\""
],
"Inclusion": 3,
"Low": [
"\"value1\"",
"\"value2\""
]
}
}
],
"using": "gsi"
},
{
"#operator": "Fetch",
"keyspace": "my-data",
"namespace": "default"
},
{
"#operator": "Parallel",
"~child": {
"#operator": "Sequence",
"~children": [
{
"#operator": "Filter",
"condition": "..."
},
{
"#operator": "InitialProject",
"result_terms": [
{
"expr": "self",
"star": true
}
]
},
{
"#operator": "FinalProject"
}
]
}
}
]
}
}
]
OR:
SELECT * from \
my-data` WHERE field1=“value1” OR field2="value2"~2000ms execution
EXPLAIN SELECT * from `my-data` WHERE field1=“value1” OR field2=“value2”`
[
{
"plan": {
"#operator": "Sequence",
"~children": [
{
"#operator": "PrimaryScan",
"index": "#primary",
"keyspace": "my-data",
"namespace": "default",
"using": "gsi"
},
{
"#operator": "Fetch",
"keyspace": "my-data",
"namespace": "default"
},
{
"#operator": "Parallel",
"~child": {
"#operator": "Sequence",
"~children": [
{
"#operator": "Filter",
"condition": "..."
},
{
"#operator": "InitialProject",
"result_terms": [
{
"expr": "self",
"star": true
}
]
},
{
"#operator": "FinalProject"
}
]
}
}
]
}
}
]
As you can see, with the OR statement, it doesn’t use myTestIndex
, and (I guess) the fetch results in massive performance degradation.