I have got three tables whose data I need to join based on a common field.
sample pseudo table defs:
barometer_log(device ,pressure float,sampleTime timestamp)
temperature_log(device int,temperature float,sampleTime timestamp)
magnitude_log(device int, magnitude float,utcTime timestamp)
The tables each will contain billions of rows eventually but currently contain around 500,000 rows each.
I need to be able to combine data(FULL JOIN) from the tables to so that the sampleTime is merged as one column (COALESE) to give me rows as: device, sampleTime, pressure,temperature,magnitude
I need to be able to query data by specifying a device and start and end date, e.g. select .... where device=1000 and sampleTime between '2011-10-11' and '2011-10-17'
I tried different UNION ALL technique with RIGHT and LEFT joins as suggested in MySql full join (union) and ordering on multiple date columns and MySql full join (union) and ordering on multiple date columns , but the query takes too long and i have to stop it or throws error about temp file size after running for hours. What is the best way for me to query the three tables and merge their output in an acceptable time frame?
Here's the full table definition as suggested. note: device table hasn't been included .
magnitude_log
CREATE TABLE magnitude_log (
device int(11) NOT NULL,
magnitude float not NULL,
sampleTime timestamp NOT NULL,
PRIMARY KEY (device,sampleTime),
CONSTRAINT magnitudeLog_device
FOREIGN KEY (device)
REFERENCES device (id)
ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
barometer_log
CREATE TABLE barometer_log (
device int(11) NOT NULL,
pressure float not NULL,
sampleTime timestamp NOT NULL,
PRIMARY KEY (device,sampleTime),
CONSTRAINT barometerLog_device
FOREIGN KEY (device)
REFERENCES device (id)
ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
temperature_log
CREATE TABLE temperature_log (
device int(11) NOT NULL,
sampleTime timestamp NOT NULL,
temperature float default NULL,
PRIMARY KEY (device,sampleTime),
CONSTRAINT temperatureLog_device
FOREIGN KEY (device)
REFERENCES device (id)
ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;