简体   繁体   中英

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

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!

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.

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