Is there any way to prevent ActiveRecord from issued a SHOW FIELDS to the database when it's not needed?
I'm working on database performance critical application, and just noticed that on a typical query my SELECT takes 0.5 ms and the related SHOW FIELDS takes 2 ms -- 4 times longer! Even more importantly, it's not needed because I'm already specifying the only column I want to retrieve:
UsersAddress.find(:all, :conditions => {:user_id => 1}, :select => :address_id)
UsersAddress Load (0.5ms) SELECT address_id FROM
users_addresses
WHERE (users_addresses
.user_id
= 1)UsersAddress Columns (2.1ms) SHOW FIELDS FROM
users_addresses
Granted, this only happens once each time some table is touched for the first time, but shouldn't it be avoidable complete? First of all, that info is already in my schema. Second, I don't need it.
Any ideas how to optimize this so that Rails won't run a SHOW FIELDS unless it really needs it?
Thanks!
In production mode it will load only once after starting a server (not every request).
In development mode it is loaded on every request (because it is development mode and it restarts almost everything every request)
So you don't have to worry about it in production mode.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With