Created
March 30, 2009 10:06
-
-
Save sdsykes/87725 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#### fetches the ids | |
>> ii=Inbro.find(:all, :limit=>5) | |
Inbro Load Scrooged (0.3ms) SELECT `inbro`.id FROM `inbro` LIMIT 5 | |
#### causes reload of all columns, and fetches id of each client. Association is noted. | |
>> ii.each {|i| i.inbro_client.id} | |
Inbro Scrooge Reload (15.0ms) SELECT `inbro`.name,`inbro`.header,`inbro`.prompt,`inbro`.banner_name,`inbro`.banner_width,`inbro`.banner_height | |
FROM `inbro` WHERE `inbro`.id IN ('1','2','3','4','5') | |
InbroClient Load Scrooged (58.9ms) SELECT `inbro_client`.id FROM `inbro_client` WHERE (`inbro_client`.`id` = 7120) | |
InbroClient Load Scrooged (0.5ms) SELECT `inbro_client`.id FROM `inbro_client` WHERE (`inbro_client`.`id` = 7120) | |
InbroClient Load Scrooged (0.3ms) SELECT `inbro_client`.id FROM `inbro_client` WHERE (`inbro_client`.`id` = 7120) | |
InbroClient Load Scrooged (0.2ms) SELECT `inbro_client`.id FROM `inbro_client` WHERE (`inbro_client`.`id` = 7120) | |
InbroClient Load Scrooged (0.2ms) SELECT `inbro_client`.id FROM `inbro_client` WHERE (`inbro_client`.`id` = 1) | |
#### remembers client_id is needed | |
>> ii=Inbro.find(:all, :limit=>5) | |
Inbro Load Scrooged (82.3ms) SELECT `inbro`.id,`inbro`.client_id FROM `inbro` LIMIT 5 | |
#### still fetches each client, association is marked as used by 5 records. | |
>> ii.each {|i| i.inbro_client.id} | |
InbroClient Load Scrooged (0.4ms) SELECT `inbro_client`.id FROM `inbro_client` WHERE (`inbro_client`.`id` = 1) | |
InbroClient Load Scrooged (0.3ms) SELECT `inbro_client`.id FROM `inbro_client` WHERE (`inbro_client`.`id` = 7120) | |
InbroClient Load Scrooged (0.2ms) SELECT `inbro_client`.id FROM `inbro_client` WHERE (`inbro_client`.`id` = 7120) | |
InbroClient Load Scrooged (0.2ms) SELECT `inbro_client`.id FROM `inbro_client` WHERE (`inbro_client`.`id` = 7120) | |
InbroClient Load Scrooged (0.2ms) SELECT `inbro_client`.id FROM `inbro_client` WHERE (`inbro_client`.`id` = 1) | |
#### association is fetched on load | |
>> ii=Inbro.find(:all, :limit=>5) | |
Inbro Load Scrooged (0.8ms) SELECT `inbro`.id,`inbro`.client_id FROM `inbro` LIMIT 5 | |
InbroClient Load Scrooged (0.4ms) SELECT `inbro_client`.id FROM `inbro_client` WHERE (`inbro_client`.`id` IN (7120,1)) | |
#### nothing to do | |
>> ii.each {|i| i.inbro_client.id} | |
#### now we need the client name. It is efficiently loaded for all rows simultaneously. | |
>> ii.each {|i| i.inbro_client.name} | |
InbroClient Scrooge Reload (92.2ms) SELECT `inbro_client`.name,`inbro_client`.username,`inbro_client`.password,`inbro_client`.id FROM `inbro_client` | |
WHERE `inbro_client`.id IN ('1','7120') | |
#### remembers to fetch the client name also | |
>> ii=Inbro.find(:all, :limit=>5) | |
Inbro Load Scrooged (0.8ms) SELECT `inbro`.id,`inbro`.client_id FROM `inbro` LIMIT 5 | |
InbroClient Load Scrooged (0.9ms) SELECT `inbro_client`.name,`inbro_client`.id FROM `inbro_client` | |
WHERE (`inbro_client`.`id` IN (7120,1)) | |
#### NEW SESSION | |
#### | |
#### fetches the ids | |
>> ii=Inbro.find(:all, :limit=>5) | |
Inbro Load Scrooged (0.3ms) SELECT `inbro`.id FROM `inbro` LIMIT 5 | |
#### causes reload of all columns, and fetches id of each client. Association is noted. | |
>> ii.each {|i| i.inbro_client.id} | |
Inbro Scrooge Reload (15.0ms) SELECT `inbro`.name,`inbro`.header,`inbro`.prompt,`inbro`.banner_name,`inbro`.banner_width,`inbro`.banner_height | |
FROM `inbro` WHERE `inbro`.id IN ('1','2','3','4','5') | |
InbroClient Load Scrooged (58.9ms) SELECT `inbro_client`.id FROM `inbro_client` WHERE (`inbro_client`.`id` = 7120) | |
InbroClient Load Scrooged (0.5ms) SELECT `inbro_client`.id FROM `inbro_client` WHERE (`inbro_client`.`id` = 7120) | |
InbroClient Load Scrooged (0.3ms) SELECT `inbro_client`.id FROM `inbro_client` WHERE (`inbro_client`.`id` = 7120) | |
InbroClient Load Scrooged (0.2ms) SELECT `inbro_client`.id FROM `inbro_client` WHERE (`inbro_client`.`id` = 7120) | |
InbroClient Load Scrooged (0.2ms) SELECT `inbro_client`.id FROM `inbro_client` WHERE (`inbro_client`.`id` = 1) | |
#### remembers client_id is needed | |
>> ii=Inbro.find(:all, :limit=>5) | |
Inbro Load Scrooged (82.3ms) SELECT `inbro`.id,`inbro`.client_id FROM `inbro` LIMIT 5 | |
#### still fetches each client, association is marked as used by 1 record. | |
>> ii[0].inbro_client.id | |
InbroClient Load Scrooged (0.4ms) SELECT `inbro_client`.id FROM `inbro_client` WHERE (`inbro_client`.`id` = 1) | |
#### association is NOT fetched on load because of 25% rule | |
>> ii=Inbro.find(:all, :limit=>5) | |
Inbro Load Scrooged (0.8ms) SELECT `inbro`.id,`inbro`.client_id FROM `inbro` LIMIT 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment