Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE PROCEDURE `Cache_Network_Observations` ()
- BEGIN
- -- Declare all variables
- /* This cursor is hitting the view which should be returning a number of rows on the scale of ~5M+ records
- */
- DECLARE cursor1 CURSOR FOR
- SELECT * FROM usanpn2.vw_Network_Observation;
- CREATE TABLE Cached_Network_Observation_Temp (observation_id int, name varchar(100), id int);
- OPEN cursor1;
- load_loop: loop
- FETCH cursor1 INTO observation_id, id1, name1, id2, name2, id3, name3, gid1, gname1, gid2, gname2, gid3, gname3;
- IF id1 IS NOT NULL THEN
- INSERT INTO usanpn2.Cached_Network_Observation_Temp values (observation_id, name1, id1);
- END IF;
- -- some additional logic here, essentially just the same as the above if statement
- END LOOP;
- CLOSE cursor1;
- END
- | 1076 | root | localhost | mydb | Query | 3253 | update | INSERT INTO usanpn2.Cached_Network_Observation values ( NAME_CONST('observation_id',2137912), NAME_ |
- DECLARE done INT DEFAULT FALSE;
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
- IF done THEN
- LEAVE load_loop;
- END IF;
- INSERT INTO Cached_Network_Observation_Temp (observation_id, `name`, id)
- SELECT s.observation_id, s.name1 AS `name`, s.id1 AS id
- FROM usanpn2.vw_Network_Observation s
- WHERE s.id1 IS NOT NULL
- INSERT INTO Cached_Network_Observation_Temp (observation_id, `name`, id)
- SELECT s1.observation_id, s1.name1 AS `name`, s1.id1 AS id
- FROM usanpn2.vw_Network_Observation s1
- WHERE s1.id1 IS NOT NULL
- UNION ALL
- SELECT s2.observation_id, s2.name2 AS `name`, s2.id2 AS id
- FROM usanpn2.vw_Network_Observation s2
- WHERE s2.id2 IS NOT NULL
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement