Hello everyone, I’m having a lot of problem with this query that runs much too slow.
The table contains about 120 000 records and the query is returning 150 results.
Removing the distinct does not really help increase the speed and without it the query returns 1500 results.
The query takes about 10 seconds to execute.
Strange thing is that increasing the available ram (the mysql server is running on a vmware server) from 1Gb to 3Gb the query was even more slow (taking about 25 seconds).
I have tried many different index without good results.
At this point I’m not sure if the problem is with the query or the MySQL server configuration. Mysql version is 4.1.20.
Any help is greatly appreciated,
Regards
Carol
select distinct q1.timestamp as timestamp,
q1.agent_channel as agent_channel,
q1.event as event, q2.event_parameter1 as agent
from queue_logs q1, queue_logs q2
where (q1.timestamp >= ‘1184413563’ and
q1.timestamp < ‘1184499963’ and
q2.timestamp >= ‘1184413563’ and
q2.timestamp < ‘1184499963’) and
(
(
(q1.event = ‘PAUSE’ or
q1.event = ‘UNPAUSE’ or
q1.event = ‘AGENTLOGOFF’) and
q1.agent_channel = q2.agent_channel and
q2.event = ‘AGENTLOGIN’ and
q2.timestamp =
(
select max(q3.timestamp)
from queue_logs q3
where q3.timestamp >= ‘1184413563’ and
q3.timestamp < ‘1184499963’ and
q3.timestamp < q1.timestamp and
q3.event = ‘AGENTLOGIN’ and
q3.agent_channel = q1.agent_channel
)
)
or (q1.event = ‘AGENTLOGIN’ and q1.id = q2.id)
)
EXPLAIN
id 1
select_type PRIMARY
table q1
type range
possible_keys PRIMARY,ql_t_index,ql_eat_index,ql_e_index,ql_ea_index
key ql_t_index
key_len 4
ref NULL
rows 1996
Extra Using where; Using temporary
id 1
select_type PRIMARY
table q2
type range
possible_keys PRIMARY,ql_t_index,ql_eat_index,ql_e_index,ql_ea_index ql_t_index
key ql_t_index
key_len 4
ref NULL
rows 1996
Extra Using where
id 2
select_type DEPENDENT SUBQUERY
table q3
type range
possible_keys ql_t_index,ql_eat_index,ql_e_index,ql_ea_index ql_e_index
key ql_e_index
key_len 56
ref NULL
rows 810
Extra Using where
CREATE TABLE queue_logs
(
id
int(11) NOT NULL auto_increment,
timestamp
int(10) unsigned NOT NULL default ‘0’,
call_identifier
tinytext,
queue_name
tinytext,
agent_channel
tinytext,
event
text NOT NULL,
event_parameter1
tinytext,
event_parameter2
tinytext,
event_parameter3
tinytext,
PRIMARY KEY (id
),
KEY ql_t_index
(timestamp
),
KEY ql_eat_index
(event
(18),agent_channel
(12),timestamp
),
KEY ql_e_index
(event
(18)),
KEY ql_ea_index
(event
(18),agent_channel
(12))
) ENGINE=MyISAM DEFAULT CHARSET=utf8;