josevalim/rails-footnotes — Issue #61: Generating excessive queries with SQL Server Relationships
Author: chadcf
Created: 2011-10-26 19:11:15+00:00
State: open

I can't say what all this affects, however my app is using activerecord-sqlserver-adapter and tiny_tds to connect to a SQL Server 2008 Database. I have been beating my head against the wall as when I do a simple query such as:

@users = Users.limit(25).includes([:addresses])

the request takes over a minute and rails footnotes indicates there are 300 and some queries being run, most of which are:

SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' ORDER BY TABLE_NAME

This query is run over and over again hundreds of times. This confused me thoroughly as it DID NOT do this from the console, and the development.log reflected nothing of those queries.

Then finally it dawned on me. I removed rails footnotes and the page now loads almost instantly without all those queries. Not sure what is up here, however it is definitely footnotes causing those to be run. In addition it also seems to only affect queries with .includes, if I remove the includes things work normally.

I am using:

rails-footnotes (3.7.5)
activerecord (3.1.1)
activerecord-sqlserver-adapter (3.1.1)
tiny_tds (0.4.5)
freetds (0.9.1)

I know not a lot of people use sql server with rails, and this is a legacy database with non-conventional column names, so I'm happy to provide whatever environment information or debugging I can do to help.