Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Random "SELECT 1" query in all requests on rails

I'm profiling my rails 3.2 app with miniprofiler, and it shows me a

SELECT 1

query at the beginning of each page load or ajax call. It only takes 0.4ms, but it is still a seemingly unnecessary database query.

Anyone know why this query is happening or how to get rid of it?

enter image description here

like image 292
Tyler Avatar asked Jul 17 '13 12:07

Tyler


2 Answers

SELECT 1 is like a ping - the cheapest query to test whether the session is alive and kicking. Various clients use it for that purpose. It may be useless in your case ...

like image 135
Erwin Brandstetter Avatar answered Oct 22 '22 02:10

Erwin Brandstetter


For Postgres you can find it in this line on Github.

Or, if you using MySQL, you can see the solution in this groupon engineering blog.

like image 31
betoharres Avatar answered Oct 22 '22 04:10

betoharres