MySQL Forums
Forum List  »  Optimizer & Parser

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
14249
September 24, 2006 11:40PM
4766
September 25, 2006 03:00AM
4487
September 25, 2006 08:09AM
3744
September 25, 2006 09:55PM
3585
September 26, 2006 03:35AM
5079
September 26, 2006 04:06AM
3139
September 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.