php - Indexes on foreign key in MySQL -


i have simple code.

create table foo (  client_id int, order_id int,  primary key (client_id, order_id), index (order_id),  foreign key (client_id) references baz(id), foreign key (order_id) references bar(id)  ); 

i know mysql automatic add index column primary key, if have complex primary key? (example in code). why must add index second column in primary key? think mysql automatic add index first column second, third ... must add constraint manually? answer in official documentation?

you can refer link http://dev.mysql.com/doc/refman/5.0/en/mysql-indexes.html

if table has multi-column index eg: (col1, col2, col3), can have search capabilities (col1), (col1, col2), , (col1, col2, col3)

this index never used if search not form left prefix on index, in case col1

so need have col1 prefix , search col2,col3 wont use index

you might need different index same, have index col2 separately


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -