Hello, everyone.
I need some help with some people who can do query optimization.
We have in the mythconverg database, a program table, which contains for lack of a better term, the Electronic Program Guide (EPG)...
This is being read into a data grid source as a single query, that gets the active program on every channel.
SELECT chanid, title, starttime, endtime, seriesid, programid FROM program WHERE starttime < '2009-06-21 10:52:10' AND endtime>'2009-06-21 10:52:10';
which outputs, for me, an example table:
mysql> SELECT chanid, title, starttime, endtime, seriesid, programid FROM program WHERE starttime < '2009-06-21 10:52:10' AND endtime>'2009-06-21 10:52:10';
+--------+--------------------------------------------------------------+---------------------+---------------------+------------+----------------+
| chanid | title | starttime | endtime | seriesid | programid |
+--------+--------------------------------------------------------------+---------------------+---------------------+------------+----------------+
| 2226 | Dr. G: Medical Examiner | 2009-06-21 10:00:00 | 2009-06-21 11:00:00 | EP00666611 | EP006666110047 |
| 2260 | Monmouth Replay Show | 2009-06-21 10:30:00 | 2009-06-21 11:00:00 | EP00924108 | SH009241080000 |
| 2542 | Pop Latino | 2009-06-21 10:00:00 | 2009-06-21 12:00:00 | EP00672118 | SH006721180000 |
| 2266 | ATP Tennis | 2009-06-21 08:30:00 | 2009-06-21 11:00:00 | EP00554477 | EP005544772067 |
| 2041 | Sunday Housecall With Dr. Rosenfeld | 2009-06-21 10:30:00 | 2009-06-21 11:00:00 | EP01135543 | SH011355430000 |
| 1481 | Ed Young TV | 2009-06-21 10:30:00 | 2009-06-21 11:00:00 | EP00711915 | SH007119150000 |
| 1381 | Phantom Gourmet | 2009-06-21 10:30:00 | 2009-06-21 11:00:00 | EP00604850 | EP006048500756 |
.... some bits removed ......
| 2009-06-21 11:00:00 | EP00115044 | SH001150440000 |
| 2234 | Turning Point | 2009-06-21 10:30:00 | 2009-06-21 11:00:00 | EP00370169 | SH003701690000 |
| 2452 | Filthy's Ass Obsession 2 | 2009-06-21 10:30:00 | 2009-06-21 12:00:00 | | MV002404910000 |
| 2039 | MythBusters | 2009-06-21 10:00:00 | 2009-06-21 11:00:00 | EP00557678 | EP005576780023 |
| 2501 | Sounds of the Seasons | 2009-06-21 10:00:00 | 2009-06-21 12:00:00 | EP00875092 | SH008750920000 |
| 2868 | Tropic Thunder | 2009-06-21 09:30:00 | 2009-06-21 11:35:00 | | MV002367310000 |
+--------+--------------------------------------------------------------+---------------------+---------------------+------------+----------------+
323 rows in set (0.00 sec)
This query, uncached, takes 26 seconds.
UGH.
the EXPLAIN SELECT makes this even more apparent:
mysql> EXPLAIN SELECT chanid, title, starttime, endtime, seriesid, programid FROM program WHERE starttime < '2009-06-21 10:52:10' AND endtime>'2009-06-21 10:52:10';
+----+-------------+---------+------+-------------------------------------------------------+------+---------+------+--------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+---------+------+-------------------------------------------------------+------+---------+------+--------+-------------+
| 1 | SIMPLE | program | ALL | endtime,starttime,program_start_time,program_end_time | NULL | NULL | NULL | 158575 | Using where |
+----+-------------+---------+------+-------------------------------------------------------+------+---------+------+--------+-------------+
WTF?!
(pay no attention to the program_foo keys that I added, i was trying to force the issue!)
the EXPLAIN program:
mysql> explain program;
+-------------------------+-------------------------------------------------------------------+------+-----+---------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------------------+-------------------------------------------------------------------+------+-----+---------------------+-------+
| chanid | int(10) unsigned | NO | PRI | 0 | |
| starttime | datetime | NO | PRI | 0000-00-00 00:00:00 | |
| endtime | datetime | NO | MUL | 0000-00-00 00:00:00 | |
| title | varchar(128) | NO | MUL | | |
| subtitle | varchar(128) | NO | | | |
| description | text | NO | | NULL | |
| category | varchar(64) | NO | | | |
| category_type | varchar(64) | NO | | | |
| airdate | year(4) | NO | | 0000 | |
| stars | float | NO | | 0 | |
| previouslyshown | tinyint(4) | NO | MUL | 0 | |
| title_pronounce | varchar(128) | NO | MUL | | |
| stereo | tinyint(1) | NO | | 0 | |
| subtitled | tinyint(1) | NO | | 0 | |
| hdtv | tinyint(1) | NO | | 0 | |
| closecaptioned | tinyint(1) | NO | | 0 | |
| partnumber | int(11) | NO | | 0 | |
| parttotal | int(11) | NO | | 0 | |
| seriesid | varchar(40) | NO | MUL | | |
| originalairdate | date | YES | | NULL | |
| showtype | varchar(30) | NO | | | |
| colorcode | varchar(20) | NO | | | |
| syndicatedepisodenumber | varchar(20) | NO | | | |
| programid | varchar(40) | NO | MUL | | |
| manualid | int(10) unsigned | NO | PRI | 0 | |
| generic | tinyint(1) | YES | | 0 | |
| listingsource | int(11) | NO | | 0 | |
| first | tinyint(1) | NO | | 0 | |
| last | tinyint(1) | NO | | 0 | |
| audioprop | set('STEREO','MONO','SURROUND','DOLBY','HARDHEAR','VISUALIMPAIR') | NO | | NULL | |
| subtitletypes | set('HARDHEAR','NORMAL','ONSCREEN','SIGNED') | NO | | NULL | |
| videoprop | set('HDTV','WIDESCREEN','AVC') | NO | | NULL | |
+-------------------------+-------------------------------------------------------------------+------+-----+---------------------+-------+
32 rows in set (0.00 sec)
.....
What's going on, here? this one is an interesting critical query problem, because the fact that the query takes over 26 seconds is enough to cause Orbiter to deadlock and time out, thinking that something has frozen.
Any ideas, fellas?
-Thom