I have a view : vcompanyendofday
The following query executes in just 0.7 secs
Select * from vcompanyendofday
But a simple where condition to this query takes around 200.0 secs
select * from vcompanyendofday where companyid <= 51;
This is the view definition:
CREATE VIEW `vcompanyendofday` AS select `c`.`companyid` AS `companyid`, `c`.`scripcode` AS `scripcode`, `e`.`eoddate` AS `eoddate`, `e`.`prevclose` AS `prevclose`, `e`.`delqty` AS `delqty` from ( `company` `c` left join `endofday` `e` on ((`c`.`companyid` = `e`.`companyid`))) where (`e`.`eoddate` = ( select max(`e2`.`eoddate`) AS `max(eoddate)` from `endofday` `e2` where (`e2`.`companyid` = `c`.`companyid`) ) );