Forum: Ruby on Rails triple join asking for trouble?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
David B. (Guest)
on 2009-03-19 18:45
(Received via mailing list)
Model.scoped_by_body_type_id
( event.body_type_ids ).scoped_by_skin_color_id
( event.skin_color_ids ).find( :all,
      :conditions => ['weight_pounds <= ? AND total_height_inches >= ?
AND minimum_pay <= ? AND job_types.id = ? AND regions.id = ? AND
languages.id in (?)',
        event.maximum_weight_in_pounds,
        event.total_minimum_height_inches,
        event.payment_per_head,
        event.job_type_id,
        event.region_id,
        event.language_ids ],
      :joins => [:job_types, :regions, :languages])

Is this triple join asking for trouble?  I mean is my server going to
hate me?  language, region and job_types are going to have less than
10 row entries, but job_type_preferences, language_preferences and
region_preferences will scale linearly with the number of users....


  Model Load (0.7ms)   SELECT `models`.* FROM `models` INNER JOIN
`job_type_preferences` ON (`models`.`id` =
`job_type_preferences`.`model_id`) INNER JOIN `job_types` ON
(`job_types`.`id` = `job_type_preferences`.`job_type_id`) INNER JOIN
`region_preferences` ON (`models`.`id` =
`region_preferences`.`model_id`) INNER JOIN `regions` ON
(`regions`.`id` = `region_preferences`.`region_id`) INNER JOIN
`language_preferences` ON (`models`.`id` =
`language_preferences`.`model_id`) INNER JOIN `languages` ON
(`languages`.`id` = `language_preferences`.`language_id`) WHERE
(weight_pounds <= NULL AND total_height_inches >= 60 AND minimum_pay
<= 2000 AND job_types.id = 4 AND regions.id = 1 AND languages.id in
(NULL)) AND ((`models`.`body_type_id` IN (4) AND
`models`.`skin_color_id` IN (4)))
Frederick C. (Guest)
on 2009-03-19 19:01
(Received via mailing list)
On Mar 19, 4:45 pm, David B. <removed_email_address@domain.invalid> wrote:

> Is this triple join asking for trouble?  I mean is my server going to
> hate me?  language, region and job_types are going to have less than
> 10 row entries, but job_type_preferences, language_preferences and
> region_preferences will scale linearly with the number of users....
>
In the absence of all other things they fewer joins the better but if
they're needed to do the job then that's ok. Just be sure that you
have indexes on those columns you join on and keep an eye on the
explain output for that query.

Fred
This topic is locked and can not be replied to.