rails-sqlserver/activerecord-sqlserver-adapter — Issue #162: Lowercase Reflection Performance
Author: pmorton
Created: 2012-02-12 22:04:14+00:00
State: open

So I have come across an interesting situation. I am using the activerecord-sqlserver-adapter with lower case reflection enabled. Everything worked great, or so I though. As my data sets and relationships grew, so did the time that it would take to execute a query and render the result. I had some queries that would take up to 50 seconds to execute through the adapter, while executing the same exact query (ala rails logging) on SSMS (from the same machine) and it would return the results in less than a second. I hooked my application up to new-relic to inspect what was happening.

With lowercase reflection turned off:
Total SQL Queries: 153
Rails Returns in: 15 Seconds
Latency:

With lowercase reflection turned on:
Total SQL Queries: 534
Railes Returns in: 51 Seconds.

It seems that "SELECT LOWER(TABLE_NAME) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = ? ORDER BY TABLE_NAME" is run an additoonal ~380 times when lowercase reflection is turned on.