MySQL在存储过程中耗尽内存

时间:2012-05-08 09:59:57

标签: mysql stored-procedures temp-tables

到目前为止,我有一个MySQL存储过程包含大约20个创建临时表语句而没有其他任何东西。但是当我跑步时,商店会发出一条消息“Out of memory” 这里是商店代码:

CREATE DEFINER = 'thanhnt'@'192.168.6.31' PROCEDURE `test_out_of_memory`()
    NOT DETERMINISTIC
    CONTAINS SQL
    SQL SECURITY DEFINER
    COMMENT ''
BEGIN

SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;

#SET max tmp size
SET @@tmp_table_size = 1073741824; 

drop table if exists tbllogging;
create TABLE tbllogging(t TIMESTAMP, step int) ENGINE=INNODB;

DROP TABLE IF EXISTS norep_campaigntmp;
CREATE TEMPORARY TABLE `norep_campaigntmp` (
    `campaignid` MEDIUMINT(9)  NOT NULL DEFAULT '0' ,  
    `num` MEDIUMINT(9)  NOT NULL DEFAULT '0'          
)ENGINE=INNODB;

INSERT INTO tbllogging SELECT CURRENT_TIMESTAMP,0;
DROP TABLE IF EXISTS norep_campaign_NB_tmp;
CREATE TEMPORARY TABLE `norep_campaign_NB_tmp` (
    `campaignid` MEDIUMINT(9)  NOT NULL DEFAULT '0' ,  
    `num` MEDIUMINT(9)  NOT NULL DEFAULT '0'          
)ENGINE=INNODB;

INSERT INTO tbllogging SELECT CURRENT_TIMESTAMP,1;
DROP TABLE IF EXISTS norep_zonebannertmp;
CREATE TEMPORARY TABLE `norep_zonebannertmp` (
    `zoneid` SMALLINT(6)  NOT NULL DEFAULT '0' ,
    `block` TINYINT(4)  NOT NULL DEFAULT '0' ,
    `location` TINYINT(4)  NOT NULL DEFAULT '0' ,
    `bannerid` MEDIUMINT(9)  NOT NULL DEFAULT '0' ,
     KEY `location` (`location`),
     KEY `bannerid` (`bannerid`),
     KEY `block` (`block`),
     KEY `zoneid` (`zoneid`)             
)ENGINE=INNODB;

INSERT INTO tbllogging SELECT CURRENT_TIMESTAMP,2;
DROP TABLE IF EXISTS norep_zonebannertmp_bk;
CREATE TEMPORARY TABLE `norep_zonebannertmp_bk` (
    `zoneid` SMALLINT(6)  NOT NULL DEFAULT '0' ,
    `block` TINYINT(4)  NOT NULL DEFAULT '0' ,
    `location` TINYINT(4)  NOT NULL DEFAULT '0' ,
    `bannerid` MEDIUMINT(9)  NOT NULL DEFAULT '0' ,
     KEY `location` (`location`),
     KEY `bannerid` (`bannerid`),
     KEY `block` (`block`),
     KEY `zoneid` (`zoneid`)             
)ENGINE=INNODB;

INSERT INTO tbllogging SELECT CURRENT_TIMESTAMP,3;
DROP TABLE IF EXISTS norep_zonebanner_delete_tmp;
CREATE TEMPORARY TABLE `norep_zonebanner_delete_tmp` (
    `zoneid` SMALLINT(6)  NOT NULL DEFAULT '0' ,
    `block` TINYINT(4)  NOT NULL DEFAULT '0' ,
    `location` TINYINT(4)  NOT NULL DEFAULT '0' ,
    `bannerid` MEDIUMINT(9)  NOT NULL DEFAULT '0' ,
     KEY `location` (`location`),
     KEY `bannerid` (`bannerid`),
     KEY `block` (`block`),
     KEY `zoneid` (`zoneid`)             
)ENGINE=INNODB;

