mysql存储过程加速

浏览:
字体:
发布时间:2013-12-20 16:18:25
来源:

首先看一个存储过程,这个存储过程是为了构造数据使用的。当然贴出来的存储过程简化了一些不必要的表结构。

CREATE PROCEDURE modifyRootEntry()BEGIN  DECLARE done INT DEFAULT FALSE;  DECLARE userId INT;    DECLARE userIdIter CURSOR FOR SELECT DISTINCT user_id from entries;   OPEN userIdIter;  read_loop: LOOP    FETCH userIdIter INTO userId;       IF done THEN      LEAVE read_loop;    END IF;	INSERT INTO entries (id, name, user_id, parent_id) VALUES(0, 'root_parent', userId, 0);	UPDATE entries SET parent_id=0 where user_id=userId AND name='file_root' AND parent_id is NULL;  END LOOP;  CLOSE userIdIter;END;
CREATE PROCEDURE modifyRootEntry()BEGIN  DECLARE done INT DEFAULT FALSE;  DECLARE userId INT;    DECLARE userIdIter CURSOR FOR SELECT DISTINCT user_id from entries;   START TRANSACTION; // here !  OPEN userIdIter;   	  read_loop: LOOP    FETCH userIdIter INTO userId;       IF done THEN      LEAVE read_loop;    END IF;	INSERT INTO entries (id, name, user_id, parent_id) VALUES(0, 'root_parent', userId, 0);	UPDATE entries SET parent_id=0 where user_id=userId AND name='file_root' AND parent_id is NULL;  END LOOP;  CLOSE userIdIter;  COMMIT;// here !END;
UPDATE entries SET parent_id=0 where user_id=userId AND name='file_root' AND parent_id is NULL;
CREATE PROCEDURE modifyRootEntry()BEGIN  DECLARE done INT DEFAULT FALSE;  DECLARE userId INT;    DECLARE userIdIter CURSOR FOR SELECT DISTINCT user_id from entries;   START TRANSACTION; // here !  OPEN userIdIter;   	  read_loop: LOOP    FETCH userIdIter INTO userId;       IF done THEN      LEAVE read_loop;    END IF;	INSERT INTO entries (id, name, user_id, parent_id) VALUES(0, 'root_parent', userId, 0);	  END LOOP;  UPDATE entries SET parent_id=0 where user_id=userId AND name='file_root' AND parent_id is NULL; // here!  CLOSE userIdIter;  COMMIT;// here !END;
 CREATE PROCEDURE pFastCreateNums (cnt INT UNSIGNED)BEGINDECLARE s INT UNSIGNED DEFAULT 1;TRUNCATE TABLE Nums;INSERT INTO Nums SELECT s;WHILE s*2 <= cnt DOBEGININSERT INTO Nums SELECT a+s FROM Nums;SET s = s*2;END;END WHILE;END;
>更多相关文章
24小时热门资讯
24小时回复排行
资讯 | QQ | 安全 | 编程 | 数据库 | 系统 | 网络 | 考试 | 站长 | 关于东联 | 安全雇佣 | 搞笑视频大全 | 微信学院 | 视频课程 |
关于我们 | 联系我们 | 广告服务 | 免责申明 | 作品发布 | 网站地图 | 官方微博 | 技术培训
Copyright © 2007 - 2024 Vm888.Com. All Rights Reserved
粤公网安备 44060402001498号 粤ICP备19097316号 请遵循相关法律法规
');})();