Rails generates strange mysql queries

I use rack-mini-profiler in a rails application, and when it loads a page, sometimes some strange requests appear, for example

SHOW FULL FIELDS FROM `tablename` SHOW TABLES LIKE 'tablename' SHOW CREATE TABLE `tablename` 

They say that requests come from the controller that processes the request, from a line with

 @model = Model.first() 

These requests are not executed on successive page loads.

Why do rails generate these weird queries?

+4
source share
1 answer

You probably know that Rails automatically matches fields in the database according to the properties of your models by convention, so you don’t need to explicitly define "id", "name", etc. in implementations of the ActiveRecord class.

In order for your ActiveRecord models to generate the properties you need, Rails must interrogate your database schema. Mysql supports the above commands for checking the schema.

ActiveRecord makes the assumption that your scheme will not change throughout the life cycle of the running application, so there is no need to ask these questions in subsequent requests.

+5
source

All Articles