Monday, 15 July 2013

MySQL script optimization -



MySQL script optimization -

i have 2 mysql tables, graphics, rasp:

my query works, too slow (limit 1 200+ seconds, , 50 000 records).

i need select 2 records in 1 graphics (result record http://oi57.tinypic.com/2edbhvk.jpg):

- same graphics.`trainid` - same graphics.`date` - first record graphics.`stationid1` = rasp.`stationfrom` - first record graphics.`comment` near rasp.`from` (about +- 30 minutes) - sec record graphics.`stationid1` = rasp.`stationto` - sec record graphics.`comment` near rasp.`to` (about +- 30 minutes)

my query:

select r.num, r.from, r.to, g.id, g.comment, g.stationid1, g2.id, g2.comment, g2.stationid1 graphics g, graphics g2, rasp r abs(timestampdiff(minute,g.dt,concat(g.date,' ',r.from)))<30 , g2.id>g.id , g.stationid1=r.stationfrom , abs(timestampdiff(minute,g2.dt,concat(g2.date,' ',r.to)))<30 , g2.stationid2=r.stationto , g.date=g2.date , g.trainid=g2.trainid grouping g.date, g.comment limit 1

i tryed utilize joins, executes same time select.

i grateful help

mysql

No comments:

Post a Comment