Home » Performance » MySQL » Need Help for Mysql-Query optimization
Need Help for Mysql-Query optimization [message #3702] Fri, 07 November 2008 07:26 Go to next message
yashvant  is currently offline yashvant
Messages: 1
Registered: November 2008
Junior Member
I have run this query make a more time please any body optimize this query as blew

$sql="SELECT f.feeder_code, f.subdivision_code FROM `feeder` f, sentout s
where ( f.start_date <= '2008-07-01' and f.end_date >= '2008-07-01' and
(s.month = 7 and s.year = 8 )) and f.feeder_code = s.feeder_code
UNION
SELECT feeder_code, subdivision_code FROM ht WHERE ht.month = 7 and
ht.year = 8 and concat( feeder_code, subdivision_code ) NOT IN
(SELECT concat( f.feeder_code, f.subdivision_code )
FROM `feeder` f, sentout s where (f.start_date <= '2008-07-01' and f.end_date >='2008-07-01' and (s.month = 7 and s.year = 8)) and f.feeder_code = s.feeder_code)
UNION
SELECT feeder_code, subdivision_code FROM lt WHERE lt.month = 7
and lt.year = 8 and concat( feeder_code, subdivision_code ) NOT IN
( SELECT concat( f.feeder_code, f.subdivision_code ) FROM feeder f, sentout s
where (f.start_date<= '2008-07-01' and f.end_date >= '2008-07-01' and
(s.month = 7 and s.year = 8)) and f.feeder_code = s.feeder_code
) AND concat( feeder_code, subdivision_code ) NOT IN ( SELECT concat( feeder_Code, subdivision_code )
FROM ht WHERE ht.month = 7 and ht.year = 8)
ORDER BY feeder_code, subdivision_code";

solved this problem because this take a more time

[Updated on: Fri, 07 November 2008 07:31]

Re: Need Help for Mysql-Query optimization [message #5288 is a reply to message #3702 ] Sat, 23 January 2010 12:41 Go to previous message
xaprb  is currently offline xaprb
Messages: 168
Registered: April 2008
Location: Charlottesville, Virginia...
Senior Member
Don't use NOT IN() subqueries. Use an exclusion join instead.


Baron Schwartz, Director of Consulting, Percona Inc.
http://www.percona.com/ | http://www.mysqlperformanceblog.com/
24/7 Emergency : +1 888 401 3401 ext 911
Previous Topic:Limits and datatype for connection_id()
Next Topic:New to MySQL -- convert MSSQL to MySQL syntax
Goto Forum:
  


Current Time: Tue Mar 16 02:30:07 EDT 2010

Total time taken to generate the page: 0.13610 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 2.7.7.
Copyright ©2001-2007 FUD Forum Bulletin Board Software

MySQL is a trademark of Sun Microsystems.
InnoDB is a trademark of Oracle Corp.

Percona Performance Forums are a service of Percona, Inc.
Not affiliated with Sun Microsystems or Oracle Corp.