Hi,
despite I read the manual, I still have 4 questions about MySQL indexes (hope this is the right place to ask them):
1) If I use a primary or unique key on field1, do I need to add an index on this field to make the search faster when it is used in a WHERE clause?
I guess no, but would like a confirmation 🙂
2) I have the following 3 queries run on the same table:
- SELECT FROM table WHERE Field1 = Field2 AND Field3 ='$var1'
- SELECT FROM table WHERE Field1 != Field2 AND Field3 ='$var1'
- SELECT * FROM table WHERE Field1 = '$var2' AND Field3 ='$var1'
(where Field1,Field2 and Field3 are MySQL fields).
Is creating an index such as (Field1,Field2,Field3) optimal?
I am wondering this because this may be unusual to compare MySQL fields (and not their values)...
3.1) Now, I have another query:
SELECT * FROM table WHERE Field1 != Field2 AND Field2 IN ('$list')
Is creating an index such as field1_field2(Field1,Field2) optimal?
3.2) And sometimes, another criteria could add up to this query:
SELECT * FROM table WHERE Field1 != Field2 AND Field2 IN ('$list') AND Field3='$var'
Shall I then create another index with field1_field2_field3(Field1,Field2,Field3)?
Hope somebody'll be able to answer my questions... 🙂)