title: Mysql Cursor not sorting result in correct order
body: <p>This is an abstraction of my original code as it´ll be easier to read for you guys.</p>
  
  <p>I´m new to Mysql Storage procedures and from Cursors.</p>
  
  <p>Whats happening is that Cursor is not bringing the results properly sorted as I set the ORDER BY instruction on the query.</p>
  
  <p>Here´s all the structure and data for the tables to reproduce the issue.</p>
  
  <p>Log Table :</p>
  
  <pre><code>    DROP TABLE IF EXISTS `log`;
      CREATE TABLE `log` (
        `key` text NOT NULL,
        `value` text NOT NULL
      ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  </code></pre>
  
  <p>Test Table :</p>
  
  <pre><code>    DROP TABLE IF EXISTS `test1`;
      CREATE TABLE `test1` (
        `ID` bigint(8) unsigned NOT NULL AUTO_INCREMENT,
        `price` float(16,8) NOT NULL,
        PRIMARY KEY (`ID`),
        KEY `price` (`price`)
      ) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=latin1;
  </code></pre>
  
  <p>Test table data :</p>
  
  <pre><code>    INSERT INTO `test1` (`price`)
      VALUES (100),(200),(300),(400),(300),(200),(100);
  </code></pre>
  
  <p>Query:</p>
  
  <pre><code>    SELECT *
      FROM `test1`
      ORDER BY price DESC;
  </code></pre>
  
  <p>Expected results works fine with query directly:</p>
  
  <ul>
  <li>4 - 400.00000000</li>
  <li>5 - 300.00000000</li>
  <li>3 - 300.00000000</li>
  <li>6 - 200.00000000</li>
  <li>2 - 200.00000000</li>
  <li>7 - 100.00000000</li>
  <li>1 - 100.00000000</li>
  </ul>
  
  <p>Stored Procedure</p>
  
  <pre><code>    DROP PROCEDURE IF EXISTS `test_proc1`;
      DELIMITER ;;
  
      CREATE DEFINER=`root`@`localhost` PROCEDURE `test_proc1`()
      BEGIN
  
        DECLARE done INT DEFAULT 0;
        DECLARE ID BIGINT(8);
        DECLARE price FLOAT(16,8);
  
        DECLARE cur1 CURSOR FOR
        SELECT * FROM `test1` ORDER BY price DESC; #Exact Query
  
        DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
  
        START TRANSACTION;
          OPEN cur1;
          #Cleaning log
          TRUNCATE `log`;
          read_loop:
          LOOP
            FETCH cur1 INTO ID,price;
            IF done = 1 THEN
              LEAVE read_loop;
            END IF;
            #Inserting data to log
            INSERT INTO `log`
            VALUES (ID,price);
          END LOOP read_loop;
  
          CLOSE cur1;
        COMMIT;
  
      #Bring log for result
      SELECT * FROM log;
  
      END;;
      DELIMITER ;
  </code></pre>
  
  <p>Call procedure</p>
  
  <pre><code>    CALL test_proc1();
  </code></pre>
  
  <p>The CURSOR has exactly the same query as I posted at the top, you can check that on the Stored Procedure. But when I loop through it, I get another order.</p>
  
  <ul>
  <li>15   100.00000000</li>
  <li>21   100.00000000</li>
  <li>16   200.00000000</li>
  <li>20   200.00000000</li>
  <li>17   300.00000000</li>
  <li>19   300.00000000</li>
  <li>18   400.00000000</li>
  </ul>
  
  <p>Whats going on? Can somebody help me on this?
  I also tried nesting the query like this with no fix at all.</p>
  
  <pre><code>SELECT * FROM(
  SELECT *
  FROM `test1`
  ORDER BY price DESC) AS tmp_tbl
  </code></pre>