简体   繁体   中英

Couchbase order by index is very slow

我在s1_date中创建了一个索引,但是此查询仍然很慢(15 s),但是当我删除“由s1_date desc排序”时,它的速度更快(大约10毫秒),这是查询

          SELECT * FROM `bucket_1` WHERE  type = 'type1' AND (batch_number1 like '' OR batch_number2 like '' OR  batch_number2 like '' OR batch_number3 like '' OR batch_number4 like '' OR batch_number5 like '') order by s1_date desc limit 10

This is a real nightmare of a query. An index on s1_date isn't going to help because the query engine has to apply the predicates type = 'type1' AND (batch_number1 like '' OR batch_number2 like '' OR batch_number2 like '' OR batch_number3 like '' OR batch_number4 like '' OR batch_number5 like '') first before doing any ordering, and it's the predicates that are going to be the majority of the work. In particular those ORs really mess things up for indexing, which means getting the query to run quickly is going to be a problem.

See if you can represent your data in some other manner so you don't have to use those ORs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM