title: A procedure or a loop
body: <p>I've a table named <code>messages</code> where users of my local hub store their messages(kind of like a web-forums). Currently, a majority of users are participating and I get nearly 30 to 50 new entries to my table everyday.</p>
  
  <p>Since this has been going on for past few years, we've got nearly 100,000 rows of data in table. The table structure is kind of <a href="http://www.hastebin.com/xerupepaku.sql" rel="nofollow">like this</a>. Where <code>fid</code> is the <code>PRIMARY</code> and <code>ip</code> and <code>id</code>(nickname) are just <code>INDEX</code>.</p>
  
  <p>I was using <a href="http://www.hastebin.com/cigimaxine.sql" rel="nofollow">this kind of query uptil now</a>; and then iterating the resultset in <a href="http://math2.org/luasearch/luasql.html#iterator_use" rel="nofollow">luasql as shown in this link</a>. This, according to me, consumes a lot of time and space(in buffers).</p>
  
  <pre><code>`msg` VARCHAR(280) NOT NULL,
  `id` VARCHAR(30) NOT NULL,
  `ctg` VARCHAR(10) NOT NULL,
  `date` DATE NOT NULL COMMENT 'date_format( %m/%d/%y )',
  `time` TIME NOT NULL COMMENT 'date_format( %H:%i:%s )',
  `fid` BIGINT(20) NOT NULL AUTO_INCREMENT,
  `ip` CHAR(39) NOT NULL DEFAULT '127.0.0.1'
  </code></pre>
  
  <p>My problem is that now-a-days, we've switched to new API of <strong>PtokaX</strong> and the number of requests to read and write have increased dramatically. Since, I recently read about MySQL procedures, I was thinking if these procedures are a <em>faster</em> <strong>or</strong> <em>safer</em> way of dealing with this situation.</p>
  
  <pre><code>SELECT *
  FROM ( SELECT *
      FROM `messages`
      ORDER BY `fid` DESC
      LIMIT 50 ) AS `temp`
  ORDER BY `fid` ASC;
  </code></pre>
  
  <h1>P.S.</h1>
  
  <p>We get around one request to read one message every 7 to 10 seconds on average. On weekends, it rises to around one every 3 seconds.</p>
  
  <p>Please let me know if anything more is required.</p>
  
  <hr>
  
  <h2>TO SUM UP</h2>
  
  <p>Is their a way that I can call a stored procedure and get the final result in a smaller time. Current query(and method) takes it nearly 3 seconds to fetch and organize the data.</p>