MySQL Forums
Forum List  »  Optimizer & Parser

Query is taking lot of time with not in clause
Posted by: shahbaz khan
Date: August 16, 2009 05:06AM

Beloq mentioned query is taking huge amount of time with not in clause.Without this it is taking significantly low time.How should i improve on this.

set @clinicid:=3;
set @location := (select entity_id from hlclocations where locsiteid=@clinicid and loctypelviid=5);
select
s.sitedesc,
hlcitems.itemcode,
hlcitems.itemdesc,
0 TranIn,
0 TranOut,
0 Sales,
0 Consumption,
0 Adjustment
,hlcinventory.invtotalqty closing
,hlcinventory.invtotalqty opening


from hlcinventory
inner join ( select hlcinventory.invitemid invitemid,
Max(hlcinventory.invcreatedat) MaxDate from hlcinventory
where (hlcinventory.invlocid = @location and invdcnid = @clinicid and
(hlcinventory.invcreatedat < '2009-07-01'))
group by hlcinventory.invitemid ) Q1 on (hlcinventory.invcreatedat=Q1.MaxDate and hlcinventory.invitemid=Q1.invitemid)
inner join hlcitems on (hlcinventory.invitemid = hlcitems.entity_id)
inner join hlcsites s on s.entity_id=@clinicid
where hlcitems.entity_id not in (select group_concat(invitemid) from hlcinventory where
invcreatedat between '2009-07-01 00:00:00' and '2009-07-05 23:59:59'
and invlocid = @location and invdcnid = @clinicid)
and invlocid = @location and invdcnid = @clinicid
group by itemcode
order by itemcode;

Options: ReplyQuote


Subject
Views
Written By
Posted
Query is taking lot of time with not in clause
3957
August 16, 2009 05:06AM


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.