Take the 2-minute tour ×

I'm using rack-mini-profiler in a rails application, and when it loads a page, it sometimes shows some strange queries like:

SHOW TABLES LIKE 'tablename'

They say the queries are coming from the controller that handles the request, from a line which has

@model = Model.first()

These queries are not executed on successive page loads.

Why does rails generate these strange queries?

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

You are probably aware that Rails automagically maps fields in the database to properties in your models by convention, so that you don't have to explicitly define "id", "name", etc in your ActiveRecord class implementations.

In order for your ActiveRecord models to generate the right properties, Rails must interrogate your database schema. Mysql supports the commands above in order to inspect the schema.

ActiveRecord makes the assumption that your schema won't change during the lifetime of the application running, however, so it's not necessary to ask these questions on subsequent requests.

share|improve this answer
And this magic happens when the model class is declared? Which is when the model is first used since rails does lazy loading of model classes right? –  Cameron Martin Aug 16 '12 at 1:01
add comment

Your Answer


