SHOW TABLES is absurdly slow in Rails

For some reason, extremely simple queries like SHOW TABLES can take a lot of time on my local machine.

 # line from log/development.log SQL (955.1ms) SHOW TABLES 

If I execute the same request in dbconsole manually, it starts in <0.01 s

Looking through the logs for any long queries except migrations, all of them are displayed using SHOW TABLES.

  SQL (170.6ms) SHOW TABLES SQL (165.7ms) SHOW TABLES SQL (166.1ms) SHOW TABLES SQL (176.9ms) SHOW TABLES SQL (166.1ms) SHOW TABLES SQL (273.7ms) SHOW TABLES SQL (165.9ms) SHOW TABLES SQL (145.6ms) SHOW TABLES SQL (142.8ms) SHOW TABLES SQL (165.8ms) SHOW TABLES SQL (165.9ms) SHOW TABLES SQL (166.1ms) SHOW TABLES SQL (199.2ms) SHOW TABLES SQL (155.0ms) SHOW TABLES SQL (143.7ms) SHOW TABLES SQL (143.4ms) SHOW TABLES SQL (153.1ms) SHOW TABLES SQL (354.5ms) SHOW TABLES SQL (210.3ms) SHOW TABLES SQL (1060.0ms) SHOW TABLES SQL (854.7ms) SHOW TABLES SQL (254.4ms) SHOW TABLES 

Running Mac OS X using Server version: 5.1.46 MySQL Community Server (GPL)

This issue had a problem with Rails 2 and Rails 3.

+4
source share
2 answers

Try switching to the new mysql2 stone. This can solve the problem.

/ Karsten

+1
source

You can try to "cache" the columns:

In the / some _file.rb initializers, do the following:

 User.columns OtherModel.columns and so on... 

This will be done when the server starts, so the first time the request is launched, it will not be delayed by the SHOW TABLES request.

This is not a solution, of course, there must be something wrong with your tables, moreover, I do not use it in production, I use this trick when I debug something in the console to avoid Rails to show all SHOW TABLES requests.

0
source

All Articles