My database query is taking about 15 Seconds to show me the result from mysql two tables. I want to optimize the performance of the result.
We want to show total number of items not present in table "products"
but present in table "vendor_products"
#
# Table structure for table 'vendor_products'
#
CREATE TABLE `vendor_products` (
`vpid` int(10) unsigned NOT NULL auto_increment,
`vendor_id` int(10) unsigned default NULL,
`mfg_no` varchar(25) default NULL,
`price` decimal(10,2) default NULL,
PRIMARY KEY (`vpid`),
KEY `mfg_no` (`mfg_no`),
KEY `vendor_id` (`vendor_id`)
) TYPE=MyISAM;
#
# Table structure for table 'products'
#
CREATE TABLE `products` (
`pid` int(10) unsigned NOT NULL auto_increment,
`mfg_no` varchar(25) default NULL,
`price` decimal(10,2) default NULL,
PRIMARY KEY (`pid`),
UNIQUE KEY `mfg_no` (`mfg_no`)
) TYPE=MyISAM;
SELECT count(*) as rejected_products FROM `vendor_products` as v
left outer join products as p on (v.mfg_no = p.mfg_no)
where p.mfg_no is null and vendor_id=1002;
The Explain requery shows :-
table,type,possible_keys,key,key_len,ref,rows,Extra
v,ALL,vendor_id,NULL,NULL,NULL,315033,Using where
p,ref,mfg_no,mfg_no,26,v.mfg_no,10,Using where; Using index
total records in tables :-
vendor_products = 820044
products = 409475
Any help should be highly appricated.