4

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 while the second one only 10 records.

The duration of the execution of this query is more than 5 seconds:

SELECT * FROM test_sample 
INNER JOIN new_table 
ON test_sample.idtest_sample = new_table.idnew_table

while this query is executed immediately (less than 0.001 second):

SELECT * FROM test_sample 
WHERE test_sample.idtest_sample IN 
('3','1597','25963','170596','196485',
'545963','999999','1265896','1569485','1999999')

Why the first query takes so long?

4

2 に答える 2