I have a table with 3 columns: submission_id, column_id, data. Each submission_id has 25 columns and data values.
I have a page that displays all submissions where column_id = 16 and data = ('' or 0). To get this, I use a subquery to get all the distinct submission_id's that I need, and then I get all columns in the main query. My query is:
SELECT sid,cid,data FROM webform_submitted_data WHERE sid in(select distinct sid from webform_submitted_data where cid=16 and data in (' ',0)) ORDER BY sid ASC
The table is getting large, and the query now takes 30-40 seconds when run from PHP, (though only 1.0e-6 seconds from MYSQL) It is not PHP overhead, I checked using the mysqld-slow.log file, I get the following: <-- # Query_time: 32.975552 Lock_time: 0.000138 Rows_sent: 108 Rows_examined: 177396 -->
I also tried running an explain in PHP ![explain]:(https://i.stack.imgur.com/3U2e5.png)
One more thing, this page updates the current submission and puts an ID value in column_id 16, which takes it off of the page when it reloads. Reloads without an update take less than a second, but when we need to update 100 records, it rebuilds the cache every time.
Any thoughts would be greatly appreciated.