I am trying to create an event in mysql
Schema :
create event alert_2 ON SCHEDULE EVERY 300 SECOND DO
BEGIN
DECLARE current_time DATETIME;
DECLARE attempted INT;
DECLARE completed INT;
DECLARE calc_value DECIMAL;
set @current_time = CONVERT_TZ(NOW(), @@session.time_zone, '+0:00');
select count(uniqueid) as @attempted,SUM(CASE WHEN seconds > 0 THEN 1 ELSE 0 END) as @completed from callinfo where date >= DATE_SUB(@current_time, INTERVAL 300 SECOND) AND date <= @current_time;
SET @calc_value = (ROUND((@completed/@attempted)*100,2);
IF @calc_value <= 10.00 THEN
INSERT INTO report(value1) value (@calc_value);
END IF;
END;
Problem : Event is not going to creating
Need suggestion :
Is this create any overload on callinfo table ?
If yes,Would you like to suggest any other way to achieve same thing ?
May i create similar but multiple around 50.Will it create huge load on call info table.
Call info schema :
CREATE TABLE `callinfo` ( `uniqueid` varchar(60) NOT NULL DEFAULT '', `accountid` int(11) DEFAULT '0', `type` tinyint(1) NOT NULL DEFAULT '0', `callerid` varchar(120) NOT NULL, `callednum` varchar(30) NOT NULL DEFAULT '', `seconds` smallint(6) NOT NULL DEFAULT '0', `trunk_id` smallint(6) NOT NULL DEFAULT '0', `trunkip` varchar(15) NOT NULL DEFAULT '', `callerip` varchar(15) NOT NULL DEFAULT '', `disposition` varchar(45) NOT NULL DEFAULT '', `date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `debit` decimal(20,6) NOT NULL DEFAULT '0.000000', `cost` decimal(20,6) NOT NULL DEFAULT '0.000000', `provider_id` int(11) NOT NULL DEFAULT '0', `pricelist_id` smallint(6) NOT NULL DEFAULT '0', `package_id` int(11) NOT NULL DEFAULT '0', `pattern` varchar(20) NOT NULL, `notes` varchar(80) NOT NULL, `invoiceid` int(11) NOT NULL DEFAULT '0', `rate_cost` decimal(20,6) NOT NULL DEFAULT '0.000000', `reseller_id` int(11) NOT NULL DEFAULT '0', `reseller_code` varchar(20) NOT NULL, `reseller_code_destination` varchar(80) DEFAULT NULL, `reseller_cost` decimal(20,6) NOT NULL DEFAULT '0.000000', `provider_code` varchar(20) NOT NULL, `provider_code_destination` varchar(80) NOT NULL, `provider_cost` decimal(20,6) NOT NULL DEFAULT '0.000000', `provider_call_cost` decimal(20,6) NOT NULL, `call_direction` enum('outbound','inbound') NOT NULL, `calltype` enum('STANDARD','DID','FREE','CALLINGCARD') NOT NULL DEFAULT 'STANDARD', `profile_start_stamp` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `answer_stamp` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `bridge_stamp` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `progress_stamp` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `progress_media_stamp` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `end_stamp` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `billmsec` int(11) NOT NULL DEFAULT '0', `answermsec` int(11) NOT NULL DEFAULT '0', `waitmsec` int(11) NOT NULL DEFAULT '0', `progress_mediamsec` int(11) NOT NULL DEFAULT '0', `flow_billmsec` int(11) NOT NULL DEFAULT '0', `is_recording` tinyint(1) NOT NULL DEFAULT '1' COMMENT '0 for On,1 for Off' ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='callinfo'; ALTER TABLE `callinfo` ADD UNIQUE KEY `uniqueid` (`uniqueid`), ADD KEY `user_id` (`accountid`);
More Information about callinfo table :
In call info table around 20K/hour rercords are inserted. Please suggest ,If need to apply any indexing in schema to get good performance.
DELIMITERstatement before creating it?