Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsDiscussion Forum → [Tech] stupid MySQL optimization question
[Tech] stupid MySQL optimization question
2008-12-18, 5:22 PM #1
I feel stupid for asking this, but

Say I have a table with a massive number of entries (for example, 10000). Say this table has a column that has at least 5000 unique values in it.

Code:
id    | ... | value| ...
----------------------------
0     | ... | 5231 | ...
1     | ... | 1603 | ...  
.     |     |      |
.     |     |      |
.     |     |      |
10000 | ... | 4614 | ...
I have a list of specific values for the "value" column somewhere else.
Code:
1524
5614
5231
.
.
.
I want to select all the rows in the table that contain a value that matches ANY ENTRY in that list.

Would it be better to simply select EVERYTHING from this massive table and then loop through the resulting array and find the correct rows with PHP, or to use a massively long SELECT statement such as

SELECT * from massive_table where value like "1524" OR value like "5614" ... OR value like ...

...that specifies every entry in the list of values, thereby decreasing the number of rows returned? The latter approach would have me using a PHP loop all the same, but to form the query rather than to process the array.


My brain is fried and I feel like I'm missing something / there must be a less stupid way to do this. I readily admit this is stupid. Any help? >_<
一个大西瓜
2008-12-18, 5:24 PM #2
SELECT * FROM massive_table WHERE column IN(1524,5614,2345,13215)

is that what you are talking about?
"Nulla tenaci invia est via"
2008-12-18, 5:40 PM #3
Ah thanks Zan -- that is what I was looking for ... do you know if it's as fast / faster than using UNIONs with a ton of select statements?

For instance

SELECT * from massive_table where value = 1524
UNION
SELECT * from massive_table where value = 5614

etc

(I just looked it up in the manual and it said you lose the index speed advantage if you use OR ...)

Edit: nvm got what I needed, thanks
一个大西瓜

↑ Up to the top!