I have got a MySQL database table, that has the following form:
CREATE TABLE IF NOT EXISTS data_packet (
id BIGINT NOT NULL AUTO_INCREMENT,
time_received BIGINT NOT NULL,
content TEXT NOT NULL,
recording_id INT NOT NULL,
PRIMARY KEY (id),
INDEX fk_data_packet_recording_idx (recording_id ASC),
CONSTRAINT fk_data_packet_recording
FOREIGN KEY (recording_id)
REFERENCES recording(id)
)
Inside this table I have got data like this:
<Dat url="vehicleSpeed">
<Abs name="speed" val="97"/>
<Enm name="unit" val="kmh"/>
<Enm name="state" val="valid"/>
</Dat>
The table can contain up to 1.000.000 rows. Now I have got queries like the one following, to select special data packets with a certain url. Every data packet has such a url attribute.
SELECT *
FROM data_packet
WHERE recording_id = 1
AND content LIKE '%vehicleSpeed%'
AND time_received BETWEEN 1435843095338 AND 1435843095996
ORDER BY time_received ASC;
I think this constellation can be optimized. In MySQL workbench this query takes 47ms where the table only contains about 35.000 rows. A Java application shall execute the queries later and I noticed, that it takes more time to execute it via the JDBC.
What optimization can you recommend? Index? Another column? Another table?
Thank you very much.