tags:

views:

46

answers:

3

hi All I have two tables (MYISAM)

create table A (email varchar(50));
create table B( email varchar(50) key 'email' (email));

Table A has 130K records Table B has 20K records

why does this sql statement take very long time (more than two minutes, then i aborted query by Ctrl+C) Statement is:

select count(*) from user A, tmp B where A.email=B.email;

Thanks

+2  A: 

I'd guess that the Query optimizer has nothing to go on. Why don't you try defining indexes on the email columns.

Allain Lalonde
Table A is for another project and i am not allowed to make any change in it :(however this is what i have in explain| id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra || 1 | SIMPLE | B | index | NULL | email | 53 | NULL | 21401 | 100.00 | Using index | | 1 | SIMPLE | A | ALL | NULL | NULL | NULL | NULL | 136437 | 100.00 | Using where; Using join buffer |
Alaa
If you don't add an index on A.email, DB engine will always perform a full table A scan while running this query. There is nothing you can do about it if you are not allowed to add index.
a1ex07
A: 

In general, joining on strings is more expensive than joining on shorter data types like int.

You could speed up this query by making sure both email columns are indexed.

BC
A: 

If table A has an int ID field then table B should store that ID instead of storing the email string again. That would decrease the DB size and along with indexes would provide a much faster query speed than a string would ever give you.

nzgeoff