INSERT INTO tbllogging SELECT CURRENT_TIMESTAMP,4;
DROP TABLE IF EXISTS norep_zonebanner_cur_tmp;
CREATE TEMPORARY TABLE `norep_zonebanner_cur_tmp` (
    `zoneid` SMALLINT(6)  NOT NULL DEFAULT '0' ,
    `location` TINYINT(4)  NOT NULL DEFAULT '0' ,
    `bannerid` MEDIUMINT(9)  NOT NULL DEFAULT '0' ,
     KEY `location` (`location`),
     KEY `bannerid` (`bannerid`),
     KEY `zoneid` (`zoneid`)             
)ENGINE=INNODB;
INSERT INTO tbllogging SELECT CURRENT_TIMESTAMP,5;
DROP TABLE IF EXISTS norep_grouptmp;
CREATE TEMPORARY TABLE `norep_grouptmp` (
    `groupid` SMALLINT(6)  NOT NULL DEFAULT '0' ,  
    `w` MEDIUMINT(9)  NOT NULL DEFAULT '0'          
)ENGINE=INNODB;

INSERT INTO tbllogging SELECT CURRENT_TIMESTAMP,6;
DROP TABLE IF EXISTS norep_block_delete_tmp;
CREATE TEMPORARY TABLE `norep_block_delete_tmp` (
    `zoneid` INT(9)  NOT NULL DEFAULT '0' ,  
    `location` TINYINT(4)  NOT NULL DEFAULT '0' , 
    `block` TINYINT(4)  NOT NULL DEFAULT '0' ,
     KEY `zoneid` (`zoneid`),
     KEY `location` (`location`),
     KEY `block` (`block`)          
)ENGINE=INNODB;

INSERT INTO tbllogging SELECT CURRENT_TIMESTAMP,7;
DROP TABLE IF EXISTS norep_banner_channel_tmp;
CREATE TEMPORARY TABLE `norep_banner_channel_tmp` (
    `bannerid` INT(9)  NOT NULL DEFAULT '0' ,  
    `channelid` INT(9)  NOT NULL DEFAULT '0' ,  
    `location` TINYINT(4)  NOT NULL DEFAULT '0',
      KEY `channelid` (`channelid`)            
)ENGINE=INNODB;

INSERT INTO tbllogging SELECT CURRENT_TIMESTAMP,8;
DROP TABLE IF EXISTS norep_user_zone_tmp;
CREATE TEMPORARY TABLE `norep_user_zone_tmp` (
    `userid` INT(9)  NOT NULL DEFAULT '0' ,  
    `zoneid` INT(9)  NOT NULL DEFAULT '0' ,  
    `location` TINYINT(4)  NOT NULL DEFAULT '0' ,      
      KEY `userid` (`userid`) ,           
      KEY `zoneid` (`zoneid`) ,      
      KEY `location` (`location`)           
)ENGINE=INNODB;

INSERT INTO tbllogging SELECT CURRENT_TIMESTAMP,9;
DROP TABLE IF EXISTS norep_user_zone_loc_tmp;
CREATE TEMPORARY TABLE `norep_user_zone_loc_tmp` (
    `userid` INT(9)  NOT NULL DEFAULT '0' ,  
    `zoneid` INT(9)  NOT NULL DEFAULT '0' ,  
    `loc` TINYINT(4)  NOT NULL DEFAULT '0' ,  
    `num` TINYINT(4)  NOT NULL DEFAULT '0'          
)ENGINE=INNODB;

