简体   繁体   English

Active Record查询/ SQL导致性能下降

[英]Active Record Query/ SQL joins poor performance

I am working on an Active Record Query, and I'm trying to find a way to pull records as efficiently as possible. 我正在进行活动记录查询,并且试图找到一种尽可能高效地提取记录的方法。

4 tables 4桌

Restaurants, Employees, District, Items 餐厅,员工,地区,物品

I want to grab all restaurants where 我想抢到所有餐馆

‘Employees.salary > ?, 15'
‘District.name = ?, Bay_Area’
‘Items.avg_return > ?, 10’
.uniq

Currently I am using joins for Employees, District, and Items, but I feel like this is not efficient. 目前,我正在为员工,地区和项目使用联接,但是我觉得这样做效率不高。 how can I do this as performant as possible? 我怎样才能做到最好? Active record or SQL solutions accepted! 接受活动记录或SQL解决方案!

As long as the tables and the joins are well defined and you have not much more than all the restaurants in Europe in your list, the query time should be very fine. 只要表和联接的定义正确,并且列表中的餐厅不超过欧洲所有餐厅,查询时间就应该非常好。 Four joins is not much when done right. 如果做对的话,四个联接并不多。

Show your table structures, and very important: find out for yourself wich data the user wants to see. 显示你的表结构,而且非常重要:找到自己的用户希望看到至极的数据。 When you give the user a table with hundrets of rows, then something is very wrong. 当您为用户提供一个包含数百行的表时,这是非常错误的。

Let MySQL do the searches. 让MySQL进行搜索。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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