Rails query loading bug or not?

I noticed that when I was formatting my code, because I have a very long
query being built I made it easier for myself by separating the lines
one by one, for viewing. But, when testing, I noticed that my query
went from 8.0ms to 1475.0ms. I thought it was a bug so I restarted my
rails app but it still persisted.

So, I condensed every bit of my code into only a few lines (very long
lines) and was able to get it to go back to 8.0ms.

Here’s an example:

The 8.0

e[4;35;1mTeam Load (8.0ms)e[0m e[0mSELECT
teams.name,teams.mascot,teams.formal_name,teams.image,tsrs_ratings.tsrs,tsos_offenses.totoff
AS offtotalrating,tsos_defenses.totdef AS
deftotalrating,tsos_offenses.rushoff AS offrushrating,
tsos_defenses.rushdef AS defrushrating,tsos_offenses.passoff AS
offpassrating,tsos_defenses.passdef AS
defpassrating,tsos_offenses.scoroff AS
offscoringrating,tsos_defenses.scordef AS defscoringrating,
tsos_offenses.rzonoff AS offrzonerating,tsos_defenses.rzondef AS
defrzonerating,total_defenses.ydspgm AS deftotal,total_offenses.ydspgm
AS offtotal,rushing_offenses.ydspg AS offrush,rushing_defenses.ydspg AS
defrush,
passing_offenses.ydspgm AS offpass,pass_defenses.ydspgm AS
defpass,scoring_offenses.avg AS offscoring,scoring_defenses.ptspgm AS
defscoring,red_zone_offenses.pct AS offrzone,red_zone_defenses.pct AS
defrzone FROM teams INNER JOIN tsrs_ratings ON tsrs_ratings.team_id
= teams.id INNER JOIN tsos_offenses ON tsos_offenses.team_id =
teams.id INNER JOIN tsos_defenses ON tsos_defenses.team_id = teams.id
INNER JOIN total_offenses ON total_offenses.team_id = teams.id INNER
JOIN total_defenses ON total_defenses.team_id = teams.id INNER JOIN
rushing_offenses ON rushing_offenses.team_id = teams.id INNER JOIN
rushing_defenses ON rushing_defenses.team_id = teams.id INNER JOIN
passing_offenses ON passing_offenses.team_id = teams.id INNER JOIN
pass_defenses ON pass_defenses.team_id = teams.id INNER JOIN
scoring_offenses ON scoring_offenses.team_id = teams.id INNER JOIN
scoring_defenses ON scoring_defenses.team_id = teams.id INNER JOIN
red_zone_offenses ON red_zone_offenses.team_id = teams.id INNER JOIN
red_zone_defenses ON red_zone_defenses.team_id = teams.id WHERE
(teams.id IN (10,12) AND (scoring_offenses.compiled_on BETWEEN
‘2009-07-27’ AND ‘2009-08-02’ AND total_defenses.compiled_on BETWEEN
‘2009-07-27’ AND ‘2009-08-02’ AND red_zone_offenses.compiled_on
BETWEEN ‘2009-07-27’ AND ‘2009-08-02’ AND
rushing_defenses.compiled_on BETWEEN ‘2009-07-27’ AND ‘2009-08-02’
AND tsrs_ratings.compiled_on BETWEEN ‘2009-07-27’ AND ‘2009-08-02’
AND rushing_offenses.compiled_on BETWEEN ‘2009-07-27’ AND
‘2009-08-02’ AND pass_defenses.compiled_on BETWEEN ‘2009-07-27’ AND
‘2009-08-02’ AND passing_offenses.compiled_on BETWEEN ‘2009-07-27’
AND ‘2009-08-02’ AND tsos_offenses.compiled_on BETWEEN ‘2009-07-27’
AND ‘2009-08-02’ AND scoring_defenses.compiled_on BETWEEN
‘2009-07-27’ AND ‘2009-08-02’ AND total_offenses.compiled_on BETWEEN
‘2009-07-27’ AND ‘2009-08-02’ AND tsos_defenses.compiled_on BETWEEN
‘2009-07-27’ AND ‘2009-08-02’ AND red_zone_defenses.compiled_on
BETWEEN ‘2009-07-27’ AND ‘2009-08-02’)) ORDER BY teams.id

=============================
AND the 1508.0 ms

e[4;35;1mTeam Load (1508.0ms)e[0m e[0mSELECT teams.name,
teams.mascot,
teams.formal_name,
teams.image,
tsrs_ratings.tsrs,
tsos_offenses.totoff AS offtotalrating,
tsos_defenses.totdef AS deftotalrating,
tsos_offenses.rushoff AS offrushrating,
tsos_defenses.rushdef AS defrushrating,
tsos_offenses.passoff AS offpassrating,
tsos_defenses.passdef AS defpassrating,
tsos_offenses.scoroff AS offscoringrating,
tsos_defenses.scordef AS defscoringrating,
tsos_offenses.rzonoff AS offrzonerating,
tsos_defenses.rzondef AS defrzonerating,
total_defenses.ydspgm AS deftotal,
total_offenses.ydspgm AS offtotal,
rushing_offenses.ydspg AS offrush,
rushing_defenses.ydspg AS defrush,
passing_offenses.ydspgm AS offpass,
pass_defenses.ydspgm AS defpass,
scoring_offenses.avg AS offscoring,
scoring_defenses.ptspgm AS defscoring,
red_zone_offenses.pct AS offrzone,
red_zone_defenses.pct AS defrzone FROM teams INNER JOIN
tsrs_ratings ON tsrs_ratings.team_id = teams.id INNER JOIN
tsos_offenses ON tsos_offenses.team_id = teams.id INNER JOIN
tsos_defenses ON tsos_defenses.team_id = teams.id INNER JOIN
total_offenses ON total_offenses.team_id = teams.id INNER JOIN
total_defenses ON total_defenses.team_id = teams.id INNER JOIN
rushing_offenses ON rushing_offenses.team_id = teams.id INNER JOIN
rushing_defenses ON rushing_defenses.team_id = teams.id INNER JOIN
passing_offenses ON passing_offenses.team_id = teams.id INNER JOIN
pass_defenses ON pass_defenses.team_id = teams.id INNER JOIN
scoring_offenses ON scoring_offenses.team_id = teams.id INNER JOIN
scoring_defenses ON scoring_defenses.team_id = teams.id INNER JOIN
red_zone_offenses ON red_zone_offenses.team_id = teams.id INNER JOIN
red_zone_defenses ON red_zone_defenses.team_id = teams.id WHERE
(teams.id IN (10,12) AND (scoring_offenses.compiled_on BETWEEN
‘2009-07-27’ AND ‘2009-08-02’ AND total_defenses.compiled_on BETWEEN
‘2009-07-27’ AND ‘2009-08-02’ AND red_zone_offenses.compiled_on
BETWEEN ‘2009-07-27’ AND ‘2009-08-02’ AND
rushing_defenses.compiled_on BETWEEN ‘2009-07-27’ AND ‘2009-08-02’
AND tsrs_ratings.compiled_on BETWEEN ‘2009-07-27’ AND ‘2009-08-02’
AND rushing_offenses.compiled_on BETWEEN ‘2009-07-27’ AND
‘2009-08-02’ AND pass_defenses.compiled_on BETWEEN ‘2009-07-27’ AND
‘2009-08-02’ AND passing_offenses.compiled_on BETWEEN ‘2009-07-27’
AND ‘2009-08-02’ AND tsos_offenses.compiled_on BETWEEN ‘2009-07-27’
AND ‘2009-08-02’ AND scoring_defenses.compiled_on BETWEEN
‘2009-07-27’ AND ‘2009-08-02’ AND total_offenses.compiled_on BETWEEN
‘2009-07-27’ AND ‘2009-08-02’ AND tsos_defenses.compiled_on BETWEEN
‘2009-07-27’ AND ‘2009-08-02’ AND red_zone_defenses.compiled_on
BETWEEN ‘2009-07-27’ AND ‘2009-08-02’)) ORDER BY teams.id

Is this normal?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs