如何将 USE INDEX(索引名)添加到 ObjectionJS 查询中



>我有一个选择语句:

const myObject = await MyObject 
.query()
.eager('foo')
.eager('foo.bar')
.omit(['some_big_data']) // Skip the giant field to improve performance/memory
.where('when_created', '>', '2019-09-01')
.whereNotNull('player_details')
.whereNull('region_id')
.limit(10000);

这将生成以下 SQL:

select `foo`.*
from `foo` 
where `when_created` > '2019-09-01'
and `player_details` is not null
and `region_id` is null
limit 1000;

我想将 SQLuse index (my_index)添加到查询中,因此它变为:

select `foo`.*
from `foo` 
use index (my_index)
where `when_created` > '2019-09-01'
and `player_details` is not null
and `region_id` is null
limit 1000;

这是否可以在 ObjectionJS 中完成,或者我需要下降到原始查询?

Knex 0.20 也没有反对意见支持这样做。您需要编写原始查询来实现它。

最新更新