Hi, I am using Couchbase Server 4.1.0-5005 Enterprise Edition (build-5005).
and I has created a index by:
CREATE INDEX idx_pk_prefix on `db`(substr(meta().id,0,6));
when I execute the following N1QL:
select * from db where substr(meta().id,0,6) != "_sync:" limit 1000;
the result shows that:
Execution:21.07s
Result Count: 1000
but when I execute:
explain select * from db where substr(meta().id,0,6) != "_sync:";
It shows index works:
[
{
"#operator": "Sequence",
"~children": [
{
"#operator": "UnionScan",
"scans": [
{
"#operator": "IndexScan",
"index": "idx_pk_prefix",
"keyspace": "db",
"namespace": "default",
"spans": [
{
"Range": {
"High": [
"\"_sync:\""
],
"Inclusion": 0
}
},
{
"Range": {
"Inclusion": 0,
"Low": [
"\"_sync:\""
]
}
}
],
"using": "gsi"
}
]
},
{
"#operator": "Parallel",
"~child": {
"#operator": "Sequence",
"~children": [
{
"#operator": "Fetch",
"keyspace": "db",
"namespace": "default"
},
{
"#operator": "Filter",
"condition": "(not (substr((meta(`db`).`id`), 0, 6) = \"_sync:\"))"
},
{
"#operator": "InitialProject",
"result_terms": [
{
"expr": "self",
"star": true
}
]
},
{
"#operator": "FinalProject"
}
]
}
}
]
}
]
PS: I have total 9660 docs in my db.
In fact, when I am not create index, the query is much faster(Execution:16.24s)
I want to know why?