MySQL Forums
Forum List  »  Newbie

indexe questions
Posted by: tata668
Date: June 26, 2005 09:26AM

Hi,

First message here! :-)

Let's say I have two tables. "id" is the primary key and there is a indexe on "other1/id".
---------------
[ test1]
id: int(11)
other1: int(11)
other2: int(11)
--------------

Another table, same indexes:
---------------
[ test2 ]
id: int(11)
other1: int(11)
--------------

I'm doing an "EXPLAIN" for the following query and it tells me that the indexe "other1/id" is not used for table "test1"! Why?

=========
EXPLAIN SELECT *
FROM test1
WHERE
( test1.other1 = '2' OR test1.other1 = '3' )
AND test1.id
IN
(
SELECT test2.id
FROM test2
WHERE test2.other1 = '1'
)
==========

id - select_type - table - type - possible_keys - key - key_len - ref - rows - Extra
1 PRIMARY test1 ALL other NULL NULL NULL 4 Using where

2 DEPENDENT SUBQUERY test2 unique_subquery PRIMARY,other PRIMARY 4 func 1 Using index; Using where
==========

If I replace "( test1.other1 = '2' OR test1.other1 = '3' )" by "test1.other1 = '2'" EXPLAIN doesn't give me the "ALL" type and everything looks fine... but I need those "OR"!

Any help?

Options: ReplyQuote


Subject
Written By
Posted
indexe questions
June 26, 2005 09:26AM
June 26, 2005 11:11AM
June 26, 2005 12:47PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.