I have two tables:
CREATE TABLE `test_sample` ( `idtest_sample` varchar(50) NOT NULL, `test_samplecol` varchar(45) DEFAULT NULL, UNIQUE KEY `idtest_sample_UNIQUE` (`idtest_sample`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8
and
CREATE TABLE `new_table` ( `idnew_table` int(11) NOT NULL, UNIQUE KEY `idnew_table_UNIQUE` (`idnew_table`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8
The first table contains 5 million records, and the second contains only 10 records.
The duration of this request is more than 5 seconds:
SELECT * FROM test_sample INNER JOIN new_table ON test_sample.idtest_sample = new_table.idnew_table
while this request is being executed immediately (less than 0.001 seconds):
SELECT * FROM test_sample WHERE test_sample.idtest_sample IN ('3','1597','25963','170596','196485', '545963','999999','1265896','1569485','1999999')
Why does the first request take so long?
source share