I am having trouble getting this query to run faster:

SELECT * FROM t1 WHERE col1 = 'text' OR col2 = 'text';

Here is the output of the explain for that query

+-------+------+-------------------+------+---------+------+------+---------
---+
| table | type | possible_keys     | key  | key_len | ref  | rows | Extra
|
+-------+------+-------------------+------+---------+------+------+---------
---+
| users | ALL  | col1,col2 | NULL |    NULL | NULL | 1321 | where used |
+-------+------+-------------------+------+---------+------+------+---------
---+

Here is the "show index from t1":

+-------+------------+-------------+--------------+-------------+-----------
+-------------+----------+--------+---------+
| Table | Non_unique | Key_name    | Seq_in_index | Column_name | Collation
| Cardinality | Sub_part | Packed | Comment |
+-------+------------+-------------+--------------+-------------+-----------
+-------------+----------+--------+---------+
| users |          1 | col1_2     |            1 | col1       | A         |
124114 |     NULL | NULL   |         |
| users |          1 | col1_2     |            2 | col2 | A         |
124114 |     NULL | NULL   |         |
| users |          1 | col2 |            1 | col2 | A         |      124114
|     NULL | NULL   |         |
+-------+------------+-------------+--------------+-------------+-----------
+-------------+----------+--------+---------+

If I split the query into two, ie:
SELECT * FROM t1 WHERE col1 = 'text'; SELECT * FROM t1 WHERE col2 = 'text';
Both complete in no time at all, however the query with the OR takes a few
seconds.

How can I make the query take advantage of the indexes better?

Thanks for the help!

ryan


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to