title: MySQL Stored Procedure Insert Hanging
body: <p>What I'm trying to do is write a stored procedure that will query a view, process each row and and make one or more inserts into a table for each row pulled from the view. Everything seems fine, except for the fact that, arbitrarily, mid-point during the process, the server seems to hang on the insert command. I have no idea if there's some memory limit on cursor results sets, or what could be happening. Relevant parts of the SP and a few clarifying comments posted below.</p>
  
  <pre><code>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
  </code></pre>
  
  <p>That being the SP, when I actually run it, everything goes off without a hitch until the process runs and runs and runs. Taking a look at the active query report, I am seeing this:</p>
  
  <pre><code>| 1076 | root    | localhost                              | mydb | Query   | 3253 | update | INSERT INTO usanpn2.Cached_Network_Observation values ( NAME_CONST('observation_id',2137912),  NAME_ |
  </code></pre>
  
  <p>Not positive where the NAME_CONST function is coming from or what that has to do with anything. I've tried this multiple times, the observation_id variable / row in the view varies each time, so it doesn't seem to be anything tied to the record.</p>
  
  <p>TIA!</p>