1

I'm using a mysql memory table as a way to cache data rows which are read several times. I chose this alternative because I'm not able to use xcache or memcache in my solution. After reading the mysql manual and forum about this topic I have concluded that an error will be raised when the table reaches its maximum memory size. I want to know if there is a way to catch this error in order to truncate the table and free the memory. I don't want to raise the limit of memory that can be used, I need a way to free the memory automatically so the table can continue working.

Thanks.

Lucia
  • 4,657
  • 6
  • 43
  • 57

2 Answers2

5

If you're out of memory, the engine will raise the error 1114 with the following error message:

The table 'table_name' is full

You should catch this error on the client side and delete some data from the table.

Quassnoi
  • 413,100
  • 91
  • 616
  • 614
1

You should use normal, persistent tables instead and rely on the inherent caching. For tables where the contents can safely be thrown away, MyISAM is a safe engine (provided you are happy to do a TRUNCATE TABLE on each boot up), alternatively, you can use the same engine as your permanent tables (e.g. InnoDB).

Memory tables are extremely sucky anyway (In all released MySQL versions; better in Drizzle and some others) because they pad rows to the maximum length, which means you can't really start putting VARCHARs in them sensibly.

Unfortunately, you cannot yet set the innodb durability parameter on a per-table (or per-transaction) basis, so you must decide on a per-server basis how much durability you need - in your case, none, so you can set innodb_flush_log_at_trx_commit to 2 (or even 0, but it gains you little)

MarkR
  • 62,604
  • 14
  • 116
  • 151
  • It's no longer true that MEMORY storage engine pads VARCHARs to full length. Recent versions of Percona MySQL server fixed that. – matt Mar 28 '12 at 08:21
  • I'm fairly sure the statement was true for all GA mainline versions of MySQL at the time I wrote it. Many of the forks have fixed the memory ending padding. – MarkR Mar 28 '12 at 12:00