I have a table with 2.4M+ rows, and no indexes. I am 100% sure all the rows have one column (we’ll call this id) that is unique, it is of type VARCHAR(255).
I now have a file of approximately 10,000 id‘s and need to pull the entire row for each.
Is using IN(...) my best option? Should I add an index?
I was thinking for some thinking of something like this:
SELECT * FROM archive_table WHERE id IN('id1', 'id2', ... 'idn');
This is effectively archived data and only accessed by me every few weeks.
System: MySQL 5.0.45
Table: MyISAM
Yes, add an index over both tables (2.4mil and 10,000).
Assuming transaction_table is 10,000 rows, archive_table is 2.4mil rows and you’ve built an index overr archive_table you could code:
Using an EXISTS clause over a JOIN is more readable and has the same performance as the join.