I have this query:
SELECT stringa FROM table WHERE stringb = 'x' OR stringb = 'y' OR stringb = 'z'
That's only a shortened version, the actual query has over 1,000 'OR' clauses in the one query.
It takes minutes to execute, which is no good.
I've tried doing one query at a time like so:
SELECT stringa FROM table WHERE stringb = 'x'
SELECT stringa FROM table WHERE stringb = 'y'
SELECT stringa FROM table WHERE stringb = 'z'
But that takes even longer. I also tried one big query like so:
SELECT stringa FROM table WHERE stringb = 'x'
UNION
SELECT stringa FROM table WHERE stringb = 'y'
UNION
SELECT stringa FROM table WHERE stringb = 'z'
But again that took even longer.
If anyone has any suggestions to increase performance it would be greatly appreciated. My table is MyISAM, if it's important.
Edit:
Here's the structure of the table:
Columns:
key (CHAR PRIMARY), stringa (CHAR), stringb (CHAR)
And the rows look like so: (key - stringa - stringb)
key - a - b
key - a - c
key - a - d
key - a - e
key - a - f
key - b - b
key - b - c
key - b - d
key - c - c
key - c - d
key - c - f
key - d - f
etc. etc. ..There are nearly a million rows.
I need to select all 'stringa' where 'stringb' equals a OR b OR c, etc.
Of course stringa and stringb aren't just 'a' and 'b', they contain CHARs of length varying between 3 - 80 characters.
I hope that helps in some way
SELECT column WHERE a in (SELECT valid_terms FROM other_table)? Or is each OR really on a different column with a single value? If it's the latter...something's not righta,bandcindexed? Show us the table and indexes definitions. We'll have a better chance of helping you.