Description
Repro:
create index ix1 on default (DISTINCT ARRAY v.id FOR v IN arr1 END); |
create index ix2 on default (c1); |
EXPLAIN SELECT d.c1 FROM default AS d WHERE d.c1 IS NOT NULL GROUP BY d.c1; |
Above one uses index aggregates.
Run the following statement (there extra predicate v.x so the span will not exact)
EXPLAIN SELECT 1 FROM default AS d WHERE ANY v IN d.arr1 SATISFIES v.id IS NOT NULL AND v.x = 10 END; |
Now Rerun. It no longer uses index aggregates. Only option is restart query service.
EXPLAIN SELECT d.c1 FROM default AS d WHERE d.c1 IS NOT NULL GROUP BY d.c1; |
Reason:
There v.id IS NOT NULL , v.id is array index key. It generates _EXACT_VALUED_SPANS (Static span) Later it sets false (https://github.com/couchbase/query/blob/master/planner/sarg_any.go#L116) without making copy. Also at it modifies others https://github.com/couchbase/query/blob/master/planner/sarg_any.go#L87-L97
This can happen any other static spans.
Possible fix is at https://github.com/couchbase/query/blob/master/planner/sarg_any.go#L86
sp = sp.Copy()