# MySQL client ran out of memory

**URL:** <https://www.ruby-forum.com/t/mysql-client-ran-out-of-memory/73117>\
**Category:** Rails\
**Created:** [February 25, 2006, 5:03am UTC](https://www.ruby-forum.com/t/mysql-client-ran-out-of-memory/73117 "2006-02-25T05:03:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicholas\_Van\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/b5ac83/32.png) [@Nicholas\_Van\_W](https://www.ruby-forum.com/u/Nicholas_Van_W)\
**Post date:** [February 25, 2006, 5:03am UTC](https://www.ruby-forum.com/t/mysql-client-ran-out-of-memory/73117/1 "2006-02-25T05:03:32Z")

</div>

I’m getting the following error unexpectedly for my rails app. I just  
exported the databae from dreamhost and imported it on textdrive for  
my rails app.

Mysql::Error: MySQL client ran out of memory: SELECT COUNT(\*) FROM  
comments WHERE (comments.listing\_id = 2666)

/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active\_record/connection\_adapters/abstract\_adapter.rb:88:in  
`log' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/connection_adapters/mysql_adapter.rb:180:in`execute’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active\_record/connection\_adapters/mysql\_adapter.rb:322:in  
`select' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/connection_adapters/mysql_adapter.rb:175:in`select\_one’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active\_record/connection\_adapters/abstract/database\_statements.rb:16:in  
`select_value' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:518:in`count\_by\_sql’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active\_record/base.rb:511:in  
`count' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/associations/has_many_association.rb:49:in`count’

Anyone have any suggestions as to what the issue might be?

Thanks,  
Nick

---

<div class="post-metadata">

**Author:** ![Nicholas\_Van\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/b5ac83/32.png) [@Nicholas\_Van\_W](https://www.ruby-forum.com/u/Nicholas_Van_W)\
**Post date:** [February 25, 2006, 6:28am UTC](https://www.ruby-forum.com/t/mysql-client-ran-out-of-memory/73117/2 "2006-02-25T06:28:04Z")

</div>

A few ideas:

- how much memory is on the Textdrive machine vs. the Dreamhost  
machine? If it’s less, that may be the problem right there
- did you bring your indexes across from Dreamhost to the Textdrive  
machine?
- are you presenting seriously big wads of data on a single Web page?
- is it consistently happening? If not, maybe some other user is  
doing something at the same time that’s causing you grief
- do you have indexes on your tables, and are they indexing the  
correct fields? If not, and you’re using a few joins in your SQL  
statements, your code may be causing MySQL to load in lots of unwanted  
data unnecessarily
- are you doing a big SELECT, maybe across a few joined tables, with  
an ORDER BY? That’s a common cause of exhausting memory in most  
databases; lots of data has to be held in memory at once, so the ORDER  
BY can do its stuff. Typically you can restructure your SQL statement  
to get around this; you might need to resort to manually using  
find\_by\_sql with Rails to do so

You can use EXPLAIN in the MySQL command line client to see how  
specific SQL statements work. That might be a help, if you understand  
SQL.

Good luck

Dave M.

---

<div class="post-metadata">

**Author:** ![Nicholas\_Van\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/b5ac83/32.png) [@Nicholas\_Van\_W](https://www.ruby-forum.com/u/Nicholas_Van_W)\
**Post date:** [February 25, 2006, 6:31am UTC](https://www.ruby-forum.com/t/mysql-client-ran-out-of-memory/73117/3 "2006-02-25T06:31:06Z")

</div>

Ah, sorry - just noticed in your error message…

Do you have an index on the comments.listing\_id field? If not, you  
probably should. If you do, is it the correct type of index? For  
example, MySQL ideally wants to see different types of indexes for  
fields that must be unique vs. fields that may have many records with  
the same index value.

Regards

Dave M.

---

<div class="post-metadata">

**Author:** ![Nicholas\_Van\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/b5ac83/32.png) [@Nicholas\_Van\_W](https://www.ruby-forum.com/u/Nicholas_Van_W)\
**Post date:** [February 25, 2006, 11:29pm UTC](https://www.ruby-forum.com/t/mysql-client-ran-out-of-memory/73117/4 "2006-02-25T23:29:52Z")

</div>

Thanks.

Textdrive has a 80MB virtual and 48M physical limit for my user account,  
and  
I’m hitting that. Now to get that down…

Thanks,  
Nick

---

<div class="post-metadata">

**Author:** ![Nicholas\_Van\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/b5ac83/32.png) [@Nicholas\_Van\_W](https://www.ruby-forum.com/u/Nicholas_Van_W)\
**Post date:** [February 26, 2006, 12:15am UTC](https://www.ruby-forum.com/t/mysql-client-ran-out-of-memory/73117/5 "2006-02-26T00:15:42Z")

</div>

I’d look at your indexes - if you’ve got any big tables, you really  
don’t want to be doing sequential scans through them if you can avoid  
it.

Regards

Dave M.

---

<div class="post-metadata">

**Author:** ![Nicholas\_Van\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/b5ac83/32.png) [@Nicholas\_Van\_W](https://www.ruby-forum.com/u/Nicholas_Van_W)\
**Post date:** [February 26, 2006, 2:11am UTC](https://www.ruby-forum.com/t/mysql-client-ran-out-of-memory/73117/6 "2006-02-26T02:11:09Z")

</div>

Thanks.

But would that effect dispatch.fcgi memory? I would have thought mysql  
server memory.

Thanks,  
Nick
