database - MySQL Relationships & Joins -


in mysql database there relationships between tables , primary key of 1 table stored foreign key in second table, there still need perform join?

if there is, point on declaring relationship? i'd take stab in dark , it's indexing or related tables can find related records faster? i've tried googleing this, can't seem find much. i'm sure there loads out there on this, don't know keywords search for.

here example of table 1 , table 2:

------------------- table 1 ---------------------- create table if not exists `db_hint`.`user` ( `id` int unsigned not null auto_increment, `fb_id` int not null, `last_logged_in` datetime null, `permissions` int unsigned not null, primary key (`id`), index `permissions_id_idx` (`permissions` asc), constraint `permissions_id` foreign key (`permissions`) references `db_hint`.`permissions` (`id`) on delete no action on update no action) engine = innodb;  ----------------- table 2 ---------------------- create table if not exists `db_hint`.`user_stat` ( `id` int unsigned not null auto_increment, `user_id` int unsigned not null, primary key (`id`), index `user_id_idx3` (`user_id` asc), constraint `user_id` foreign key (`user_id`) references `db_hint`.`user` (`id`) on delete no action on update no action) engine = innodb; 

when performing kind of join, innodb engine use relationship in way? thanks.

the point of declaring foreign key enforce data consistency. still need join in order desired data. in mysql foreign keys improve performance, don't expect comparable indexes.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -