Bug #11374 SQL command OPTIMIZE TABLE memory leak
Submitted: 16 Jun 2005 10:11 Modified: 23 Jun 2005 13:41
Reporter: Julien VALIENTE Email Updates:
Status: Can't repeat Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:4.0.17 OS:Linux (RedHat 8.0)
Assigned to: CPU Architecture:Any

[16 Jun 2005 10:11] Julien VALIENTE
Description:
When executing the code bellow ("how to repeat" section) linked with libmysqlclient 4.0.17, the mysqld daemon grows quickly in memory (about 600 bytes per second). I use the mysqld official binaries version 4.0.17 and also tried the 4.0.24, both using libmysqlclient 4.0.17.

The code bellow calls the sql OPTIMIZE TABLE continuously. I also tried to insert a sleep function between queries without solving the problem of mysqld growing after each query.

Thanks to telling me if the problem is due to my code.

Thanks a lot,

J. Valiente

How to repeat:
#include <stdio.h>
#include <string.h>
#include "my_config.h"
#include "mysql.h"

/*********************************
	SQL simple table sample

CREATE DATABASE test_optimize;
CREATE TABLE `test` (
  `id` bigint(10) NOT NULL auto_increment,
  PRIMARY KEY  (`id`)
) TYPE=MyISAM COMMENT='' AUTO_INCREMENT=62 ;
INSERT INTO `test` VALUES ('');

*********************************/

int main()
{
	int i;
	MYSQL* mysql;

	i = 0;
	while( 1 )
	{
		mysql = mysql_init((MYSQL*) 0);
		if( mysql_real_connect(mysql, "127.0.0.1", <login>, <password>, NULL, 3306, NULL, 0) == NULL )
		{
			printf("Connexion fails\n");
			return -1;
		}

		if( !(mysql_select_db(mysql, "test_optimize") == 0) )
		{
			printf("Db selection fails (%d: %s)\n", mysql_errno(mysql), mysql_error(mysql));
			return -1;
		}

		if( mysql_query(mysql, "OPTIMIZE TABLE test") != 0 )
		{
			printf("Query fails (%d: %s)\n", mysql_errno(mysql), mysql_error(mysql));
		}

// This part of code increase more again the mysqld memory usage
//		MYSQL_RES* res = mysql_use_result(mysql);
//		mysql_free_result(res);

		if( i%100 == 0 ) { printf("%d req\n", i); }
		i++;

		mysql_close(mysql);
	}

	return 0;
}
[23 Jun 2005 13:41] Aleksey Kishkin
Hi! run your program against mysql 4.0.24 and tested memory it ate:

$> for i in `seq 1 20`;do ps -eo fname,sz |grep mysql|tail -n 1;sleep 1; done
mysqld   14272
mysqld   14489
mysqld   14926
mysqld   14755
mysqld   14371
mysqld   14189
mysqld   14713
mysqld   14135
mysqld   14140
mysqld   15029
mysqld   14596
mysqld   14366
mysqld   14233
mysqld   15023
mysqld   14434
mysqld   14714
mysqld   14434
mysqld   14141
mysqld   14091
mysqld   14282

I dont see if mysql server grows. How did you estimated  mysql server size in memory?
[23 Jun 2005 14:02] Julien VALIENTE
I used the linux 'top' tool to estimate the mysql daemon memory usage.