MySQL Forums
Forum List  »  InnoDB

Query Is to Slow
Posted by: Scott Hanebutt
Date: October 29, 2012 05:47AM

The following two queres when ran separatly give me results inless then a second.

set @start = '2012-01-01';
set @stop = '2012-12-31';

select
distinct concat(users.first_name, " ", users.last_name) as Name
from
users
left join tasks on users.id = tasks.created_by
where
(tasks.date_start between @start and @stop)
order by concat(users.first_name, " ", users.last_name)
;

set @start = '2012-01-01';
set @stop = '2012-12-31';

select
distinct concat(users.first_name, " ", users.last_name) as Name
from
users
left join meetings on users.id = meetings.created_by
where
(meetings.date_start between @start and @stop)
order by concat(users.first_name, " ", users.last_name)
;

However when I combine the queries in to the following it takes munites (I have never waited long enough for it to finish).

set @start = '2012-01-01';
set @stop = '2012-12-31';

select
distinct concat(users.first_name, " ", users.last_name) as Name
from
users
left join tasks on users.id = tasks.created_by
left join meetings on users.id = meetings.created_by
where
(tasks.date_start between @start and @stop)
or (meetings.date_start between @start and @stop)
order by concat(users.first_name, " ", users.last_name)
;

What am I doing wrong, or is this just a performance issue?

Thank you,
Scott

Options: ReplyQuote


Subject
Views
Written By
Posted
Query Is to Slow
1521
October 29, 2012 05:47AM
767
October 29, 2012 05:58AM
829
October 30, 2012 11:48AM
766
October 30, 2012 11:53AM
747
October 31, 2012 08:13AM


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.