Presentation is loading. Please wait.

Presentation is loading. Please wait.

MySQL Explain examples

Similar presentations


Presentation on theme: "MySQL Explain examples"— Presentation transcript:

1 MySQL Explain examples

2 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;

3 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;

4 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)


Download ppt "MySQL Explain examples"

Similar presentations


Ads by Google