sql查询我的rails查询如下所示…当我为每个目标id单独运行查询时,与使用in操作符运行相比,总时间更少。
SELECT DISTINCT
requested_trips.id
FROM
requested_trips
INNER JOIN
requested_trips_destinations ON requested_trips_destinations.requested_trip_id = requested_trips.id
INNER JOIN
destinations ON destinations.id = requested_trips_destinations.destination_id
WHERE
(requested_trips.status = 'Active' and requested_trips.trip_stage = 4
and (destinations.id in (64,100,545,...)))
Ayushi
是的,您将提供=操作符,它将更快。但是如果使用in操作符,则定义了多个搜索项。SQL需要花费时间来搜索所有变量并显示结果。
希望你得到它。这就是你需要的,对吗?