首頁 > 資料庫 > mysql教程 > mysql存储过程加速_MySQL

mysql存储过程加速_MySQL

WBOY
發布: 2016-06-01 13:26:48
原創
969 人瀏覽過

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 <= cnt DOBEGININSERT INTO Nums SELECT a+s FROM Nums;SET s = s*2;END;END WHILE;END;
登入後複製
bitsCN.com
相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板