parm.95
parm.95

Reputation: 13

mysql query and index

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

Upvotes: 0

Views: 71

Answers (2)

Mark Byers
Mark Byers

Reputation: 839194

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

Upvotes: 2

Frank Heikens
Frank Heikens

Reputation: 127556

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.

Upvotes: 1

Related Questions