This project is archived and is in readonly mode.
Repeated SHOW FIELDS FROM... queries with STI
-
foca
The problem with using
@@variables is that they are shared across the entire ancestor chain, thus:@@@ruby class Base
def self.columns@@columns ||= {}end end
class A < Base; end
class B < Base; endA.columns[:foo] = "I'm a column!"
B.columns #=> {:foo=>"I'm a column!"}
-
Luke Melia
@foca, yep, my proposed solution actually takes advantage of that "feature" of class variables. It uses a single hash for the entire inheritance hierarchy, with table names as keys and the column collections as values.
-
José Valim
Not sure if this is concern, these queries run only once in production and in development they do not represent a bottleneck.
-
Michael Koziarski
yeah, I'm with Jose, how many subclasses do you really have?
-
Luke Melia
We have about 300 models in our app. About a third of them are subclasses. I started looking at this today because these queries popped up in some New Relic transaction traces.
According to http://blog.lukeludwig.com/index.php/2009/01/08/rails-patch-for-cac... :
"Turns out that MySQL creates a temporary table on disk for 'SHOW FIELDS' queries, so if the disk is busy with something else these queries can take awhile to complete as seen here."
In addition, the overhead can be impactful in development or during repeated test runs, where you're reloading frequently.
What do you think? If this doesn't belong in core, I can maintain my patch locally.
-
Santiago Pastorino
- State changed from new to open
- Importance changed from to Low
This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.
Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.
-
Santiago Pastorino
- State changed from open to stale