I am having an issue querying a couple of MySQL VIEWS.
The MySQL tables are generated hourly from a process that pulls data from a central Oracle database. Once the update is complete, a query automatically updates the VIEWS. (I do believe this is standard. I could be wrong).
At this point, I am using PHP to query said VIEWS to return data to the page. This is where my problem begins.
When the query begins, it can take well over 30 seconds to return 4 records. The VIEW contains no more than 30K records. But when I try to return a larger data set to the page, it now causes the server to freeze.
The query from my PHP script is very simple. It is looking like the following:
SELECT
DISCHARGE_ETA,
TERMINAL_DISCH,
IMPORT_RAMP,
ORIG_RAMP_FINAL_DEST_ETA,
POOL_LOCATION_FROM_IMP,
POOL_LOCATION_TO_IMP,
ROAD_HAULIER_IMP
// few more columns
FROM
view1
WHERE
" . $_SESSION['where'] . ";
I am using jQuery to send parameters over to the PHP script. PHP then builds the query by plugging all the parameters into the WHERE clause. The data is then returned via JSON.
The query that builds the actual VIEW in MySQL is a little more intense (currently not shown here).
My question is: are VIEWS the best route in retrieving the data I need?
I was thinking it would seem easier to query a TABLE instead of a VIEW. Perhaps the same hourly process that is updating the VIEWS could instead update a single TABLE. That way, I could query the TABLE instead of the VIEW.
Would this be the best bet? If not, are there any alternatives?
Edit
Here is the results from EXPLAIN