INSERT INTO tbllogging SELECT CURRENT_TIMESTAMP,10;
DROP TABLE IF EXISTS norep_bannertmp_KH;
CREATE TEMPORARY TABLE `norep_bannertmp_KH` (
    `campaignid` MEDIUMINT(6)  NOT NULL DEFAULT '0' , 
    `isexpire` MEDIUMINT(6)  NOT NULL DEFAULT '0' , 
    `bannerid` MEDIUMINT(6)  NOT NULL DEFAULT '0' ,
     KEY `bannerid` (`bannerid`) ,  
     KEY `campaignid` (`campaignid`)           
)ENGINE=INNODB;
INSERT INTO tbllogging SELECT CURRENT_TIMESTAMP,11;
DROP TABLE IF EXISTS norep_bannertmp_NB;
CREATE TEMPORARY TABLE `norep_bannertmp_NB` (
    `groupid` MEDIUMINT(6)  NOT NULL DEFAULT '0' ,
    `campaignid` MEDIUMINT(6)  NOT NULL DEFAULT '0' , 
    `bannerid` MEDIUMINT(6)  NOT NULL DEFAULT '0' ,
     `isexpire` MEDIUMINT(6)  NOT NULL DEFAULT '0' ,    
     KEY `bannerid` (`bannerid`) ,  
     KEY `campaignid` (`campaignid`)           
)ENGINE=INNODB;
INSERT INTO tbllogging SELECT CURRENT_TIMESTAMP,12;
DROP TABLE IF EXISTS norep_bannertmp1;
CREATE TEMPORARY TABLE `norep_bannertmp1` (
    `groupid` INT(9)  NOT NULL DEFAULT '0' , 
    `userid` INT(9)  NOT NULL DEFAULT '0' , 
    `campaignid` INT(9)  NOT NULL DEFAULT '0' , 
    `bannerid` INT(9)  NOT NULL DEFAULT '0' ,    
    `location` TINYINT(4)   ,
    `typegroup` TINYINT(4) DEFAULT 0 ,  
    `w` INT  DEFAULT 0 , 
     KEY `campaignid` (`campaignid`) ,         
     KEY `bannerid` (`bannerid`) ,  
     KEY `groupid` (`groupid`) , 
     KEY `userid` (`userid`) ,           
     KEY `location` (`location`) ,      
     KEY `typegroup` (`typegroup`) 

)ENGINE=INNODB;
INSERT INTO tbllogging SELECT CURRENT_TIMESTAMP,13;

DROP TABLE IF EXISTS norep_101_tmp;
CREATE TEMPORARY TABLE `norep_101_tmp` (
    `userid` INT , 
    `bannerid` INT ,
    `ctr` decimal(6,3) NOT NULL,
    `views` INT ,
     KEY `userid` (`userid`) ,  
     KEY `bannerid` (`bannerid`)            
)ENGINE=INNODB;

INSERT INTO tbllogging SELECT CURRENT_TIMESTAMP,14;
DROP TABLE IF EXISTS norep_banner_zone_in;
CREATE TEMPORARY TABLE `norep_banner_zone_in` (
    `channelid` INT , 
    `zoneid` INT , 
    `location` TINYINT(4) , 
    `bannerid` INT ,
    `CTR` DECIMAL(6,3) ,
    `money` INT,
     KEY `channelid` (`channelid`) ,  
     KEY `zoneid` (`zoneid`) ,  
     KEY `bannerid` (`bannerid`) ,  
     KEY `location` (`location`)           
)ENGINE=MYISAM;
INSERT INTO tbllogging SELECT CURRENT_TIMESTAMP,15;
DROP TABLE IF EXISTS norep_banner_zone_no_gen_tmp;
CREATE TEMPORARY TABLE `norep_banner_zone_no_gen_tmp` (
    `zoneid` INT , 
    `location` TINYINT(4) , 
    `bannerid` INT ,
    `userid` INT ,
     KEY `userid` (`userid`) ,  
     KEY `zoneid` (`zoneid`) ,  
     KEY `bannerid` (`bannerid`) ,  
     KEY `location` (`location`)           
)ENGINE=INNODB;

