0

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

2
  • Have you tried? A better question would have been: "I've made a small benchmark and found that this query is slower if I change indexes. Why is that?" Commented Jun 6, 2010 at 14:15
  • How many rows does your table have? How many rows will typically have t.id=1? Commented Jun 6, 2010 at 14:16

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

1

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.

2 Comments

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 use EXPLAIN to find this out!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.