I'm trying to find the gaps in temporal data, but the problem is my data is not a fixed interval sequence, so I think I cannot use this solution: How to find gaps in sequential numbering in mysql?
My temporal data is in milliseconds (bigint), normally there is at least one value every second, so I was thinking in something like:
SELECT *
FROM mytable AS t1
LEFT JOIN mytable AS t2 ON t2.time > t1.time AND (t2.time - t1.time) < 1000
WHERE t2.id IS NULL
ORDER BY t1.time ASC
LIMIT 100
But that query is taking forever (my table has more than 100M records).
Is there any faster solution? // MySQL version 5.7.14
I've also found this: MySQL / MariaDB: how to find gaps in timebased data? but is using multiple subselects which I think will be even slower
MCRE:
CREATE TABLE `test` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`time` bigint(20) unsigned NOT NULL,
PRIMARY KEY (`id`),
KEY `TIME` (`time`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
INSERT INTO test (time) VALUES
(10), (30), (50), (60), (65), (100), (150), (200), (350), (1000), (2500), (2600), (2660), (2700), (2800), (3000), (3500), (5000), (5100), (5150);