EXPLAIN ANALYZE
SELECT  m.machine_id as machine_id, s.timestamp, s.errorcode as errorcode
FROM events m
INNER JOIN spsdata_2012m08 as s ON (
	  	   m.machine_id=s.machine_id AND 
		   s.timestamp > (m.timestamp - interval '30 seconds')
		   AND 
		   s.timestamp <= m.timestamp)
WHERE
	m.timestamp BETWEEN '2012-08-10' AND '2012-08-30'
AND 
    m.code = '2024'
AND 
    s.errorcode = '2024';

