title: Using Stored Procedures in Rails
body: <p>As I said in a previous post, our Rails app has to interface with an E-A-V type of table in a third-party application that we're pulling data from.  I had created a View to make the data normal but it is taking way too long to run.  We had one of our offshore PHP developers create a stored procedure to help speed it up.</p>
  
  <p>Now we run into the issue that we need to call this stored procedure from the Rails app, as well as provide searching and filtering.  The view could do this because Rails was treating it as a traditional Rails model.  How could I do this with the stored proc?  Would we need to write custom searching and ordering (we were using Searchlogic)?  Management is incapable of understanding the drawbacks of using a stored proc from Rails; all they say is that the current method is taking too long to load the data and needs to be fixed, but searching and filtering are critical functions.</p>
  
  <p><strong>EDIT</strong> I posted the code for this query here: <a href="https://stackoverflow.com/questions/1944217/optimizing-a-strange-mysql-query/">Optimizing a strange MySQL Query</a>.  What is funny is that when I run this query in a GUI (Navicat) it runs in about 5 seconds, but on the web page it takes over a minute to run; the view is complicated for reasons I outline in the original post but I would think that MySQL optimizes and caches views like SQL Server does (or rather, how I read that SQL Server does) to improve performance.</p>