The following MySql update state seems to take too long to complete a set of records (~ 5000 records). It takes an average of 12 seconds to complete the update instruction. I am currently planning to launch this calculation on 5 different periods and about 500 different characters. This translates to 12 seconds * 5 calculations * 500 characters = 30,000 seconds or 8..33 hours.
Update operation:
UPDATE tblStockDataMovingAverages_AAPL JOIN (SELECT t1.Sequence, ( SELECT AVG(t2.Close) FROM tblStockDataMovingAverages_AAPL AS t2 WHERE (t1.Sequence - t2.Sequence)BETWEEN 0 AND 7 )AS "8SMA" FROM tblStockDataMovingAverages_AAPL AS t1 ORDER BY t1.Sequence) AS ma_query ON tblStockDataMovingAverages_AAPL.Sequence = ma_query.Sequence SET tblStockDataMovingAverages_AAPL.8MA_Price = ma_query.8SMA
Table design:
CREATE TABLE `tblStockDataMovingAverages_AAPL` ( `Symbol` char(6) NOT NULL DEFAULT '', `TradeDate` date NOT NULL DEFAULT '0000-00-00', `Sequence` int(11) DEFAULT NULL, `Close` decimal(18,5) DEFAULT NULL, `200MA_Price` decimal(18,5) DEFAULT NULL, `100MA_Price` decimal(18,5) DEFAULT NULL, `50MA_Price` decimal(18,5) DEFAULT NULL, `20MA_Price` decimal(18,5) DEFAULT NULL, `8MA_Price` decimal(18,5) DEFAULT NULL, `50_200_Cross` int(5) DEFAULT NULL, PRIMARY KEY (`Symbol`,`Sequence`), KEY `idxSequnce` (`Sequence`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1$$
Any help on speeding up the process is welcome.
Result of selection Explanation:
id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 index NULL idxSymbol_Sequnce 11 NULL 5205 Using index; Using filesort 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5271 Using where
source share