Couchbase 4 beta “ORDER BY” performance

2019-08-14 12:18发布

问题:

I have one question about performance of "ORDER BY" in Couchbase 4 Beta (Ubuntu 64bits).

I create a Bucket "testing" and a primary index:

CREATE PRIMARY INDEX `testing-idx` ON `testing` USING GSI;

And a second index:

CREATE INDEX testing_field_value_idx ON `testing`(field_value) USING GSI

In my bucket I have items such as:

{
  "type": "entry",
  "field_name": "field-testing",
  "field_value": "1 bla bla bla bla bla bla bla bla"
},
{
  "type": "entry",
  "field_name": "field-testing",
  "field_value": "2 bla bla bla bla bla bla bla bla"
},
{
  "type": "entry",
  "field_name": "field-testing",
  "field_value": "3 bla bla bla bla bla bla bla bla"
}
...

When I execute the query without ORDER BY the response is fast (milliseconds):

SELECT field_value FROM testing LIMIT 10;

1.000 items: 53 ms
100.000 items: 82 ms

But when I execute the query with ORDER BY, the response is slow (seconds):

SELECT field_value FROM testing ORDER BY field_value ASC LIMIT 10;

1.000 items: 4.6 secs
100.000 items: 6.2 secs

How to get better performance with ORDER BY?

** All the queries are executed in "cbq".