Kevin, Matt, thank you for the help... > the N+1 db calls is 1 db call for the customers and then another N > calls
right.. thank you for the axplanation... I'll definitely have a look at this... sometimes more accesses to the db, but a lot shorter are really faster than big queries... > As to why your query is taking longer to run in db console, it must be > how you're running the query as it should be no longer than an Well... it's not taking longer, it takes almost the same time (minus some overhead), but what I can see is that the generated (By Active Record) SQL query is the same as if I would write by myself, and trying both of them in the mysql console, the generated one, that I can take from the log file and the one I've written by hand to test if it would have returned what I wanted (this is the prototype, the query that I translated "rails way"(TM) ^_-), take almost the same time.. so, either I manage to fine tune the query to have an execution time comparable to the one of the 2 queries alone, or I must find a way to concatenate the two query's results without losing the Scope class... > equivalent rails call and should be slightly quicker as it doesn't > have the overhead of building the sql code to make the call. > Maybe this is being silly, but couldn't you just add a flag to your > customer model? A > little denormalization > to get a big performance increase isn't that bad... Well.. I don't like to denormalize too much, but this looks like an acceptable trade off... > > Other ideas: > - make both cellphones and emails subclasses of a single object? Hmmm! you are right, I can't remember why I previously discarded this solution, probably it has to deal with my dislike in unclean and not linear solutions, I mean, customer has_many some other models, that are similar to both cellphones and emails, but they all have some differences, thus, integrating all in the same table, would add too much empty fields.. I could just STI emails and cellphones, but it looks so unclean to me having such an hybrid solution... (ok, maybe I have to be a bit easier with this "cleaness" paranoia.. ^_-) > - I haven't played with it enough, but maybe some kind of inner join? I'll give a chance to this.. trying to refactor the SQL query for this pourpouse, thank you for the hint! > > Finally, have you tried using the MySQL query debugging stuff (EXPLAIN > and friends)? > Well not.. thank even for this hint... -- G. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Hobo Users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/hobousers?hl=en -~----------~----~----~----~------~----~------~--~---
