Advertisement
Guest User

Untitled

a guest
May 6th, 2015
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. CREATE PROCEDURE `Cache_Network_Observations` ()
  2. BEGIN
  3.  
  4. -- Declare all variables
  5.  
  6. /* This cursor is hitting the view which should be returning a number of rows on the scale of ~5M+ records
  7. */
  8. DECLARE cursor1 CURSOR FOR
  9. SELECT * FROM usanpn2.vw_Network_Observation;
  10.  
  11. CREATE TABLE Cached_Network_Observation_Temp (observation_id int, name varchar(100), id int);
  12.  
  13. OPEN cursor1;
  14.  
  15. load_loop: loop
  16.  
  17. FETCH cursor1 INTO observation_id, id1, name1, id2, name2, id3, name3, gid1, gname1, gid2, gname2, gid3, gname3;
  18.  
  19. IF id1 IS NOT NULL THEN
  20. INSERT INTO usanpn2.Cached_Network_Observation_Temp values (observation_id, name1, id1);
  21. END IF;
  22.  
  23. -- some additional logic here, essentially just the same as the above if statement
  24.  
  25. END LOOP;
  26. CLOSE cursor1;
  27.  
  28. END
  29.  
  30. | 1076 | root | localhost | mydb | Query | 3253 | update | INSERT INTO usanpn2.Cached_Network_Observation values ( NAME_CONST('observation_id',2137912), NAME_ |
  31.  
  32. DECLARE done INT DEFAULT FALSE;
  33. DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
  34.  
  35. IF done THEN
  36. LEAVE load_loop;
  37. END IF;
  38.  
  39. INSERT INTO Cached_Network_Observation_Temp (observation_id, `name`, id)
  40. SELECT s.observation_id, s.name1 AS `name`, s.id1 AS id
  41. FROM usanpn2.vw_Network_Observation s
  42. WHERE s.id1 IS NOT NULL
  43.  
  44. INSERT INTO Cached_Network_Observation_Temp (observation_id, `name`, id)
  45.  
  46. SELECT s1.observation_id, s1.name1 AS `name`, s1.id1 AS id
  47. FROM usanpn2.vw_Network_Observation s1
  48. WHERE s1.id1 IS NOT NULL
  49.  
  50. UNION ALL
  51.  
  52. SELECT s2.observation_id, s2.name2 AS `name`, s2.id2 AS id
  53. FROM usanpn2.vw_Network_Observation s2
  54. WHERE s2.id2 IS NOT NULL
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement