MySQL Explain examples
create table customers ( custid integer primary key, renew date, magid int ); create table magazines ( magid int primary key, cost int ); select sum(cost) from magazines where magid in (select magid from customers); select sum(cost) from customers join magazines on customers.magid = magazines.magid;
create table customers ( custid integer primary key, renew date, magid int ); create table magazines ( magid int primary key, cost int ); alter table customers add constraint foreign key(magid) references magazines(magid); select sum(cost) from magazines where magid in ( select magid from customers ); select sum(cost) from customers join magazines on customers.magid = magazines.magid;
Using index; FirstMatch(magazines) create table customers ( custid integer primary key, renew date, magid int ); create table magazines ( magid int primary key, cost int ); alter table customers add constraint foreign key(magid) references magazines(magid); select sum(cost) from magazines where magid in ( select magid from customers ); id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE magazines index PRIMARY,FK2 FK2 9 NULL Using index customers FK1 5 magazines.magid Using index; FirstMatch(magazines)