MySQL Forums
Forum List  »  Optimizer & Parser

SUBQUERY PROBLEM
Posted by: Odimar Tomazeli
Date: February 07, 2006 04:21PM

Hi everybody,

I'm having problems with subquery a simple query takes almost haft an hour to run

Here the table structure:

CREATE TABLE `consolidatetaxe`.`nm1_customer_exempt` (
`idnm1_customer_exempt` bigint(20) NOT NULL auto_increment,
`ReportID` varchar(8) NOT NULL,
`ReportName` varchar(50) default NULL,
`FromDate` datetime default NULL,
`ToDate` datetime default NULL,
`Market` varchar(3) default NULL,
`Entity` varchar(8) default NULL,
`Submarket` varchar(30) default NULL,
`CurrencyCode` varchar(3) default NULL,
`Customer` varchar(10) default NULL
PRIMARY KEY (`idnm1_customer_exempt`),
KEY `IDX_FromDate` (`FromDate`,`ReportName`),
KEY `IDX_ToDate` (`ToDate`),
KEY `IDX_FromDateToDate` (`FromDate`,`ToDate`),
KEY `IDX_SubmarketCode` (`Submarket`),
KEY `IDX_ALL` (`Market`,`Entity`,`Submarket`,`CurrencyCode`,`Customer`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;


here my query

SELECT DISTINCT ReportID, ReportName, FromDate, ToDate, Market, Entity, Submarket, CurrencyCode, Customer
FROM nm1_customer_exempt
WHERE FromDate >= '2005-12-01 00:00:00' and ToDate <= '2005-12-31 00:00:00'
and CONCAT(Market,Entity,Submarket,CurrencyCode,Customer)
NOT IN (SELECT DISTINCT CONCAT(nce.Market,nce.Entity,nce.Submarket,nce.CurrencyCode,nce.Customer)
FROM nm1_customer_exempt nce
WHERE nce.FromDate >= '2005-11-01 00:00:00' and nce.ToDate <= '2005-11-30 00:00:00')

Here I'm trying to display the customers added in the current month that weren't in the last month.

Anyone have any idea, why is taking so long?

Thanks


Odimar Tomazeli

Options: ReplyQuote


Subject
Views
Written By
Posted
SUBQUERY PROBLEM
3401
February 07, 2006 04:21PM
2291
February 07, 2006 04:45PM
2166
February 07, 2006 04:52PM
2306
February 08, 2006 04:57AM
2144
February 08, 2006 03:59PM
2167
February 08, 2006 08:37AM
2405
February 13, 2006 11:06AM
2310
February 13, 2006 11:17AM
2241
February 13, 2006 11:22AM
2104
February 13, 2006 12:16PM


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.