This is a question that I never received a definitive answer. I am using MySQL in this example.
Given a fairly large set of values (say, 500). Faster looking for a table using these values with the IN () clause:
SELECT * FROM table WHERE field IN(values)
Or creating a temporary table in memory, filling it with values and attaching them to the desired table:
CREATE TEMPORARY TABLE `temp_table` (`field` varchar(255) NOT NULL) ENGINE=MyISAM DEFAULT CHARSET=latin1; INSERT INTO temp_table VALUES (values) SELECT * FROM table t1 JOIN temp_table t2 ON t1.field = t2.field
Both methods will create the same result set.
I did some of my own tests of the basic test and found that when working with more than 500 values, it becomes faster to use a temporary table than the IN () clause.
Can someone explain to me the inner workings of MySQL and what is the correct answer to this question?
Thanks Leo
source share