views:

28

answers:

2

Does this query will be faster with a index on "t.type1" and "x.type1" or only index on "x.type1" is enought?

SELECT t.id, x.id
FROM t
INNER JOIN x ON x.type1=t.type1
WHERE t.id=1

+1  A: 

It depends, how many records do you have and how many unique values you have in these columns? Just use EXPLAIN to see what the database does and do this with and without indexes. You'll see the difference.

Frank Heikens
Thanks for you reply Frank.I thought Mysql fetch rows from table "t" which are corresponding to the "WHERE" clause and after this join table "x" on the "t.type1" value, so "t.type1" doen't need to be an index. Could you told how Mysql proceed with this query?
parm.95
@parm.95 use `EXPLAIN` to find this out!
Martin Smith
+1  A: 

You should have an index on t.id (presumably it is the primary key?) and an index on x.type1.

Mark Byers