Skip navigation links

MySQL Forums :: Optimizer & Parser :: Optimizing left outer join query


Advanced Search

Optimizing left outer join query
Posted by: Muhammad Imran Khalid ()
Date: September 24, 2006 11:40PM

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.

Options: ReplyQuote


Subject Views Written By Posted
Optimizing left outer join query 12461 Muhammad Imran Khalid 09/24/2006 11:40PM
Re: Optimizing left outer join query 4147 Toa Sty 09/25/2006 03:00AM
Re: Optimizing left outer join query 3583 Muhammad Imran Khalid 09/25/2006 04:54AM
Re: Optimizing left outer join query 3713 Toa Sty 09/25/2006 08:09AM
Re: Optimizing left outer join query 3121 KimSeong Loh 09/25/2006 09:55PM
Re: Optimizing left outer join query 3075 Toa Sty 09/26/2006 03:35AM
Re: Optimizing left outer join query 2718 Muhammad Imran Khalid 09/26/2006 03:46AM
Re: Optimizing left outer join query 4319 Toa Sty 09/26/2006 04:06AM
Re: Optimizing left outer join query 2577 KimSeong Loh 09/26/2006 06:31PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.