欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

mysql存储过程加速_MySQL

程序员文章站 2022-06-12 12:26:18
...
bitsCN.com

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

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 						bitsCN.com
相关标签: mysql