代码之家  ›  专栏  ›  技术社区  ›  riorio

Couchbase在扫描存储桶中的某些文档时出现性能问题-获取超时异常

  •  2
  • riorio  · 技术社区  · 7 年前

    我们有一个 Couchbase 服务器版本 Community Edition 5.1.1 build 5723

    在我们 Cars 桶我们有 Car Make 它制造。

    Id 汽车制造 我们将其另存为Car文档中的另一个字段(如MySQL表中的外键)。

    查询需要很多时间-

    select * from cars where model="Camry"  <-- we expect to have about 50,000 results for that
    

    我们通过两种方式执行查询:

    1. 一款Spring boot应用程序,在7.5秒后不断出现TimeOutException

    我们认为问题在于缺少一个桶的索引。

    因此,我们添加了一个索引:

    CREATE INDEX cars_idx ON cars(makeName, modelName, makeId, _class) USING GSI;
    

    SELECT * FROM system:indexes
    

    2 回复  |  直到 7 年前
        1
  •  4
  •   paralen    7 年前

    尝试

    CREATE INDEX model_idx ON cars(model);
    

    CREATE INDEX `type_idx` ON `cars`(`_class`)
    
        2
  •  2
  •   riorio    7 年前

    我们就是这样解决这个问题的:

    1. 使用 this link
        do{
           Pageable pageable = PageRequest.of(pageNumber, SLICE_SIZE, Sort.by("id"));
           Slice slice carsRepository.findAllByModelName("Camry", pageable);
           List cars = slice.getContent();
        } while (slice.hasNext());
    
    推荐文章