How do I do a reverse scan ona string field?

index
n1ql

#1

I want to do a query with ORDER BY DESC as well as ASC.
Since Couchbase does not do reverse scans., I need to create two indexes. How do I do a descending index on a string field?

(This thread from 2016 addresses a related area, but there is no answer to this specific question about strings.)

Apparently this is supported in Couchbase 5.5. But given earlier statements that descending-index is supported by the CREATE INDEX syntax but is actually unsupported, I would like some confirmation.


#2

Couchbase supports ASC, DESC in ORDER BY in all releases.
But in 5.0 on words only you can created DESC index and query will use index order if possible. Reverse Scan is not supported.

Example: CREATE INDEX ix1 ON default (a);
SELECT * FROM default a > “a” ORDER BY a DESC;
Pre 5.0 Couchbase gets all qualified items and does explicit sort to satisfies queries.
Post 5.0 If there is index CREATE INDEX ix1 ON default (a DESC );
N1QL can optimize query based on index, If query ORDER BY matches with index key order (LEFT to right) including collation order, and query semantics does’t alter avoid sort and use index order. By any reason it can’t use index order it will do explicit sort.