I recently started noticing that a large sum of my tmp tables of my MySQL is being created on my Disk rather then in the memory.

TEMP TABLES
Current max_heap_table_size = 128 M
Current tmp_table_size = 128 M
Of 73993 temp tables, 46% were created on disk
Perhaps you should increase your tmp_table_size and/or max_heap_table_size
to reduce the number of disk-based temporary tables
Note! BLOB and TEXT columns are not allow in memory tables.
If you are using these columns raising these values might not impact your
ratio of on disk temp tables.

How can I optimize this so that it uses memory rather then the disk since it would be faster.

link|improve this question

feedback

2 Answers

up vote 2 down vote accepted

The text you printed tells you what you need to do:

Perhaps you should increase your tmp_table_size and/or max_heap_table_size to reduce the number of disk-based temporary tables

http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar_tmp_table_size http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar_max_heap_table_size

link|improve this answer
feedback

You may want to consider a RAM disk

In the Linux OS of one of my MySQL Clients, there is a 16GB RAM Disk

I ran the command 'cat /etc/fstab' I saw this

[root***~]# cat /etc/fstab
/dev/vg1/root           /                       ext3    defaults        1 1
/dev/vg2/data01           /data                   ext3    defaults        1 1
/dev/sdc1                 /backup                       ext3    defaults        1 1
LABEL=/boot             /boot                   ext3    defaults        1 2
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
/dev/vg1/swap           swap                    swap    defaults        0 0
none                    /var/tmpfs              tmpfs   defaults,size=16g        1 2

The last line had 16GB of RAM mounted on /var/tmpfs

The client has this defined in /etc/my.cnf

mysql> show variables like 'tmpdir';
+---------------+------------+
| Variable_name | Value      |
+---------------+------------+
| tmpdir        | /var/tmpfs |
+---------------+------------+
1 row in set (0.00 sec)

Now here is something funny you can do once you have /var/tmpfs setup:

Deliberately set tmp_table_size=1K.

That's right, this is not a typo.

I said 1K. This will immediately create all tmp tables in the RAM disk.

Give it a Try !!!

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.