INSERT INTO tbllogging SELECT CURRENT_TIMESTAMP,16;
DROP TABLE IF EXISTS norep_banner_zone_no_gen_tmp1;
CREATE TEMPORARY TABLE `norep_banner_zone_no_gen_tmp1` (
    `zoneid` INT , 
    `location` TINYINT(4) , 
    `bannerid` INT ,
    `userid` INT ,
     KEY `userid` (`userid`) ,  
     KEY `zoneid` (`zoneid`) ,  
     KEY `bannerid` (`bannerid`) ,  
     KEY `location` (`location`)           
)ENGINE=INNODB;

INSERT INTO tbllogging SELECT CURRENT_TIMESTAMP,17;
DROP TABLE IF EXISTS norep_banner_zone_no_gen_today_tmp;
CREATE TEMPORARY TABLE `norep_banner_zone_no_gen_today_tmp` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `zoneid` INT , 
    `location` TINYINT(4) , 
    `bannerid` INT ,
    `userid` INT ,
     KEY `id` (`id`) , 
     KEY `userid` (`userid`) ,  
     KEY `zoneid` (`zoneid`) ,  
     KEY `bannerid` (`bannerid`) ,  
     KEY `location` (`location`)           
)ENGINE=INNODB;

INSERT INTO tbllogging SELECT CURRENT_TIMESTAMP,18;
DROP TABLE IF EXISTS norep_banner_zone_no_gen_today_tmp1;
CREATE TEMPORARY TABLE `norep_banner_zone_no_gen_today_tmp1` (
    `id` int(11) NOT NULL,
    `zoneid` INT , 
    `location` TINYINT(4) , 
    `bannerid` INT ,
    `userid` INT ,
     KEY `id` (`id`) ,  
     KEY `userid` (`userid`) ,  
     KEY `zoneid` (`zoneid`) ,  
     KEY `bannerid` (`bannerid`) ,  
     KEY `location` (`location`)           
)ENGINE=INNODB;


INSERT INTO tbllogging SELECT CURRENT_TIMESTAMP,19;
DROP TABLE IF EXISTS norep_ssv_tmp;
CREATE TEMPORARY TABLE `norep_ssv_tmp` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `userid` int(11) unsigned NOT NULL,
  `bannerid` int(11) unsigned NOT NULL,
  `money` int(11) unsigned NOT NULL,
  `ctr` decimal(6,3) NOT NULL,
  `createtime` datetime DEFAULT NULL,
  `typegroup` tinyint(4) NOT NULL DEFAULT '0'  ,
  KEY `id` (`id`) ,
  KEY `typegroup` (`typegroup`) ,  
  KEY `userid` (`userid`) 
) ENGINE=INNODB;
INSERT INTO tbllogging SELECT CURRENT_TIMESTAMP,20;
DROP TABLE IF EXISTS norep_ssv_tmp1;
CREATE TEMPORARY TABLE `norep_ssv_tmp1` (
   `id` int(11) NOT NULL,
  `userid` int(11) unsigned NOT NULL,
  `bannerid` int(11) unsigned NOT NULL,
  `money` int(11) unsigned NOT NULL,
  `ctr` decimal(6,3) NOT NULL,
  `createtime` datetime DEFAULT NULL,
  `typegroup` tinyint(4) NOT NULL DEFAULT '0'  ,
  KEY `typegroup` (`typegroup`) ,  
  KEY `userid` (`userid`) 
) ENGINE=INNODB;

INSERT INTO tbllogging SELECT CURRENT_TIMESTAMP,21; 

SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ; 
INSERT INTO tbllogging select CURRENT_TIMESTAMP, 22;

SELECT * FROM tbllogging;
END;

http://pastebin.com/q6sETytk

MySQL 5.5 RAM:48 GB

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

您的所有存储过程似乎都在丢弃并重新创建一些临时表。

如果是这种情况,那么您应该用DROP替换所有CREATE TABLETRUNCATE TABLE语句(并使用create where not exists)。

您调用的所有DROP语句可能会耗尽内存DROP可以回滚