old table struct: CREATE TABLE `t_iteminfo` ( `aid` bigint(20) NOT NULL auto_increment, `charguid` int(11) NOT NULL, `guid` int(11) NOT NULL, `world` int(11) NOT NULL, `server` int(11) NOT NULL, `itemtype` int(11) NOT NULL, `pos` smallint(6) NOT NULL, `p1` int(11) NOT NULL, `p2` int(11) NOT NULL, `p3` int(11) NOT NULL, `p4` int(11) NOT NULL, `p5` int(11) NOT NULL, `p6` int(11) NOT NULL, `p7` int(11) NOT NULL, `p8` int(11) NOT NULL, `p9` int(11) NOT NULL, `p10` int(11) NOT NULL, `p11` int(11) NOT NULL, `p12` int(11) NOT NULL, `p13` int(11) NOT NULL, `p14` int(11) NOT NULL, `p15` int(11) default '0', `p16` int(11) default '0', `p17` int(11) default '0', `creator` varchar(40) default '0', `isvalid` smallint(6) NOT NULL default '1', `dbversion` int(11) default '0', `fixattr` varchar(200) NOT NULL, `var` varchar(40) default '0', `visualid` int(11) NOT NULL default '0', `maxgemid` int(11) NOT NULL default '-1', PRIMARY KEY (`aid`), KEY `Index_it_charguid` (`charguid`,`pos`), KEY `Index_it_itemguid` (`guid`,`world`,`server`), KEY `Index_iteminfo_itemtype` (`itemtype`,`isvalid`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 old stored procedure: CREATE DEFINER=`root`@`localhost` PROCEDURE `save_iteminfo`( pcharguid int, pguid int, pworld int, pserver int, pitemtype int, ppos smallint, pvisualid int, pmaxgemid int, pfixattr varchar(100), pp1 int, pp2 int, pp3 int, pp4 int, pp5 int, pp6 int, pp7 int, pp8 int, pp9 int, pp10 int, pp11 int, pp12 int, pp13 int, pp14 int, pp15 int, pp16 int, pp17 int, pisvalid smallint, pdbversion int, pcreator varchar(40), pvar varchar(40)) begin declare rguid int; declare rpos int; declare rdbversion int; declare sameid int; set sameid = -1; start transaction; select guid into sameid from t_iteminfo where world=pworld and server=pserver and guid=pguid and isvalid=1; if sameid<>-1 then update t_iteminfo set isvalid =0 where world=pworld and server=pserver and guid=pguid; end if; select charguid,pos,dbversion into rguid,rpos,rdbversion from t_iteminfo where charguid = pcharguid and pos=ppos limit 1; if rguid = pcharguid then update t_iteminfo set charguid = pcharguid, guid = pguid, world = pworld, server = pserver, itemtype = pitemtype, pos = ppos, visualid = pvisualid, maxgemid = pmaxgemid, fixattr = pfixattr, p1 = pp1, p2 = pp2, p3 = pp3, p4 = pp4, p5 = pp5, p6 = pp6, p7 = pp7, p8 = pp8, p9 = pp9, p10 = pp10, p11 = pp11, p12 = pp12, p13 = pp13, p14 = pp14, p15 = pp15, p16 = pp16, p17 = pp17, isvalid = pisvalid, dbversion = pdbversion, creator = pcreator, var = pvar where charguid=pcharguid and pos=ppos and rdbversion<=pdbversion; else insert into t_iteminfo(charguid,world,server,guid,itemtype, pos,visualid,maxgemid,fixattr,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16,p17, isvalid,dbversion,creator,var) values(pcharguid,pworld,pserver,pguid,pitemtype,ppos,pvisualid,pmaxgemid, pfixattr,pp1,pp2,pp3,pp4,pp5,pp6,pp7,pp8,pp9,pp10, pp11,pp12,pp13,pp14,pp15,pp16,pp17,pisvalid,pdbversion,pcreator,pvar); end if; commit; end new table struct: CREATE TABLE `t_iteminfo` ( `aid` bigint(20) NOT NULL auto_increment, `charguid` int(11) NOT NULL, `guid` int(11) NOT NULL, `world` int(11) NOT NULL, `server` int(11) NOT NULL, `itemtype` int(11) NOT NULL, `pos` smallint(6) NOT NULL, `p1` int(11) NOT NULL, `p2` int(11) NOT NULL, `p3` int(11) NOT NULL, `p4` int(11) NOT NULL, `p5` int(11) NOT NULL, `p6` int(11) NOT NULL, `p7` int(11) NOT NULL, `p8` int(11) NOT NULL, `p9` int(11) NOT NULL, `p10` int(11) NOT NULL, `p11` int(11) NOT NULL, `p12` int(11) NOT NULL, `p13` int(11) NOT NULL, `p14` int(11) NOT NULL, `p15` int(11) default '0', `p16` int(11) default '0', `p17` int(11) default '0', `creator` varchar(40) default '0', `isvalid` smallint(6) NOT NULL default '1', `dbversion` int(11) default '0', `fixattr` varchar(200) NOT NULL, `var` varchar(40) default '0', `visualid` int(11) NOT NULL default '0', `maxgemid` int(11) NOT NULL default '-1', PRIMARY KEY (`aid`), UNIQUE KEY `Index_it_charguid` (`charguid`,`pos`), KEY `Index_it_itemguid` (`guid`,`world`,`server`), KEY `Index_iteminfo_itemtype` (`itemtype`,`isvalid`) ) ENGINE=InnoDB AUTO_INCREMENT=6086726 DEFAULT CHARSET=latin1 new stored procedure: CREATE DEFINER=`root`@`localhost` PROCEDURE `save_iteminfo`( pcharguid int, pguid int, pworld int, pserver int, pitemtype int, ppos smallint, pvisualid int, pmaxgemid int, pfixattr varchar(100), pp1 int, pp2 int, pp3 int, pp4 int, pp5 int, pp6 int, pp7 int, pp8 int, pp9 int, pp10 int, pp11 int, pp12 int, pp13 int, pp14 int, pp15 int, pp16 int, pp17 int, pisvalid smallint, pdbversion int, pcreator varchar(40), pvar varchar(40)) begin declare rguid int; declare rpos int; declare raid bigint; declare rcount int default 0; start transaction; select aid,charguid,pos into raid,rguid,rpos from t_iteminfo where charguid = pcharguid and pos=ppos; if rguid = pcharguid then update t_iteminfo set charguid = pcharguid, guid = pguid, world = pworld, server = pserver, itemtype = pitemtype, pos = ppos, visualid = pvisualid, maxgemid = pmaxgemid, fixattr = pfixattr, p1 = pp1, p2 = pp2, p3 = pp3, p4 = pp4, p5 = pp5, p6 = pp6, p7 = pp7, p8 = pp8, p9 = pp9, p10 = pp10, p11 = pp11, p12 = pp12, p13 = pp13, p14 = pp14, p15 = pp15, p16 = pp16, p17 = pp17, isvalid = pisvalid, dbversion = pdbversion, creator = pcreator, var = pvar where aid=raid and dbversion<=pdbversion; select row_count() into rcount; if rcount > 0 then update t_iteminfo set isvalid=0 where guid=pguid and world=pworld and server=pserver and aid <> raid; end if; else insert into t_iteminfo(charguid,world,server,guid,itemtype, pos,visualid,maxgemid,fixattr,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16,p17, isvalid,dbversion,creator,var) values(pcharguid,pworld,pserver,pguid,pitemtype,ppos,pvisualid,pmaxgemid, pfixattr,pp1,pp2,pp3,pp4,pp5,pp6,pp7,pp8,pp9,pp10, pp11,pp12,pp13,pp14,pp15,pp16,pp17,pisvalid,pdbversion,pcreator,pvar); end if; commit; end